Skip to content

Commit

Permalink
Rework Formatter.FormatConfig
Browse files Browse the repository at this point in the history
It was defined as a struct with exposed fields.  Now it's a class
with simple properties.  Default values are set explicitly, and
the contents are copied with a copy constructor instead of using
the struct member assignment.

The only functional change should be that the DelimiterSet members
are now properly cloned.  The bulk of the changes are just refactoring
renames for the property names.

This also adds comments for all the properties.
  • Loading branch information
fadden committed Jun 24, 2024
1 parent 967d468 commit 18674e6
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 255 deletions.
361 changes: 214 additions & 147 deletions Asm65/Formatter.cs

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions SourceGen/AsmGen/AsmAcme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,28 +230,28 @@ public void Configure(DisasmProject project, string workDirectory, string fileNa
/// Configures the assembler-specific format items.
/// </summary>
private void SetFormatConfigValues(ref Formatter.FormatConfig config) {
config.mSuppressImpliedAcc = true;

config.mOperandWrapLen = 64;
config.mForceDirectOpcodeSuffix = "+1";
config.mForceAbsOpcodeSuffix = "+2";
config.mForceLongOpcodeSuffix = "+3";
config.mForceDirectOperandPrefix = string.Empty;
config.mForceAbsOperandPrefix = string.Empty;
config.mForceLongOperandPrefix = string.Empty;
config.mLocalVariableLabelPrefix = ".";
config.mEndOfLineCommentDelimiter = ";";
config.mFullLineCommentDelimiterBase = ";";
config.mBoxLineCommentDelimiter = ";";
config.mNonUniqueLabelPrefix = "@";
config.mCommaSeparatedDense = false;
config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Common;
config.SuppressImpliedAcc = true;

config.OperandWrapLen = 64;
config.ForceDirectOpcodeSuffix = "+1";
config.ForceAbsOpcodeSuffix = "+2";
config.ForceLongOpcodeSuffix = "+3";
config.ForceDirectOperandPrefix = string.Empty;
config.ForceAbsOperandPrefix = string.Empty;
config.ForceLongOperandPrefix = string.Empty;
config.LocalVariableLabelPrefix = ".";
config.EndOfLineCommentDelimiter = ";";
config.FullLineCommentDelimiterBase = ";";
config.BoxLineCommentDelimiter = ";";
config.NonUniqueLabelPrefix = "@";
config.CommaSeparatedDense = false;
config.ExprMode = Formatter.FormatConfig.ExpressionMode.Common;

Formatter.DelimiterSet charSet = new Formatter.DelimiterSet();
charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM);
charSet.Set(CharEncoding.Encoding.HighAscii,
new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80"));
config.mCharDelimiters = charSet;
config.CharDelimiters = charSet;
}

// IGenerator
Expand Down
28 changes: 14 additions & 14 deletions SourceGen/AsmGen/AsmCc65.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,25 @@ public void Configure(DisasmProject project, string workDirectory, string fileNa
/// Configures the assembler-specific format items.
/// </summary>
private void SetFormatConfigValues(ref Formatter.FormatConfig config) {
config.mOperandWrapLen = 64;
config.mForceDirectOpcodeSuffix = string.Empty;
config.mForceAbsOpcodeSuffix = string.Empty;
config.mForceLongOpcodeSuffix = string.Empty;
config.mForceDirectOperandPrefix = "z:"; // zero
config.mForceAbsOperandPrefix = "a:"; // absolute
config.mForceLongOperandPrefix = "f:"; // far
config.mEndOfLineCommentDelimiter = ";";
config.mFullLineCommentDelimiterBase = ";";
config.mBoxLineCommentDelimiter = ";";
config.mNonUniqueLabelPrefix = "@";
config.mCommaSeparatedDense = true;
config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Cc65;
config.OperandWrapLen = 64;
config.ForceDirectOpcodeSuffix = string.Empty;
config.ForceAbsOpcodeSuffix = string.Empty;
config.ForceLongOpcodeSuffix = string.Empty;
config.ForceDirectOperandPrefix = "z:"; // zero
config.ForceAbsOperandPrefix = "a:"; // absolute
config.ForceLongOperandPrefix = "f:"; // far
config.EndOfLineCommentDelimiter = ";";
config.FullLineCommentDelimiterBase = ";";
config.BoxLineCommentDelimiter = ";";
config.NonUniqueLabelPrefix = "@";
config.CommaSeparatedDense = true;
config.ExprMode = Formatter.FormatConfig.ExpressionMode.Cc65;

Formatter.DelimiterSet charSet = new Formatter.DelimiterSet();
charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM);
charSet.Set(CharEncoding.Encoding.HighAscii,
new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80"));
config.mCharDelimiters = charSet;
config.CharDelimiters = charSet;
}

// IGenerator
Expand Down
30 changes: 15 additions & 15 deletions SourceGen/AsmGen/AsmMerlin32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,25 @@ public void Configure(DisasmProject project, string workDirectory, string fileNa
/// Configures the assembler-specific format items.
/// </summary>
private void SetFormatConfigValues(ref Formatter.FormatConfig config) {
config.mOperandWrapLen = 64;
config.mForceDirectOpcodeSuffix = string.Empty;
config.mForceAbsOpcodeSuffix = ":";
config.mForceLongOpcodeSuffix = "l";
config.mForceDirectOperandPrefix = string.Empty;
config.mForceAbsOperandPrefix = string.Empty;
config.mForceLongOperandPrefix = string.Empty;
config.mLocalVariableLabelPrefix = "]";
config.mEndOfLineCommentDelimiter = ";";
config.mFullLineCommentDelimiterBase = ";";
config.mBoxLineCommentDelimiter = string.Empty;
config.mNonUniqueLabelPrefix = ":";
config.mCommaSeparatedDense = false;
config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Merlin;
config.OperandWrapLen = 64;
config.ForceDirectOpcodeSuffix = string.Empty;
config.ForceAbsOpcodeSuffix = ":";
config.ForceLongOpcodeSuffix = "l";
config.ForceDirectOperandPrefix = string.Empty;
config.ForceAbsOperandPrefix = string.Empty;
config.ForceLongOperandPrefix = string.Empty;
config.LocalVariableLabelPrefix = "]";
config.EndOfLineCommentDelimiter = ";";
config.FullLineCommentDelimiterBase = ";";
config.BoxLineCommentDelimiter = string.Empty;
config.NonUniqueLabelPrefix = ":";
config.CommaSeparatedDense = false;
config.ExprMode = Formatter.FormatConfig.ExpressionMode.Merlin;

Formatter.DelimiterSet charSet = new Formatter.DelimiterSet();
charSet.Set(CharEncoding.Encoding.Ascii, Formatter.SINGLE_QUOTE_DELIM);
charSet.Set(CharEncoding.Encoding.HighAscii, Formatter.DOUBLE_QUOTE_DELIM);
config.mCharDelimiters = charSet;
config.CharDelimiters = charSet;
}

// IGenerator; executes on background thread
Expand Down
44 changes: 22 additions & 22 deletions SourceGen/AsmGen/AsmTass64.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,27 +253,27 @@ public void Configure(DisasmProject project, string workDirectory, string fileNa
/// </summary>
private void SetFormatConfigValues(ref Formatter.FormatConfig config) {
// Must be lower case when --case-sensitive is used.
config.mUpperOpcodes = false;
config.mUpperPseudoOpcodes = false;
config.mUpperOperandA = false;
config.mUpperOperandS = false;
config.mUpperOperandXY = false;
config.mOperandWrapLen = 64;

config.mBankSelectBackQuote = true;

config.mForceDirectOpcodeSuffix = string.Empty;
config.mForceAbsOpcodeSuffix = string.Empty;
config.mForceLongOpcodeSuffix = string.Empty;
config.mForceDirectOperandPrefix = string.Empty;
config.mForceAbsOperandPrefix = "@w"; // word
config.mForceLongOperandPrefix = "@l"; // long
config.mEndOfLineCommentDelimiter = ";";
config.mFullLineCommentDelimiterBase = ";";
config.mBoxLineCommentDelimiter = ";";
config.mNonUniqueLabelPrefix = ""; // should be '_', but that's a valid label char
config.mCommaSeparatedDense = true;
config.mExpressionMode = Formatter.FormatConfig.ExpressionMode.Common;
config.UpperOpcodes = false;
config.UpperPseudoOpcodes = false;
config.UpperOperandA = false;
config.UpperOperandS = false;
config.UpperOperandXY = false;
config.OperandWrapLen = 64;

config.BankSelectBackQuote = true;

config.ForceDirectOpcodeSuffix = string.Empty;
config.ForceAbsOpcodeSuffix = string.Empty;
config.ForceLongOpcodeSuffix = string.Empty;
config.ForceDirectOperandPrefix = string.Empty;
config.ForceAbsOperandPrefix = "@w"; // word
config.ForceLongOperandPrefix = "@l"; // long
config.EndOfLineCommentDelimiter = ";";
config.FullLineCommentDelimiterBase = ";";
config.BoxLineCommentDelimiter = ";";
config.NonUniqueLabelPrefix = ""; // should be '_', but that's a valid label char
config.CommaSeparatedDense = true;
config.ExprMode = Formatter.FormatConfig.ExpressionMode.Common;
}

// IGenerator
Expand All @@ -296,7 +296,7 @@ public GenerationResults GenerateSource(BackgroundWorker worker) {
charDelimSet.Set(CharEncoding.Encoding.HighAscii,
new Formatter.DelimiterDef(string.Empty, '\'', '\'', " | $80"));

config.mCharDelimiters = charDelimSet;
config.CharDelimiters = charDelimSet;

SourceFormatter = new Formatter(config);

Expand Down
30 changes: 15 additions & 15 deletions SourceGen/AsmGen/GenCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private static void GenerateInstruction(IGenerator gen, StreamWriter sw,
}
if (gen.Quirks.BankZeroAbsPBRRestrict) {
// Hack to avoid having to define a new FormatConfig.ExpressionMode for 64tass.
// Get rid of this 64tass gets its own exp mode.
// Get rid of this if 64tass gets its own exp mode.
opFlags |= PseudoOp.FormatNumericOpFlags.Is64Tass;
}

Expand Down Expand Up @@ -494,36 +494,36 @@ private static int GetLabelOffsetFromOperand(IGenerator gen, int offset) {
/// <param name="config">Format config struct.</param>
public static void ConfigureFormatterFromSettings(AppSettings settings,
ref Formatter.FormatConfig config) {
config.mUpperHexDigits =
config.UpperHexDigits =
settings.GetBool(AppSettings.FMT_UPPER_HEX_DIGITS, false);
config.mUpperOpcodes =
config.UpperOpcodes =
settings.GetBool(AppSettings.FMT_UPPER_OP_MNEMONIC, false);
config.mUpperPseudoOpcodes =
config.UpperPseudoOpcodes =
settings.GetBool(AppSettings.FMT_UPPER_PSEUDO_OP_MNEMONIC, false);
config.mUpperOperandA =
config.UpperOperandA =
settings.GetBool(AppSettings.FMT_UPPER_OPERAND_A, false);
config.mUpperOperandS =
config.UpperOperandS =
settings.GetBool(AppSettings.FMT_UPPER_OPERAND_S, false);
config.mUpperOperandXY =
config.UpperOperandXY =
settings.GetBool(AppSettings.FMT_UPPER_OPERAND_XY, false);
config.mSpacesBetweenBytes =
config.SpacesBetweenBytes =
settings.GetBool(AppSettings.FMT_SPACES_BETWEEN_BYTES, false);
config.mAddSpaceLongComment =
config.AddSpaceLongComment =
settings.GetBool(AppSettings.FMT_ADD_SPACE_FULL_COMMENT, true);
config.mOperandWrapLen =
config.OperandWrapLen =
settings.GetInt(AppSettings.FMT_OPERAND_WRAP_LEN, 0);

config.mForceAbsOpcodeSuffix =
config.ForceAbsOpcodeSuffix =
settings.GetString(AppSettings.FMT_OPCODE_SUFFIX_ABS, string.Empty);
config.mForceLongOpcodeSuffix =
config.ForceLongOpcodeSuffix =
settings.GetString(AppSettings.FMT_OPCODE_SUFFIX_LONG, string.Empty);
config.mForceAbsOperandPrefix =
config.ForceAbsOperandPrefix =
settings.GetString(AppSettings.FMT_OPERAND_PREFIX_ABS, string.Empty);
config.mForceLongOperandPrefix =
config.ForceLongOperandPrefix =
settings.GetString(AppSettings.FMT_OPERAND_PREFIX_LONG, string.Empty);

string exprMode = settings.GetString(AppSettings.FMT_EXPRESSION_MODE, string.Empty);
config.mExpressionMode = Formatter.FormatConfig.ParseExpressionMode(exprMode);
config.ExprMode = Formatter.FormatConfig.ParseExpressionMode(exprMode);

// Not doing the delimiter patterns here, because what's in the config file is
// intended for on-screen display, and hence likely to be unsuited for an assembler.
Expand Down
12 changes: 6 additions & 6 deletions SourceGen/Exporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void ConfigureColumns(ActiveColumnFlags leftFlags, int[] rightWidths) {
// A limit of 8 gets us 4 bytes from dense display ("20edfd60") and 3 if spaces
// are included ("20 ed fd") with no excess. We want to increase it to 11 so
// we can always show 4 bytes. Add one for a trailing "+".
width = mFormatter.Config.mSpacesBetweenBytes ? 12 : 9;
width = mFormatter.Config.SpacesBetweenBytes ? 12 : 9;
total = mColStart[(int)Col.Bytes + 1] = total + width + 1;
} else {
mColStart[(int)Col.Bytes + 1] = total;
Expand Down Expand Up @@ -232,14 +232,14 @@ private string GenerateParameterString() {
StringBuilder sb = new StringBuilder(mParameterStringBase);

sb.Append(";byteSpc=");
sb.Append(mFormatter.Config.mSpacesBetweenBytes.ToString());
sb.Append(mFormatter.Config.SpacesBetweenBytes.ToString());
sb.Append(";commaBulk=");
sb.Append(mFormatter.Config.mCommaSeparatedDense.ToString());
sb.Append(mFormatter.Config.CommaSeparatedDense.ToString());
sb.Append(";nonuPfx='");
sb.Append(mFormatter.Config.mNonUniqueLabelPrefix);
sb.Append(mFormatter.Config.NonUniqueLabelPrefix);
sb.Append('\'');
sb.Append(";varPfx='");
sb.Append(mFormatter.Config.mLocalVariableLabelPrefix);
sb.Append(mFormatter.Config.LocalVariableLabelPrefix);
sb.Append('\'');
sb.Append(";labelBrk=");
sb.Append(LongLabelNewLine.ToString());
Expand All @@ -248,7 +248,7 @@ private string GenerateParameterString() {
sb.Append(";gfx=");
sb.Append(GenerateImageFiles.ToString());
sb.Append(";opWrap=");
sb.Append(mFormatter.Config.mOperandWrapLen);
sb.Append(mFormatter.Config.OperandWrapLen);

// Not included: pseudo-op definitions; delimiter definitions

Expand Down
1 change: 1 addition & 0 deletions SourceGen/LineListGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ private void GenerateLineList(int startOffset, int endOffset, List<Line> lines)
//
// TODO: integrate into FormattedOperandCache so we don't have to
// regenerate them unless they change. Use the MLC as the dependency.
// Better: create FormattedMLCCache, use the MLC and Formatter.
if (mProject.Notes.TryGetValue(offset, out MultiLineComment noteData)) {
List<string> formatted = noteData.FormatText(mFormatter, "NOTE: ");
StringListToLines(formatted, offset, Line.Type.Note,
Expand Down
16 changes: 8 additions & 8 deletions SourceGen/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,25 +492,25 @@ public void ApplyAppSettings() {
mFormatterConfig = new Formatter.FormatConfig();
AsmGen.GenCommon.ConfigureFormatterFromSettings(AppSettings.Global,
ref mFormatterConfig);
mFormatterConfig.mEndOfLineCommentDelimiter = ";";
mFormatterConfig.mFullLineCommentDelimiterBase = ";";
mFormatterConfig.mBoxLineCommentDelimiter = string.Empty;
mFormatterConfig.EndOfLineCommentDelimiter = ";";
mFormatterConfig.FullLineCommentDelimiterBase = ";";
mFormatterConfig.BoxLineCommentDelimiter = string.Empty;

mFormatterConfig.mNonUniqueLabelPrefix =
mFormatterConfig.NonUniqueLabelPrefix =
settings.GetString(AppSettings.FMT_NON_UNIQUE_LABEL_PREFIX, string.Empty);
mFormatterConfig.mLocalVariableLabelPrefix =
mFormatterConfig.LocalVariableLabelPrefix =
settings.GetString(AppSettings.FMT_LOCAL_VARIABLE_PREFIX, string.Empty);
mFormatterConfig.mCommaSeparatedDense =
mFormatterConfig.CommaSeparatedDense =
settings.GetBool(AppSettings.FMT_COMMA_SEP_BULK_DATA, true);

string chrDelCereal = settings.GetString(AppSettings.FMT_CHAR_DELIM, null);
if (chrDelCereal != null) {
mFormatterConfig.mCharDelimiters =
mFormatterConfig.CharDelimiters =
Formatter.DelimiterSet.Deserialize(chrDelCereal);
}
string strDelCereal = settings.GetString(AppSettings.FMT_STRING_DELIM, null);
if (strDelCereal != null) {
mFormatterConfig.mStringDelimiters =
mFormatterConfig.StringDelimiters =
Formatter.DelimiterSet.Deserialize(strDelCereal);
}

Expand Down
2 changes: 1 addition & 1 deletion SourceGen/MultiLineComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public MultiLineComment(string text, Color bkgndColor) : this(text) {
/// <returns>Array of formatted strings.</returns>
public List<string> FormatText(Asm65.Formatter formatter, string textPrefix) {
const char boxChar = '*';
const char spcRep = '\u2219';
const char spcRep = '\u2219'; // BULLET OPERATOR
string workString = string.IsNullOrEmpty(textPrefix) ? Text : textPrefix + Text;
List<string> lines = new List<string>();

Expand Down
4 changes: 2 additions & 2 deletions SourceGen/PseudoOp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public static List<string> FormatStringOp(Formatter formatter, PseudoOpNames opN
FormatDescriptor dfd, byte[] data, int offset, out string popcode) {

StringOpFormatter.ReverseMode revMode = StringOpFormatter.ReverseMode.Forward;
Formatter.DelimiterSet delSet = formatter.Config.mStringDelimiters;
Formatter.DelimiterSet delSet = formatter.Config.StringDelimiters;
Formatter.DelimiterDef delDef;

CharEncoding.Convert charConv;
Expand Down Expand Up @@ -736,7 +736,7 @@ private static void FormatNumericSymbolCommon(Formatter formatter, Symbol sym,
string selOp;
if (dfd.SymbolRef.ValuePart == WeakSymbolRef.Part.Bank) {
symbolValue = (sym.Value >> 16) & 0xff;
if (formatter.Config.mBankSelectBackQuote) {
if (formatter.Config.BankSelectBackQuote) {
selOp = "`";
} else {
selOp = "^";
Expand Down
4 changes: 2 additions & 2 deletions SourceGen/Tools/WpfGui/HexDumpViewer.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ private void ReplaceFormatter() {
// initializing
return;
}
config.mHexDumpCharConvMode = item.Mode;
config.HexDumpCharConvMode = item.Mode;

config.mHexDumpAsciiOnly = AsciiOnlyDump;
config.HexDumpAsciiOnly = AsciiOnlyDump;

// Keep app settings up to date.
AppSettings.Global.SetBool(AppSettings.HEXD_ASCII_ONLY, mAsciiOnlyDump);
Expand Down
Loading

0 comments on commit 18674e6

Please sign in to comment.