├── .gitignore
├── .travis.yml
├── DParser2.Unittest.sln
├── DParser2
├── Completion
│ ├── CodeCompletion.cs
│ ├── ICompletionDataGenerator.cs
│ ├── IEditorData.cs
│ ├── MemberCompletionEnumeration.cs
│ ├── ParamInsightVisitor.cs
│ ├── ParameterInsightResolution.cs
│ ├── Providers
│ │ ├── AbstractCompletionProvider.cs
│ │ ├── AttributeCompletionProvider.cs
│ │ ├── CompletionProviderVisitor.cs
│ │ ├── CtrlSpaceCompletionProvider.cs
│ │ ├── ImportStatementCompletionProvider.cs
│ │ ├── InlineAsmCompletionProvider.cs
│ │ ├── MemberCompletionProvider.cs
│ │ ├── MethodOverrideCompletionProvider.cs
│ │ ├── ModuleStatementCompletionProvider.cs
│ │ ├── SelectiveImportCompletionProvider.cs
│ │ ├── StructInitializerCompletion.cs
│ │ └── VariableNameSuggestionCompletionProvider.cs
│ └── ToolTips
│ │ ├── NodeTooltipRepresentationGen.Headers.cs
│ │ └── NodeTooltipRepresentationGen.cs
├── DParser2.csproj
├── DParser2.sln
├── Dom
│ ├── AbstractTypeDeclaration.cs
│ ├── Attribute.cs
│ ├── CodeLocation.cs
│ ├── DDeclarations.cs
│ ├── Expressions
│ │ ├── AbstractVariableInitializer.cs
│ │ ├── AddExpression.cs
│ │ ├── AndAndExpression.cs
│ │ ├── AndExpression.cs
│ │ ├── AnonymousClassExpression.cs
│ │ ├── ArrayInitializer.cs
│ │ ├── ArrayLiteralExpression.cs
│ │ ├── AsmRegisterExpression.cs
│ │ ├── AssertExpression.cs
│ │ ├── AssignExpression.cs
│ │ ├── AssocArrayExpression.cs
│ │ ├── CastExpression.cs
│ │ ├── CatExpression.cs
│ │ ├── ConditionalExpression.cs
│ │ ├── ContainerExpression.cs
│ │ ├── DeleteExpression.cs
│ │ ├── EqualExpression.cs
│ │ ├── Expression.cs
│ │ ├── FunctionLiteral.cs
│ │ ├── IExpression.cs
│ │ ├── IVariableInitializer.cs
│ │ ├── IdentifierExpression.cs
│ │ ├── IdentityExpression.cs
│ │ ├── ImportExpression.cs
│ │ ├── InExpression.cs
│ │ ├── IsExpression.cs
│ │ ├── MixinExpression.cs
│ │ ├── MulExpression.cs
│ │ ├── NewExpression.cs
│ │ ├── OperatorBasedExpression.cs
│ │ ├── OrExpression.cs
│ │ ├── OrOrExpression.cs
│ │ ├── PostfixExpression.cs
│ │ ├── PostfixExpression_Access.cs
│ │ ├── PostfixExpression_ArrayAccess.cs
│ │ ├── PostfixExpression_Decrement.cs
│ │ ├── PostfixExpression_Increment.cs
│ │ ├── PostfixExpression_MethodCall.cs
│ │ ├── PowExpression.cs
│ │ ├── PrimaryExpression.cs
│ │ ├── RelExpression.cs
│ │ ├── ScalarConstantExpression.cs
│ │ ├── ShiftExpression.cs
│ │ ├── SimpleUnaryExpression.cs
│ │ ├── StringLiteralExpression.cs
│ │ ├── StructInitializer.cs
│ │ ├── StructMemberInitializer.cs
│ │ ├── SurroundingParenthesesExpression.cs
│ │ ├── TemplateInstanceExpression.cs
│ │ ├── TokenExpression.cs
│ │ ├── TraitsArgument.cs
│ │ ├── TraitsExpression.cs
│ │ ├── TypeDeclarationExpression.cs
│ │ ├── TypeidExpression.cs
│ │ ├── UnaryExpression.cs
│ │ ├── UnaryExpression_Add.cs
│ │ ├── UnaryExpression_And.cs
│ │ ├── UnaryExpression_Cat.cs
│ │ ├── UnaryExpression_Decrement.cs
│ │ ├── UnaryExpression_Increment.cs
│ │ ├── UnaryExpression_Mul.cs
│ │ ├── UnaryExpression_Not.cs
│ │ ├── UnaryExpression_SegmentBase.cs
│ │ ├── UnaryExpression_Sub.cs
│ │ ├── UnaryExpression_Type.cs
│ │ ├── VoidInitializer.cs
│ │ └── XorExpression.cs
│ ├── IDeclarationCondition.cs
│ ├── ISyntaxRegion.cs
│ ├── ImportStatement.cs
│ ├── ModulePackage.cs
│ ├── Nodes
│ │ ├── AbstractNode.cs
│ │ ├── AttributeBlock.cs
│ │ ├── DBlockNode.cs
│ │ ├── DModule.cs
│ │ ├── DNode.cs
│ │ ├── NodeDictionary.cs
│ │ ├── NodeInterfaces.cs
│ │ └── OtherNodeDefinitions.cs
│ ├── ParserError.cs
│ ├── Statements
│ │ ├── AbstractStatement.cs
│ │ ├── AsmAlignStatement.cs
│ │ ├── AsmInstructionStatement.cs
│ │ ├── AsmRawDataStatement.cs
│ │ ├── AsmStatement.cs
│ │ ├── BlockStatement.cs
│ │ ├── BreakStatement.cs
│ │ ├── ContinueStatement.cs
│ │ ├── ContractStatement.cs
│ │ ├── DebugSpecificiation.cs
│ │ ├── DeclarationStatement.cs
│ │ ├── ExpressionStatement.cs
│ │ ├── ForStatement.cs
│ │ ├── ForeachStatement.cs
│ │ ├── GotoStatement.cs
│ │ ├── IDeclarationContainingStatement.cs
│ │ ├── IExpressionContainingStatement.cs
│ │ ├── IStatement.cs
│ │ ├── IfStatement.cs
│ │ ├── LabeledStatement.cs
│ │ ├── MixinStatement.cs
│ │ ├── PragmaStatement.cs
│ │ ├── ReturnStatement.cs
│ │ ├── ScopeGuardStatement.cs
│ │ ├── StatementCondition.cs
│ │ ├── StatementContainingStatement.cs
│ │ ├── StaticAssertStatement.cs
│ │ ├── StaticForeachStatement.cs
│ │ ├── SwitchStatement.cs
│ │ ├── SynchronizedStatement.cs
│ │ ├── TemplateMixin.cs
│ │ ├── ThrowStatement.cs
│ │ ├── TryStatement.cs
│ │ ├── VersionSpecification.cs
│ │ ├── VolatileStatement.cs
│ │ ├── WhileStatement.cs
│ │ └── WithStatement.cs
│ ├── StaticStatement.cs
│ ├── TemplateParameters.cs
│ └── Visitors
│ │ ├── AstElementHashingVisitor.cs
│ │ ├── DefaultDepthFirstVisitor.cs
│ │ ├── IVisitable.cs
│ │ └── Visitors.cs
├── Formatting
│ ├── DFormattingOptions.cs
│ ├── DFormattingVisitor.Impl.cs
│ ├── DFormattingVisitor.cs
│ ├── DocumentAdapter.cs
│ ├── Formatter.cs
│ ├── FormattingIndentStack.cs
│ ├── ITextEditorOptions.cs
│ └── Indent
│ │ ├── DIndentEngine.cs
│ │ ├── IDocumentIndentEngine.cs
│ │ ├── IStateMachineIndentEngine.cs
│ │ ├── IndentEngine.cs
│ │ ├── IndentEngineWrapper.cs
│ │ ├── IndentStack.cs
│ │ └── IndentStates.cs
├── Misc
│ ├── CompletionOptions.cs
│ ├── DocumentHelper.cs
│ ├── GlobalParseCache.cs
│ ├── HashNumbers.cs
│ ├── Logger.cs
│ ├── Mangling
│ │ ├── Demangler.cs
│ │ └── Mangler.cs
│ ├── ModuleNameHelper.cs
│ ├── ParseCacheView.cs
│ ├── ParseLog.cs
│ ├── StringCache.cs
│ ├── StringExtension.cs
│ ├── StringView.cs
│ └── VersionIdEvaluation.cs
├── Parser
│ ├── DDocParser.cs
│ ├── Implementations
│ │ ├── DAsmStatementParser.cs
│ │ ├── DAttributesParser.cs
│ │ ├── DBodiedSymbolsParser.cs
│ │ ├── DDeclarationParser.cs
│ │ ├── DExpressionsParser.cs
│ │ ├── DModulesParser.cs
│ │ ├── DParserImplementationPart.cs
│ │ ├── DParserParts.cs
│ │ ├── DParserStateContext.cs
│ │ ├── DStatementParser.cs
│ │ └── DTemplatesParser.cs
│ ├── IncrementalParsing.cs
│ ├── Lexer.cs
│ ├── Parser.cs
│ └── Tokens
│ │ ├── Comment.cs
│ │ ├── DToken.cs
│ │ ├── DTokens.cs
│ │ ├── DTokensSemanticHelpers.cs
│ │ ├── LiteralFormat.cs
│ │ └── LiteralSubformat.cs
├── Refactoring
│ ├── ClassInterfaceDerivativeFinder.cs
│ ├── ITextDocument.cs
│ ├── ImportStmtCreation.cs
│ ├── ReferencesFinder.cs
│ ├── SortImportsRefactoring.cs
│ └── TypeReferenceFinder.cs
├── Resolver
│ ├── ASTScanner
│ │ ├── AbstractResolutionVisitor.cs
│ │ ├── AbstractVisitor.StatementHandler.cs
│ │ ├── AbstractVisitor.cs
│ │ ├── ConditionsFrame.cs
│ │ ├── ItemCheckParameters.cs
│ │ ├── ItemEnumeration.cs
│ │ ├── MemberFilter.cs
│ │ ├── NameScan.cs
│ │ ├── SingleNodeNameScan.cs
│ │ └── Util
│ │ │ ├── IndexKeyExtendingEnumerable.cs
│ │ │ ├── IotaEnumerable.cs
│ │ │ └── StringCharValuesEnumerable.cs
│ ├── Caching
│ │ ├── ExpressionCache.cs
│ │ └── ResolutionCache.cs
│ ├── ConditionalCompilation.cs
│ ├── ConditionalCompilationFlags.cs
│ ├── DTypeToCodeVisitor.cs
│ ├── DTypeToTypeDeclVisitor.cs
│ ├── ExpressionSemantics
│ │ ├── CTFE
│ │ │ └── FunctionEvaluation.cs
│ │ ├── Evaluation.Identifiers.cs
│ │ ├── Evaluation.IsExpression.cs
│ │ ├── Evaluation.OperandExpressions.cs
│ │ ├── Evaluation.PostfixExpressions.cs
│ │ ├── Evaluation.PrimaryExpression.cs
│ │ ├── Evaluation.Traits.cs
│ │ ├── Evaluation.TypeidExpression.cs
│ │ ├── Evaluation.UnaryExpressions.cs
│ │ ├── Evaluation.cs
│ │ ├── EvaluationException.cs
│ │ ├── Exceptions
│ │ │ ├── CtfeException.cs
│ │ │ ├── EvaluationStackOverflowException.cs
│ │ │ └── VariableNotInitializedException.cs
│ │ ├── ExpressionTypeEvaluation.cs
│ │ ├── ExpressionValues.cs
│ │ ├── ISymbolValue.cs
│ │ ├── ISymbolValueVisitor.cs
│ │ ├── LeftValueSetterVisitor.cs
│ │ ├── LeftValues.cs
│ │ ├── MathOperationEvaluation.cs
│ │ ├── MethodOverloadCandidateSearchVisitor.cs
│ │ ├── MethodOverloadsByParameterTypeComparisonFilter.cs
│ │ ├── StatefulEvaluationContext.cs
│ │ ├── SymbolValueComparer.cs
│ │ └── VariableValueEvaluation.cs
│ ├── IResolvedTypeVisitor.cs
│ ├── MixinAnalysis.cs
│ ├── Model
│ │ ├── ComplexValue.cs
│ │ ├── ContextFrame.cs
│ │ ├── DType.cs
│ │ └── ISemantic.cs
│ ├── ResolutionContext.cs
│ ├── ResolutionError.cs
│ ├── ResolutionHooks
│ │ ├── HookAttribute.cs
│ │ ├── HookRegistry.cs
│ │ ├── Hooks
│ │ │ ├── Tuple.cs
│ │ │ ├── autoimplement.cs
│ │ │ └── bitfields.cs
│ │ └── IHook.cs
│ ├── ResolutionOptions.cs
│ ├── ResolvedTypeCloner.cs
│ ├── ResultComparer.cs
│ ├── StaticProperties.cs
│ ├── StorageClassImplicitCastCheck.cs
│ ├── Templates
│ │ ├── DeducedTypeDictionary.cs
│ │ ├── SpecializationOrdering.cs
│ │ ├── TemplateInstanceHandler.cs
│ │ ├── TemplateParameterDeduction.cs
│ │ ├── TemplateParameterDeductionVisitor.cs
│ │ └── TemplateTypeParameterTypeMatcher.cs
│ └── TypeResolution
│ │ ├── ASTSearchHelper.cs
│ │ ├── ClassInterfaceResolver.cs
│ │ ├── DSymbolBaseTypeResolver.cs
│ │ ├── LooseResolution.cs
│ │ ├── OpDispatchResolution.cs
│ │ ├── Resolver.cs
│ │ ├── ScopedObjectVisitor.cs
│ │ ├── SingleResolverVisitor.cs
│ │ ├── TypeDeclarationResolver.cs
│ │ └── UFCSResolver.cs
└── readme.txt
├── ExaustiveCompletionTester
├── CompletionFacilities.cs
├── Config.cs
├── ExaustiveCompletionTester.csproj
├── FileProcessingData.cs
├── Program.cs
└── SpecializedDataGen.cs
├── IndependentTests
├── IndependentTests.csproj
├── IndependentTests.sln
├── Program.cs
└── Properties
│ └── AssemblyInfo.cs
├── TestTool
├── BotanProfil.cs
├── Program.cs
└── TestTool.csproj
├── Tests
├── Completion
│ ├── CompletionTests.cs
│ ├── TestCompletionDataGen.cs
│ ├── TestUtil.cs
│ ├── TestsEditorData.cs
│ └── TooltipGenerationTests.cs
├── ExpressionEvaluation
│ ├── CtfeTests.cs
│ ├── EvaluationTests.cs
│ └── TraitsEvaluationTests.cs
├── FormatterTests.cs
├── IndentationTests.cs
├── Misc
│ ├── DemanglerTests.cs
│ └── GlobalParseCacheTests.cs
├── ParseTests.cs
├── Resolution
│ ├── DeclDefScopingTests.cs
│ ├── DeclarationConstraintsTests.cs
│ ├── ImplicitConversionTests.cs
│ ├── LooseResolutionTests.cs
│ ├── MethodCallOverloadRelatedTests.cs
│ ├── MixinResolutionTests.cs
│ ├── OperatorOverloadingTests.cs
│ ├── ReferenceFindingTests.cs
│ ├── ResolutionTestHelper.cs
│ ├── ResolutionTests.cs
│ ├── StatementTests.cs
│ ├── TemplateMixinResolutionTests.cs
│ ├── TemplateParameterDeductionTests.cs
│ └── UFCSTests.cs
├── Tests.csproj
└── formatterTests.txt
├── license.txt
└── readme.md
/.travis.yml:
--------------------------------------------------------------------------------
1 | ## Travis CI Integration
2 |
3 | notifications:
4 | email: false
5 | irc: "chat.freenode.net#d.mono-d"
6 |
7 | language: csharp
8 | mono: none
9 | dotnet: 3.1.103
10 | solution: DParser2.Unittest.sln
11 | cache: bundler
12 |
13 | install:
14 | - dotnet restore
15 |
16 | script:
17 | - dotnet build /p:Configuration=Debug "/p:Platform=Any CPU"
18 | - dotnet test ./Tests/bin/Debug/netcoreapp3.0/Tests.dll
--------------------------------------------------------------------------------
/DParser2/Completion/ICompletionDataGenerator.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom;
2 |
3 | namespace D_Parser.Completion
4 | {
5 | public interface ICompletionDataGenerator
6 | {
7 | ///
8 | /// Adds a token entry
9 | ///
10 | void Add(byte token);
11 |
12 | ///
13 | /// Adds a property attribute
14 | ///
15 | void AddPropertyAttribute(string attributeText);
16 |
17 | void AddIconItem(string iconName, string text, string description);
18 | void AddTextItem(string text, string description);
19 |
20 | ///
21 | /// Adds a node to the completion data
22 | ///
23 | ///
24 | void Add(INode node);
25 |
26 | void AddModule(DModule module,string nameOverride = null);
27 | void AddPackage(string packageName);
28 |
29 | ///
30 | /// Used for method override completion
31 | ///
32 | void AddCodeGeneratingNodeItem(INode node, string codeToGenerate);
33 |
34 | ///
35 | /// Sets a prefix or a 'contains'-Pattern that indicates items that will be added later on.
36 | /// The first matching item may be pre-selected in the completion list then.
37 | ///
38 | void SetSuggestedItem(string item);
39 |
40 | ///
41 | /// Notifies completion high-levels that the completion has been stopped due to taking too much time.
42 | /// After this message has been sent, other completion items may still be added!
43 | ///
44 | void NotifyTimeout();
45 |
46 | ///
47 | /// Used for calculating the text region that shall be replaced on a completion commit.
48 | /// Can be null.
49 | ///
50 | ISyntaxRegion TriggerSyntaxRegion { set; }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/AbstractCompletionProvider.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom;
2 |
3 | namespace D_Parser.Completion.Providers
4 | {
5 | public abstract class AbstractCompletionProvider
6 | {
7 | protected readonly ICompletionDataGenerator CompletionDataGenerator;
8 |
9 | protected AbstractCompletionProvider(ICompletionDataGenerator completionDataGenerator)
10 | {
11 | CompletionDataGenerator = completionDataGenerator;
12 | }
13 |
14 | #region Helper Methods
15 | public static bool CanItemBeShownGenerally(INode dn)
16 | {
17 | if (dn == null || dn.NameHash == 0)
18 | return false;
19 |
20 | if (dn is DMethod)
21 | {
22 | var dm = dn as DMethod;
23 |
24 | if (dm.SpecialType == DMethod.MethodType.Unittest ||
25 | dm.SpecialType == DMethod.MethodType.Destructor ||
26 | dm.SpecialType == DMethod.MethodType.Constructor)
27 | return false;
28 | }
29 |
30 | return true;
31 | }
32 | #endregion
33 |
34 | protected abstract void BuildCompletionDataInternal(IEditorData editor, char enteredChar);
35 |
36 | public void BuildCompletionData(IEditorData editor, char enteredChar) =>
37 | BuildCompletionDataInternal(editor, enteredChar);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/ImportStatementCompletionProvider.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using D_Parser.Dom;
3 | namespace D_Parser.Completion.Providers
4 | {
5 | ///
6 | /// import io = |;
7 | /// import |;
8 | ///
9 | class ImportStatementCompletionProvider : AbstractCompletionProvider
10 | {
11 | readonly ImportStatement.Import imp;
12 |
13 | public ImportStatementCompletionProvider(
14 | ICompletionDataGenerator gen,
15 | ImportStatement.Import imp)
16 | : base(gen)
17 | {
18 | this.imp = imp;
19 | }
20 |
21 | protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
22 | {
23 | if(Editor.ParseCache == null)
24 | return;
25 |
26 | string pack = null;
27 |
28 | if (imp.ModuleIdentifier != null && imp.ModuleIdentifier.InnerDeclaration != null)
29 | {
30 | pack = imp.ModuleIdentifier.InnerDeclaration.ToString();
31 |
32 | // Will occur after an initial dot
33 | if (string.IsNullOrEmpty(pack))
34 | return;
35 | }
36 |
37 | foreach (var p in Editor.ParseCache.LookupPackage(Editor.SyntaxTree, pack))
38 | {
39 | if (p == null)
40 | continue;
41 |
42 | foreach (var kv_pack in p.Packages)
43 | CompletionDataGenerator.AddPackage(kv_pack.Value.Name);
44 |
45 | foreach (var kv_mod in p.Modules)
46 | CompletionDataGenerator.AddModule(kv_mod.Value);
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/ModuleStatementCompletionProvider.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace D_Parser.Completion.Providers
3 | {
4 | class ModuleStatementCompletionProvider : AbstractCompletionProvider
5 | {
6 | public ModuleStatementCompletionProvider(ICompletionDataGenerator dg) : base(dg){}
7 |
8 | protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
9 | {
10 | CompletionDataGenerator.AddModule(Editor.SyntaxTree, Editor.SyntaxTree.ModuleName);
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/SelectiveImportCompletionProvider.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom;
2 | using D_Parser.Resolver;
3 | using D_Parser.Resolver.ASTScanner;
4 | using System.Linq;
5 | namespace D_Parser.Completion.Providers
6 | {
7 | ///
8 | /// import std.stdio : |, foo = |;
9 | ///
10 | class SelectiveImportCompletionProvider : AbstractCompletionProvider
11 | {
12 | readonly ImportStatement.Import import;
13 |
14 | public SelectiveImportCompletionProvider(ICompletionDataGenerator gen, ImportStatement.Import imp) : base(gen) {
15 | import = imp;
16 | }
17 |
18 | protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
19 | {
20 | if (Editor.ParseCache == null)
21 | return;
22 |
23 | var module = Editor.ParseCache.LookupModuleName(Editor.SyntaxTree, import.ModuleIdentifier.ToString(true)).FirstOrDefault();
24 |
25 | if (module == null)
26 | return;
27 |
28 | var ctxt = ResolutionContext.Create(Editor, true);
29 |
30 | /*
31 | * Show all members of the imported module
32 | * + public imports
33 | * + items of anonymous enums
34 | */
35 |
36 | MemberCompletionEnumeration.EnumChildren(CompletionDataGenerator, ctxt, module, true, MemberFilter.All, true);
37 |
38 | return;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/StructInitializerCompletion.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom;
2 | using D_Parser.Dom.Expressions;
3 | using D_Parser.Resolver;
4 | using D_Parser.Resolver.ASTScanner;
5 | using D_Parser.Resolver.TypeResolution;
6 | using System.Collections.Generic;
7 |
8 | namespace D_Parser.Completion.Providers
9 | {
10 | class StructInitializerCompletion : AbstractCompletionProvider
11 | {
12 | public readonly DVariable initedVar;
13 | public readonly StructInitializer init;
14 |
15 | public StructInitializerCompletion(ICompletionDataGenerator gen,DVariable initializedVariable, StructInitializer init) : base(gen)
16 | {
17 | this.initedVar = initializedVariable;
18 | this.init = init;
19 | }
20 |
21 | protected override void BuildCompletionDataInternal(IEditorData Editor, char enteredChar)
22 | {
23 | var ctxt = ResolutionContext.Create(Editor, true);
24 | var resolvedVariable = TypeDeclarationResolver.HandleNodeMatch(initedVar, ctxt) as DSymbol;
25 |
26 | if (resolvedVariable == null)
27 | return;
28 |
29 | while (resolvedVariable is TemplateParameterSymbol)
30 | resolvedVariable = resolvedVariable.Base as DSymbol;
31 |
32 | var structType = resolvedVariable.Base as TemplateIntermediateType;
33 |
34 | if (structType == null)
35 | return;
36 |
37 | var alreadyTakenNames = new List();
38 | foreach (var m in init.MemberInitializers)
39 | alreadyTakenNames.Add(m.MemberNameHash);
40 |
41 | new StructVis(structType,alreadyTakenNames,CompletionDataGenerator,ctxt);
42 | }
43 |
44 | class StructVis : AbstractVisitor
45 | {
46 | readonly List alreadyTakenNames;
47 | readonly ICompletionDataGenerator gen;
48 |
49 | public StructVis(TemplateIntermediateType structType,List tkn,ICompletionDataGenerator gen,ResolutionContext ctxt)
50 | : base(ctxt)
51 | {
52 | this.alreadyTakenNames = tkn;
53 | this.gen = gen;
54 |
55 | if (ctxt.CompletionOptions.ShowStructMembersInStructInitOnly)
56 | this.DeepScanClass(structType, new ItemCheckParameters(MemberFilter.Variables), false);
57 | else
58 | IterateThroughScopeLayers(CodeLocation.Empty, MemberFilter.All);
59 | }
60 |
61 | protected override bool PreCheckItem (INode n) => !alreadyTakenNames.Contains (n.NameHash);
62 |
63 | protected override void HandleItem(INode n, AbstractType resolvedCurrentScope) => gen.Add(n);
64 | protected override void HandleItem(PackageSymbol pack) { }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/DParser2/Completion/Providers/VariableNameSuggestionCompletionProvider.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom;
2 | using D_Parser.Resolver;
3 | using D_Parser.Resolver.TypeResolution;
4 |
5 | namespace D_Parser.Completion.Providers
6 | {
7 | public class VariableNameSuggestionCompletionProvider : AbstractCompletionProvider
8 | {
9 | private readonly DNode _node;
10 |
11 | public VariableNameSuggestionCompletionProvider(ICompletionDataGenerator completionDataGenerator, DNode node)
12 | : base(completionDataGenerator)
13 | {
14 | _node = node;
15 | }
16 |
17 | protected override void BuildCompletionDataInternal(IEditorData editor, char enteredChar)
18 | {
19 | var ctxt = ResolutionContext.Create(editor, true);
20 | var type = TypeDeclarationResolver.ResolveSingle(_node.Type, ctxt);
21 | while (type is TemplateParameterSymbol tps)
22 | type = tps.Base;
23 | if (type is TemplateIntermediateType tit && !string.IsNullOrEmpty(tit.Definition.Name))
24 | {
25 | var name = tit.Definition.Name;
26 | var camelCasedName = char.ToLowerInvariant(name[0]) + name.Substring(1);
27 | CompletionDataGenerator.SetSuggestedItem(camelCasedName);
28 | CompletionDataGenerator.AddTextItem(camelCasedName, string.Empty);
29 | }
30 | }
31 | }
32 | }
--------------------------------------------------------------------------------
/DParser2/DParser2.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | {0290A229-9AA1-41C3-B525-CAFB86D8BC42}
7 | Library
8 | D_Parser
9 | default
10 | netstandard2.0
11 | prompt
12 | 4
13 | True
14 | D_Parser
15 | $(Platform)
16 | full
17 |
18 |
19 |
20 | False
21 | bin\Debug\
22 | DEBUG;TRACE
23 |
24 |
25 | True
26 | bin\Release\
27 |
28 |
29 |
30 |
31 |
38 |
--------------------------------------------------------------------------------
/DParser2/DParser2.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DParser2", "DParser2.csproj", "{0290A229-9AA1-41C3-B525-CAFB86D8BC42}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {0290A229-9AA1-41C3-B525-CAFB86D8BC42}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {0290A229-9AA1-41C3-B525-CAFB86D8BC42}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {0290A229-9AA1-41C3-B525-CAFB86D8BC42}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {0290A229-9AA1-41C3-B525-CAFB86D8BC42}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/DParser2/Dom/CodeLocation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom
4 | {
5 | ///
6 | /// A line/column position.
7 | /// NRefactory lines/columns are counting from one.
8 | ///
9 | public struct CodeLocation : IComparable, IEquatable
10 | {
11 | public static readonly CodeLocation Empty = new CodeLocation(-1, -1);
12 |
13 | public readonly int Column, Line;
14 |
15 | public CodeLocation(int column, int line)
16 | {
17 | Column = column;
18 | Line = line;
19 | }
20 |
21 | public bool IsEmpty
22 | {
23 | get
24 | {
25 | return Line + Column < 1;
26 | }
27 | }
28 |
29 | public override string ToString()
30 | {
31 | return string.Format("(Line {1}, Col {0})", Column, Line);
32 | }
33 |
34 | public override int GetHashCode()
35 | {
36 | return unchecked(87 * Column.GetHashCode() ^ Line.GetHashCode());
37 | }
38 |
39 | public override bool Equals(object obj)
40 | {
41 | if (!(obj is CodeLocation)) return false;
42 | return (CodeLocation)obj == this;
43 | }
44 |
45 | public bool Equals(CodeLocation other)
46 | {
47 | return this == other;
48 | }
49 |
50 | public static bool operator ==(CodeLocation a, CodeLocation b)
51 | {
52 | return a.Column == b.Column && a.Line == b.Line;
53 | }
54 |
55 | public static bool operator !=(CodeLocation a, CodeLocation b)
56 | {
57 | return a.Column != b.Column || a.Line != b.Line;
58 | }
59 |
60 | public static bool operator <(CodeLocation a, CodeLocation b)
61 | {
62 | if (a.Line < b.Line)
63 | return true;
64 | else if (a.Line == b.Line)
65 | return a.Column < b.Column;
66 | else
67 | return false;
68 | }
69 |
70 | public static bool operator >(CodeLocation a, CodeLocation b)
71 | {
72 | if (a.Line > b.Line)
73 | return true;
74 | else if (a.Line == b.Line)
75 | return a.Column > b.Column;
76 | else
77 | return false;
78 | }
79 |
80 | public static bool operator <=(CodeLocation a, CodeLocation b)
81 | {
82 | return !(a > b);
83 | }
84 |
85 | public static bool operator >=(CodeLocation a, CodeLocation b)
86 | {
87 | return !(a < b);
88 | }
89 |
90 | public int CompareTo(CodeLocation other)
91 | {
92 | if (this == other)
93 | return 0;
94 | if (this < other)
95 | return -1;
96 | else
97 | return 1;
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AbstractVariableInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public abstract class AbstractVariableInitializer : IVariableInitializer,IExpression
6 | {
7 | public const int AbstractInitializerHash = 1234;
8 |
9 | public CodeLocation Location
10 | {
11 | get;
12 | set;
13 | }
14 |
15 | public CodeLocation EndLocation
16 | {
17 | get;
18 | set;
19 | }
20 |
21 | public abstract void Accept(ExpressionVisitor vis);
22 |
23 | public abstract R Accept(ExpressionVisitor vis);
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AddExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a + b; a - b;
8 | ///
9 | public class AddExpression : OperatorBasedExpression
10 | {
11 | public AddExpression(bool isMinus)
12 | {
13 | OperatorToken = isMinus ? DTokens.Minus : DTokens.Plus;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AndAndExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a && b;
8 | ///
9 | public class AndAndExpression : OperatorBasedExpression
10 | {
11 | public AndAndExpression()
12 | {
13 | OperatorToken = DTokens.LogicalAnd;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AndExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a & b;
8 | ///
9 | public class AndExpression : OperatorBasedExpression
10 | {
11 | public AndExpression()
12 | {
13 | OperatorToken = DTokens.BitwiseAnd;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AnonymousClassExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// NewArguments ClassArguments BaseClasslist { DeclDefs }
8 | /// new ParenArgumentList_opt class ParenArgumentList_opt SuperClass_opt InterfaceClasses_opt ClassBody
9 | ///
10 | public class AnonymousClassExpression : UnaryExpression, ContainerExpression
11 | {
12 | public IExpression[] NewArguments { get; set; }
13 |
14 | public DClassLike AnonymousClass { get; set; }
15 |
16 | public IExpression[] ClassArguments { get; set; }
17 |
18 | public override string ToString()
19 | {
20 | var ret = "new";
21 |
22 | if (NewArguments != null)
23 | {
24 | ret += "(";
25 | foreach (var e in NewArguments)
26 | ret += e.ToString() + ",";
27 | ret = ret.TrimEnd(',') + ")";
28 | }
29 |
30 | ret += " class";
31 |
32 | if (ClassArguments != null)
33 | {
34 | ret += '(';
35 | foreach (var e in ClassArguments)
36 | ret += e.ToString() + ",";
37 |
38 | ret = ret.TrimEnd(',') + ")";
39 | }
40 |
41 | if (AnonymousClass != null && AnonymousClass.BaseClasses != null)
42 | {
43 | ret += ":";
44 |
45 | foreach (var t in AnonymousClass.BaseClasses)
46 | ret += t.ToString() + ",";
47 |
48 | ret = ret.TrimEnd(',');
49 | }
50 |
51 | ret += " {...}";
52 |
53 | return ret;
54 | }
55 |
56 | public CodeLocation Location
57 | {
58 | get;
59 | set;
60 | }
61 |
62 | public CodeLocation EndLocation
63 | {
64 | get;
65 | set;
66 | }
67 |
68 | public IEnumerable SubExpressions
69 | {
70 | get
71 | {
72 | if (NewArguments != null)
73 | foreach (var arg in NewArguments)
74 | yield return arg;
75 |
76 | if (ClassArguments != null)
77 | foreach (var arg in ClassArguments)
78 | yield return arg;
79 |
80 | //ISSUE: Add the Anonymous class object to the return list somehow?
81 | }
82 | }
83 |
84 | public void Accept(ExpressionVisitor vis)
85 | {
86 | vis.Visit(this);
87 | }
88 |
89 | public R Accept(ExpressionVisitor vis)
90 | {
91 | return vis.Visit(this);
92 | }
93 | }
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ArrayInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class ArrayInitializer : AssocArrayExpression,IVariableInitializer
6 | {
7 | public override void Accept(ExpressionVisitor vis)
8 | {
9 | vis.Visit(this);
10 | }
11 |
12 | public override R Accept(ExpressionVisitor vis)
13 | {
14 | return vis.Visit(this);
15 | }
16 | }
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ArrayLiteralExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 | using System.Collections.Generic;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | ///
8 | /// auto arr= [1,2,3,4,5,6];
9 | ///
10 | public class ArrayLiteralExpression : PrimaryExpression, ContainerExpression
11 | {
12 | public readonly IEnumerable Elements;
13 |
14 | public ArrayLiteralExpression(IEnumerable elements)
15 | {
16 | Elements = elements;
17 | }
18 |
19 | public override string ToString()
20 | {
21 | var s = "[";
22 |
23 | //HACK: To prevent exessive string building flood, limit element count to 100
24 | int i = 0;
25 | foreach(var ex in Elements)
26 | {
27 | s += ex.ToString() + ", ";
28 | if (++i == 100)
29 | {
30 | s += "...";
31 | break;
32 | }
33 | }
34 | s = s.TrimEnd(' ', ',') + "]";
35 | return s;
36 | }
37 |
38 | public CodeLocation Location
39 | {
40 | get;
41 | set;
42 | }
43 |
44 | public CodeLocation EndLocation
45 | {
46 | get;
47 | set;
48 | }
49 |
50 | public IEnumerable SubExpressions
51 | {
52 | get { return Elements; }
53 | }
54 |
55 | public void Accept(ExpressionVisitor vis)
56 | {
57 | vis.Visit(this);
58 | }
59 |
60 | public R Accept(ExpressionVisitor vis)
61 | {
62 | return vis.Visit(this);
63 | }
64 | }
65 | }
66 |
67 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AssertExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class AssertExpression : PrimaryExpression, ContainerExpression
7 | {
8 | public List AssignExpressions;
9 |
10 | public override string ToString()
11 | {
12 | var ret = "assert(";
13 |
14 | foreach (var e in AssignExpressions)
15 | ret += e.ToString() + ",";
16 |
17 | return ret.TrimEnd(',') + ")";
18 | }
19 |
20 | public CodeLocation Location
21 | {
22 | get;
23 | set;
24 | }
25 |
26 | public CodeLocation EndLocation
27 | {
28 | get;
29 | set;
30 | }
31 |
32 | public IEnumerable SubExpressions
33 | {
34 | get { return AssignExpressions; }
35 | }
36 |
37 | public void Accept(ExpressionVisitor vis)
38 | {
39 | vis.Visit(this);
40 | }
41 |
42 | public R Accept(ExpressionVisitor vis)
43 | {
44 | return vis.Visit(this);
45 | }
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AssignExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// a = b;
7 | /// a += b;
8 | /// a *= b; etc.
9 | ///
10 | public class AssignExpression : OperatorBasedExpression
11 | {
12 | public AssignExpression(byte opToken)
13 | {
14 | OperatorToken = opToken;
15 | }
16 |
17 | public override void Accept(ExpressionVisitor vis)
18 | {
19 | vis.Visit(this);
20 | }
21 |
22 | public override R Accept(ExpressionVisitor vis)
23 | {
24 | return vis.Visit(this);
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/AssocArrayExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// auto arr=['a':0xa, 'b':0xb, 'c':0xc, 'd':0xd, 'e':0xe, 'f':0xf];
8 | ///
9 | public class AssocArrayExpression : PrimaryExpression, ContainerExpression
10 | {
11 | public IList> Elements = new List>();
12 |
13 | public override string ToString()
14 | {
15 | var s = "[";
16 | foreach (var expr in Elements)
17 | s += expr.Key.ToString() + ":" + expr.Value.ToString() + ", ";
18 | s = s.TrimEnd(' ', ',') + "]";
19 | return s;
20 | }
21 |
22 | public CodeLocation Location
23 | {
24 | get;
25 | set;
26 | }
27 |
28 | public CodeLocation EndLocation
29 | {
30 | get;
31 | set;
32 | }
33 |
34 | public IEnumerable SubExpressions
35 | {
36 | get
37 | {
38 | foreach (var kv in Elements)
39 | {
40 | if (kv.Key != null)
41 | yield return kv.Key;
42 | if (kv.Value != null)
43 | yield return kv.Value;
44 | }
45 | }
46 | }
47 |
48 | public virtual void Accept(ExpressionVisitor vis)
49 | {
50 | vis.Visit(this);
51 | }
52 |
53 | public virtual R Accept(ExpressionVisitor vis)
54 | {
55 | return vis.Visit(this);
56 | }
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/CastExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 | using D_Parser.Parser;
5 |
6 | namespace D_Parser.Dom.Expressions
7 | {
8 | ///
9 | /// CastExpression:
10 | /// cast ( Type ) UnaryExpression
11 | /// cast ( CastParam ) UnaryExpression
12 | ///
13 | public class CastExpression : UnaryExpression, ContainerExpression
14 | {
15 | public bool IsTypeCast
16 | {
17 | get { return Type != null; }
18 | }
19 |
20 | public IExpression UnaryExpression;
21 |
22 | public ITypeDeclaration Type { get; set; }
23 |
24 | public byte[] CastParamTokens { get; set; }
25 |
26 | public override string ToString()
27 | {
28 | var ret = new StringBuilder("cast(");
29 |
30 | if (IsTypeCast)
31 | ret.Append(Type.ToString());
32 | else if (CastParamTokens != null && CastParamTokens.Length != 0)
33 | {
34 | foreach (var tk in CastParamTokens)
35 | ret.Append(DTokens.GetTokenString(tk)).Append(' ');
36 | ret.Remove(ret.Length - 1, 1);
37 | }
38 |
39 | ret.Append(')');
40 |
41 | if (UnaryExpression != null)
42 | ret.Append(' ').Append(UnaryExpression.ToString());
43 |
44 | return ret.ToString();
45 | }
46 |
47 | public CodeLocation Location
48 | {
49 | get;
50 | set;
51 | }
52 |
53 | public CodeLocation EndLocation
54 | {
55 | get;
56 | set;
57 | }
58 |
59 | public IEnumerable SubExpressions
60 | {
61 | get { yield return UnaryExpression; }
62 | }
63 |
64 | public void Accept(ExpressionVisitor vis)
65 | {
66 | vis.Visit(this);
67 | }
68 |
69 | public R Accept(ExpressionVisitor vis)
70 | {
71 | return vis.Visit(this);
72 | }
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/CatExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a ~ b
8 | ///
9 | public class CatExpression : OperatorBasedExpression
10 | {
11 | public CatExpression()
12 | {
13 | OperatorToken = DTokens.Tilde;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ConditionalExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a ? b : b;
8 | ///
9 | public class ConditionalExpression : IExpression, ContainerExpression
10 | {
11 | public IExpression OrOrExpression { get; set; }
12 |
13 | public IExpression TrueCaseExpression { get; set; }
14 |
15 | public IExpression FalseCaseExpression { get; set; }
16 |
17 | public override string ToString()
18 | {
19 | return (OrOrExpression != null ? OrOrExpression.ToString() : "") + "?" +
20 | (TrueCaseExpression != null ? TrueCaseExpression.ToString() : "") + ':' +
21 | (FalseCaseExpression != null ? FalseCaseExpression.ToString() : "");
22 | }
23 |
24 | public CodeLocation Location
25 | {
26 | get { return OrOrExpression.Location; }
27 | }
28 |
29 | public CodeLocation EndLocation
30 | {
31 | get { return (FalseCaseExpression ?? TrueCaseExpression ?? OrOrExpression).EndLocation; }
32 | }
33 |
34 | public IEnumerable SubExpressions
35 | {
36 | get {
37 | if (OrOrExpression != null)
38 | yield return OrOrExpression;
39 | if (TrueCaseExpression != null)
40 | yield return TrueCaseExpression;
41 | if (FalseCaseExpression != null)
42 | yield return FalseCaseExpression;
43 | }
44 | }
45 |
46 | public void Accept(ExpressionVisitor vis)
47 | {
48 | vis.Visit(this);
49 | }
50 |
51 | public R Accept(ExpressionVisitor vis)
52 | {
53 | return vis.Visit(this);
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ContainerExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// Expressions that contain other sub-expressions somewhere share this interface
8 | ///
9 | public interface ContainerExpression : IExpression
10 | {
11 | IEnumerable SubExpressions { get; }
12 | }
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/DeleteExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class DeleteExpression : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Delete; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/EqualExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a == b; a != b;
8 | ///
9 | public class EqualExpression : OperatorBasedExpression
10 | {
11 | public EqualExpression(bool isUnEqual)
12 | {
13 | OperatorToken = isUnEqual ? DTokens.NotEqual : DTokens.Equal;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/Expression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class Expression : IExpression, IEnumerable, ContainerExpression
7 | {
8 | public readonly List Expressions = new List();
9 |
10 | public void Add(IExpression ex)
11 | {
12 | Expressions.Add(ex);
13 | }
14 |
15 | public IEnumerator GetEnumerator()
16 | {
17 | return Expressions.GetEnumerator();
18 | }
19 |
20 | public override string ToString()
21 | {
22 | var s = "";
23 | if (Expressions != null)
24 | foreach (var ex in Expressions)
25 | s += (ex == null ? string.Empty : ex.ToString()) + ",";
26 | return s.TrimEnd(',');
27 | }
28 |
29 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
30 | {
31 | return Expressions.GetEnumerator();
32 | }
33 |
34 | public CodeLocation Location
35 | {
36 | get { return Expressions.Count > 0 ? Expressions[0].Location : CodeLocation.Empty; }
37 | }
38 |
39 | public CodeLocation EndLocation
40 | {
41 | get { return Expressions.Count > 0 ? Expressions[Expressions.Count - 1].EndLocation : CodeLocation.Empty; }
42 | }
43 |
44 | public IEnumerable SubExpressions
45 | {
46 | get { return Expressions; }
47 | }
48 |
49 | public void Accept(ExpressionVisitor vis)
50 | {
51 | vis.Visit(this);
52 | }
53 |
54 | public R Accept(ExpressionVisitor vis)
55 | {
56 | return vis.Visit(this);
57 | }
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/FunctionLiteral.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using D_Parser.Parser;
4 | using D_Parser.Dom.Statements;
5 |
6 | namespace D_Parser.Dom.Expressions
7 | {
8 | public class FunctionLiteral : PrimaryExpression
9 | {
10 | public byte LiteralToken = DTokens.Delegate;
11 | public readonly bool IsLambda;
12 | public readonly DMethod AnonymousMethod = new DMethod(DMethod.MethodType.AnonymousDelegate);
13 |
14 | public FunctionLiteral(bool lambda = false)
15 | {
16 | IsLambda = lambda;
17 | if (lambda)
18 | AnonymousMethod.SpecialType |= DMethod.MethodType.Lambda;
19 | }
20 |
21 | public FunctionLiteral(byte InitialLiteral)
22 | {
23 | LiteralToken = InitialLiteral;
24 | }
25 |
26 | public override string ToString()
27 | {
28 | if (IsLambda)
29 | {
30 | var sb = new StringBuilder();
31 |
32 | if (AnonymousMethod.Parameters.Count == 1 && AnonymousMethod.Parameters[0].Type == null)
33 | sb.Append(AnonymousMethod.Parameters[0].Name);
34 | else
35 | {
36 | sb.Append('(');
37 | foreach (INode param in AnonymousMethod.Parameters)
38 | {
39 | sb.Append(param).Append(',');
40 | }
41 |
42 | if (AnonymousMethod.Parameters.Count > 0)
43 | sb.Remove(sb.Length - 1, 1);
44 | sb.Append(')');
45 | }
46 |
47 | sb.Append(" => ");
48 |
49 | if (AnonymousMethod.Body != null)
50 | {
51 | var en = AnonymousMethod.Body.SubStatements.GetEnumerator();
52 | if (en.MoveNext() && en.Current is ReturnStatement)
53 | sb.Append((en.Current as ReturnStatement).ReturnExpression.ToString());
54 | else
55 | sb.Append(AnonymousMethod.Body.ToCode());
56 | en.Dispose();
57 | }
58 | else
59 | sb.Append("{}");
60 |
61 | return sb.ToString();
62 | }
63 |
64 | return DTokens.GetTokenString(LiteralToken) + (AnonymousMethod.NameHash == 0 ? "" : " ") + AnonymousMethod.ToString();
65 | }
66 |
67 | public CodeLocation Location
68 | {
69 | get;
70 | set;
71 | }
72 |
73 | public CodeLocation EndLocation
74 | {
75 | get;
76 | set;
77 | }
78 |
79 | public void Accept(ExpressionVisitor vis)
80 | {
81 | vis.Visit(this);
82 | }
83 |
84 | public R Accept(ExpressionVisitor vis)
85 | {
86 | return vis.Visit(this);
87 | }
88 | }
89 | }
90 |
91 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/IExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public interface IExpression : ISyntaxRegion, IVisitable
6 | {
7 | R Accept(ExpressionVisitor vis);
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/IVariableInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public interface IVariableInitializer
6 | {
7 |
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/IdentifierExpression.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace D_Parser.Dom.Expressions
3 | {
4 | public interface IntermediateIdType : ISyntaxRegion
5 | {
6 | bool ModuleScoped { get; set; }
7 | int IdHash{get;}
8 | }
9 |
10 | public class IdentifierExpression : PrimaryExpression, IntermediateIdType
11 | {
12 | public bool ModuleScoped {
13 | get;
14 | set;
15 | }
16 |
17 | public int IdHash {
18 | get;
19 | private set;
20 | }
21 |
22 | public string StringValue => Strings.TryGet(IdHash);
23 |
24 | public IdentifierExpression(string id)
25 | {
26 | Strings.Add(id);
27 | IdHash = id.GetHashCode();
28 | }
29 |
30 | public override string ToString()
31 | {
32 | return (ModuleScoped ? "." : "") + StringValue;
33 | }
34 |
35 | public CodeLocation Location
36 | {
37 | get;
38 | set;
39 | }
40 |
41 | public CodeLocation EndLocation
42 | {
43 | get;
44 | set;
45 | }
46 |
47 | public void Accept(ExpressionVisitor vis)
48 | {
49 | vis.Visit(this);
50 | }
51 |
52 | public R Accept(ExpressionVisitor vis)
53 | {
54 | return vis.Visit(this);
55 | }
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/IdentityExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a is b; a !is b;
8 | ///
9 | public class IdentityExpression : OperatorBasedExpression
10 | {
11 | public bool Not;
12 | public readonly int opColumn, opLine;
13 |
14 | public IdentityExpression(bool notIs, CodeLocation oploc)
15 | {
16 | Not = notIs;
17 | opColumn = oploc.Column;
18 | opLine = oploc.Line;
19 | OperatorToken = DTokens.Is;
20 | }
21 |
22 | public override string ToString()
23 | {
24 | return LeftOperand.ToString() + (Not ? " !" : " ") + "is " + RightOperand.ToString();
25 | }
26 |
27 | public override void Accept(ExpressionVisitor vis)
28 | {
29 | vis.Visit(this);
30 | }
31 |
32 | public override R Accept(ExpressionVisitor vis)
33 | {
34 | return vis.Visit(this);
35 | }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ImportExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | public class ImportExpression : PrimaryExpression,ContainerExpression
8 | {
9 | public IExpression AssignExpression;
10 |
11 | public override string ToString()
12 | {
13 | return "import(" + AssignExpression.ToString() + ")";
14 | }
15 |
16 | public CodeLocation Location
17 | {
18 | get;
19 | set;
20 | }
21 |
22 | public CodeLocation EndLocation
23 | {
24 | get;
25 | set;
26 | }
27 |
28 | public IEnumerable SubExpressions
29 | {
30 | get { yield return AssignExpression; }
31 | }
32 |
33 | public void Accept(ExpressionVisitor vis)
34 | {
35 | vis.Visit(this);
36 | }
37 |
38 | public R Accept(ExpressionVisitor vis)
39 | {
40 | return vis.Visit(this);
41 | }
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/InExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a in b; a !in b
8 | ///
9 | public class InExpression : OperatorBasedExpression
10 | {
11 | public bool Not;
12 | public readonly int opColumn, opLine;
13 |
14 | public InExpression(bool notIn, CodeLocation oploc)
15 | {
16 | Not = notIn;
17 | opColumn = oploc.Column;
18 | opLine = oploc.Line;
19 | OperatorToken = DTokens.In;
20 | }
21 |
22 | public override string ToString()
23 | {
24 | return LeftOperand.ToString() + (Not ? " !" : " ") + "in " + RightOperand.ToString();
25 | }
26 |
27 | public override void Accept(ExpressionVisitor vis)
28 | {
29 | vis.Visit(this);
30 | }
31 |
32 | public override R Accept(ExpressionVisitor vis)
33 | {
34 | return vis.Visit(this);
35 | }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/MixinExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | public class MixinExpression : PrimaryExpression, ContainerExpression
8 | {
9 | public IExpression AssignExpression;
10 |
11 | public override string ToString()
12 | {
13 | return "mixin(" + AssignExpression.ToString() + ")";
14 | }
15 |
16 | public CodeLocation Location
17 | {
18 | get;
19 | set;
20 | }
21 |
22 | public CodeLocation EndLocation
23 | {
24 | get;
25 | set;
26 | }
27 |
28 | public IEnumerable SubExpressions
29 | {
30 | get { yield return AssignExpression; }
31 | }
32 |
33 | public void Accept(ExpressionVisitor vis)
34 | {
35 | vis.Visit(this);
36 | }
37 |
38 | public R Accept(ExpressionVisitor vis)
39 | {
40 | return vis.Visit(this);
41 | }
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/MulExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// a * b; a / b; a % b;
7 | ///
8 | public class MulExpression : OperatorBasedExpression
9 | {
10 | public MulExpression(byte mulOperator)
11 | {
12 | OperatorToken = mulOperator;
13 | }
14 |
15 | public override void Accept(ExpressionVisitor vis)
16 | {
17 | vis.Visit(this);
18 | }
19 |
20 | public override R Accept(ExpressionVisitor vis)
21 | {
22 | return vis.Visit(this);
23 | }
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/NewExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// NewExpression:
8 | /// NewArguments Type [ AssignExpression ]
9 | /// NewArguments Type ( ArgumentList )
10 | /// NewArguments Type
11 | ///
12 | public class NewExpression : UnaryExpression, ContainerExpression
13 | {
14 | public ITypeDeclaration Type { get; set; }
15 |
16 | public IExpression[] NewArguments { get; set; }
17 |
18 | public IExpression[] Arguments { get; set; }
19 |
20 | public override string ToString()
21 | {
22 | var ret = "new";
23 |
24 | if (NewArguments != null)
25 | {
26 | ret += "(";
27 | foreach (var e in NewArguments)
28 | ret += e.ToString() + ",";
29 | ret = ret.TrimEnd(',') + ")";
30 | }
31 |
32 | if (Type != null)
33 | ret += " " + Type.ToString();
34 |
35 | if (!(Type is ArrayDecl))
36 | {
37 | ret += '(';
38 | if (Arguments != null)
39 | foreach (var e in Arguments)
40 | ret += e.ToString() + ",";
41 |
42 | ret = ret.TrimEnd(',') + ')';
43 | }
44 |
45 | return ret;
46 | }
47 |
48 | public CodeLocation Location
49 | {
50 | get;
51 | set;
52 | }
53 |
54 | public CodeLocation EndLocation
55 | {
56 | get;
57 | set;
58 | }
59 |
60 | public IEnumerable SubExpressions
61 | {
62 | get
63 | {
64 | // In case of a template instance
65 | if (Type is IExpression)
66 | yield return Type as IExpression;
67 |
68 | if (NewArguments != null)
69 | foreach (var arg in NewArguments)
70 | yield return arg;
71 |
72 | if (Arguments != null)
73 | foreach (var arg in Arguments)
74 | yield return arg;
75 | }
76 | }
77 |
78 | public void Accept(ExpressionVisitor vis)
79 | {
80 | vis.Visit(this);
81 | }
82 |
83 | public R Accept(ExpressionVisitor vis)
84 | {
85 | return vis.Visit(this);
86 | }
87 | }
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/OperatorBasedExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public abstract class OperatorBasedExpression : ContainerExpression
7 | {
8 | public IExpression LeftOperand { get; set; }
9 |
10 | public IExpression RightOperand { get; set; }
11 |
12 | public byte OperatorToken { get; protected set; }
13 |
14 | public override string ToString()
15 | {
16 | return LeftOperand + DTokens.GetTokenString(OperatorToken) + (RightOperand != null ? RightOperand.ToString() : "");
17 | }
18 |
19 | public CodeLocation Location => LeftOperand?.Location ?? CodeLocation.Empty;
20 |
21 | public CodeLocation EndLocation => RightOperand?.EndLocation ?? CodeLocation.Empty;
22 |
23 | public IEnumerable SubExpressions
24 | {
25 | get {
26 | if (LeftOperand != null) yield return LeftOperand;
27 | if (RightOperand != null) yield return RightOperand;
28 | }
29 | }
30 |
31 | public abstract void Accept(ExpressionVisitor v);
32 |
33 | public abstract R Accept(ExpressionVisitor v);
34 | }
35 | }
36 |
37 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/OrExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a | b;
8 | ///
9 | public class OrExpression : OperatorBasedExpression
10 | {
11 | public OrExpression()
12 | {
13 | OperatorToken = DTokens.BitwiseOr;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/OrOrExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a || b;
8 | ///
9 | public class OrOrExpression : OperatorBasedExpression
10 | {
11 | public OrOrExpression()
12 | {
13 | OperatorToken = DTokens.LogicalOr;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PostfixExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public abstract class PostfixExpression : IExpression, ContainerExpression
7 | {
8 | public IExpression PostfixForeExpression { get; set; }
9 |
10 | public CodeLocation Location
11 | {
12 | get { return PostfixForeExpression != null ? PostfixForeExpression.Location : CodeLocation.Empty; }
13 | }
14 |
15 | public abstract CodeLocation EndLocation { get; set; }
16 |
17 | public virtual IEnumerable SubExpressions
18 | {
19 | get { yield return PostfixForeExpression; }
20 | }
21 |
22 | public abstract void Accept(ExpressionVisitor vis);
23 |
24 | public abstract R Accept(ExpressionVisitor vis);
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PostfixExpression_Access.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// PostfixExpression . Identifier
8 | /// PostfixExpression . TemplateInstance
9 | /// PostfixExpression . NewExpression
10 | ///
11 | public class PostfixExpression_Access : PostfixExpression
12 | {
13 | ///
14 | /// Can be either
15 | /// 1) An Identifier
16 | /// 2) A Template Instance
17 | /// 3) A NewExpression
18 | ///
19 | public IExpression AccessExpression;
20 |
21 | public override string ToString()
22 | {
23 | var r = PostfixForeExpression.ToString() + '.';
24 |
25 | if (AccessExpression != null)
26 | r += AccessExpression.ToString();
27 |
28 | return r;
29 | }
30 |
31 | public override CodeLocation EndLocation
32 | {
33 | get;
34 | set;
35 | }
36 |
37 | public override IEnumerable SubExpressions
38 | {
39 | get
40 | {
41 | yield return PostfixForeExpression;
42 | yield return AccessExpression;
43 | }
44 | }
45 |
46 | public override void Accept(ExpressionVisitor vis)
47 | {
48 | vis.Visit(this);
49 | }
50 |
51 | public override R Accept(ExpressionVisitor vis)
52 | {
53 | return vis.Visit(this);
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PostfixExpression_Decrement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class PostfixExpression_Decrement : PostfixExpression
6 | {
7 | public override string ToString()
8 | {
9 | return PostfixForeExpression.ToString() + "--";
10 | }
11 |
12 | public sealed override CodeLocation EndLocation
13 | {
14 | get;
15 | set;
16 | }
17 |
18 | public override void Accept(ExpressionVisitor vis)
19 | {
20 | vis.Visit(this);
21 | }
22 |
23 | public override R Accept(ExpressionVisitor vis)
24 | {
25 | return vis.Visit(this);
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PostfixExpression_Increment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class PostfixExpression_Increment : PostfixExpression
6 | {
7 | public override string ToString()
8 | {
9 | return PostfixForeExpression.ToString() + "++";
10 | }
11 |
12 | public sealed override CodeLocation EndLocation
13 | {
14 | get;
15 | set;
16 | }
17 |
18 | public override void Accept(ExpressionVisitor vis)
19 | {
20 | vis.Visit(this);
21 | }
22 |
23 | public override R Accept(ExpressionVisitor vis)
24 | {
25 | return vis.Visit(this);
26 | }
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PostfixExpression_MethodCall.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// PostfixExpression ( )
8 | /// PostfixExpression ( ArgumentList )
9 | ///
10 | public class PostfixExpression_MethodCall : PostfixExpression
11 | {
12 | public IExpression[] Arguments;
13 |
14 | public int ArgumentCount => Arguments?.Length ?? 0;
15 |
16 | public override string ToString()
17 | {
18 | var sb = new StringBuilder(PostfixForeExpression.ToString());
19 | sb.Append('(');
20 |
21 | if (Arguments != null)
22 | foreach (var a in Arguments)
23 | if (a != null)
24 | sb.Append(a.ToString()).Append(',');
25 |
26 | if (sb[sb.Length - 1] == ',')
27 | sb.Remove(sb.Length - 1, 1);
28 |
29 | return sb.Append(')').ToString();
30 | }
31 |
32 | public sealed override CodeLocation EndLocation
33 | {
34 | get;
35 | set;
36 | }
37 |
38 | public override IEnumerable SubExpressions
39 | {
40 | get
41 | {
42 | if (Arguments != null)
43 | foreach (var arg in Arguments)
44 | yield return arg;
45 |
46 | if (PostfixForeExpression != null)
47 | yield return PostfixForeExpression;
48 | }
49 | }
50 |
51 | public override void Accept(ExpressionVisitor vis)
52 | {
53 | vis.Visit(this);
54 | }
55 |
56 | public override R Accept(ExpressionVisitor vis)
57 | {
58 | return vis.VisitPostfixExpression_Methodcall(this);
59 | }
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PowExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class PowExpression : OperatorBasedExpression, UnaryExpression
7 | {
8 | public PowExpression()
9 | {
10 | OperatorToken = DTokens.Pow;
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/PrimaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public interface PrimaryExpression : IExpression
6 | {
7 |
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/RelExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// a <>= b etc.
7 | ///
8 | public class RelExpression : OperatorBasedExpression
9 | {
10 | public RelExpression(byte relationalOperator)
11 | {
12 | OperatorToken = relationalOperator;
13 | }
14 |
15 | public override void Accept(ExpressionVisitor vis)
16 | {
17 | vis.Visit(this);
18 | }
19 |
20 | public override R Accept(ExpressionVisitor vis)
21 | {
22 | return vis.Visit(this);
23 | }
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ScalarConstantExpression.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Parser;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class ScalarConstantExpression : PrimaryExpression
6 | {
7 | public readonly object Value;
8 | public readonly LiteralFormat Format;
9 | public readonly LiteralSubformat Subformat;
10 | public readonly int EscapeStringHash;
11 |
12 | public ScalarConstantExpression(object value,
13 | LiteralFormat literalFormat,
14 | LiteralSubformat subformat = LiteralSubformat.None,
15 | string escapeString = null)
16 | {
17 | Value = value;
18 | Format = literalFormat;
19 | Subformat = subformat;
20 |
21 | if (escapeString != null)
22 | {
23 | Strings.Add(escapeString);
24 | EscapeStringHash = escapeString.GetHashCode();
25 | }
26 | }
27 |
28 | public override string ToString()
29 | {
30 | if (Format == LiteralFormat.CharLiteral)
31 | return "'" + (EscapeStringHash != 0 ? ("\\" + Strings.TryGet(EscapeStringHash)) : ((char)Value).ToString()) + "'";
32 |
33 | if(Value is decimal)
34 | return ((decimal)Value).ToString(System.Globalization.CultureInfo.InvariantCulture);
35 |
36 | return Value != null ? Value.ToString() : "";
37 | }
38 |
39 | public CodeLocation Location
40 | {
41 | get;
42 | set;
43 | }
44 |
45 | public CodeLocation EndLocation
46 | {
47 | get;
48 | set;
49 | }
50 |
51 | public void Accept(ExpressionVisitor vis)
52 | {
53 | vis.VisitScalarConstantExpression(this);
54 | }
55 |
56 | public R Accept(ExpressionVisitor vis)
57 | {
58 | return vis.VisitScalarConstantExpression(this);
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/ShiftExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// a >> b; a << b; a >>> b;
7 | ///
8 | public class ShiftExpression : OperatorBasedExpression
9 | {
10 | public ShiftExpression(byte shiftOperator)
11 | {
12 | OperatorToken = shiftOperator;
13 | }
14 |
15 | public override void Accept(ExpressionVisitor vis)
16 | {
17 | vis.Visit(this);
18 | }
19 |
20 | public override R Accept(ExpressionVisitor vis)
21 | {
22 | return vis.Visit(this);
23 | }
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/SimpleUnaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public abstract class SimpleUnaryExpression : UnaryExpression, ContainerExpression
7 | {
8 | public abstract byte ForeToken { get; }
9 |
10 | public IExpression UnaryExpression { get; set; }
11 |
12 | public override string ToString()
13 | {
14 | return DTokens.GetTokenString(ForeToken) + UnaryExpression.ToString();
15 | }
16 |
17 | public virtual CodeLocation Location
18 | {
19 | get;
20 | set;
21 | }
22 |
23 | public CodeLocation EndLocation
24 | {
25 | get { return UnaryExpression.EndLocation; }
26 | }
27 |
28 | public virtual IEnumerable SubExpressions
29 | {
30 | get { yield return UnaryExpression; }
31 | }
32 |
33 | public abstract void Accept(ExpressionVisitor vis);
34 |
35 | public abstract R Accept(ExpressionVisitor vis);
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/StringLiteralExpression.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Parser;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class StringLiteralExpression : PrimaryExpression
6 | {
7 | public readonly int ValueStringHash;
8 | public readonly LiteralFormat Format;
9 | public readonly LiteralSubformat Subformat;
10 |
11 | public string Value { get { return Strings.TryGet(ValueStringHash); } }
12 |
13 | public StringLiteralExpression(string stringValue, bool isVerbatim = false, LiteralSubformat Subformat = 0)
14 | {
15 | Strings.Add(stringValue);
16 | ValueStringHash = stringValue.GetHashCode();
17 | Format = isVerbatim ? LiteralFormat.VerbatimStringLiteral : LiteralFormat.StringLiteral;
18 | this.Subformat = Subformat;
19 | }
20 |
21 | public override string ToString()
22 | {
23 | switch (Format)
24 | {
25 | default:
26 | return "\"" + Value + "\"";
27 | case LiteralFormat.VerbatimStringLiteral:
28 | return "r\"" + Value + "\"";
29 | }
30 | }
31 |
32 | public CodeLocation Location
33 | {
34 | get;
35 | set;
36 | }
37 |
38 | public CodeLocation EndLocation
39 | {
40 | get;
41 | set;
42 | }
43 |
44 | public void Accept(ExpressionVisitor vis)
45 | {
46 | vis.VisitStringLiteralExpression(this);
47 | }
48 |
49 | public R Accept(ExpressionVisitor vis)
50 | {
51 | return vis.VisitStringLiteralExpression(this);
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/StructInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 | using System.Collections.Generic;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | public class StructInitializer : AbstractVariableInitializer, ContainerExpression
8 | {
9 | public StructMemberInitializer[] MemberInitializers;
10 |
11 | public sealed override string ToString()
12 | {
13 | var ret = "{";
14 |
15 | if (MemberInitializers != null)
16 | foreach (var i in MemberInitializers)
17 | ret += i.ToString() + ",";
18 |
19 | return ret.TrimEnd(',') + "}";
20 | }
21 |
22 | public IEnumerable SubExpressions
23 | {
24 | get
25 | {
26 | if (MemberInitializers != null)
27 | foreach (var mi in MemberInitializers)
28 | if (mi.Value != null)
29 | yield return mi.Value;
30 | }
31 | }
32 |
33 | public override void Accept(ExpressionVisitor vis)
34 | {
35 | vis.Visit(this);
36 | }
37 |
38 | public override R Accept(ExpressionVisitor vis)
39 | {
40 | return vis.Visit(this);
41 | }
42 | }
43 | }
44 |
45 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/StructMemberInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class StructMemberInitializer : ISyntaxRegion, IVisitable
6 | {
7 | public string MemberName {
8 | get { return Strings.TryGet(MemberNameHash); }
9 | set {
10 | Strings.Add(value);
11 | MemberNameHash = value.GetHashCode();
12 | }
13 | }
14 | public int MemberNameHash = 0;
15 | public IExpression Value;
16 |
17 | public sealed override string ToString()
18 | {
19 | return (MemberNameHash != 0 ? (MemberName + ": ") : "") + (Value != null ? Value.ToString() : "");
20 | }
21 |
22 | public CodeLocation Location
23 | {
24 | get;
25 | set;
26 | }
27 |
28 | public CodeLocation EndLocation
29 | {
30 | get;
31 | set;
32 | }
33 |
34 | public void Accept(ExpressionVisitor vis)
35 | {
36 | vis.Visit(this);
37 | }
38 |
39 | public R Accept(ExpressionVisitor vis)
40 | {
41 | return vis.Visit(this);
42 | }
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/SurroundingParenthesesExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | ///
8 | /// ( Expression )
9 | ///
10 | public class SurroundingParenthesesExpression : PrimaryExpression,ContainerExpression
11 | {
12 | public IExpression Expression;
13 |
14 | public override string ToString()
15 | {
16 | return "(" + (Expression != null ? Expression.ToString() : string.Empty) + ")";
17 | }
18 |
19 | public CodeLocation Location
20 | {
21 | get;
22 | set;
23 | }
24 |
25 | public CodeLocation EndLocation
26 | {
27 | get;
28 | set;
29 | }
30 |
31 | public IEnumerable SubExpressions
32 | {
33 | get { yield return Expression; }
34 | }
35 |
36 | public void Accept(ExpressionVisitor vis)
37 | {
38 | vis.Visit(this);
39 | }
40 |
41 | public R Accept(ExpressionVisitor vis)
42 | {
43 | return vis.Visit(this);
44 | }
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/TokenExpression.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Parser;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class TokenExpression : PrimaryExpression
6 | {
7 | public readonly byte Token;
8 |
9 | public TokenExpression(byte token)
10 | {
11 | Token = token;
12 | }
13 |
14 | public TokenExpression(byte token, CodeLocation startLocation, CodeLocation endLocation) : this(token)
15 | {
16 | Location = startLocation;
17 | EndLocation = endLocation;
18 | }
19 |
20 | public override string ToString()
21 | {
22 | return DTokens.GetTokenString(Token);
23 | }
24 |
25 | public CodeLocation Location
26 | {
27 | get;
28 | }
29 |
30 | public CodeLocation EndLocation
31 | {
32 | get;
33 | }
34 |
35 | public void Accept(ExpressionVisitor vis)
36 | {
37 | vis.Visit(this);
38 | }
39 |
40 | public R Accept(ExpressionVisitor vis)
41 | {
42 | return vis.Visit(this);
43 | }
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/TraitsArgument.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public class TraitsArgument : ISyntaxRegion
6 | {
7 | public readonly ITypeDeclaration Type;
8 | public readonly IExpression AssignExpression;
9 |
10 | public TraitsArgument(ITypeDeclaration t)
11 | {
12 | this.Type = t;
13 | }
14 |
15 | public TraitsArgument(IExpression x)
16 | {
17 | this.AssignExpression = x;
18 | }
19 |
20 | public override string ToString()
21 | {
22 | return Type != null ? Type.ToString(true) : AssignExpression.ToString();
23 | }
24 |
25 | public CodeLocation Location
26 | {
27 | get;
28 | set;
29 | }
30 |
31 | public CodeLocation EndLocation
32 | {
33 | get;
34 | set;
35 | }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/TraitsExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | public class TraitsExpression : PrimaryExpression, ContainerExpression
8 | {
9 | public string Keyword;
10 | public TraitsArgument[] Arguments;
11 |
12 | public override string ToString()
13 | {
14 | var ret = "__traits(" + Keyword;
15 |
16 | if (Arguments != null)
17 | foreach (var a in Arguments)
18 | ret += "," + a.ToString();
19 |
20 | return ret + ")";
21 | }
22 |
23 | public CodeLocation Location
24 | {
25 | get;
26 | set;
27 | }
28 |
29 | public CodeLocation EndLocation
30 | {
31 | get;
32 | set;
33 | }
34 |
35 | public void Accept(ExpressionVisitor vis)
36 | {
37 | vis.Visit(this);
38 | }
39 |
40 | public R Accept(ExpressionVisitor vis)
41 | {
42 | return vis.Visit(this);
43 | }
44 |
45 | public IEnumerable SubExpressions
46 | {
47 | get
48 | {
49 | if (Arguments != null)
50 | foreach (var arg in Arguments)
51 | if (arg.AssignExpression != null)
52 | yield return arg.AssignExpression;
53 | }
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/TypeDeclarationExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// BasicType . Identifier
7 | ///
8 | public class TypeDeclarationExpression : PrimaryExpression
9 | {
10 | public readonly ITypeDeclaration Declaration;
11 |
12 | public static IExpression TryWrap(ISyntaxRegion expressionOrDeclaration)
13 | {
14 | return expressionOrDeclaration != null ? expressionOrDeclaration as IExpression ??
15 | new TypeDeclarationExpression(expressionOrDeclaration as ITypeDeclaration) : null;
16 | }
17 |
18 | TypeDeclarationExpression(ITypeDeclaration td)
19 | {
20 | Declaration = td;
21 | }
22 |
23 | public override string ToString()
24 | {
25 | return Declaration.ToString();
26 | }
27 |
28 | public CodeLocation Location
29 | {
30 | get { return Declaration.Location; }
31 | }
32 |
33 | public CodeLocation EndLocation
34 | {
35 | get { return Declaration.EndLocation; }
36 | }
37 |
38 | public void Accept(ExpressionVisitor vis)
39 | {
40 | vis.Visit(this);
41 | }
42 |
43 | public R Accept(ExpressionVisitor vis)
44 | {
45 | return vis.Visit(this);
46 | }
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/TypeidExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Dom.Expressions
6 | {
7 | public class TypeidExpression : PrimaryExpression,ContainerExpression
8 | {
9 | public ITypeDeclaration Type;
10 | public IExpression Expression;
11 |
12 | public override string ToString()
13 | {
14 | return "typeid(" + (Type != null ? Type.ToString() : Expression.ToString()) + ")";
15 | }
16 |
17 | public CodeLocation Location
18 | {
19 | get;
20 | set;
21 | }
22 |
23 | public CodeLocation EndLocation
24 | {
25 | get;
26 | set;
27 | }
28 |
29 | public IEnumerable SubExpressions
30 | {
31 | get
32 | {
33 | if (Expression != null)
34 | yield return Expression;
35 | else if (Type != null)
36 | yield return TypeDeclarationExpression.TryWrap(Type);
37 | }
38 | }
39 |
40 | public void Accept(ExpressionVisitor vis)
41 | {
42 | vis.Visit(this);
43 | }
44 |
45 | public R Accept(ExpressionVisitor vis)
46 | {
47 | return vis.Visit(this);
48 | }
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | public interface UnaryExpression : IExpression
6 | {
7 |
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Add.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class UnaryExpression_Add : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Plus; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_And.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// Creates a pointer from the trailing type
8 | ///
9 | public class UnaryExpression_And : SimpleUnaryExpression
10 | {
11 | public override byte ForeToken
12 | {
13 | get { return DTokens.BitwiseAnd; }
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Cat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// Bitwise negation operation:
8 | ///
9 | /// int a=56;
10 | /// int b=~a;
11 | ///
12 | /// b will be -57;
13 | ///
14 | public class UnaryExpression_Cat : SimpleUnaryExpression
15 | {
16 | public override byte ForeToken
17 | {
18 | get { return DTokens.Tilde; }
19 | }
20 |
21 | public override void Accept(ExpressionVisitor vis)
22 | {
23 | vis.Visit(this);
24 | }
25 |
26 | public override R Accept(ExpressionVisitor vis)
27 | {
28 | return vis.Visit(this);
29 | }
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Decrement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class UnaryExpression_Decrement : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Decrement; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Increment.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class UnaryExpression_Increment : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Increment; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Mul.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// Gets the pointer base type
8 | ///
9 | public class UnaryExpression_Mul : SimpleUnaryExpression
10 | {
11 | public override byte ForeToken
12 | {
13 | get { return DTokens.Times; }
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Not.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class UnaryExpression_Not : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Not; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_SegmentBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public sealed class UnaryExpression_SegmentBase : SimpleUnaryExpression
7 | {
8 | public IExpression RegisterExpression { get; set; }
9 | // This should never be called for this.
10 | public override byte ForeToken { get { throw new NotSupportedException(); } }
11 |
12 | public override string ToString()
13 | {
14 | return RegisterExpression.ToString() + ":" + UnaryExpression.ToString();
15 | }
16 |
17 | public override CodeLocation Location
18 | {
19 | get { return RegisterExpression.Location; }
20 | set { throw new NotSupportedException(); }
21 | }
22 |
23 | public override IEnumerable SubExpressions
24 | {
25 | get
26 | {
27 | if (RegisterExpression != null)
28 | yield return RegisterExpression;
29 | if (UnaryExpression != null)
30 | yield return UnaryExpression;
31 | }
32 | }
33 |
34 | public override void Accept(ExpressionVisitor vis) { vis.Visit(this); }
35 | public override R Accept(ExpressionVisitor vis) { return vis.Visit(this); }
36 | }
37 | }
38 |
39 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Sub.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class UnaryExpression_Sub : SimpleUnaryExpression
7 | {
8 | public override byte ForeToken
9 | {
10 | get { return DTokens.Minus; }
11 | }
12 |
13 | public override void Accept(ExpressionVisitor vis)
14 | {
15 | vis.Visit(this);
16 | }
17 |
18 | public override R Accept(ExpressionVisitor vis)
19 | {
20 | return vis.Visit(this);
21 | }
22 | }
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/UnaryExpression_Type.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Expressions
4 | {
5 | ///
6 | /// (Type).Identifier
7 | ///
8 | public class UnaryExpression_Type : UnaryExpression
9 | {
10 | public ITypeDeclaration Type { get; set; }
11 |
12 | public int AccessIdentifierHash;
13 |
14 | public string AccessIdentifier
15 | {
16 | get { return Strings.TryGet(AccessIdentifierHash); }
17 | set
18 | {
19 | AccessIdentifierHash = value != null ? value.GetHashCode() : 0;
20 | Strings.Add(value);
21 | }
22 | }
23 |
24 | public override string ToString()
25 | {
26 | return "(" + Type.ToString() + ")." + AccessIdentifier;
27 | }
28 |
29 | public CodeLocation Location
30 | {
31 | get;
32 | set;
33 | }
34 |
35 | public CodeLocation EndLocation
36 | {
37 | get;
38 | set;
39 | }
40 |
41 | public void Accept(ExpressionVisitor vis)
42 | {
43 | vis.Visit(this);
44 | }
45 |
46 | public R Accept(ExpressionVisitor vis)
47 | {
48 | return vis.Visit(this);
49 | }
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/VoidInitializer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | public class VoidInitializer : AbstractVariableInitializer
7 | {
8 | public VoidInitializer()
9 | {
10 | }
11 |
12 | public override void Accept(ExpressionVisitor vis)
13 | {
14 | vis.Visit(this);
15 | }
16 |
17 | public override R Accept(ExpressionVisitor vis)
18 | {
19 | return vis.Visit(this);
20 | }
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/DParser2/Dom/Expressions/XorExpression.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 |
4 | namespace D_Parser.Dom.Expressions
5 | {
6 | ///
7 | /// a ^ b;
8 | ///
9 | public class XorExpression : OperatorBasedExpression
10 | {
11 | public XorExpression()
12 | {
13 | OperatorToken = DTokens.Xor;
14 | }
15 |
16 | public override void Accept(ExpressionVisitor vis)
17 | {
18 | vis.Visit(this);
19 | }
20 |
21 | public override R Accept(ExpressionVisitor vis)
22 | {
23 | return vis.Visit(this);
24 | }
25 | }
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/DParser2/Dom/IDeclarationCondition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace D_Parser.Dom
3 | {
4 | public interface IDeclarationCondition : IEquatable
5 | {
6 |
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/DParser2/Dom/ISyntaxRegion.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Threading;
5 | namespace D_Parser.Dom
6 | {
7 | public interface ISyntaxRegion
8 | {
9 | CodeLocation Location { get; }
10 | CodeLocation EndLocation { get; }
11 |
12 | //int Kind { get; }
13 | }
14 |
15 | public static class SyntaxRegionHelper
16 | {
17 | public static ISyntaxRegion First(this ISyntaxRegion a, ISyntaxRegion b)
18 | {
19 | return a.Location <= b.Location ? a : b;
20 | }
21 |
22 | static int NextTypeKind = 0;
23 | static Dictionary Kinds = new Dictionary();
24 |
25 | public static int Kind(this ISyntaxRegion sr)
26 | {
27 | int k;
28 | if (Kinds.TryGetValue(sr.GetType(), out k))
29 | return k;
30 |
31 | k = Interlocked.Increment(ref NextTypeKind);
32 | Kinds[sr.GetType()] = k;
33 | return k;
34 | }
35 |
36 | public static int Kind()
37 | {
38 | int k;
39 | if (Kinds.TryGetValue(typeof(T), out k))
40 | return k;
41 |
42 | k = Interlocked.Increment(ref NextTypeKind);
43 | Kinds[typeof(T)] = k;
44 | return k;
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/DParser2/Dom/Nodes/NodeInterfaces.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | namespace D_Parser.Dom
3 | {
4 | public interface IBlockNode: INode, IEnumerable
5 | {
6 | CodeLocation BlockStartLocation { get; set; }
7 | NodeDictionary Children { get; }
8 |
9 | void Add(INode Node);
10 | void AddRange(IEnumerable Nodes);
11 | int Count { get; }
12 | void Clear();
13 |
14 | IEnumerable this[string Name] { get; }
15 | IEnumerable this[int NameHash] { get; }
16 | }
17 |
18 | public interface INode : ISyntaxRegion, IVisitable
19 | {
20 | string Name { get; set; }
21 | int NameHash { get; set; }
22 | CodeLocation NameLocation { get; set; }
23 | string Description { get; set; }
24 | ITypeDeclaration Type { get; set; }
25 |
26 | new CodeLocation Location { get; set; }
27 | new CodeLocation EndLocation { get; set; }
28 |
29 | ///
30 | /// Assigns a node's properties
31 | ///
32 | ///
33 | void AssignFrom(INode Other);
34 |
35 | INode Parent { get; set; }
36 | INode NodeRoot { get; }
37 |
38 | R Accept(NodeVisitor vis);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/DParser2/Dom/ParserError.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace D_Parser.Dom
3 | {
4 | public class ParserError
5 | {
6 | public readonly bool IsSemantic;
7 | public readonly string Message;
8 | public readonly int Token;
9 | public readonly CodeLocation Location;
10 |
11 | public ParserError(bool IsSemanticError, string Message, int KeyToken, CodeLocation ErrorLocation)
12 | {
13 | IsSemantic = IsSemanticError;
14 | this.Message = Message;
15 | this.Token = KeyToken;
16 | this.Location = ErrorLocation;
17 | }
18 |
19 | public override string ToString()
20 | {
21 | return "[Parse error] " + Message;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/AbstractStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public abstract class AbstractStatement:IStatement
6 | {
7 | public virtual CodeLocation Location { get; set; }
8 |
9 | public virtual CodeLocation EndLocation { get; set; }
10 |
11 | readonly WeakReference parentStmt = new WeakReference(null);
12 | readonly WeakReference parentNode = new WeakReference(null);
13 |
14 | public IStatement Parent
15 | {
16 | get
17 | {
18 | return parentStmt.Target as IStatement;
19 | }
20 | set
21 | {
22 | parentStmt.Target = value;
23 | }
24 | }
25 |
26 | public INode ParentNode
27 | {
28 | get
29 | {
30 | var n = parentNode.Target as INode;
31 | if (n != null)
32 | return n;
33 | var t = parentStmt.Target as IStatement;
34 | if (t != null)
35 | return t.ParentNode;
36 | return null;
37 | }
38 | set
39 | {
40 | var ps = parentStmt.Target as IStatement;
41 | if (ps != null)
42 | ps.ParentNode = value;
43 | else
44 | parentNode.Target = value;
45 | }
46 | }
47 |
48 | public abstract string ToCode();
49 |
50 | public override string ToString()
51 | {
52 | return ToCode();
53 | }
54 |
55 | public abstract void Accept(IStatementVisitor vis);
56 |
57 | public abstract R Accept(StatementVisitor vis);
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/AsmAlignStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public sealed class AsmAlignStatement : AbstractStatement
7 | {
8 | public IExpression ValueExpression { get; set; }
9 |
10 | public override string ToCode()
11 | {
12 | if (ValueExpression == null)
13 | return "align ";
14 | var ie = ValueExpression as ScalarConstantExpression;
15 | if (ie != null && ie.Value.Equals(2m))
16 | return "even";
17 | else
18 | return "align " + ValueExpression.ToString();
19 | }
20 |
21 | public override void Accept(IStatementVisitor vis) { vis.VisitAsmAlignStatement(this); }
22 | public override R Accept(StatementVisitor vis) { return vis.VisitAsmAlignStatement(this); }
23 | }
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/AsmRawDataStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using D_Parser.Dom.Expressions;
4 |
5 | namespace D_Parser.Dom.Statements
6 | {
7 | public sealed class AsmRawDataStatement : AbstractStatement
8 | {
9 | public DataType TypeOfData { get; set; }
10 | public IExpression[] Data { get; set; }
11 |
12 | public enum DataType
13 | {
14 | __UNKNOWN__,
15 |
16 | Byte,
17 | Word,
18 | DWord,
19 | QWord,
20 | Single,
21 | Double,
22 | Real,
23 | }
24 |
25 | public static bool TryParseDataType(string str, out DataType tp)
26 | {
27 | switch (str.ToLower())
28 | {
29 | case "db":
30 | tp = DataType.Byte;
31 | return true;
32 | case "dw":
33 | case "ds":
34 | tp = DataType.Word;
35 | return true;
36 | case "di":
37 | tp = DataType.DWord;
38 | return true;
39 | case "dq":
40 | case "dl":
41 | tp = DataType.QWord;
42 | return true;
43 | case "df":
44 | tp = DataType.Single;
45 | return true;
46 | case "dd":
47 | tp = DataType.Double;
48 | return true;
49 | case "de":
50 | tp = DataType.Real;
51 | return true;
52 | default:
53 | tp = DataType.__UNKNOWN__;
54 | return false;
55 | }
56 | }
57 |
58 | public override string ToCode()
59 | {
60 | var sb = new StringBuilder(Data.Length * 4);
61 | switch (TypeOfData)
62 | {
63 | case DataType.Byte:
64 | sb.Append("db");
65 | break;
66 | case DataType.Word:
67 | sb.Append("ds");
68 | break;
69 | case DataType.DWord:
70 | sb.Append("di");
71 | break;
72 | case DataType.QWord:
73 | sb.Append("dl");
74 | break;
75 | case DataType.Single:
76 | sb.Append("df");
77 | break;
78 | case DataType.Double:
79 | sb.Append("dd");
80 | break;
81 | case DataType.Real:
82 | sb.Append("de");
83 | break;
84 | case DataType.__UNKNOWN__:
85 | sb.Append("");
86 | break;
87 | default:
88 | throw new NotSupportedException();
89 | }
90 |
91 | for (int i = 0; i < Data.Length; i++)
92 | {
93 | if (i > 0)
94 | sb.Append(',');
95 | sb.Append(' ');
96 | sb.Append(Data[i].ToString());
97 | }
98 | return sb.ToString();
99 | }
100 |
101 | public override void Accept(IStatementVisitor vis) { vis.VisitAsmRawDataStatement(this); }
102 | public override R Accept(StatementVisitor vis) { return vis.VisitAsmRawDataStatement(this); }
103 | }
104 | }
105 |
106 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/AsmStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class AsmStatement : StatementContainingStatement
7 | {
8 | public bool Naked { get; set; }
9 | public AbstractStatement[] Instructions;
10 |
11 | public override string ToCode()
12 | {
13 | var ret = "asm {";
14 |
15 | if (Instructions != null && Instructions.Length > 0)
16 | {
17 | foreach (var i in Instructions)
18 | ret += Environment.NewLine + i.ToCode() + ';';
19 | ret += Environment.NewLine;
20 | }
21 |
22 | return ret + '}';
23 | }
24 |
25 | public override IEnumerable SubStatements { get { return Instructions; } }
26 |
27 | public override void Accept(IStatementVisitor vis) { vis.VisitAsmStatement(this); }
28 | public override R Accept(StatementVisitor vis) { return vis.VisitAsmStatement(this); }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/BlockStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class BlockStatement : StatementContainingStatement, IEnumerable
7 | {
8 | internal readonly List _Statements = new List();
9 |
10 | public IEnumerator GetEnumerator()
11 | {
12 | return _Statements.GetEnumerator();
13 | }
14 |
15 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
16 | {
17 | return _Statements.GetEnumerator();
18 | }
19 |
20 | public override string ToCode()
21 | {
22 | var ret = "{" + Environment.NewLine;
23 |
24 | foreach (var s in _Statements)
25 | ret += s.ToCode() + Environment.NewLine;
26 |
27 | return ret + "}";
28 | }
29 |
30 | public void Add(IStatement s)
31 | {
32 | if (s == null)
33 | return;
34 | s.Parent = this;
35 | _Statements.Add(s);
36 | }
37 |
38 | public override IEnumerable SubStatements
39 | {
40 | get
41 | {
42 | return _Statements;
43 | }
44 | }
45 |
46 | public override void Accept(IStatementVisitor vis)
47 | {
48 | vis.Visit(this);
49 | }
50 |
51 | public override R Accept(StatementVisitor vis)
52 | {
53 | return vis.Visit(this);
54 | }
55 |
56 | public override string ToString()
57 | {
58 | return " " + base.ToString();
59 | }
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/BreakStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class BreakStatement : AbstractStatement,IExpressionContainingStatement
7 | {
8 | public int IdentifierHash;
9 |
10 | public string Identifier
11 | {
12 | get{ return Strings.TryGet(IdentifierHash); }
13 | set
14 | {
15 | Strings.Add(value);
16 | IdentifierHash = value != null ? value.GetHashCode() : 0;
17 | }
18 | }
19 |
20 | public override string ToCode()
21 | {
22 | return "break" + (string.IsNullOrEmpty(Identifier) ? "" : (' ' + Identifier)) + ';';
23 | }
24 |
25 | public IExpression[] SubExpressions
26 | {
27 | get { return string.IsNullOrEmpty(Identifier) ? null : new[] { new IdentifierExpression(Identifier) }; }
28 | }
29 |
30 | public override void Accept(IStatementVisitor vis)
31 | {
32 | vis.Visit(this);
33 | }
34 |
35 | public override R Accept(StatementVisitor vis)
36 | {
37 | return vis.Visit(this);
38 | }
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ContinueStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ContinueStatement : AbstractStatement, IExpressionContainingStatement
7 | {
8 | public int IdentifierHash;
9 |
10 | public string Identifier
11 | {
12 | get{ return Strings.TryGet(IdentifierHash); }
13 | set
14 | {
15 | Strings.Add(value);
16 | IdentifierHash = value != null ? value.GetHashCode() : 0;
17 | }
18 | }
19 |
20 | public override string ToCode()
21 | {
22 | return "continue" + (string.IsNullOrEmpty(Identifier) ? "" : (' ' + Identifier)) + ';';
23 | }
24 |
25 | public IExpression[] SubExpressions
26 | {
27 | get { return string.IsNullOrEmpty(Identifier) ? null : new[] { new IdentifierExpression(Identifier) }; }
28 | }
29 |
30 | public override void Accept(IStatementVisitor vis)
31 | {
32 | vis.Visit(this);
33 | }
34 |
35 | public override R Accept(StatementVisitor vis)
36 | {
37 | return vis.Visit(this);
38 | }
39 | }
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ContractStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ContractStatement : StatementContainingStatement, IExpressionContainingStatement
7 | {
8 | public IExpression Condition;
9 | public IExpression Message;
10 | public bool isOut; // true for Out
11 | public IdentifierDeclaration OutResultVariable;
12 |
13 | public override string ToCode()
14 | {
15 | string s = isOut ? "out" : "in";
16 | if (Condition != null)
17 | {
18 | s += "(";
19 | if (OutResultVariable != null)
20 | s += OutResultVariable.ToString();
21 | if (isOut)
22 | s += ";";
23 | s += Condition.ToString();
24 | if (Message != null)
25 | s += "," + Message.ToString();
26 | s += ")";
27 | }
28 | else if (ScopedStatement != null)
29 | {
30 | if (OutResultVariable != null)
31 | s += "(" + OutResultVariable.ToString() + ")";
32 | s += Environment.NewLine + ScopedStatement.ToString();
33 | }
34 | return s;
35 | }
36 |
37 | public IExpression[] SubExpressions
38 | {
39 | get {
40 | if (Condition != null && Message != null)
41 | return new[] { Condition, Message };
42 | if (Condition != null)
43 | return new[] { Condition };
44 | return new Expression[0];
45 | }
46 | }
47 |
48 | public override void Accept(IStatementVisitor vis)
49 | {
50 | vis.Visit(this);
51 | }
52 |
53 | public override R Accept(StatementVisitor vis)
54 | {
55 | return vis.Visit(this);
56 | }
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/DebugSpecificiation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public class DebugSpecification : AbstractStatement, StaticStatement
6 | {
7 | public string SpecifiedId;
8 | public ulong SpecifiedDebugLevel;
9 |
10 | public override string ToCode()
11 | {
12 | return "debug = " + (SpecifiedId ?? SpecifiedDebugLevel.ToString()) + ";";
13 | }
14 |
15 | public override void Accept(IStatementVisitor vis)
16 | {
17 | vis.Visit(this);
18 | }
19 |
20 | public override R Accept(StatementVisitor vis)
21 | {
22 | return vis.Visit(this);
23 | }
24 |
25 | public DAttribute[] Attributes
26 | {
27 | get;
28 | set;
29 | }
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/DeclarationStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 | using System.Collections.Generic;
4 |
5 | namespace D_Parser.Dom.Statements
6 | {
7 | public class DeclarationStatement : AbstractStatement,IDeclarationContainingStatement
8 | {
9 | ///
10 | /// Declarations done by this statement. Contains more than one item e.g. on int a,b,c;
11 | ///
12 | //public INode[] Declaration;
13 |
14 | public override string ToCode()
15 | {
16 | if (Declarations == null || Declarations.Length < 1)
17 | return ";";
18 |
19 | var r = Declarations[0].ToString();
20 |
21 | for (int i = 1; i < Declarations.Length; i++)
22 | {
23 | var d = Declarations[i];
24 | r += ',' + d.Name;
25 |
26 | var dv = d as DVariable;
27 | if (dv != null && dv.Initializer != null)
28 | r += '=' + dv.Initializer.ToString();
29 | }
30 |
31 | return r + ';';
32 | }
33 |
34 | public INode[] Declarations
35 | {
36 | get;
37 | set;
38 | }
39 |
40 | public override void Accept(IStatementVisitor vis)
41 | {
42 | vis.Visit(this);
43 | }
44 |
45 | public override R Accept(StatementVisitor vis)
46 | {
47 | return vis.Visit(this);
48 | }
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ExpressionStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ExpressionStatement : AbstractStatement,IExpressionContainingStatement
7 | {
8 | public IExpression Expression;
9 |
10 | public override string ToCode()
11 | {
12 | return Expression.ToString() + ';';
13 | }
14 |
15 | public IExpression[] SubExpressions
16 | {
17 | get { return new[]{ Expression }; }
18 | }
19 |
20 | public override void Accept(IStatementVisitor vis)
21 | {
22 | vis.Visit(this);
23 | }
24 |
25 | public override R Accept(StatementVisitor vis)
26 | {
27 | return vis.Visit(this);
28 | }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ForStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 | using System.Collections.Generic;
4 |
5 | namespace D_Parser.Dom.Statements
6 | {
7 | public class ForStatement : StatementContainingStatement, IExpressionContainingStatement
8 | {
9 | public IStatement Initialize;
10 | public IExpression Test;
11 | public IExpression Increment;
12 |
13 | public IExpression[] SubExpressions
14 | {
15 | get { return new[] { Test, Increment }; }
16 | }
17 |
18 | public override IEnumerable SubStatements
19 | {
20 | get
21 | {
22 | if (Initialize != null)
23 | yield return Initialize;
24 | if (ScopedStatement != null)
25 | yield return ScopedStatement;
26 | }
27 | }
28 |
29 | public override string ToCode()
30 | {
31 | var ret = "for(";
32 |
33 | if (Initialize != null)
34 | ret += Initialize.ToCode();
35 |
36 | ret += ';';
37 |
38 | if (Test != null)
39 | ret += Test.ToString();
40 |
41 | ret += ';';
42 |
43 | if (Increment != null)
44 | ret += Increment.ToString();
45 |
46 | ret += ')';
47 |
48 | if (ScopedStatement != null)
49 | ret += ' ' + ScopedStatement.ToCode();
50 |
51 | return ret;
52 | }
53 |
54 | public override void Accept(IStatementVisitor vis)
55 | {
56 | vis.Visit(this);
57 | }
58 |
59 | public override R Accept(StatementVisitor vis)
60 | {
61 | return vis.Visit(this);
62 | }
63 | }
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ForeachStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ForeachStatement : StatementContainingStatement, IExpressionContainingStatement, IDeclarationContainingStatement
7 | {
8 | public bool IsRangeStatement
9 | {
10 | get { return UpperAggregate != null; }
11 | }
12 |
13 | public bool IsReverse = false;
14 | public DVariable[] ForeachTypeList;
15 |
16 | public INode[] Declarations
17 | {
18 | get { return ForeachTypeList; }
19 | }
20 |
21 | public IExpression Aggregate;
22 | ///
23 | /// Used in ForeachRangeStatements. The Aggregate field will be the lower expression then.
24 | ///
25 | public IExpression UpperAggregate;
26 |
27 | public IExpression[] SubExpressions
28 | {
29 | get
30 | {
31 | if (Aggregate != null)
32 | {
33 | if (UpperAggregate == null)
34 | return new[]{ Aggregate };
35 | return new[]{ Aggregate, UpperAggregate };
36 | }
37 | if (UpperAggregate != null)
38 | return new[]{ UpperAggregate };
39 | return new IExpression[0];
40 | }
41 | }
42 |
43 | public override string ToCode()
44 | {
45 | var ret = (IsReverse ? "foreach_reverse" : "foreach") + '(';
46 |
47 | if (ForeachTypeList != null)
48 | {
49 | foreach (var v in ForeachTypeList)
50 | ret += v.ToString() + ',';
51 |
52 | ret = ret.TrimEnd(',') + ';';
53 | }
54 |
55 | if (Aggregate != null)
56 | ret += Aggregate.ToString();
57 |
58 | if (UpperAggregate != null)
59 | ret += ".." + UpperAggregate.ToString();
60 |
61 | ret += ')';
62 |
63 | if (ScopedStatement != null)
64 | ret += ' ' + ScopedStatement.ToCode();
65 |
66 | return ret;
67 | }
68 |
69 | public override void Accept(IStatementVisitor vis)
70 | {
71 | vis.Visit(this);
72 | }
73 |
74 | public override R Accept(StatementVisitor vis)
75 | {
76 | return vis.Visit(this);
77 | }
78 | }
79 | }
80 |
81 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/GotoStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Parser;
3 | using D_Parser.Dom.Expressions;
4 |
5 | namespace D_Parser.Dom.Statements
6 | {
7 | public class GotoStatement : AbstractStatement, IExpressionContainingStatement
8 | {
9 | public enum GotoStmtType : byte
10 | {
11 | Identifier = DTokens.Identifier,
12 | Case = DTokens.Case,
13 | Default = DTokens.Default
14 | }
15 |
16 | public int LabelIdentifierHash;
17 |
18 | public string LabelIdentifier
19 | {
20 | get{ return Strings.TryGet(LabelIdentifierHash); }
21 | set
22 | {
23 | Strings.Add(value);
24 | LabelIdentifierHash = value != null ? value.GetHashCode() : 0;
25 | }
26 | }
27 |
28 | public IExpression CaseExpression;
29 | public GotoStmtType StmtType = GotoStmtType.Identifier;
30 |
31 | public override string ToCode()
32 | {
33 | switch (StmtType)
34 | {
35 | case GotoStmtType.Identifier:
36 | return "goto " + LabelIdentifier + ';';
37 | case GotoStmtType.Default:
38 | return "goto default;";
39 | case GotoStmtType.Case:
40 | return "goto" + (CaseExpression == null ? "" : (' ' + CaseExpression.ToString())) + ';';
41 | }
42 |
43 | return null;
44 | }
45 |
46 | public IExpression[] SubExpressions
47 | {
48 | get { return CaseExpression != null ? new[] { CaseExpression } : null; }
49 | }
50 |
51 | public override void Accept(IStatementVisitor vis)
52 | {
53 | vis.Visit(this);
54 | }
55 |
56 | public override R Accept(StatementVisitor vis)
57 | {
58 | return vis.Visit(this);
59 | }
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/IDeclarationContainingStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public interface IDeclarationContainingStatement : IStatement
6 | {
7 | INode[] Declarations { get; }
8 | }
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/IExpressionContainingStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public interface IExpressionContainingStatement : IStatement
7 | {
8 | IExpression[] SubExpressions { get; }
9 | }
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/IStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public interface IStatement : ISyntaxRegion, IVisitable
6 | {
7 | new CodeLocation Location { get; set; }
8 |
9 | new CodeLocation EndLocation { get; set; }
10 |
11 | IStatement Parent { get; set; }
12 |
13 | INode ParentNode { get; set; }
14 |
15 | string ToCode();
16 |
17 | R Accept(StatementVisitor vis);
18 | }
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/IfStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 | using System.Collections.Generic;
4 | using System.Text;
5 |
6 | namespace D_Parser.Dom.Statements
7 | {
8 | public class IfStatement : StatementContainingStatement,IDeclarationContainingStatement,IExpressionContainingStatement
9 | {
10 | public IExpression IfCondition;
11 | public DVariable IfVariable;
12 |
13 | public IStatement ThenStatement
14 | {
15 | get { return ScopedStatement; }
16 | set { ScopedStatement = value; }
17 | }
18 |
19 | public IStatement ElseStatement;
20 |
21 | public override IEnumerable SubStatements
22 | {
23 | get
24 | {
25 | if (ThenStatement != null)
26 | yield return ThenStatement;
27 | if (ElseStatement != null)
28 | yield return ElseStatement;
29 | }
30 | }
31 |
32 | public override CodeLocation EndLocation
33 | {
34 | get
35 | {
36 | if (ScopedStatement == null)
37 | return base.EndLocation;
38 | return ElseStatement != null ? ElseStatement.EndLocation : ScopedStatement.EndLocation;
39 | }
40 | set
41 | {
42 | if (ScopedStatement == null)
43 | base.EndLocation = value;
44 | }
45 | }
46 |
47 | public override string ToCode()
48 | {
49 | var sb = new StringBuilder("if(");
50 |
51 | if (IfCondition != null)
52 | sb.Append(IfCondition.ToString());
53 | else if (IfVariable != null)
54 | sb.Append(IfVariable.ToString(true, false, true));
55 |
56 | sb.AppendLine(")");
57 |
58 | if (ScopedStatement != null)
59 | sb.Append(ScopedStatement.ToCode());
60 |
61 | if (ElseStatement != null)
62 | sb.AppendLine().Append("else ").Append(ElseStatement.ToCode());
63 |
64 | return sb.ToString();
65 | }
66 |
67 | public IExpression[] SubExpressions
68 | {
69 | get
70 | {
71 | return new[] { IfCondition };
72 | }
73 | }
74 |
75 | public INode[] Declarations
76 | {
77 | get
78 | {
79 | return IfVariable == null ? null : new[]{ IfVariable };
80 | }
81 | }
82 |
83 | public override void Accept(IStatementVisitor vis)
84 | {
85 | vis.Visit(this);
86 | }
87 |
88 | public override R Accept(StatementVisitor vis)
89 | {
90 | return vis.Visit(this);
91 | }
92 | }
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/LabeledStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public class LabeledStatement : AbstractStatement
6 | {
7 | public int IdentifierHash;
8 |
9 | public string Identifier
10 | {
11 | get{ return Strings.TryGet(IdentifierHash); }
12 | set
13 | {
14 | Strings.Add(value);
15 | IdentifierHash = value != null ? value.GetHashCode() : 0;
16 | }
17 | }
18 |
19 | public override string ToCode()
20 | {
21 | return Identifier + ":";
22 | }
23 |
24 | public override void Accept(IStatementVisitor vis)
25 | {
26 | vis.Visit(this);
27 | }
28 |
29 | public override R Accept(StatementVisitor vis)
30 | {
31 | return vis.Visit(this);
32 | }
33 | }
34 | }
35 |
36 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/MixinStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class MixinStatement : AbstractStatement,IExpressionContainingStatement,StaticStatement
7 | {
8 | public IExpression MixinExpression;
9 |
10 | public override string ToCode()
11 | {
12 | return "mixin(" + (MixinExpression == null ? "" : MixinExpression.ToString()) + ");";
13 | }
14 |
15 | public IExpression[] SubExpressions
16 | {
17 | get { return new[]{ MixinExpression }; }
18 | }
19 |
20 | public override void Accept(IStatementVisitor vis)
21 | {
22 | vis.VisitMixinStatement(this);
23 | }
24 |
25 | public override R Accept(StatementVisitor vis)
26 | {
27 | return vis.VisitMixinStatement(this);
28 | }
29 |
30 | public DAttribute[] Attributes{ get; set; }
31 | }
32 | }
33 |
34 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/PragmaStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class PragmaStatement : StatementContainingStatement
7 | {
8 | public PragmaAttribute Pragma;
9 |
10 | public override string ToCode()
11 | {
12 | var r = Pragma == null ? "" : Pragma.ToString();
13 |
14 | r += ScopedStatement == null ? "" : (" " + ScopedStatement.ToCode());
15 |
16 | return r;
17 | }
18 |
19 | public override void Accept(IStatementVisitor vis)
20 | {
21 | vis.Visit(this);
22 | }
23 |
24 | public override R Accept(StatementVisitor vis)
25 | {
26 | return vis.Visit(this);
27 | }
28 | }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ReturnStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ReturnStatement : AbstractStatement,IExpressionContainingStatement
7 | {
8 | public IExpression ReturnExpression;
9 |
10 | public override string ToCode()
11 | {
12 | return "return" + (ReturnExpression == null ? "" : (' ' + ReturnExpression.ToString())) + ';';
13 | }
14 |
15 | public IExpression[] SubExpressions
16 | {
17 | get { return new[]{ ReturnExpression }; }
18 | }
19 |
20 | public override void Accept(IStatementVisitor vis)
21 | {
22 | vis.Visit(this);
23 | }
24 |
25 | public override R Accept(StatementVisitor vis)
26 | {
27 | return vis.Visit(this);
28 | }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ScopeGuardStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public class ScopeGuardStatement : StatementContainingStatement
6 | {
7 | public const string ExitScope = "exit";
8 | public const string SuccessScope = "success";
9 | public const string FailureScope = "failure";
10 | public string GuardedScope = ExitScope;
11 |
12 | public override string ToCode()
13 | {
14 | return "scope(" + GuardedScope + ')' + (ScopedStatement == null ? "" : ScopedStatement.ToCode());
15 | }
16 |
17 | public override void Accept(IStatementVisitor vis)
18 | {
19 | vis.Visit(this);
20 | }
21 |
22 | public override R Accept(StatementVisitor vis)
23 | {
24 | return vis.Visit(this);
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/StatementCondition.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text;
3 | using System.Collections.Generic;
4 | using D_Parser.Dom.Expressions;
5 |
6 | namespace D_Parser.Dom.Statements
7 | {
8 | public class StatementCondition : StatementContainingStatement
9 | {
10 | public IStatement ElseStatement;
11 | public DeclarationCondition Condition;
12 |
13 | public override string ToCode()
14 | {
15 | var sb = new StringBuilder("if(");
16 |
17 | if (Condition != null)
18 | sb.Append(Condition.ToString());
19 | sb.AppendLine(")");
20 |
21 | if (ElseStatement != null)
22 | sb.Append(ElseStatement);
23 |
24 | return sb.ToString();
25 | }
26 |
27 | public override IEnumerable SubStatements
28 | {
29 | get
30 | {
31 | if (ElseStatement != null)
32 | yield return ElseStatement;
33 | if (ScopedStatement != null)
34 | yield return ScopedStatement;
35 | }
36 | }
37 |
38 | public override void Accept(IStatementVisitor vis)
39 | {
40 | vis.Visit(this);
41 | }
42 |
43 | public override R Accept(StatementVisitor vis)
44 | {
45 | return vis.Visit(this);
46 | }
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/StatementContainingStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | ///
7 | /// Represents a statement that can contain other statements, which may become scoped.
8 | ///
9 | public abstract class StatementContainingStatement : AbstractStatement
10 | {
11 | public virtual IStatement ScopedStatement { get; set; }
12 |
13 | public virtual IEnumerable SubStatements { get { return ScopedStatement != null ? new[] { ScopedStatement } : new IStatement[0]; } }
14 | }
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/StaticAssertStatement.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom.Expressions;
2 | using System;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class StaticAssertStatement : AbstractStatement, IExpressionContainingStatement, StaticStatement
7 | {
8 | public IExpression AssertedExpression;
9 | public IExpression Message;
10 |
11 | public override string ToCode()
12 | {
13 | return "static assert(" + (AssertedExpression != null ? AssertedExpression.ToString() : "") +
14 | (Message == null ? "" : ("," + Message)) + ");";
15 | }
16 |
17 | public IExpression[] SubExpressions
18 | {
19 | get { return new[] { AssertedExpression }; }
20 | }
21 |
22 | public DAttribute[] Attributes
23 | {
24 | get;
25 | set;
26 | }
27 |
28 | public override void Accept(IStatementVisitor vis)
29 | {
30 | vis.Visit(this);
31 | }
32 |
33 | public override R Accept(StatementVisitor vis)
34 | {
35 | return vis.Visit(this);
36 | }
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/StaticForeachStatement.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom.Expressions;
2 | using System;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class StaticForeachStatement : ForeachStatement, StaticStatement
7 | {
8 | public DAttribute[] Attributes { get; set; }
9 |
10 | public bool inSemanticAnalysis = false;
11 |
12 | public override string ToCode()
13 | {
14 | return "static " + base.ToCode();
15 | }
16 |
17 | public override void Accept(IStatementVisitor vis)
18 | {
19 | vis.Visit(this);
20 | }
21 |
22 | public override R Accept(StatementVisitor vis)
23 | {
24 | return vis.Visit(this);
25 | }
26 | }
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/SynchronizedStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class SynchronizedStatement : StatementContainingStatement,IExpressionContainingStatement
7 | {
8 | public IExpression SyncExpression;
9 |
10 | public override string ToCode()
11 | {
12 | var ret = "synchronized";
13 |
14 | if (SyncExpression != null)
15 | ret += '(' + SyncExpression.ToString() + ')';
16 |
17 | if (ScopedStatement != null)
18 | ret += ' ' + ScopedStatement.ToCode();
19 |
20 | return ret;
21 | }
22 |
23 | public IExpression[] SubExpressions
24 | {
25 | get { return new[]{ SyncExpression }; }
26 | }
27 |
28 | public override void Accept(IStatementVisitor vis)
29 | {
30 | vis.Visit(this);
31 | }
32 |
33 | public override R Accept(StatementVisitor vis)
34 | {
35 | return vis.Visit(this);
36 | }
37 | }
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/TemplateMixin.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 | using System.Collections.Generic;
4 |
5 | namespace D_Parser.Dom.Statements
6 | {
7 | public class TemplateMixin : AbstractStatement, StaticStatement
8 | {
9 | public ITypeDeclaration Qualifier;
10 | public string MixinId;
11 | public CodeLocation IdLocation;
12 |
13 | public override string ToCode()
14 | {
15 | var r = "mixin";
16 |
17 | if (Qualifier != null)
18 | r += " " + Qualifier.ToString();
19 |
20 | if (!string.IsNullOrEmpty(MixinId))
21 | r += ' ' + MixinId;
22 |
23 | return r + ';';
24 | }
25 |
26 | public override void Accept(IStatementVisitor vis)
27 | {
28 | vis.Visit(this);
29 | }
30 |
31 | public override R Accept(StatementVisitor vis)
32 | {
33 | return vis.Visit(this);
34 | }
35 |
36 | public DAttribute[] Attributes
37 | {
38 | get;
39 | set;
40 | }
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/ThrowStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class ThrowStatement : AbstractStatement,IExpressionContainingStatement
7 | {
8 | public IExpression ThrowExpression;
9 |
10 | public override string ToCode()
11 | {
12 | return "throw" + (ThrowExpression == null ? "" : (' ' + ThrowExpression.ToString())) + ';';
13 | }
14 |
15 | public IExpression[] SubExpressions
16 | {
17 | get { return new[]{ ThrowExpression }; }
18 | }
19 |
20 | public override void Accept(IStatementVisitor vis)
21 | {
22 | vis.Visit(this);
23 | }
24 |
25 | public override R Accept(StatementVisitor vis)
26 | {
27 | return vis.Visit(this);
28 | }
29 | }
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/VersionSpecification.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public class VersionSpecification : AbstractStatement, StaticStatement
6 | {
7 | public string SpecifiedId;
8 | public ulong SpecifiedNumber;
9 |
10 | public override string ToCode()
11 | {
12 | return "version = " + (SpecifiedId ?? SpecifiedNumber.ToString()) + ";";
13 | }
14 |
15 | public override void Accept(IStatementVisitor vis)
16 | {
17 | vis.Visit(this);
18 | }
19 |
20 | public override R Accept(StatementVisitor vis)
21 | {
22 | return vis.Visit(this);
23 | }
24 |
25 | public DAttribute[] Attributes
26 | {
27 | get;
28 | set;
29 | }
30 | }
31 | }
32 |
33 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/VolatileStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Dom.Statements
4 | {
5 | public class VolatileStatement : StatementContainingStatement
6 | {
7 | public override string ToCode()
8 | {
9 | return "volatile " + (ScopedStatement == null ? "" : ScopedStatement.ToCode());
10 | }
11 |
12 | public override void Accept(IStatementVisitor vis)
13 | {
14 | vis.Visit(this);
15 | }
16 |
17 | public override R Accept(StatementVisitor vis)
18 | {
19 | return vis.Visit(this);
20 | }
21 | }
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/WhileStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class WhileStatement : StatementContainingStatement, IExpressionContainingStatement
7 | {
8 | public IExpression Condition;
9 |
10 | public override CodeLocation EndLocation
11 | {
12 | get
13 | {
14 | if (ScopedStatement == null)
15 | return base.EndLocation;
16 | return ScopedStatement.EndLocation;
17 | }
18 | set
19 | {
20 | if (ScopedStatement == null)
21 | base.EndLocation = value;
22 | }
23 | }
24 |
25 | public override string ToCode()
26 | {
27 | var ret = "while(";
28 |
29 | if (Condition != null)
30 | ret += Condition.ToString();
31 |
32 | ret += ") " + Environment.NewLine;
33 |
34 | if (ScopedStatement != null)
35 | ret += ScopedStatement.ToCode();
36 |
37 | return ret;
38 | }
39 |
40 | public IExpression[] SubExpressions
41 | {
42 | get { return new[]{ Condition }; }
43 | }
44 |
45 | public override void Accept(IStatementVisitor vis)
46 | {
47 | vis.Visit(this);
48 | }
49 |
50 | public override R Accept(StatementVisitor vis)
51 | {
52 | return vis.Visit(this);
53 | }
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/DParser2/Dom/Statements/WithStatement.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using D_Parser.Dom.Expressions;
3 |
4 | namespace D_Parser.Dom.Statements
5 | {
6 | public class WithStatement : StatementContainingStatement, IExpressionContainingStatement
7 | {
8 | public IExpression WithExpression;
9 | public ITypeDeclaration WithSymbol;
10 |
11 | public override string ToCode()
12 | {
13 | var ret = "with(";
14 |
15 | if (WithExpression != null)
16 | ret += WithExpression.ToString();
17 | else if (WithSymbol != null)
18 | ret += WithSymbol.ToString();
19 |
20 | ret += ')';
21 |
22 | if (ScopedStatement != null)
23 | ret += ScopedStatement.ToCode();
24 |
25 | return ret;
26 | }
27 |
28 | public IExpression[] SubExpressions
29 | {
30 | get
31 | {
32 | return new[] { WithExpression };
33 | }
34 | }
35 |
36 | public override void Accept(IStatementVisitor vis)
37 | {
38 | vis.Visit(this);
39 | }
40 |
41 | public override R Accept(StatementVisitor vis)
42 | {
43 | return vis.Visit(this);
44 | }
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/DParser2/Dom/StaticStatement.cs:
--------------------------------------------------------------------------------
1 | using D_Parser.Dom.Statements;
2 |
3 | namespace D_Parser.Dom
4 | {
5 | public interface StaticStatement : IStatement
6 | {
7 | DAttribute[] Attributes { get; set; }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/DParser2/Dom/Visitors/IVisitable.cs:
--------------------------------------------------------------------------------
1 | namespace D_Parser.Dom
2 | {
3 | public interface IVisitable where Visitor : IVisitor
4 | {
5 | void Accept(Visitor vis);
6 | //R Accept(RetVisitor vis);
7 | }
8 | /*
9 | public interface IVisitiable_Return where Visitor : IVisitor
10 | {
11 | R Accept(IVisitor vis);
12 | }*/
13 | }
14 |
--------------------------------------------------------------------------------
/DParser2/Formatting/Formatter.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 | using D_Parser.Dom;
3 | using D_Parser.Parser;
4 |
5 | namespace D_Parser.Formatting
6 | {
7 | public static class Formatter
8 | {
9 | public static string FormatCode(string code, DModule ast = null, IDocumentAdapter document = null, DFormattingOptions options = null, ITextEditorOptions textStyle = null)
10 | {
11 | options = options ?? DFormattingOptions.CreateDStandard();
12 | textStyle = textStyle ?? TextEditorOptions.Default;
13 | ast = ast ?? DParser.ParseString(code) as DModule;
14 |
15 | var formattingVisitor = new DFormattingVisitor(options, document ?? new TextDocument{ Text = code }, ast, textStyle);
16 |
17 | formattingVisitor.WalkThroughAst();
18 |
19 | var sb = new StringBuilder(code);
20 |
21 | formattingVisitor.ApplyChanges((int start, int length, string insertedText) => {
22 | sb.Remove(start,length);
23 | sb.Insert(start,insertedText);
24 | });
25 |
26 | return sb.ToString();
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/DParser2/Formatting/ITextEditorOptions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace D_Parser.Formatting
4 | {
5 | public interface ITextEditorOptions
6 | {
7 | string EolMarker {get;}
8 | bool TabsToSpaces {get;}
9 | int TabSize{get;}
10 | bool KeepAlignmentSpaces { get; }
11 |
12 | int IndentSize {get;}
13 | int ContinuationIndent {get;}
14 | int LabelIndent {get;}
15 |
16 | bool RemoveTrailingWhitespaces { get; }
17 | }
18 |
19 | public class TextEditorOptions : ITextEditorOptions
20 | {
21 | public string EolMarker {get;set;}
22 | public bool TabsToSpaces {get;set;}
23 | public int TabSize {get;set;}
24 | public int IndentSize {get;set;}
25 | public int ContinuationIndent {get;set;}
26 | public int LabelIndent {get;set;}
27 | public bool KeepAlignmentSpaces { get; set; }
28 | public bool RemoveTrailingWhitespaces { get; set; }
29 |
30 | public static TextEditorOptions Default = new TextEditorOptions{
31 | EolMarker = Environment.NewLine,
32 | TabsToSpaces = false,
33 | TabSize = 4,
34 | IndentSize = 4,
35 | ContinuationIndent = 4,
36 | LabelIndent = 0,
37 | KeepAlignmentSpaces = true,
38 | RemoveTrailingWhitespaces = false};
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/DParser2/Formatting/Indent/IStateMachineIndentEngine.cs:
--------------------------------------------------------------------------------
1 | //
2 | // IStateMachineIndentEngine.cs
3 | //
4 | // Author:
5 | // Alexander Bothe
6 | //
7 | // Copyright (c) 2014 Alexander Bothe
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | using System;
27 |
28 | namespace D_Parser.Formatting.Indent
29 | {
30 | interface IStateMachineIndentEngine : IDocumentIndentEngine
31 | {
32 | Inside Inside {get;}
33 |
34 | new IStateMachineIndentEngine Clone();
35 | }
36 | }
37 |
38 |
--------------------------------------------------------------------------------
/DParser2/Misc/Logger.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace D_Parser.Misc
5 | {
6 | public class Logger
7 | {
8 | public static readonly List Loggers = new List();
9 |
10 | static Logger()
11 | {
12 | Loggers.Add (new ConsoleLogger());
13 | }
14 |
15 | public static void Log(LogLevel lvl, string msg, Exception ex = null)
16 | {
17 | foreach (var l in Loggers)
18 | l.Log (lvl, msg, ex);
19 | }
20 |
21 | public static void LogError(string msg, Exception ex = null)
22 | {
23 | Log (LogLevel.Error, msg, ex);
24 | }
25 |
26 | public static void LogWarn(string msg, Exception ex = null)
27 | {
28 | Log (LogLevel.Warn, msg, ex);
29 | }
30 | }
31 |
32 | class ConsoleLogger : ILogger
33 | {
34 | public void Log (LogLevel lvl, string msg, Exception ex)
35 | {
36 | switch (lvl) {
37 | case LogLevel.Debug:
38 | Console.Write ("Debug: ");
39 | break;
40 | case LogLevel.Error:
41 | Console.Write ("Error: ");
42 | break;
43 | case LogLevel.Fatal:
44 | Console.Write ("Fatal error: ");
45 | break;
46 | case LogLevel.Info:
47 | Console.Write ("Info: ");
48 | break;
49 | case LogLevel.Warn:
50 | Console.Write ("Warning: ");
51 | break;
52 | }
53 |
54 | if (msg != null)
55 | Console.Write (msg);
56 |
57 | if (ex != null) {
58 | Console.WriteLine ();
59 | Console.WriteLine (ex.Message);
60 | Console.Write (ex.StackTrace);
61 | }
62 |
63 | Console.WriteLine ();
64 | }
65 |
66 | public LogLevel EnabledLogLevel {
67 | get {
68 | return LogLevel.Info;
69 | }
70 | }
71 |
72 | public string Name {
73 | get {
74 | return "Console";
75 | }
76 | }
77 | }
78 |
79 | public interface ILogger
80 | {
81 | LogLevel EnabledLogLevel { get;}
82 | string Name {get;}
83 | void Log(LogLevel lvl, string msg, Exception ex);
84 | }
85 |
86 | public enum LogLevel
87 | {
88 | Fatal = 1,
89 | Error,
90 | Warn = 4,
91 | Info = 8,
92 | Debug = 16
93 | }
94 | }
95 |
96 |
--------------------------------------------------------------------------------
/DParser2/Misc/Mangling/Mangler.cs:
--------------------------------------------------------------------------------
1 | //
2 | // Mangler.cs - D mangling helper. For a spec, see http://dlang.org/abi.html
3 | //
4 | // Author:
5 | // Alexander Bothe
6 | //
7 | // Copyright (c) 2013 Alexander Bothe
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | using System.Text;
27 |
28 | using D_Parser.Dom;
29 | namespace D_Parser.Misc.Mangling
30 | {
31 | public class Mangler
32 | {
33 | public Mangler ()
34 | {
35 | }
36 |
37 | public static string Mangle(ITypeDeclaration td)
38 | {
39 | var sb = new StringBuilder ();
40 | Mangle (td, sb);
41 | return sb.ToString ();
42 | }
43 |
44 | static void Mangle(ITypeDeclaration td, StringBuilder sb)
45 | {
46 |
47 | }
48 | }
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/DParser2/Misc/ModuleNameHelper.cs:
--------------------------------------------------------------------------------
1 |
2 | namespace D_Parser.Misc
3 | {
4 | public static class ModuleNameHelper
5 | {
6 | ///
7 | /// a.b.c.d => a.b.c
8 | ///
9 | public static string ExtractPackageName(string ModuleName)
10 | {
11 | if (string.IsNullOrEmpty(ModuleName))
12 | return "";
13 |
14 | var i = ModuleName.LastIndexOf('.');
15 |
16 | return i == -1 ? "" : ModuleName.Substring(0, i);
17 | }
18 |
19 | ///
20 | /// a.b.c.d => d
21 | ///
22 | public static string ExtractModuleName(string ModuleName)
23 | {
24 | if (string.IsNullOrEmpty(ModuleName))
25 | return "";
26 |
27 | var i = ModuleName.LastIndexOf('.');
28 |
29 | return i == -1 ? ModuleName : ModuleName.Substring(i + 1);
30 | }
31 |
32 | public static string[] SplitModuleName(string ModuleName)
33 | {
34 | return ModuleName.Split('.');
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/DParser2/Misc/ParseLog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.IO;
6 | using D_Parser.Dom;
7 |
8 | namespace D_Parser.Misc
9 | {
10 | #if IGNORE
11 | public class ParseLog
12 | {
13 | StreamWriter sw;
14 | bool hadErrors;
15 |
16 | public static void Write(ParseCache cache, string outputLog)
17 | {
18 | var ms = new MemoryStream(32000);
19 |
20 | var pl = new ParseLog(ms);
21 |
22 | pl.Write(cache);
23 |
24 | if (File.Exists(outputLog))
25 | File.Delete(outputLog);
26 |
27 | File.WriteAllBytes(outputLog, ms.ToArray());
28 | ms.Close();
29 | }
30 |
31 | public ParseLog(Stream s)
32 | {
33 | sw = new StreamWriter(s, System.Text.Encoding.Unicode) { AutoFlush=false };
34 | }
35 |
36 | ~ParseLog()
37 | {
38 | sw.Close();
39 | }
40 |
41 | public void Write(ParseCache cache)
42 | {
43 | sw.WriteLine("Parser error log");
44 | sw.WriteLine();
45 |
46 | Write(cache.Root);
47 |
48 | if(!hadErrors)
49 | sw.WriteLine("No errors found.");
50 |
51 | sw.WriteLine();
52 | sw.Flush();
53 | }
54 |
55 | void Write(ModulePackage package)
56 | {
57 | foreach (var kv in package.Modules)
58 | {
59 | if (kv.Value.ParseErrors.Count < 1)
60 | continue;
61 | hadErrors = true;
62 | sw.WriteLine(kv.Value.ModuleName + "\t\t(" + kv.Value.FileName + ")");
63 | foreach (var err in kv.Value.ParseErrors)
64 | sw.WriteLine(string.Format("\t\t{0}\t{1}\t{2}", err.Location.Line, err.Location.Column, err.Message));
65 |
66 | sw.WriteLine();
67 | }
68 |
69 | sw.Flush();
70 |
71 | foreach (var kv in package.Packages)
72 | Write(kv.Value);
73 | }
74 | }
75 | #endif
76 | }
77 |
--------------------------------------------------------------------------------
/DParser2/Misc/StringCache.cs:
--------------------------------------------------------------------------------
1 | //
2 | // StringCache.cs
3 | //
4 | // Author:
5 | // Alexander Bothe
6 | //
7 | // Copyright (c) 2013 Alexander Bothe
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | using System;
27 | using System.Collections.Generic;
28 |
29 | namespace D_Parser
30 | {
31 | public static class Strings
32 | {
33 | static readonly Dictionary Table = new Dictionary();
34 |
35 | public static void Add(string s)
36 | {
37 | if (!string.IsNullOrEmpty (s)) {
38 | var hash = s.GetHashCode ();
39 | lock (Table)
40 | {
41 | Table [hash] = s;
42 | }
43 | }
44 | }
45 |
46 | public static string TryGet(int hash)
47 | {
48 | if (hash != 0)
49 | {
50 | string s;
51 | Table.TryGetValue(hash, out s);
52 | return s;
53 | }
54 | return string.Empty;
55 | }
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/DParser2/Misc/StringExtension.cs:
--------------------------------------------------------------------------------
1 | //
2 | // StringExtension.cs
3 | //
4 | // Author:
5 | // Alexander Bothe
6 | //
7 | // Copyright (c) 2013 Alexander Bothe
8 | //
9 | // Permission is hereby granted, free of charge, to any person obtaining a copy
10 | // of this software and associated documentation files (the "Software"), to deal
11 | // in the Software without restriction, including without limitation the rights
12 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | // copies of the Software, and to permit persons to whom the Software is
14 | // furnished to do so, subject to the following conditions:
15 | //
16 | // The above copyright notice and this permission notice shall be included in
17 | // all copies or substantial portions of the Software.
18 | //
19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 | // THE SOFTWARE.
26 | using System.Text;
27 |
28 | namespace D_Parser
29 | {
30 | public static class StringExtension
31 | {
32 | public static StringBuilder Trim(this StringBuilder sb)
33 | {
34 | int trimLen = 0;
35 | for (;trimLen < sb.Length && char.IsWhiteSpace (sb [trimLen]); trimLen++);
36 | if(trimLen != 0)
37 | sb.Remove (0, trimLen);
38 |
39 | if (sb.Length != 0) {
40 | for (trimLen = sb.Length - 1; trimLen >= 0 && char.IsWhiteSpace (sb [trimLen]); trimLen--);
41 | sb.Length = trimLen + 1;
42 | }
43 | return sb;
44 | }
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/DParser2/Misc/StringView.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 |
3 | namespace D_Parser.Misc
4 | {
5 | ///