1
0
mirror of https://github.com/fadden/6502bench.git synced 2024-11-05 06:04:36 +00:00
6502bench/SourceGenWPF/DefSymbol.cs
Andy McFadden 575f834b1d Copy some non-UI code over
Mostly a straight copy & paste of the files.  The only significant
change was to move the localizable strings from Properties/Resources
(RESX) to Res/Strings.xaml (Resource Dictionary).  I expect a
number of strings will no longer be needed, since WPF lets you put
more of the UI/UX logic into the design side.

I also renamed the namespace to SourceGenWPF, and put the app icon
into the Res directory so it can be a resource rather than a loose
file.  I'm merging the "Setup" directory contents into the main app
since there wasn't a whole lot going on there.

The WPF Color class lacks conversions to/from a 32-bit integer, so
I added those.

None of the stuff is wired up yet.
2019-05-02 15:45:40 -07:00

105 lines
4.0 KiB
C#

/*
* Copyright 2019 faddenSoft
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace SourceGenWPF {
/// <summary>
/// Subclass of Symbol used for symbols defined in the platform or project.
///
/// Instances are immutable.
/// </summary>
public class DefSymbol : Symbol {
/// <summary>
/// Data format descriptor.
/// </summary>
public FormatDescriptor DataDescriptor { get; private set; }
/// <summary>
/// User-supplied comment.
/// </summary>
public string Comment { get; private set; }
public string Tag { get; private set; }
/// <summary>
/// Cross-reference data, generated by the analyzer.
/// </summary>
public XrefSet Xrefs { get; private set; }
// NOTE: might be nice to identify the symbol's origin, e.g. which platform
// symbol file it was defined in. This could then be stored in a
// DisplayList line, for benefit of the Info panel.
/// <summary>
/// Internal base-object constructor, called by other constructors.
/// </summary>
private DefSymbol(string label, int value, Source source, Type type)
: base(label, value, source, type) {
Debug.Assert(source == Source.Platform || source == Source.Project);
Debug.Assert(type == Type.ExternalAddr || type == Type.Constant);
Xrefs = new XrefSet();
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="label">Symbol's label.</param>
/// <param name="value">Symbol's value.</param>
/// <param name="source">Symbol source (general point of origin).</param>
/// <param name="type">Symbol type.</param>
/// <param name="formatSubType">Format descriptor sub-type, so we know how the
/// user wants the value to be displayed.</param>
/// <param name="comment">End-of-line comment.</param>
/// <param name="tag">Symbol tag, used for grouping platform symbols.</param>
public DefSymbol(string label, int value, Source source, Type type,
FormatDescriptor.SubType formatSubType, string comment, string tag)
: this(label, value, source, type) {
Debug.Assert(comment != null);
Debug.Assert(tag != null);
// Length doesn't matter; use 1 to get prefab object.
DataDescriptor = FormatDescriptor.Create(1,
FormatDescriptor.Type.NumericLE, formatSubType);
Comment = comment;
Tag = tag;
}
/// <summary>
/// Constructs a DefSymbol from a Symbol and a format descriptor. This is used
/// for project symbols.
/// </summary>
/// <param name="sym">Base symbol.</param>
/// <param name="dfd">Format descriptor.</param>
/// <param name="comment">End-of-line comment.</param>
public DefSymbol(Symbol sym, FormatDescriptor dfd, string comment)
: this(sym.Label, sym.Value, sym.SymbolSource, sym.SymbolType) {
Debug.Assert(comment != null);
DataDescriptor = dfd;
Comment = comment;
Tag = string.Empty;
}
public override string ToString() {
return base.ToString() + ":" + DataDescriptor + ";" + Comment +
(string.IsNullOrEmpty(Tag) ? "" : " [" + Tag + "]");
}
}
}