diff --git a/Decompiler.csproj b/Decompiler.csproj index b62aa1fa6..3c1ce0799 100644 --- a/Decompiler.csproj +++ b/Decompiler.csproj @@ -25,9 +25,6 @@ - - lib\NRefactory\ICSharpCode.NRefactory.dll - @@ -76,5 +73,9 @@ {D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE} Mono.Cecil + + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} + NRefactory + \ No newline at end of file diff --git a/Decompiler.sln b/Decompiler.sln index d0132cdfb..5657d292b 100644 --- a/Decompiler.sln +++ b/Decompiler.sln @@ -1,10 +1,14 @@  -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual Studio 2008 # SharpDevelop 3.0.0.2914 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decompiler", "Decompiler.csproj", "{EE3A3C1A-F9C3-4C75-853D-A9476E518C3A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "lib\cecil-0.6\src\Mono.Cecil\Mono.Cecil.csproj", "{D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "lib\NRefactory\Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryASTGenerator", "lib\NRefactory\NRefactoryASTGenerator\NRefactoryASTGenerator.csproj", "{B22522AA-B5BF-4A58-AC6D-D4B45805521F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Cecil", "lib\cecil-0.6\src\Mono.Cecil\Mono.Cecil.csproj", "{C58CA4B3-20ED-4D22-A55B-AD5DE9DEB125}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -20,5 +24,21 @@ Global {D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}.Release|Any CPU.Build.0 = Release|Any CPU {D8F63DFF-5230-43E4-9AB2-DA6E721A1FAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.Build.0 = Release|Any CPU + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Release|Any CPU.Build.0 = Release|Any CPU + {B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6075AD9-053B-4B6B-ABAF-92DC5EDC877B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6075AD9-053B-4B6B-ABAF-92DC5EDC877B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6075AD9-053B-4B6B-ABAF-92DC5EDC877B}.Release|Any CPU.Build.0 = Release|Any CPU + {E6075AD9-053B-4B6B-ABAF-92DC5EDC877B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C58CA4B3-20ED-4D22-A55B-AD5DE9DEB125}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C58CA4B3-20ED-4D22-A55B-AD5DE9DEB125}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C58CA4B3-20ED-4D22-A55B-AD5DE9DEB125}.Release|Any CPU.Build.0 = Release|Any CPU + {C58CA4B3-20ED-4D22-A55B-AD5DE9DEB125}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection EndGlobal diff --git a/lib/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs b/lib/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs new file mode 100644 index 000000000..f9e02ccff --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs @@ -0,0 +1,314 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace NRefactoryASTGenerator.Ast +{ + [CustomImplementation] + abstract class Expression : AbstractNode, INullable {} + + [CustomImplementation] + class PrimitiveExpression : Expression {} + + enum ParameterModifiers { In } + + class ParameterDeclarationExpression : Expression { + List attributes; + [QuestionMarkDefault] + string parameterName; + TypeReference typeReference; + ParameterModifiers paramModifier; + Expression defaultValue; + + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName) {} + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier) {} + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier, Expression defaultValue) {} + } + + class NamedArgumentExpression : Expression { + string name; + Expression expression; + + public NamedArgumentExpression(string name, Expression expression) {} + } + + [IncludeBoolProperty("IsAnonymousType", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] + class ObjectCreateExpression : Expression { + TypeReference createType; + List parameters; + CollectionInitializerExpression objectInitializer; + + public ObjectCreateExpression(TypeReference createType, List parameters) {} + } + + [IncludeBoolProperty("IsImplicitlyTyped", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] + class ArrayCreateExpression : Expression { + TypeReference createType; + List arguments; + CollectionInitializerExpression arrayInitializer; + + public ArrayCreateExpression(TypeReference createType) {} + public ArrayCreateExpression(TypeReference createType, List arguments) {} + public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) {} + } + + [ImplementNullable(NullableImplementation.Shadow)] + class CollectionInitializerExpression : Expression { + List createExpressions; + + public CollectionInitializerExpression() {} + public CollectionInitializerExpression(List createExpressions) {} + } + + enum AssignmentOperatorType {} + + class AssignmentExpression : Expression { + Expression left; + AssignmentOperatorType op; + Expression right; + + public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right) {} + } + + class BaseReferenceExpression : Expression {} + + enum BinaryOperatorType {} + + class BinaryOperatorExpression : Expression + { + Expression left; + BinaryOperatorType op; + Expression right; + + public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) {} + } + + enum CastType {} + + class CastExpression : Expression + { + TypeReference castTo; + Expression expression; + CastType castType; + + public CastExpression(TypeReference castTo) {} + public CastExpression(TypeReference castTo, Expression expression, CastType castType) {} + } + + [IncludeMember("[Obsolete] public string FieldName { get { return MemberName; } set { MemberName = value; } }")] + class MemberReferenceExpression : Expression + { + Expression targetObject; + string memberName; + List typeArguments; + + public MemberReferenceExpression(Expression targetObject, string memberName) {} + } + + class PointerReferenceExpression : Expression { + Expression targetObject; + string identifier; + List typeArguments; + + public PointerReferenceExpression(Expression targetObject, string identifier) {} + } + + class IdentifierExpression : Expression { + string identifier; + List typeArguments; + + public IdentifierExpression(string identifier) {} + } + + class InvocationExpression : Expression { + Expression targetObject; + List arguments; + + public InvocationExpression(Expression targetObject) {} + public InvocationExpression(Expression targetObject, List arguments) {} + } + + class ParenthesizedExpression : Expression { + Expression expression; + + public ParenthesizedExpression(Expression expression) {} + } + + class ThisReferenceExpression : Expression {} + + class TypeOfExpression : Expression { + TypeReference typeReference; + + public TypeOfExpression(TypeReference typeReference) {} + } + + [IncludeMember("public TypeReferenceExpression(string typeName) : this(new TypeReference(typeName)) {}")] + class TypeReferenceExpression : Expression { + TypeReference typeReference; + + public TypeReferenceExpression(TypeReference typeReference) {} + } + + enum UnaryOperatorType {} + + class UnaryOperatorExpression : Expression { + UnaryOperatorType op; + Expression expression; + + public UnaryOperatorExpression(UnaryOperatorType op) {} + public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) {} + } + + class AnonymousMethodExpression : Expression { + List parameters; + BlockStatement body; + bool hasParameterList; + } + + class LambdaExpression : Expression { + List parameters; + BlockStatement statementBody; + Expression expressionBody; + } + + class CheckedExpression : Expression { + Expression expression; + + public CheckedExpression(Expression expression) {} + } + + class ConditionalExpression : Expression { + Expression condition; + Expression trueExpression; + Expression falseExpression; + + public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) {} + } + + class DefaultValueExpression : Expression { + TypeReference typeReference; + + public DefaultValueExpression(TypeReference typeReference) {} + } + + enum FieldDirection {} + + class DirectionExpression : Expression { + FieldDirection fieldDirection; + Expression expression; + + public DirectionExpression(FieldDirection fieldDirection, Expression expression) {} + } + + class IndexerExpression : Expression { + Expression targetObject; + List indexes; + + public IndexerExpression(Expression targetObject, List indexes) {} + } + + class SizeOfExpression : Expression { + TypeReference typeReference; + + public SizeOfExpression(TypeReference typeReference) {} + } + + class StackAllocExpression : Expression { + TypeReference typeReference; + Expression expression; + + public StackAllocExpression(TypeReference typeReference, Expression expression) {} + } + + class UncheckedExpression : Expression { + Expression expression; + + public UncheckedExpression(Expression expression) {} + } + + class AddressOfExpression : Expression { + Expression expression; + + public AddressOfExpression(Expression expression) {} + } + + class ClassReferenceExpression : Expression {} + + class TypeOfIsExpression : Expression { + Expression expression; + TypeReference typeReference; + + public TypeOfIsExpression(Expression expression, TypeReference typeReference) {} + } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpression : Expression { + QueryExpressionFromClause fromClause; + List fromLetWhereClauses; + List orderings; + QueryExpressionClause selectOrGroupClause; + QueryExpressionIntoClause intoClause; + } + + [ImplementNullable] + abstract class QueryExpressionClause : AbstractNode, INullable { } + + class QueryExpressionWhereClause : QueryExpressionClause { + Expression condition; + } + + class QueryExpressionLetClause : QueryExpressionClause { + [QuestionMarkDefault] + string identifier; + Expression expression; + } + + abstract class QueryExpressionFromOrJoinClause : QueryExpressionClause { + TypeReference type; + [QuestionMarkDefault] + string identifier; + Expression inExpression; + } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpressionFromClause : QueryExpressionFromOrJoinClause { } + + class QueryExpressionJoinClause : QueryExpressionFromOrJoinClause { + Expression onExpression; + Expression equalsExpression; + + string intoIdentifier; + } + + class QueryExpressionOrdering : AbstractNode { + Expression criteria; + QueryExpressionOrderingDirection direction; + } + + enum QueryExpressionOrderingDirection { + None, Ascending, Descending + } + + class QueryExpressionSelectClause : QueryExpressionClause { + Expression projection; + } + + class QueryExpressionGroupClause : QueryExpressionClause { + Expression projection; + Expression groupBy; + } + + [ImplementNullable(NullableImplementation.Shadow)] + class QueryExpressionIntoClause : QueryExpressionClause { + [QuestionMarkDefault] + string intoIdentifier; + + QueryExpression continuedQuery; + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs b/lib/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs new file mode 100644 index 000000000..bdcf2566e --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs @@ -0,0 +1,95 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace NRefactoryASTGenerator.Ast +{ + [CustomImplementation, HasChildren] + class CompilationUnit : AbstractNode {} + + [HasChildren] + class NamespaceDeclaration : AbstractNode + { + string name; + + public NamespaceDeclaration(string name) {} + } + + class TemplateDefinition : AttributedNode + { + [QuestionMarkDefault] + string name; + List bases; + + public TemplateDefinition(string name, List attributes) : base(attributes) {} + } + + class DelegateDeclaration : AttributedNode + { + [QuestionMarkDefault] + string name; + TypeReference returnType; + List parameters; + List templates; + + public DelegateDeclaration(Modifiers modifier, List attributes) : base(modifier, attributes) {} + } + + enum ClassType { Class } + + [HasChildren] + class TypeDeclaration : AttributedNode + { + // Children of Struct: FieldDeclaration, MethodDeclaration, EventDeclaration, ConstructorDeclaration, + // OperatorDeclaration, TypeDeclaration, IndexerDeclaration, PropertyDeclaration, in VB: DeclareDeclaration + // Childrean of class: children of struct, DestructorDeclaration + // Children of Interface: MethodDeclaration, PropertyDeclaration, IndexerDeclaration, EventDeclaration, in VB: TypeDeclaration(Enum) too + // Children of Enum: FieldDeclaration + string name; + ClassType type; + List baseTypes; + List templates; + Location bodyStartLocation; + + public TypeDeclaration(Modifiers modifier, List attributes) : base(modifier, attributes) {} + } + + [IncludeBoolProperty("IsAlias", "return !alias.IsNull;")] + class Using : AbstractNode + { + [QuestionMarkDefault] + string name; + TypeReference alias; + + public Using(string name) {} + public Using(string name, TypeReference alias) {} + } + + [IncludeMember("public UsingDeclaration(string @namespace) : this(@namespace, null) {}")] + [IncludeMember("public UsingDeclaration(string @namespace, TypeReference alias) {" + + " usings = new List(1);" + + " usings.Add(new Using(@namespace, alias)); " + + "}")] + class UsingDeclaration : AbstractNode + { + List usings; + + public UsingDeclaration(List usings) {} + } + + enum OptionType { None } + + class OptionDeclaration : AbstractNode + { + OptionType optionType; + bool optionValue; + + public OptionDeclaration(OptionType optionType, bool optionValue) {} + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/AST/Node.cs b/lib/NRefactory/NRefactoryASTGenerator/AST/Node.cs new file mode 100644 index 000000000..8c6ea7ff2 --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AST/Node.cs @@ -0,0 +1,72 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace NRefactoryASTGenerator.Ast +{ + interface INode {} + interface INullable {} + struct Location {} + + enum Modifiers { None } + + [CustomImplementation] + abstract class AbstractNode : INode {} + + abstract class AttributedNode : AbstractNode + { + List attributes; + Modifiers modifier; + + public AttributedNode() {} + public AttributedNode(List attributes) {} + public AttributedNode(Modifiers modifier, List attributes) {} + } + + abstract class ParametrizedNode : AttributedNode + { + string name; + List parameters; + + public ParametrizedNode() {} + + public ParametrizedNode(Modifiers modifier, List attributes, + string name, List parameters) + : base(modifier, attributes) + {} + } + + [CustomImplementation] + class TypeReference : AbstractNode + { + List genericTypes; + } + + [CustomImplementation] + class InnerClassTypeReference : TypeReference + { + TypeReference baseType; + } + + class AttributeSection : AbstractNode, INullable + { + string attributeTarget; + List attributes; + } + + class Attribute : AbstractNode + { + string name; + List positionalArguments; + List namedArguments; + + public Attribute() {} + public Attribute(string name, List positionalArguments, List namedArguments) {} + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/AST/Statements.cs b/lib/NRefactory/NRefactoryASTGenerator/AST/Statements.cs new file mode 100644 index 000000000..b9ecef4e7 --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AST/Statements.cs @@ -0,0 +1,314 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace NRefactoryASTGenerator.Ast +{ + [CustomImplementation] + abstract class Statement : AbstractNode, INullable {} + + [CustomImplementation] + abstract class StatementWithEmbeddedStatement : Statement { + Statement embeddedStatement; + } + + [CustomImplementation, HasChildren] + class BlockStatement : Statement {} + + class BreakStatement : Statement {} + + enum ContinueType {} + + class ContinueStatement : Statement { + ContinueType continueType; + + public ContinueStatement() {} + public ContinueStatement(ContinueType continueType) {} + } + + enum ConditionType {} + enum ConditionPosition {} + + class DoLoopStatement : StatementWithEmbeddedStatement { + Expression condition; + ConditionType conditionType; + ConditionPosition conditionPosition; + + public DoLoopStatement(Expression condition, Statement embeddedStatement, ConditionType conditionType, ConditionPosition conditionPosition) {} + } + + class ForeachStatement : StatementWithEmbeddedStatement { + TypeReference typeReference; + string variableName; + Expression expression; + Expression nextExpression; + + public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement) {} + public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement, Expression nextExpression) {} + } + + class ForStatement : StatementWithEmbeddedStatement { + List initializers; + Expression condition; + List iterator; + + public ForStatement(List initializers, Expression condition, List iterator, Statement embeddedStatement) {} + } + + class GotoStatement : Statement { + string label; + + public GotoStatement(string label) {} + } + + [IncludeMember(@" + public IfElseStatement(Expression condition, Statement trueStatement) + : this(condition) { + this.trueStatement.Add(Statement.CheckNull(trueStatement)); + }")] + [IncludeMember(@" + public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) + : this(condition) { + this.trueStatement.Add(Statement.CheckNull(trueStatement)); + this.falseStatement.Add(Statement.CheckNull(falseStatement)); + }")] + [IncludeBoolProperty("HasElseStatements", "return falseStatement.Count > 0;")] + [IncludeBoolProperty("HasElseIfSections", "return elseIfSections.Count > 0;")] + class IfElseStatement : Statement { + Expression condition; + List trueStatement; // List for stmt : stmt : stmt ... in VB.NET + List falseStatement; + List elseIfSections; + + public IfElseStatement(Expression condition) {} + } + + class ElseIfSection : StatementWithEmbeddedStatement { + Expression condition; + + public ElseIfSection(Expression condition, Statement embeddedStatement) {} + } + + class LabelStatement : Statement { + string label; + + public LabelStatement(string label) {} + } + + [CustomImplementation] + class LocalVariableDeclaration : Statement { + TypeReference typeReference; + Modifiers modifier; + List variables; + } + + class LockStatement : StatementWithEmbeddedStatement + { + Expression lockExpression; + + public LockStatement(Expression lockExpression, Statement embeddedStatement) {} + } + + class ReturnStatement : Statement + { + Expression expression; + + public ReturnStatement(Expression expression) { } + } + + class ExpressionStatement : Statement { + Expression expression; + + public ExpressionStatement(Expression expression) {} + } + + class SwitchStatement : Statement { + Expression switchExpression; + List switchSections; + + public SwitchStatement(Expression switchExpression, List switchSections) {} + } + + class SwitchSection : BlockStatement { + List switchLabels; + + public SwitchSection() { } + public SwitchSection(List switchLabels) { } + } + + [IncludeBoolProperty("IsDefault", "return label.IsNull;")] + class CaseLabel : AbstractNode { + Expression label; + BinaryOperatorType binaryOperatorType; + Expression toExpression; + + public CaseLabel() {} + public CaseLabel(Expression label) {} + public CaseLabel(Expression label, Expression toExpression) {} + public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label) {} + } + + class ThrowStatement : Statement { + Expression expression; + + public ThrowStatement(Expression expression) {} + } + + class TryCatchStatement : Statement { + Statement statementBlock; + List catchClauses; + Statement finallyBlock; + + public TryCatchStatement(Statement statementBlock, List catchClauses, Statement finallyBlock) {} + } + + class CatchClause : AbstractNode { + TypeReference typeReference; + string variableName; + Statement statementBlock; + Expression condition; + + public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) {} + public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) {} + public CatchClause(Statement statementBlock) {} + } + + class CheckedStatement : Statement { + Statement block; + + public CheckedStatement(Statement block) {} + } + + class EmptyStatement : Statement {} + + class FixedStatement : StatementWithEmbeddedStatement { + TypeReference typeReference; + List pointerDeclarators; + + public FixedStatement(TypeReference typeReference, List pointerDeclarators, Statement embeddedStatement) {} + } + + [IncludeBoolProperty("IsDefaultCase", "return expression.IsNull;")] + class GotoCaseStatement : Statement { + Expression expression; + + public GotoCaseStatement(Expression expression) {} + } + + class UncheckedStatement : Statement { + Statement block; + + public UncheckedStatement(Statement block) {} + } + + class UnsafeStatement : Statement { + Statement block; + + public UnsafeStatement(Statement block) {} + } + + class UsingStatement : StatementWithEmbeddedStatement { + Statement resourceAcquisition; + + public UsingStatement(Statement resourceAcquisition, Statement embeddedStatement) {} + } + + [IncludeBoolProperty("IsYieldReturn", "return statement is ReturnStatement;")] + [IncludeBoolProperty("IsYieldBreak", "return statement is BreakStatement;")] + class YieldStatement : Statement { + Statement statement; + + public YieldStatement(Statement statement) {} + } + + class AddHandlerStatement : Statement { + Expression eventExpression; + Expression handlerExpression; + + public AddHandlerStatement(Expression eventExpression, Expression handlerExpression) {} + } + + class EndStatement : Statement {} + + class EraseStatement : Statement { + List expressions; + + public EraseStatement() {} + public EraseStatement(List expressions) {} + } + + class ErrorStatement : Statement { + Expression expression; + + public ErrorStatement(Expression expression) {} + } + + enum ExitType {} + + class ExitStatement : Statement { + ExitType exitType; + + public ExitStatement(ExitType exitType) {} + } + + class ForNextStatement : StatementWithEmbeddedStatement { + Expression start; + Expression end; + Expression step; + + List nextExpressions; + TypeReference typeReference; + string variableName; + + public ForNextStatement(TypeReference typeReference, string variableName, Expression start, Expression end, Expression step, Statement embeddedStatement, List nextExpressions) {} + } + + class OnErrorStatement : StatementWithEmbeddedStatement { + public OnErrorStatement(Statement embeddedStatement) {} + } + + class RaiseEventStatement : Statement { + string eventName; + List arguments; + + public RaiseEventStatement(string eventName, List arguments) {} + } + + class ReDimStatement : Statement { + List reDimClauses; + bool isPreserve; + + public ReDimStatement(bool isPreserve) {} + } + + class RemoveHandlerStatement : Statement { + Expression eventExpression; + Expression handlerExpression; + + public RemoveHandlerStatement(Expression eventExpression, Expression handlerExpression) {} + } + + class ResumeStatement : Statement { + string labelName; + bool isResumeNext; + + public ResumeStatement(bool isResumeNext) {} + + public ResumeStatement(string labelName) {} + } + + class StopStatement : Statement {} + + class WithStatement : Statement { + Expression expression; + BlockStatement body; + + public WithStatement(Expression expression) {} + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs b/lib/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs new file mode 100644 index 000000000..767666b8a --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs @@ -0,0 +1,261 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace NRefactoryASTGenerator.Ast +{ + class VariableDeclaration : AbstractNode + { + string name; + Expression initializer; + TypeReference typeReference; + Expression fixedArrayInitialization; + + public VariableDeclaration(string name) {} + public VariableDeclaration(string name, Expression initializer) {} + public VariableDeclaration(string name, Expression initializer, TypeReference typeReference) {} + } + + class ConstructorDeclaration : ParametrizedNode + { + ConstructorInitializer constructorInitializer; + BlockStatement body; + + public ConstructorDeclaration(string name, Modifiers modifier, + List parameters, + List attributes) + : base(modifier, attributes, name, parameters) + {} + + public ConstructorDeclaration(string name, Modifiers modifier, + List parameters, + ConstructorInitializer constructorInitializer, + List attributes) + : base(modifier, attributes, name, parameters) + {} + } + + enum ConstructorInitializerType { None } + + [ImplementNullable] + class ConstructorInitializer : AbstractNode, INullable + { + ConstructorInitializerType constructorInitializerType; + List arguments; + } + + [ImplementNullable(NullableImplementation.Abstract)] + abstract class EventAddRemoveRegion : AttributedNode + { + BlockStatement block; + List parameters; + + public EventAddRemoveRegion(List attributes) : base(attributes) {} + } + + [ImplementNullable(NullableImplementation.CompleteAbstract)] + class EventAddRegion : EventAddRemoveRegion + { + public EventAddRegion(List attributes) : base(attributes) {} + } + + [ImplementNullable(NullableImplementation.CompleteAbstract)] + class EventRemoveRegion : EventAddRemoveRegion + { + public EventRemoveRegion(List attributes) : base(attributes) {} + } + + [ImplementNullable(NullableImplementation.CompleteAbstract)] + class EventRaiseRegion : EventAddRemoveRegion + { + public EventRaiseRegion(List attributes) : base(attributes) {} + } + + class InterfaceImplementation : AbstractNode + { + TypeReference interfaceType; + [QuestionMarkDefault] + string memberName; + + public InterfaceImplementation(TypeReference interfaceType, string memberName) {} + } + + [IncludeBoolProperty("HasAddRegion", "return !addRegion.IsNull;")] + [IncludeBoolProperty("HasRemoveRegion", "return !removeRegion.IsNull;")] + [IncludeBoolProperty("HasRaiseRegion", "return !raiseRegion.IsNull;")] + class EventDeclaration : MemberNode + { + EventAddRegion addRegion; + EventRemoveRegion removeRegion; + EventRaiseRegion raiseRegion; + Location bodyStart; + Location bodyEnd; + Expression initializer; + } + + [IncludeMember(@" + public TypeReference GetTypeForField(int fieldIndex) + { + if (!typeReference.IsNull) { + return typeReference; + } + return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; + }")] + [IncludeMember(@" + public VariableDeclaration GetVariableDeclaration(string variableName) + { + foreach (VariableDeclaration variableDeclaration in Fields) { + if (variableDeclaration.Name == variableName) { + return variableDeclaration; + } + } + return null; + }")] + class FieldDeclaration : AttributedNode + { + TypeReference typeReference; + List fields; + + // for enum members + public FieldDeclaration(List attributes) : base(attributes) {} + + // for all other cases + public FieldDeclaration(List attributes, TypeReference typeReference, Modifiers modifier) + : base(modifier, attributes) + {} + } + + abstract class MemberNode : ParametrizedNode + { + List interfaceImplementations; + TypeReference typeReference; + + public MemberNode() {} + + public MemberNode(Modifiers modifier, List attributes, + string name, List parameters) + : base(modifier, attributes, name, parameters) + {} + } + + class MethodDeclaration : MemberNode + { + BlockStatement body; + List handlesClause; + List templates; + bool isExtensionMethod; + } + + enum ConversionType { None } + enum OverloadableOperatorType { None } + + [IncludeBoolProperty("IsConversionOperator", "return conversionType != ConversionType.None;")] + class OperatorDeclaration : MethodDeclaration + { + ConversionType conversionType; + List returnTypeAttributes; + OverloadableOperatorType overloadableOperator; + } + + [IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")] + [IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")] + [IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")] + [IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")] + [IncludeMember(@" + internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List attributes) : this(modifier, attributes, name, null) + { + this.TypeReference = typeReference; + if ((modifier & Modifiers.ReadOnly) != Modifiers.ReadOnly) { + this.SetRegion = new PropertySetRegion(null, null); + } + if ((modifier & Modifiers.WriteOnly) != Modifiers.WriteOnly) { + this.GetRegion = new PropertyGetRegion(null, null); + } + }")] + class PropertyDeclaration : MemberNode + { + Location bodyStart; + Location bodyEnd; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + public PropertyDeclaration(Modifiers modifier, List attributes, + string name, List parameters) + : base(modifier, attributes, name, parameters) + {} + } + + [ImplementNullable(NullableImplementation.Abstract)] + abstract class PropertyGetSetRegion : AttributedNode + { + // can be null if only the definition is there (interface declaration) + BlockStatement block; + + public PropertyGetSetRegion(BlockStatement block, List attributes) : base(attributes) {} + } + + [ImplementNullable(NullableImplementation.CompleteAbstract)] + class PropertyGetRegion : PropertyGetSetRegion + { + public PropertyGetRegion(BlockStatement block, List attributes) : base(block, attributes) {} + } + + [ImplementNullable(NullableImplementation.CompleteAbstract)] + class PropertySetRegion : PropertyGetSetRegion + { + List parameters; + + public PropertySetRegion(BlockStatement block, List attributes) : base(block, attributes) {} + } + + class DestructorDeclaration : AttributedNode + { + string name; + BlockStatement body; + + public DestructorDeclaration(string name, Modifiers modifier, List attributes) : base(modifier, attributes) {} + } + + [IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")] + [IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")] + [IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")] + [IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")] + class IndexerDeclaration : AttributedNode + { + List parameters; + List interfaceImplementations; + TypeReference typeReference; + Location bodyStart; + Location bodyEnd; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + public IndexerDeclaration(Modifiers modifier, List parameters, List attributes) + : base(modifier, attributes) + {} + + public IndexerDeclaration(TypeReference typeReference, List parameters, Modifiers modifier, List attributes) + : base(modifier, attributes) + {} + } + + enum CharsetModifier { None } + + class DeclareDeclaration : ParametrizedNode + { + string alias; + string library; + CharsetModifier charset; + TypeReference typeReference; + + public DeclareDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes, string library, string alias, CharsetModifier charset) + : base(modifier, attributes, name, parameters) + {} + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/AssemblyInfo.cs b/lib/NRefactory/NRefactoryASTGenerator/AssemblyInfo.cs new file mode 100644 index 000000000..d36cc378f --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/AssemblyInfo.cs @@ -0,0 +1,33 @@ +// +// +// +// +// $Revision$ +// + +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("NRefactory AST Generator")] +[assembly: AssemblyDescription("Parser and refactoring library for C# and VB.NET")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("ic#code")] +[assembly: AssemblyProduct("SharpDevelop")] +[assembly: AssemblyCopyright("2006 AlphaSierraPapa")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("2.0.0.1")] diff --git a/lib/NRefactory/NRefactoryASTGenerator/Attributes.cs b/lib/NRefactory/NRefactoryASTGenerator/Attributes.cs new file mode 100644 index 000000000..2647e2742 --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/Attributes.cs @@ -0,0 +1,180 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.CodeDom; +using System.Reflection; +using ICSharpCode.EasyCodeDom; + +namespace NRefactoryASTGenerator +{ + public enum NullableImplementation + { + /// + /// Implement INullable with a virtual bool IsNull, create Null class and static instance + /// of it. + /// + Default, + /// + /// Create Null class and a static instance using the "new" modifier. + /// + Shadow, + /// + /// Implement INullable with a virtual bool IsNull. + /// + Abstract, + /// + /// Complete an abstract nullable implementation by creating the Null class + /// and the static instance. + /// + CompleteAbstract + } + + public abstract class TypeImplementationModifierAttribute : Attribute + { + public abstract void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type); + } + + [AttributeUsage(AttributeTargets.Class)] + public class CustomImplementationAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.Class)] + public class HasChildrenAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.Field)] + public class QuestionMarkDefaultAttribute : Attribute + { + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class IncludeMemberAttribute : TypeImplementationModifierAttribute + { + string code; + + public IncludeMemberAttribute(string code) + { + this.code = code; + } + + public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type) + { + ctd.Members.Add(new CodeSnippetTypeMember(code)); + } + } + + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] + public class IncludeBoolPropertyAttribute : TypeImplementationModifierAttribute + { + string name; + string code; + + public IncludeBoolPropertyAttribute(string name, string code) + { + this.name = name; + this.code = code; + } + + public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type) + { + CodeMemberProperty prop = new CodeMemberProperty(); + prop.Name = name; + prop.Type = new CodeTypeReference(typeof(bool)); + prop.Attributes = MemberAttributes.Public | MemberAttributes.Final; + prop.GetStatements.Add(new CodeSnippetStatement("\t\t\t\t" + code)); + ctd.Members.Add(prop); + } + } + + [AttributeUsage(AttributeTargets.Class)] + public class ImplementNullableAttribute : TypeImplementationModifierAttribute + { + NullableImplementation implementation; + + public ImplementNullableAttribute() + { + this.implementation = NullableImplementation.Default; + } + + public ImplementNullableAttribute(NullableImplementation implementation) + { + this.implementation = implementation; + } + + public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type) + { + if (implementation == NullableImplementation.Default || implementation == NullableImplementation.Abstract) { + ctd.BaseTypes.Add(new CodeTypeReference("INullable")); + CodeMemberProperty prop = new CodeMemberProperty(); + prop.Name = "IsNull"; + prop.Type = new CodeTypeReference(typeof(bool)); + prop.Attributes = MemberAttributes.Public; + prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(false))); + ctd.Members.Add(prop); + } + if (implementation != NullableImplementation.Abstract) { + EasyTypeDeclaration newType = new EasyTypeDeclaration("Null" + ctd.Name); + newType.TypeAttributes = TypeAttributes.Class | TypeAttributes.NotPublic | TypeAttributes.Sealed; + newType.BaseTypes.Add(new CodeTypeReference(ctd.Name)); + cns.Types.Add(newType); + + System.Reflection.ConstructorInfo baseCtor = MainClass.GetBaseCtor(type); + if (baseCtor != null) { + CodeConstructor ctor = new CodeConstructor(); + ctor.Attributes = MemberAttributes.Private; + foreach (object o in baseCtor.GetParameters()) { + ctor.BaseConstructorArgs.Add(new CodePrimitiveExpression(null)); + } + newType.Members.Add(ctor); + } + + CodeMemberField field = new CodeMemberField(newType.Name, "Instance"); + field.Attributes = MemberAttributes.Static | MemberAttributes.Assembly; + field.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference(newType.Name)); + newType.Members.Add(field); + + CodeMemberProperty prop = new CodeMemberProperty(); + prop.Name = "IsNull"; + prop.Type = new CodeTypeReference(typeof(bool)); + prop.Attributes = MemberAttributes.Public | MemberAttributes.Override; + prop.GetStatements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(true))); + newType.Members.Add(prop); + + CodeMemberMethod method = new CodeMemberMethod(); + method.Name = "AcceptVisitor"; + method.Attributes = MemberAttributes.Public | MemberAttributes.Override; + method.Parameters.Add(new CodeParameterDeclarationExpression("IAstVisitor", "visitor")); + method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "data")); + method.ReturnType = new CodeTypeReference(typeof(object)); + method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression(null))); + newType.Members.Add(method); + + method = new CodeMemberMethod(); + method.Name = "ToString"; + method.Attributes = MemberAttributes.Public | MemberAttributes.Override; + method.ReturnType = new CodeTypeReference(typeof(string)); + method.Statements.Add(new CodeMethodReturnStatement(new CodePrimitiveExpression("[" + newType.Name + "]"))); + newType.Members.Add(method); + + prop = new CodeMemberProperty(); + prop.Name = "Null"; + prop.Type = new CodeTypeReference(ctd.Name); + prop.Attributes = MemberAttributes.Public | MemberAttributes.Static; + if (implementation == NullableImplementation.Shadow) { + prop.Attributes |= MemberAttributes.New; + } + CodeExpression ex = new CodeTypeReferenceExpression(newType.Name); + ex = new CodePropertyReferenceExpression(ex, "Instance"); + prop.GetStatements.Add(new CodeMethodReturnStatement(ex)); + ctd.Members.Add(prop); + } + } + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/EasyCodeDom.cs b/lib/NRefactory/NRefactoryASTGenerator/EasyCodeDom.cs new file mode 100644 index 000000000..54fb44cc1 --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/EasyCodeDom.cs @@ -0,0 +1,439 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.CodeDom; + +namespace ICSharpCode.EasyCodeDom +{ + public static class Easy + { + public static CodeTypeReference TypeRef(Type type) + { + return new CodeTypeReference(type, CodeTypeReferenceOptions.GlobalReference); + } + public static CodeTypeReference TypeRef(CodeTypeDeclaration type) + { + return new CodeTypeReference(type.Name); + } + public static CodeTypeReference TypeRef(string typeName, params string[] typeArguments) + { + CodeTypeReference tr = new CodeTypeReference(typeName); + foreach (string ta in typeArguments) { + tr.TypeArguments.Add(ta); + } + return tr; + } + + /// + /// Gets the EasyExpression for any primitive value that can be expressed as literal. + /// Also works for enumeration values. + /// + public static EasyExpression Prim(object literalValue) + { + if (literalValue is Enum) { + return Type(literalValue.GetType()).Field(literalValue.ToString()); + } else { + return new EasyExpression(new CodePrimitiveExpression(literalValue)); + } + } + + public static EasyExpression Type(Type type) + { + return Type(TypeRef(type)); + } + public static EasyExpression Type(CodeTypeReference type) + { + return new EasyExpression(new CodeTypeReferenceExpression(type)); + } + public static EasyExpression Type(string type) + { + return Type(new CodeTypeReference(type)); + } + + public static EasyExpression TypeOf(Type type) + { + return TypeOf(TypeRef(type)); + } + public static EasyExpression TypeOf(CodeTypeReference type) + { + return new EasyExpression(new CodeTypeOfExpression(type)); + } + + public static EasyExpression New(Type type, params CodeExpression[] arguments) + { + return New(TypeRef(type), arguments); + } + public static EasyExpression New(CodeTypeReference type, params CodeExpression[] arguments) + { + return new EasyExpression(new CodeObjectCreateExpression(type, arguments)); + } + + public static EasyExpression Var(string name) + { + return new EasyExpression(new CodeVariableReferenceExpression(name)); + } + + public static EasyExpression Binary(CodeExpression left, + CodeBinaryOperatorType op, + CodeExpression right) + { + return new EasyExpression(new CodeBinaryOperatorExpression(left, op, right)); + } + + public static EasyExpression This { + get { + return new EasyExpression(new CodeThisReferenceExpression()); + } + } + + public static EasyExpression Base { + get { + return new EasyExpression(new CodeBaseReferenceExpression()); + } + } + + public static EasyExpression Value { + get { + return new EasyExpression(new CodePropertySetValueReferenceExpression()); + } + } + + public static EasyExpression Null { + get { + return new EasyExpression(new CodePrimitiveExpression(null)); + } + } + + public static void AddSummary(CodeTypeMember member, string summary) + { + member.Comments.Add(new CodeCommentStatement("", true)); + member.Comments.Add(new CodeCommentStatement(summary, true)); + member.Comments.Add(new CodeCommentStatement("", true)); + } + + internal static CodeAttributeDeclaration AddAttribute(CodeAttributeDeclarationCollection col, + CodeTypeReference type, + CodeExpression[] arguments) + { + CodeAttributeArgument[] attributeArguments = new CodeAttributeArgument[arguments.Length]; + for (int i = 0; i < arguments.Length; i++) { + attributeArguments[i] = new CodeAttributeArgument(arguments[i]); + } + CodeAttributeDeclaration cad = new CodeAttributeDeclaration(type, attributeArguments); + col.Add(cad); + return cad; + } + } + + public sealed class EasyExpression + { + readonly CodeExpression expr; + + public EasyExpression(CodeExpression expr) + { + this.expr = expr; + } + + public static implicit operator CodeExpression(EasyExpression expr) + { + return expr.expr; + } + + public EasyExpression InvokeMethod(string name, params CodeExpression[] arguments) + { + return new EasyExpression(new CodeMethodInvokeExpression(expr, name, arguments)); + } + + public EasyExpression CastTo(Type type) + { + return CastTo(Easy.TypeRef(type)); + } + public EasyExpression CastTo(CodeTypeReference type) + { + return new EasyExpression(new CodeCastExpression(type, expr)); + } + + public EasyExpression Index(params CodeExpression[] indices) + { + return new EasyExpression(new CodeIndexerExpression(expr, indices)); + } + + public EasyExpression Field(string name) + { + return new EasyExpression(new CodeFieldReferenceExpression(expr, name)); + } + + public EasyExpression Property(string name) + { + return new EasyExpression(new CodePropertyReferenceExpression(expr, name)); + } + } + + public class EasyCompileUnit : CodeCompileUnit + { + public EasyNamespace AddNamespace(string name) + { + EasyNamespace n = new EasyNamespace(name); + this.Namespaces.Add(n); + return n; + } + } + + public class EasyNamespace : CodeNamespace + { + public EasyNamespace() : base() {} + public EasyNamespace(string name) : base(name) {} + + public EasyTypeDeclaration AddType(string name) + { + EasyTypeDeclaration n = new EasyTypeDeclaration(name); + this.Types.Add(n); + return n; + } + + public CodeNamespaceImport AddImport(string nameSpace) + { + CodeNamespaceImport cni = new CodeNamespaceImport(nameSpace); + this.Imports.Add(cni); + return cni; + } + } + + public class EasyTypeDeclaration : CodeTypeDeclaration + { + public EasyTypeDeclaration() : base() {} + public EasyTypeDeclaration(string name) : base(name) {} + + public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments); + } + public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, type, arguments); + } + + public EasyField AddField(Type type, string name) + { + return AddField(Easy.TypeRef(type), name); + } + public EasyField AddField(CodeTypeReference type, string name) + { + EasyField f = new EasyField(type, name); + this.Members.Add(f); + return f; + } + + public EasyProperty AddProperty(Type type, string name) + { + return AddProperty(Easy.TypeRef(type), name); + } + public EasyProperty AddProperty(CodeTypeReference type, string name) + { + EasyProperty p = new EasyProperty(type, name); + this.Members.Add(p); + if (this.IsInterface == false) { + p.Attributes = MemberAttributes.Public | MemberAttributes.Final; + } + return p; + } + + public EasyProperty AddProperty(CodeMemberField field, string name) + { + EasyProperty p = AddProperty(field.Type, name); + p.Getter.Return(new CodeVariableReferenceExpression(field.Name)); + p.Attributes |= field.Attributes & MemberAttributes.Static; // copy static flag + return p; + } + + /// + /// Adds a method with return type void and attributes=Public|Final to this type. + /// + public EasyMethod AddMethod(string name) + { + return AddMethod(Easy.TypeRef(typeof(void)), name); + } + /// + /// Adds a method with return type and attributes=Public|Final to this type. + /// + public EasyMethod AddMethod(Type type, string name) + { + return AddMethod(Easy.TypeRef(type), name); + } + /// + /// Adds a method with return type and attributes=Public|Final to this type. + /// + public EasyMethod AddMethod(CodeTypeReference type, string name) + { + EasyMethod p = new EasyMethod(type, name); + this.Members.Add(p); + if (this.IsInterface == false) { + p.Attributes = MemberAttributes.Public | MemberAttributes.Final; + } + return p; + } + } + + public class EasyField : CodeMemberField + { + public EasyField() : base() {} + public EasyField(CodeTypeReference type, string name) : base(type, name) {} + + public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments); + } + public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, type, arguments); + } + } + + public class EasyProperty : CodeMemberProperty + { + EasyBlock getter, setter; + + public EasyProperty() + { + getter = new EasyBlock(this.GetStatements); + setter = new EasyBlock(this.SetStatements); + } + + public EasyProperty(CodeTypeReference type, string name) : this() + { + this.Type = type; + this.Name = name; + } + + public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments); + } + public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, type, arguments); + } + + public EasyBlock Getter { + get { return getter; } + } + + public EasyBlock Setter { + get { return setter; } + } + } + + public class EasyMethod : CodeMemberMethod + { + EasyBlock body; + + public EasyMethod() + { + body = new EasyBlock(this.Statements); + } + + public EasyMethod(CodeTypeReference type, string name) : this() + { + this.ReturnType = type; + this.Name = name; + } + + public CodeAttributeDeclaration AddAttribute(Type type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, Easy.TypeRef(type), arguments); + } + public CodeAttributeDeclaration AddAttribute(CodeTypeReference type, params CodeExpression[] arguments) + { + return Easy.AddAttribute(this.CustomAttributes, type, arguments); + } + + public CodeParameterDeclarationExpression AddParameter(Type type, string name) + { + return AddParameter(Easy.TypeRef(type), name); + } + public CodeParameterDeclarationExpression AddParameter(CodeTypeReference type, string name) + { + CodeParameterDeclarationExpression cpde; + cpde = new CodeParameterDeclarationExpression(type, name); + this.Parameters.Add(cpde); + return cpde; + } + + public EasyBlock Body { + get { return body; } + } + } + + public sealed class EasyBlock + { + readonly CodeStatementCollection csc; + + public EasyBlock(CodeStatementCollection csc) + { + this.csc = csc; + } + + public CodeMethodReturnStatement Return(CodeExpression expr) + { + CodeMethodReturnStatement st = new CodeMethodReturnStatement(expr); + csc.Add(st); + return st; + } + + public CodeAssignStatement Assign(CodeExpression lhs, CodeExpression rhs) + { + CodeAssignStatement st = new CodeAssignStatement(lhs, rhs); + csc.Add(st); + return st; + } + + /// + /// Execute one expression as statement. + /// + public CodeExpressionStatement Add(CodeExpression expr) + { + CodeExpressionStatement st = new CodeExpressionStatement(expr); + csc.Add(st); + return st; + } + + /// + /// Adds the statement. + /// + public CodeStatement Add(CodeStatement st) + { + csc.Add(st); + return st; + } + + /// + /// Invoke a method on target as statement. + /// + public CodeExpressionStatement InvokeMethod(CodeExpression target, string name, params CodeExpression[] arguments) + { + return Add(new CodeMethodInvokeExpression(target, name, arguments)); + } + + /// + /// Declares a local variable. + /// + public CodeVariableDeclarationStatement DeclareVariable(Type type, string name) + { + return DeclareVariable(Easy.TypeRef(type), name); + } + /// + /// Declares a local variable. + /// + public CodeVariableDeclarationStatement DeclareVariable(CodeTypeReference type, string name) + { + CodeVariableDeclarationStatement st = new CodeVariableDeclarationStatement(type, name); + csc.Add(st); + return st; + } + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/Main.cs b/lib/NRefactory/NRefactoryASTGenerator/Main.cs new file mode 100644 index 000000000..359b64418 --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/Main.cs @@ -0,0 +1,542 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.CodeDom; +using System.Diagnostics; +using System.Reflection; +using System.IO; +using NRefactoryASTGenerator.Ast; +using ICSharpCode.EasyCodeDom; + +namespace NRefactoryASTGenerator +{ + class MainClass + { + public const string VisitPrefix = "Visit"; + + public static void Main(string[] args) + { + string directory = "../../../Project/Src/Ast/"; + string visitorsDir = "../../../Project/Src/Visitors/"; + Debug.WriteLine("AST Generator running..."); + if (!File.Exists(directory + "INode.cs")) { + Debug.WriteLine("did not find output directory"); + return; + } + if (!File.Exists(visitorsDir + "AbstractAstTransformer.cs")) { + Debug.WriteLine("did not find visitor output directory"); + return; + } + + List nodeTypes = new List(); + foreach (Type type in typeof(MainClass).Assembly.GetTypes()) { + if (type.IsClass && typeof(INode).IsAssignableFrom(type)) { + nodeTypes.Add(type); + } + } + nodeTypes.Sort(delegate(Type a, Type b) { return a.Name.CompareTo(b.Name); }); + + EasyCompileUnit ccu = new EasyCompileUnit(); + EasyNamespace cns = ccu.AddNamespace("ICSharpCode.NRefactory.Ast"); + cns.AddImport("System"); + cns.AddImport("System.Collections.Generic"); + foreach (Type type in nodeTypes) { + if (type.GetCustomAttributes(typeof(CustomImplementationAttribute), false).Length == 0) { + EasyTypeDeclaration ctd = cns.AddType(type.Name); + if (type.IsAbstract) { + ctd.TypeAttributes |= TypeAttributes.Abstract; + } + ctd.BaseTypes.Add(new CodeTypeReference(type.BaseType.Name)); + + ProcessType(type, ctd); + + foreach (object o in type.GetCustomAttributes(false)) { + if (o is TypeImplementationModifierAttribute) { + (o as TypeImplementationModifierAttribute).ModifyImplementation(cns, ctd, type); + } + } + + if (!type.IsAbstract) { + CodeMemberMethod method = new CodeMemberMethod(); + method.Name = "AcceptVisitor"; + method.Attributes = MemberAttributes.Public | MemberAttributes.Override; + method.Parameters.Add(new CodeParameterDeclarationExpression("IAstVisitor", "visitor")); + method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "data")); + method.ReturnType = new CodeTypeReference(typeof(object)); + CodeExpression ex = new CodeVariableReferenceExpression("visitor"); + ex = new CodeMethodInvokeExpression(ex, VisitPrefix + ctd.Name, + new CodeThisReferenceExpression(), + new CodeVariableReferenceExpression("data")); + method.Statements.Add(new CodeMethodReturnStatement(ex)); + ctd.Members.Add(method); + + method = new CodeMemberMethod(); + method.Name = "ToString"; + method.Attributes = MemberAttributes.Public | MemberAttributes.Override; + method.ReturnType = new CodeTypeReference(typeof(string)); + method.Statements.Add(new CodeMethodReturnStatement(CreateToString(type))); + ctd.Members.Add(method); + } + } + } + + System.CodeDom.Compiler.CodeGeneratorOptions settings = new System.CodeDom.Compiler.CodeGeneratorOptions(); + settings.IndentString = "\t"; + settings.VerbatimOrder = true; + + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); + File.WriteAllText(directory + "Generated.cs", writer.ToString()); + } + + ccu = new EasyCompileUnit(); + cns = ccu.AddNamespace("ICSharpCode.NRefactory"); + cns.AddImport("System"); + cns.AddImport("ICSharpCode.NRefactory.Ast"); + cns.Types.Add(CreateAstVisitorInterface(nodeTypes)); + + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); + File.WriteAllText(visitorsDir + "../IAstVisitor.cs", writer.ToString()); + } + + ccu = new EasyCompileUnit(); + cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors"); + cns.AddImport("System"); + cns.AddImport("System.Collections.Generic"); + cns.AddImport("System.Diagnostics"); + cns.AddImport("ICSharpCode.NRefactory.Ast"); + cns.Types.Add(CreateAstVisitorClass(nodeTypes, false)); + + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); + File.WriteAllText(visitorsDir + "AbstractAstVisitor.cs", writer.ToString()); + } + + ccu = new EasyCompileUnit(); + cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors"); + cns.AddImport("System"); + cns.AddImport("System.Collections.Generic"); + cns.AddImport("System.Diagnostics"); + cns.AddImport("ICSharpCode.NRefactory.Ast"); + cns.Types.Add(CreateAstVisitorClass(nodeTypes, true)); + + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); + File.WriteAllText(visitorsDir + "AbstractAstTransformer.cs", writer.ToString()); + } + + ccu = new EasyCompileUnit(); + cns = ccu.AddNamespace("ICSharpCode.NRefactory.Visitors"); + cns.AddImport("System"); + cns.AddImport("ICSharpCode.NRefactory.Ast"); + cns.Types.Add(CreateNodeTrackingAstVisitorClass(nodeTypes)); + + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); + // CodeDom cannot output "sealed", so we need to use this hack: + File.WriteAllText(visitorsDir + "NodeTrackingAstVisitor.cs", + writer.ToString().Replace("public override object", "public sealed override object")); + } + } + + static CodeTypeDeclaration CreateAstVisitorInterface(List nodeTypes) + { + EasyTypeDeclaration td = new EasyTypeDeclaration("IAstVisitor"); + td.IsInterface = true; + + foreach (Type t in nodeTypes) { + if (!t.IsAbstract) { + EasyMethod m = td.AddMethod(typeof(object), VisitPrefix + t.Name); + m.AddParameter(ConvertType(t), GetFieldName(t.Name)); + m.AddParameter(typeof(object), "data"); + } + } + return td; + } + + static CodeTypeDeclaration CreateAstVisitorClass(List nodeTypes, bool transformer) + { + EasyTypeDeclaration td = new EasyTypeDeclaration(transformer ? "AbstractAstTransformer" : "AbstractAstVisitor"); + td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Abstract; + td.BaseTypes.Add(new CodeTypeReference("IAstVisitor")); + + if (transformer) { + string comment = + "The AbstractAstTransformer will iterate through the whole AST,\n " + + "just like the AbstractAstVisitor. However, the AbstractAstTransformer allows\n " + + "you to modify the AST at the same time: It does not use 'foreach' internally,\n " + + "so you can add members to collections of parents of the current node (but\n " + + "you cannot insert or delete items as that will make the index used invalid).\n " + + "You can use the methods ReplaceCurrentNode and RemoveCurrentNode to replace\n " + + "or remove the current node, totally independent from the type of the parent node."; + Easy.AddSummary(td, comment); + + EasyField field = td.AddField(Easy.TypeRef("Stack", "INode"), "nodeStack"); + field.InitExpression = Easy.New(field.Type); + + /* + CodeExpression nodeStack = Easy.Var("nodeStack"); + CodeMemberProperty p = new CodeMemberProperty(); + p.Name = "CurrentNode"; + p.Type = new CodeTypeReference("INode"); + p.Attributes = MemberAttributes.Public | MemberAttributes.Final; + p.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("currentNode"))); + p.SetStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression("currentNode"), + new CodePropertySetValueReferenceExpression())); + td.Members.Add(p); + */ + + EasyMethod m = td.AddMethod("ReplaceCurrentNode"); + m.AddParameter(Easy.TypeRef("INode"), "newNode"); + m.Statements.Add(Easy.Var("nodeStack").InvokeMethod("Pop")); + m.Statements.Add(Easy.Var("nodeStack").InvokeMethod("Push", Easy.Var("newNode"))); + + m = td.AddMethod("RemoveCurrentNode"); + m.Statements.Add(Easy.Var("nodeStack").InvokeMethod("Pop")); + m.Statements.Add(Easy.Var("nodeStack").InvokeMethod("Push", Easy.Null)); + } + + foreach (Type type in nodeTypes) { + if (!type.IsAbstract) { + EasyMethod m = td.AddMethod(typeof(object), VisitPrefix + type.Name); + m.Attributes = MemberAttributes.Public; + m.AddParameter(ConvertType(type), GetFieldName(type.Name)); + m.AddParameter(typeof(object), "data"); + + List assertions = new List(); + string varVariableName = GetFieldName(type.Name); + EasyExpression var = Easy.Var(varVariableName); + assertions.Add(AssertIsNotNull(var)); + + AddFieldVisitCode(m, type, var, assertions, transformer); + + if (type.GetCustomAttributes(typeof(HasChildrenAttribute), true).Length > 0) { + if (transformer) { + m.Statements.Add(new CodeSnippetStatement(CreateTransformerLoop(varVariableName + ".Children", "INode"))); + m.Body.Return(Easy.Null); + } else { + m.Body.Return(var.InvokeMethod("AcceptChildren", Easy.This, Easy.Var("data"))); + } + } else { + CodeExpressionStatement lastStatement = null; + if (m.Statements.Count > 0) { + lastStatement = m.Statements[m.Statements.Count - 1] as CodeExpressionStatement; + } + if (lastStatement != null) { + m.Statements.RemoveAt(m.Statements.Count - 1); + m.Body.Return(lastStatement.Expression); + } else { + m.Body.Return(Easy.Null); + } + } + + for (int i = 0; i < assertions.Count; i++) { + m.Statements.Insert(i, assertions[i]); + } + } + } + return td; + } + + static void AddFieldVisitCode(EasyMethod m, Type type, EasyExpression var, List assertions, bool transformer) + { + if (type != null) { + if (type.BaseType != typeof(StatementWithEmbeddedStatement)) { + AddFieldVisitCode(m, type.BaseType, var, assertions, transformer); + } + foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { + AddVisitCode(m, field, var, assertions, transformer); + } + if (type.BaseType == typeof(StatementWithEmbeddedStatement)) { + AddFieldVisitCode(m, type.BaseType, var, assertions, transformer); + } + } + } + + static CodeStatement AssertIsNotNull(CodeExpression expr) + { + return new CodeExpressionStatement( + Easy.Type("Debug").InvokeMethod("Assert", + Easy.Binary(expr, + CodeBinaryOperatorType.IdentityInequality, + Easy.Null)) + ); + } + + static string GetCode(CodeExpression ex) + { + using (StringWriter writer = new StringWriter()) { + new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromExpression(ex, writer, null); + return writer.ToString(); + } + } + + static string CreateTransformerLoop(string collection, string typeName) + { + return + "\t\t\tfor (int i = 0; i < " + collection + ".Count; i++) {\n" + + "\t\t\t\t" + typeName + " o = " + collection + "[i];\n" + + "\t\t\t\tDebug.Assert(o != null);\n" + + "\t\t\t\tnodeStack.Push(o);\n" + + "\t\t\t\to.AcceptVisitor(this, data);\n" + + (typeName == "INode" + ? "\t\t\t\to = nodeStack.Pop();\n" + : "\t\t\t\to = (" + typeName + ")nodeStack.Pop();\n") + + "\t\t\t\tif (o == null)\n" + + "\t\t\t\t\t" + collection + ".RemoveAt(i--);\n" + + "\t\t\t\telse\n" + + "\t\t\t\t\t" + collection + "[i] = o;\n" + + "\t\t\t}"; + } + + static bool AddVisitCode(EasyMethod m, FieldInfo field, EasyExpression var, List assertions, bool transformer) + { + EasyExpression prop = var.Property(GetPropertyName(field.Name)); + EasyExpression nodeStack = Easy.Var("nodeStack"); + if (field.FieldType.FullName.StartsWith("System.Collections.Generic.List")) { + Type elType = field.FieldType.GetGenericArguments()[0]; + if (!typeof(INode).IsAssignableFrom(elType)) + return false; + assertions.Add(AssertIsNotNull(prop)); + string code; + if (transformer) { + code = CreateTransformerLoop(GetCode(prop), ConvertType(elType).BaseType); + } else { + code = + "\t\t\tforeach (" + ConvertType(elType).BaseType + " o in " + GetCode(prop) + ") {\n" + + "\t\t\t\tDebug.Assert(o != null);\n" + + "\t\t\t\to.AcceptVisitor(this, data);\n" + + "\t\t\t}"; + } + m.Statements.Add(new CodeSnippetStatement(code)); + return true; + } + if (!typeof(INode).IsAssignableFrom(field.FieldType)) + return false; + assertions.Add(AssertIsNotNull(prop)); + if (transformer) { + m.Statements.Add(nodeStack.InvokeMethod("Push", prop)); + } + m.Statements.Add(prop.InvokeMethod("AcceptVisitor", + Easy.This, + Easy.Var("data"))); + if (transformer) { + m.Body.Assign(prop, nodeStack.InvokeMethod("Pop").CastTo(ConvertType(field.FieldType))); + } + return true; + } + + static CodeExpression CreateToString(Type type) + { + CodeMethodInvokeExpression ie = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(string)), + "Format"); + CodePrimitiveExpression prim = new CodePrimitiveExpression(); + ie.Parameters.Add(prim); + string text = "[" + type.Name; + int index = 0; + do { + foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic)) { + text += " " + GetPropertyName(field.Name) + "={" + index.ToString() + "}"; + index++; + if (typeof(System.Collections.ICollection).IsAssignableFrom(field.FieldType)) { + ie.Parameters.Add(new CodeSnippetExpression("GetCollectionString(" + GetPropertyName(field.Name) + ")")); + } else { + ie.Parameters.Add(new CodeVariableReferenceExpression(GetPropertyName(field.Name))); + } + } + type = type.BaseType; + } while (type != null); + prim.Value = text + "]"; + if (ie.Parameters.Count == 1) + return prim; + else + return ie; + // return String.Format("[AnonymousMethodExpression: Parameters={0} Body={1}]", + // GetCollectionString(Parameters), + // Body); + } + + static void ProcessType(Type type, EasyTypeDeclaration ctd) + { + foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)) { + ctd.AddField(ConvertType(field.FieldType), field.Name).Attributes = 0; + } + foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)) { + EasyProperty p = ctd.AddProperty(ConvertType(field.FieldType), GetPropertyName(field.Name)); + p.Getter.Return(Easy.Var(field.Name)); + CodeExpression ex; + if (field.FieldType.IsValueType) + ex = new CodePropertySetValueReferenceExpression(); + else + ex = GetDefaultValue("value", field); + p.Setter.Assign(Easy.Var(field.Name), ex); + if (typeof(INode).IsAssignableFrom(field.FieldType) && typeof(INullable).IsAssignableFrom(field.FieldType)) { + p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;")); + } + } + foreach (ConstructorInfo ctor in type.GetConstructors()) { + CodeConstructor c = new CodeConstructor(); + if (type.IsAbstract) + c.Attributes = MemberAttributes.Family; + else + c.Attributes = MemberAttributes.Public; + ctd.Members.Add(c); + ConstructorInfo baseCtor = GetBaseCtor(type); + foreach(ParameterInfo param in ctor.GetParameters()) { + c.Parameters.Add(new CodeParameterDeclarationExpression(ConvertType(param.ParameterType), + param.Name)); + if (baseCtor != null && Array.Exists(baseCtor.GetParameters(), delegate(ParameterInfo p) { return param.Name == p.Name; })) + continue; + c.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(GetPropertyName(param.Name)), + new CodeVariableReferenceExpression(param.Name))); + } + if (baseCtor != null) { + foreach(ParameterInfo param in baseCtor.GetParameters()) { + c.BaseConstructorArgs.Add(new CodeVariableReferenceExpression(param.Name)); + } + } + // initialize fields that were not initialized by parameter + foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)) { + if (field.FieldType.IsValueType && field.FieldType != typeof(Location)) + continue; + if (Array.Exists(ctor.GetParameters(), delegate(ParameterInfo p) { return field.Name == p.Name; })) + continue; + c.Statements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(field.Name), + GetDefaultValue(null, field))); + } + } + } + + internal static ConstructorInfo GetBaseCtor(Type type) + { + ConstructorInfo[] list = type.BaseType.GetConstructors(); + if (list.Length == 0) + return null; + else + return list[0]; + } + + internal static CodeExpression GetDefaultValue(string inputVariable, FieldInfo field) + { + string code; + // get default value: + if (field.FieldType == typeof(string)) { + code = "\"\""; + if (field.GetCustomAttributes(typeof(QuestionMarkDefaultAttribute), false).Length > 0) { + if (inputVariable == null) + return new CodePrimitiveExpression("?"); + else + return new CodeSnippetExpression("string.IsNullOrEmpty(" + inputVariable + ") ? \"?\" : " + inputVariable); + } + } else if (field.FieldType.FullName.StartsWith("System.Collections.Generic.List")) { + code = "new List<" + field.FieldType.GetGenericArguments()[0].Name + ">()"; + } else if (field.FieldType == typeof(Location)) { + code = "Location.Empty"; + } else { + code = field.FieldType.Name + ".Null"; + } + if (inputVariable != null) { + code = inputVariable + " ?? " + code; + } + return new CodeSnippetExpression(code); + } + + internal static string GetFieldName(string typeName) + { + return char.ToLower(typeName[0]) + typeName.Substring(1); + } + + internal static string GetPropertyName(string fieldName) + { + return char.ToUpper(fieldName[0]) + fieldName.Substring(1); + } + + internal static CodeTypeReference ConvertType(Type type) + { + if (type.IsGenericType && !type.IsGenericTypeDefinition) { + CodeTypeReference tr = ConvertType(type.GetGenericTypeDefinition()); + foreach (Type subType in type.GetGenericArguments()) { + tr.TypeArguments.Add(ConvertType(subType)); + } + return tr; + } else if (type.FullName.StartsWith("NRefactory") || type.FullName.StartsWith("System.Collections")) { + if (type.Name == "Attribute") + return new CodeTypeReference("ICSharpCode.NRefactory.Ast.Attribute"); + return new CodeTypeReference(type.Name); + } else { + return new CodeTypeReference(type); + } + } + + static CodeTypeDeclaration CreateNodeTrackingAstVisitorClass(List nodeTypes) + { + EasyTypeDeclaration td = new EasyTypeDeclaration("NodeTrackingAstVisitor"); + td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Abstract; + td.BaseTypes.Add(new CodeTypeReference("AbstractAstVisitor")); + + string comment = "\n " + + "The NodeTrackingAstVisitor will iterate through the whole AST,\n " + + "just like the AbstractAstVisitor, and calls the virtual methods\n " + + "BeginVisit and EndVisit for each node being visited.\n " + + ""; + td.Comments.Add(new CodeCommentStatement(comment, true)); + comment = "\n " + + "base.Visit(node, data) calls this.TrackedVisit(node, data), so if\n " + + "you want to visit child nodes using the default visiting behaviour,\n " + + "use base.TrackedVisit(parentNode, data).\n " + + ""; + td.Comments.Add(new CodeCommentStatement(comment, true)); + + EasyMethod m = td.AddMethod("BeginVisit"); + m.Attributes = MemberAttributes.Family; + m.AddParameter(Easy.TypeRef("INode"), "node"); + + m = td.AddMethod("EndVisit"); + m.Attributes = MemberAttributes.Family; + m.AddParameter(Easy.TypeRef("INode"), "node"); + + foreach (Type type in nodeTypes) { + if (!type.IsAbstract) { + + m = td.AddMethod(typeof(object), VisitPrefix + type.Name); + m.Attributes = MemberAttributes.Public | MemberAttributes.Override; + m.AddParameter(ConvertType(type), GetFieldName(type.Name)); + m.AddParameter(new CodeTypeReference(typeof(object)), "data"); + + CodeExpression var = Easy.Var(GetFieldName(type.Name)); + +// m.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "BeginVisit"), new CodeExpression[] { var })); +// m.Statements.Add(new CodeVariableDeclarationStatement(new CodeTypeReference(typeof(object)), "result", new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "TrackedVisit"), new CodeExpression[] { var, new CodeVariableReferenceExpression("data") }))); +// m.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), "EndVisit"), new CodeExpression[] { var })); +// m.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("result"))); + m.Body.InvokeMethod(Easy.This, "BeginVisit", var); + m.Body.DeclareVariable(typeof(object), "result").InitExpression + = Easy.This.InvokeMethod("TrackedVisit" + type.Name, var, Easy.Var("data")); + m.Body.InvokeMethod(Easy.This, "EndVisit", var); + m.Body.Return(Easy.Var("result")); + } + } + + foreach (Type type in nodeTypes) { + if (!type.IsAbstract) { + + m = td.AddMethod(typeof(object), "TrackedVisit" + type.Name); + m.Attributes = MemberAttributes.Public; + m.AddParameter(ConvertType(type), GetFieldName(type.Name)); + m.AddParameter(new CodeTypeReference(typeof(object)), "data"); + + m.Body.Return(Easy.Base.InvokeMethod(VisitPrefix + type.Name, Easy.Var(GetFieldName(type.Name)), Easy.Var("data"))); + } + } + + return td; + } + } +} diff --git a/lib/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj b/lib/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj new file mode 100644 index 000000000..ef7f609fe --- /dev/null +++ b/lib/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj @@ -0,0 +1,56 @@ + + + Exe + NRefactoryASTGenerator + NRefactoryASTGenerator + Debug + AnyCPU + {B22522AA-B5BF-4A58-AC6D-D4B45805521F} + False + False + False + Auto + 4194304 + AnyCPU + 4096 + 4 + 0169 + false + + + bin\Debug\ + False + DEBUG;TRACE + true + Full + True + + + bin\Release\ + True + TRACE + False + None + False + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/NRefactory/Project/Configuration/AssemblyInfo.cs b/lib/NRefactory/Project/Configuration/AssemblyInfo.cs new file mode 100644 index 000000000..6f0cf97dc --- /dev/null +++ b/lib/NRefactory/Project/Configuration/AssemblyInfo.cs @@ -0,0 +1,25 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Reflection; +using System.Runtime.CompilerServices; + +[assembly: CLSCompliant(true)] +[assembly: StringFreezing()] + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("NRefactory")] +[assembly: AssemblyDescription("Parser and refactoring library for C# and VB.NET")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] diff --git a/lib/NRefactory/Project/NRefactory.csproj b/lib/NRefactory/Project/NRefactory.csproj new file mode 100644 index 000000000..9657323c4 --- /dev/null +++ b/lib/NRefactory/Project/NRefactory.csproj @@ -0,0 +1,152 @@ + + + Debug + AnyCPU + 8.0.41115 + 2.0 + {3A9AE6AA-BC07-4A2F-972C-581E3AE2F195} + ICSharpCode.NRefactory + ICSharpCode.NRefactory + Library + 4 + False + False + OnSuccessfulBuild + Library + true + Resources\ICSharpCode.NRefactory.snk + False + False + Auto + 94896128 + AnyCPU + 4096 + False + -Microsoft.Design#CA1002;-Microsoft.Design#CA1020;-Microsoft.Design#CA1051;-Microsoft.Design#CA1062;-Microsoft.Globalization#CA1303;-Microsoft.Globalization#CA1305;-Microsoft.Naming#CA1704;-Microsoft.Performance#CA1800;-Microsoft.Performance#CA1805;-Microsoft.Usage#CA2211;-Microsoft.Usage#CA2227 + v2.0 + + + False + True + TEST; DEBUG + false + + + True + False + TEST + false + + + Full + true + bin\Debug + + + false + None + bin\Release + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lib/NRefactory/Project/NRefactory.csproj.user b/lib/NRefactory/Project/NRefactory.csproj.user new file mode 100644 index 000000000..3b61c2cc0 --- /dev/null +++ b/lib/NRefactory/Project/NRefactory.csproj.user @@ -0,0 +1,13 @@ + + + 8.0.41115 + ShowAllFiles + 0 + + + ..\..\..\..\bin\SharpDevelop.exe + + + ..\..\..\..\bin\SharpDevelop.exe + + \ No newline at end of file diff --git a/lib/NRefactory/Project/Resources/ICSharpCode.NRefactory.snk b/lib/NRefactory/Project/Resources/ICSharpCode.NRefactory.snk new file mode 100644 index 000000000..b273cdc5a Binary files /dev/null and b/lib/NRefactory/Project/Resources/ICSharpCode.NRefactory.snk differ diff --git a/lib/NRefactory/Project/Src/Ast/AbstractNode.cs b/lib/NRefactory/Project/Src/Ast/AbstractNode.cs new file mode 100644 index 000000000..a4ff1b5e0 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/AbstractNode.cs @@ -0,0 +1,76 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace ICSharpCode.NRefactory.Ast +{ + public abstract class AbstractNode : INode + { + List children = new List(); + + public INode Parent { get; set; } + public Location StartLocation { get; set; } + public Location EndLocation { get; set; } + public object UserData { get; set; } + + public List Children { + get { + return children; + } + set { + Debug.Assert(value != null); + children = value; + } + } + + public virtual void AddChild(INode childNode) + { + Debug.Assert(childNode != null); + children.Add(childNode); + } + + public abstract object AcceptVisitor(IAstVisitor visitor, object data); + + public virtual object AcceptChildren(IAstVisitor visitor, object data) + { + foreach (INode child in children) { + Debug.Assert(child != null); + child.AcceptVisitor(visitor, data); + } + return data; + } + + public static string GetCollectionString(ICollection collection) + { + StringBuilder output = new StringBuilder(); + output.Append('{'); + + if (collection != null) { + IEnumerator en = collection.GetEnumerator(); + bool isFirst = true; + while (en.MoveNext()) { + if (!isFirst) { + output.Append(", "); + } else { + isFirst = false; + } + output.Append(en.Current == null ? "" : en.Current.ToString()); + } + } else { + return "null"; + } + + output.Append('}'); + return output.ToString(); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/Enums.cs b/lib/NRefactory/Project/Src/Ast/Enums.cs new file mode 100644 index 000000000..b90245f87 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/Enums.cs @@ -0,0 +1,369 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Ast +{ + [Flags] + public enum Modifiers + { + None = 0x0000, + + // Access + Private = 0x0001, + /// C# 'internal', VB 'Friend' + Internal = 0x0002, + Protected = 0x0004, + Public = 0x0008, + Dim = 0x0010, // VB.NET SPECIFIC, for fields/local variables only + + // Scope + Abstract = 0x0010, // == MustOverride/MustInherit + Virtual = 0x0020, + Sealed = 0x0040, + /// C# 'static', VB 'Shared' + Static = 0x0080, + Override = 0x0100, + /// For fields: readonly (c# and vb), for properties: get-only (vb) + ReadOnly = 0x0200, + Const = 0x0400, + /// C# 'new', VB 'Shadows' + New = 0x0800, + Partial = 0x1000, + + // Special + Extern = 0x2000, + Volatile = 0x4000, + Unsafe = 0x8000, + Overloads = 0x10000, // VB specific + WithEvents = 0x20000, // VB specific + Default = 0x40000, // VB specific + Fixed = 0x80000, // C# specific (fixed size arrays in unsafe structs) + + /// Generated code, not part of parsed code + Synthetic = 0x200000, + /// Only for VB properties. + WriteOnly = 0x400000, // VB specific + + Visibility = Private | Public | Protected | Internal, + Classes = New | Visibility | Abstract | Sealed | Partial | Static, + VBModules = Visibility, + VBStructures = Visibility | New, + VBEnums = Visibility | New, + VBInterfacs = Visibility | New, + VBDelegates = Visibility | New, + VBMethods = Visibility | New | Static | Virtual | Sealed | Abstract | Override | Overloads, + VBExternalMethods = Visibility | New | Overloads, + VBEvents = Visibility | New | Overloads, + VBProperties = VBMethods | Default | ReadOnly | WriteOnly, + VBCustomEvents = Visibility | New | Overloads, + VBOperators = Public | Static | Overloads | New, + + + // this is not documented in the spec + VBInterfaceEvents = New, + VBInterfaceMethods = New | Overloads, + VBInterfaceProperties = New | Overloads | ReadOnly | WriteOnly | Default, + VBInterfaceEnums = New, + + Fields = New | Visibility | Static | ReadOnly | Volatile | Fixed, + PropertysEventsMethods = New | Visibility | Static | Virtual | Sealed | Override | Abstract | Extern, + Indexers = New | Visibility | Virtual | Sealed | Override | Abstract | Extern, + Operators = Public | Static | Extern, + Constants = New | Visibility, + StructsInterfacesEnumsDelegates = New | Visibility | Partial, + StaticConstructors = Extern | Static | Unsafe, + Destructors = Extern | Unsafe, + Constructors = Visibility | Extern, + } + + public enum ClassType + { + Class, + Module, + Interface, + Struct, + Enum + } + + public enum ParentType + { + ClassOrStruct, + InterfaceOrEnum, + Namespace, + Unknown + } + + public enum FieldDirection + { + None, + In, + Out, + Ref + } + + [Flags] + public enum ParameterModifiers + { + // Values must be the same as in SharpDevelop's ParameterModifiers + None = 0, + In = 1, + Out = 2, + Ref = 4, + Params = 8, + Optional = 16 + } + + public enum AssignmentOperatorType + { + None, + Assign, + + Add, + Subtract, + Multiply, + Divide, + Modulus, + + Power, // (VB only) + DivideInteger, // (VB only) + ConcatString, // (VB only) + + ShiftLeft, + ShiftRight, + + BitwiseAnd, + BitwiseOr, + ExclusiveOr, + } + + public enum BinaryOperatorType + { + None, + + /// '&' in C#, 'And' in VB. + BitwiseAnd, + /// '|' in C#, 'Or' in VB. + BitwiseOr, + /// '&&' in C#, 'AndAlso' in VB. + LogicalAnd, + /// '||' in C#, 'OrElse' in VB. + LogicalOr, + /// '^' in C#, 'Xor' in VB. + ExclusiveOr, + + /// > + GreaterThan, + /// >= + GreaterThanOrEqual, + /// '==' in C#, '=' in VB. + Equality, + /// '!=' in C#, '<>' in VB. + InEquality, + /// < + LessThan, + /// <= + LessThanOrEqual, + + /// + + Add, + /// - + Subtract, + /// * + Multiply, + /// / + Divide, + /// '%' in C#, 'Mod' in VB. + Modulus, + /// VB-only: \ + DivideInteger, + /// VB-only: ^ + Power, + /// VB-only: & + Concat, + + /// C#: << + ShiftLeft, + /// C#: >> + ShiftRight, + /// VB-only: Is + ReferenceEquality, + /// VB-only: IsNot + ReferenceInequality, + + /// VB-only: Like + Like, + /// C#: ?? + NullCoalescing, + } + + public enum CastType + { + /// + /// direct cast (C#, VB "DirectCast") + /// + Cast, + /// + /// try cast (C# "as", VB "TryCast") + /// + TryCast, + /// + /// converting cast (VB "CType") + /// + Conversion, + /// + /// primitive converting cast (VB "CString" etc.) + /// + PrimitiveConversion + } + + public enum UnaryOperatorType + { + None, + Not, + BitNot, + + Minus, + Plus, + + Increment, + Decrement, + + PostIncrement, + PostDecrement, + + /// Dereferencing pointer + Star, + /// Get address of + BitWiseAnd + } + + public enum ContinueType + { + None, + Do, + For, + While + } + + public enum ConditionType + { + None, + Until, + While, + DoWhile + } + + public enum ConditionPosition + { + None, + Start, + End + } + + public enum ExitType + { + None, + Sub, + Function, + Property, + Do, + For, + While, + Select, + Try + } + + public enum ConstructorInitializerType + { + None, + Base, + This + } + + public enum ConversionType + { + None, + Implicit, + Explicit + } + + public enum OverloadableOperatorType + { + None, + + Add, + Subtract, + Multiply, + Divide, + Modulus, + Concat, + + Not, + BitNot, + + BitwiseAnd, + BitwiseOr, + ExclusiveOr, + + ShiftLeft, + ShiftRight, + + GreaterThan, + GreaterThanOrEqual, + Equality, + InEquality, + LessThan, + LessThanOrEqual, + + Increment, + Decrement, + + IsTrue, + IsFalse, + + // VB specific + Like, + Power, + CType, + DivideInteger + } + + /// + /// Charset types, used in external methods + /// declarations (VB only). + /// + public enum CharsetModifier + { + None, + Auto, + Unicode, + Ansi + } + + /// + /// Compare type, used in the Option Compare + /// pragma (VB only). + /// + public enum OptionType + { + None, + Explicit, + Strict, + CompareBinary, + CompareText + } + + /// + /// Specifies the ordering direction of a QueryExpressionOrdering node. + /// + public enum QueryExpressionOrderingDirection + { + None, Ascending, Descending + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/BlockStatement.cs b/lib/NRefactory/Project/Src/Ast/General/BlockStatement.cs new file mode 100644 index 000000000..838bcdaae --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/BlockStatement.cs @@ -0,0 +1,63 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Ast +{ + public class BlockStatement : Statement + { + // Children in C#: LabelStatement, LocalVariableDeclaration, Statement + // Children in VB: LabelStatement, EndStatement, Statement + + public static new BlockStatement Null { + get { + return NullBlockStatement.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitBlockStatement(this, data); + } + + public override string ToString() + { + return String.Format("[BlockStatement: Children={0}]", + GetCollectionString(base.Children)); + } + } + + internal sealed class NullBlockStatement : BlockStatement + { + public static readonly NullBlockStatement Instance = new NullBlockStatement(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return data; + } + public override object AcceptChildren(IAstVisitor visitor, object data) + { + return data; + } + public override void AddChild(INode childNode) + { + throw new InvalidOperationException(); + } + + public override string ToString() + { + return String.Format("[NullBlockStatement]"); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/CompilationUnit.cs b/lib/NRefactory/Project/Src/Ast/General/CompilationUnit.cs new file mode 100644 index 000000000..9afb7ba43 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/CompilationUnit.cs @@ -0,0 +1,60 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections; + +namespace ICSharpCode.NRefactory.Ast +{ + public class CompilationUnit : AbstractNode + { + // Children in C#: UsingAliasDeclaration, UsingDeclaration, AttributeSection, NamespaceDeclaration + // Children in VB: OptionStatements, ImportsStatement, AttributeSection, NamespaceDeclaration + + Stack blockStack = new Stack(); + + public CompilationUnit() + { + blockStack.Push(this); + } + + public void BlockStart(INode block) + { + blockStack.Push(block); + } + + public void BlockEnd() + { + blockStack.Pop(); + } + + public INode CurrentBock { + get { + return blockStack.Count > 0 ? (INode)blockStack.Peek() : null; + } + } + + public override void AddChild(INode childNode) + { + if (childNode != null) { + INode parent = (INode)blockStack.Peek(); + parent.Children.Add(childNode); + childNode.Parent = parent; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitCompilationUnit(this, data); + } + + public override string ToString() + { + return String.Format("[CompilationUnit]"); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/Expression.cs b/lib/NRefactory/Project/Src/Ast/General/Expression.cs new file mode 100644 index 000000000..8e2646a69 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/Expression.cs @@ -0,0 +1,107 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Ast +{ + public abstract class Expression : AbstractNode, INullable + { + public static Expression Null { + get { + return NullExpression.Instance; + } + } + + public virtual bool IsNull { + get { + return false; + } + } + + public static Expression CheckNull(Expression expression) + { + return expression == null ? NullExpression.Instance : expression; + } + + /// + /// Returns the existing expression plus the specified integer value. + /// The old object is not modified, but might be a subobject on the new expression + /// (and thus its parent property is modified). + /// + public static Expression AddInteger(Expression expr, int value) + { + PrimitiveExpression pe = expr as PrimitiveExpression; + if (pe != null && pe.Value is int) { + int newVal = (int)pe.Value + value; + return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); + } + BinaryOperatorExpression boe = expr as BinaryOperatorExpression; + if (boe != null && boe.Op == BinaryOperatorType.Add) { + // clone boe: + boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); + + boe.Right = AddInteger(boe.Right, value); + if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) { + int newVal = (int)((PrimitiveExpression)boe.Right).Value; + if (newVal == 0) { + return boe.Left; + } else if (newVal < 0) { + ((PrimitiveExpression)boe.Right).Value = -newVal; + boe.Op = BinaryOperatorType.Subtract; + } + } + return boe; + } + if (boe != null && boe.Op == BinaryOperatorType.Subtract) { + pe = boe.Right as PrimitiveExpression; + if (pe != null && pe.Value is int) { + int newVal = (int)pe.Value - value; + if (newVal == 0) + return boe.Left; + + // clone boe: + boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right); + + if (newVal < 0) { + newVal = -newVal; + boe.Op = BinaryOperatorType.Add; + } + boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); + return boe; + } + } + BinaryOperatorType opType = BinaryOperatorType.Add; + if (value < 0) { + value = -value; + opType = BinaryOperatorType.Subtract; + } + return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo))); + } + } + + internal sealed class NullExpression : Expression + { + internal static readonly NullExpression Instance = new NullExpression(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return null; + } + + public override string ToString() + { + return String.Format("[NullExpression]"); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/LocalVariableDeclaration.cs b/lib/NRefactory/Project/Src/Ast/General/LocalVariableDeclaration.cs new file mode 100644 index 000000000..79c00ce91 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/LocalVariableDeclaration.cs @@ -0,0 +1,102 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.Ast +{ + public class LocalVariableDeclaration : Statement + { + TypeReference typeReference; + Modifiers modifier = Modifiers.None; + List variables = new List(1); + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = TypeReference.CheckNull(value); + } + } + + public Modifiers Modifier { + get { + return modifier; + } + set { + modifier = value; + } + } + + public List Variables { + get { + return variables; + } + } + + public TypeReference GetTypeForVariable(int variableIndex) + { + if (!typeReference.IsNull) { + return typeReference; + } + + for (int i = variableIndex; i < Variables.Count;++i) { + if (!((VariableDeclaration)Variables[i]).TypeReference.IsNull) { + return ((VariableDeclaration)Variables[i]).TypeReference; + } + } + return null; + } + + public LocalVariableDeclaration(VariableDeclaration declaration) : this(TypeReference.Null) + { + Variables.Add(declaration); + } + + public LocalVariableDeclaration(TypeReference typeReference) + { + this.TypeReference = typeReference; + } + + public LocalVariableDeclaration(TypeReference typeReference, Modifiers modifier) + { + this.TypeReference = typeReference; + this.modifier = modifier; + } + + public LocalVariableDeclaration(Modifiers modifier) + { + this.typeReference = TypeReference.Null; + this.modifier = modifier; + } + + public VariableDeclaration GetVariableDeclaration(string variableName) + { + foreach (VariableDeclaration variableDeclaration in variables) { + if (variableDeclaration.Name == variableName) { + return variableDeclaration; + } + } + return null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitLocalVariableDeclaration(this, data); + } + + public override string ToString() + { + return String.Format("[LocalVariableDeclaration: Type={0}, Modifier ={1} Variables={2}]", + typeReference, + modifier, + GetCollectionString(variables)); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/PrimitiveExpression.cs b/lib/NRefactory/Project/Src/Ast/General/PrimitiveExpression.cs new file mode 100644 index 000000000..2922db553 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/PrimitiveExpression.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Ast +{ + public class PrimitiveExpression : Expression + { + object val; + string stringValue; + + public object Value { + get { + return val; + } + set { + val = value; + } + } + + public string StringValue { + get { + return stringValue; + } + set { + stringValue = value == null ? String.Empty : value; + } + } + + public PrimitiveExpression(object val, string stringValue) + { + this.Value = val; + this.StringValue = stringValue; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitPrimitiveExpression(this, data); + } + + public override string ToString() + { + return String.Format("[PrimitiveExpression: Value={1}, ValueType={2}, StringValue={0}]", + stringValue, + Value, + Value == null ? "null" : Value.GetType().FullName + ); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/General/Statement.cs b/lib/NRefactory/Project/Src/Ast/General/Statement.cs new file mode 100644 index 000000000..93aa718bb --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/General/Statement.cs @@ -0,0 +1,66 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Ast +{ + public abstract class Statement : AbstractNode, INullable + { + public static Statement Null { + get { + return NullStatement.Instance; + } + } + + public virtual bool IsNull { + get { + return false; + } + } + + public static Statement CheckNull(Statement statement) + { + return statement ?? NullStatement.Instance; + } + } + + public abstract class StatementWithEmbeddedStatement : Statement + { + Statement embeddedStatement; + + public Statement EmbeddedStatement { + get { + return embeddedStatement; + } + set { + embeddedStatement = Statement.CheckNull(value); + if (value != null) + value.Parent = this; + } + } + } + + internal sealed class NullStatement : Statement + { + public static readonly NullStatement Instance = new NullStatement(); + + public override bool IsNull { + get { return true; } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return data; + } + + public override string ToString() + { + return String.Format("[NullStatement]"); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/Generated.cs b/lib/NRefactory/Project/Src/Ast/Generated.cs new file mode 100644 index 000000000..e491c1f41 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/Generated.cs @@ -0,0 +1,4956 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.1433 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ICSharpCode.NRefactory.Ast { + using System; + using System.Collections.Generic; + + + public class AddHandlerStatement : Statement { + + Expression eventExpression; + + Expression handlerExpression; + + public Expression EventExpression { + get { + return eventExpression; + } + set { + eventExpression = value ?? Expression.Null; + if (!eventExpression.IsNull) eventExpression.Parent = this; + } + } + + public Expression HandlerExpression { + get { + return handlerExpression; + } + set { + handlerExpression = value ?? Expression.Null; + if (!handlerExpression.IsNull) handlerExpression.Parent = this; + } + } + + public AddHandlerStatement(Expression eventExpression, Expression handlerExpression) { + EventExpression = eventExpression; + HandlerExpression = handlerExpression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAddHandlerStatement(this, data); + } + + public override string ToString() { + return string.Format("[AddHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); + } + } + + public class AddressOfExpression : Expression { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public AddressOfExpression(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAddressOfExpression(this, data); + } + + public override string ToString() { + return string.Format("[AddressOfExpression Expression={0}]", Expression); + } + } + + public class AnonymousMethodExpression : Expression { + + List parameters; + + BlockStatement body; + + bool hasParameterList; + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public BlockStatement Body { + get { + return body; + } + set { + body = value ?? BlockStatement.Null; + if (!body.IsNull) body.Parent = this; + } + } + + public bool HasParameterList { + get { + return hasParameterList; + } + set { + hasParameterList = value; + } + } + + public AnonymousMethodExpression() { + parameters = new List(); + body = BlockStatement.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAnonymousMethodExpression(this, data); + } + + public override string ToString() { + return string.Format("[AnonymousMethodExpression Parameters={0} Body={1} HasParameterList={2}]", GetCollectionString(Parameters), Body, HasParameterList); + } + } + + public class ArrayCreateExpression : Expression { + + TypeReference createType; + + List arguments; + + CollectionInitializerExpression arrayInitializer; + + public TypeReference CreateType { + get { + return createType; + } + set { + createType = value ?? TypeReference.Null; + } + } + + public List Arguments { + get { + return arguments; + } + set { + arguments = value ?? new List(); + } + } + + public CollectionInitializerExpression ArrayInitializer { + get { + return arrayInitializer; + } + set { + arrayInitializer = value ?? CollectionInitializerExpression.Null; + if (!arrayInitializer.IsNull) arrayInitializer.Parent = this; + } + } + + public ArrayCreateExpression(TypeReference createType) { + CreateType = createType; + arguments = new List(); + arrayInitializer = CollectionInitializerExpression.Null; + } + + public ArrayCreateExpression(TypeReference createType, List arguments) { + CreateType = createType; + Arguments = arguments; + arrayInitializer = CollectionInitializerExpression.Null; + } + + public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) { + CreateType = createType; + ArrayInitializer = arrayInitializer; + arguments = new List(); + } + + public bool IsImplicitlyTyped { + get { + return createType.IsNull || string.IsNullOrEmpty(createType.Type); + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitArrayCreateExpression(this, data); + } + + public override string ToString() { + return string.Format("[ArrayCreateExpression CreateType={0} Arguments={1} ArrayInitializer={2}]", CreateType, GetCollectionString(Arguments), ArrayInitializer); + } + } + + public class AssignmentExpression : Expression { + + Expression left; + + AssignmentOperatorType op; + + Expression right; + + public Expression Left { + get { + return left; + } + set { + left = value ?? Expression.Null; + if (!left.IsNull) left.Parent = this; + } + } + + public AssignmentOperatorType Op { + get { + return op; + } + set { + op = value; + } + } + + public Expression Right { + get { + return right; + } + set { + right = value ?? Expression.Null; + if (!right.IsNull) right.Parent = this; + } + } + + public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right) { + Left = left; + Op = op; + Right = right; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAssignmentExpression(this, data); + } + + public override string ToString() { + return string.Format("[AssignmentExpression Left={0} Op={1} Right={2}]", Left, Op, Right); + } + } + + public class Attribute : AbstractNode { + + string name; + + List positionalArguments; + + List namedArguments; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public List PositionalArguments { + get { + return positionalArguments; + } + set { + positionalArguments = value ?? new List(); + } + } + + public List NamedArguments { + get { + return namedArguments; + } + set { + namedArguments = value ?? new List(); + } + } + + public Attribute() { + name = ""; + positionalArguments = new List(); + namedArguments = new List(); + } + + public Attribute(string name, List positionalArguments, List namedArguments) { + Name = name; + PositionalArguments = positionalArguments; + NamedArguments = namedArguments; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAttribute(this, data); + } + + public override string ToString() { + return string.Format("[Attribute Name={0} PositionalArguments={1} NamedArguments={2}]", Name, GetCollectionString(PositionalArguments), GetCollectionString(NamedArguments)); + } + } + + public abstract class AttributedNode : AbstractNode { + + List attributes; + + Modifiers modifier; + + public List Attributes { + get { + return attributes; + } + set { + attributes = value ?? new List(); + } + } + + public Modifiers Modifier { + get { + return modifier; + } + set { + modifier = value; + } + } + + protected AttributedNode() { + attributes = new List(); + } + + protected AttributedNode(List attributes) { + Attributes = attributes; + } + + protected AttributedNode(Modifiers modifier, List attributes) { + Modifier = modifier; + Attributes = attributes; + } + } + + public class AttributeSection : AbstractNode { + + string attributeTarget; + + List attributes; + + public string AttributeTarget { + get { + return attributeTarget; + } + set { + attributeTarget = value ?? ""; + } + } + + public List Attributes { + get { + return attributes; + } + set { + attributes = value ?? new List(); + } + } + + public AttributeSection() { + attributeTarget = ""; + attributes = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitAttributeSection(this, data); + } + + public override string ToString() { + return string.Format("[AttributeSection AttributeTarget={0} Attributes={1}]", AttributeTarget, GetCollectionString(Attributes)); + } + } + + public class BaseReferenceExpression : Expression { + + public BaseReferenceExpression() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitBaseReferenceExpression(this, data); + } + + public override string ToString() { + return "[BaseReferenceExpression]"; + } + } + + public class BinaryOperatorExpression : Expression { + + Expression left; + + BinaryOperatorType op; + + Expression right; + + public Expression Left { + get { + return left; + } + set { + left = value ?? Expression.Null; + if (!left.IsNull) left.Parent = this; + } + } + + public BinaryOperatorType Op { + get { + return op; + } + set { + op = value; + } + } + + public Expression Right { + get { + return right; + } + set { + right = value ?? Expression.Null; + if (!right.IsNull) right.Parent = this; + } + } + + public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) { + Left = left; + Op = op; + Right = right; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitBinaryOperatorExpression(this, data); + } + + public override string ToString() { + return string.Format("[BinaryOperatorExpression Left={0} Op={1} Right={2}]", Left, Op, Right); + } + } + + public class BreakStatement : Statement { + + public BreakStatement() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitBreakStatement(this, data); + } + + public override string ToString() { + return "[BreakStatement]"; + } + } + + public class CaseLabel : AbstractNode { + + Expression label; + + BinaryOperatorType binaryOperatorType; + + Expression toExpression; + + public Expression Label { + get { + return label; + } + set { + label = value ?? Expression.Null; + if (!label.IsNull) label.Parent = this; + } + } + + public BinaryOperatorType BinaryOperatorType { + get { + return binaryOperatorType; + } + set { + binaryOperatorType = value; + } + } + + public Expression ToExpression { + get { + return toExpression; + } + set { + toExpression = value ?? Expression.Null; + if (!toExpression.IsNull) toExpression.Parent = this; + } + } + + public CaseLabel() { + label = Expression.Null; + toExpression = Expression.Null; + } + + public CaseLabel(Expression label) { + Label = label; + toExpression = Expression.Null; + } + + public CaseLabel(Expression label, Expression toExpression) { + Label = label; + ToExpression = toExpression; + } + + public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label) { + BinaryOperatorType = binaryOperatorType; + Label = label; + toExpression = Expression.Null; + } + + public bool IsDefault { + get { + return label.IsNull; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCaseLabel(this, data); + } + + public override string ToString() { + return string.Format("[CaseLabel Label={0} BinaryOperatorType={1} ToExpression={2}]", Label, BinaryOperatorType, ToExpression); + } + } + + public class CastExpression : Expression { + + TypeReference castTo; + + Expression expression; + + CastType castType; + + public TypeReference CastTo { + get { + return castTo; + } + set { + castTo = value ?? TypeReference.Null; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public CastType CastType { + get { + return castType; + } + set { + castType = value; + } + } + + public CastExpression(TypeReference castTo) { + CastTo = castTo; + expression = Expression.Null; + } + + public CastExpression(TypeReference castTo, Expression expression, CastType castType) { + CastTo = castTo; + Expression = expression; + CastType = castType; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCastExpression(this, data); + } + + public override string ToString() { + return string.Format("[CastExpression CastTo={0} Expression={1} CastType={2}]", CastTo, Expression, CastType); + } + } + + public class CatchClause : AbstractNode { + + TypeReference typeReference; + + string variableName; + + Statement statementBlock; + + Expression condition; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public string VariableName { + get { + return variableName; + } + set { + variableName = value ?? ""; + } + } + + public Statement StatementBlock { + get { + return statementBlock; + } + set { + statementBlock = value ?? Statement.Null; + if (!statementBlock.IsNull) statementBlock.Parent = this; + } + } + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock) { + TypeReference = typeReference; + VariableName = variableName; + StatementBlock = statementBlock; + condition = Expression.Null; + } + + public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition) { + TypeReference = typeReference; + VariableName = variableName; + StatementBlock = statementBlock; + Condition = condition; + } + + public CatchClause(Statement statementBlock) { + StatementBlock = statementBlock; + typeReference = TypeReference.Null; + variableName = ""; + condition = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCatchClause(this, data); + } + + public override string ToString() { + return string.Format("[CatchClause TypeReference={0} VariableName={1} StatementBlock={2} Condition={3}]" + + "", TypeReference, VariableName, StatementBlock, Condition); + } + } + + public class CheckedExpression : Expression { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public CheckedExpression(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCheckedExpression(this, data); + } + + public override string ToString() { + return string.Format("[CheckedExpression Expression={0}]", Expression); + } + } + + public class CheckedStatement : Statement { + + Statement block; + + public Statement Block { + get { + return block; + } + set { + block = value ?? Statement.Null; + if (!block.IsNull) block.Parent = this; + } + } + + public CheckedStatement(Statement block) { + Block = block; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCheckedStatement(this, data); + } + + public override string ToString() { + return string.Format("[CheckedStatement Block={0}]", Block); + } + } + + public class ClassReferenceExpression : Expression { + + public ClassReferenceExpression() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitClassReferenceExpression(this, data); + } + + public override string ToString() { + return "[ClassReferenceExpression]"; + } + } + + public class CollectionInitializerExpression : Expression { + + List createExpressions; + + public List CreateExpressions { + get { + return createExpressions; + } + set { + createExpressions = value ?? new List(); + } + } + + public CollectionInitializerExpression() { + createExpressions = new List(); + } + + public CollectionInitializerExpression(List createExpressions) { + CreateExpressions = createExpressions; + } + + public new static CollectionInitializerExpression Null { + get { + return NullCollectionInitializerExpression.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitCollectionInitializerExpression(this, data); + } + + public override string ToString() { + return string.Format("[CollectionInitializerExpression CreateExpressions={0}]", GetCollectionString(CreateExpressions)); + } + } + + internal sealed class NullCollectionInitializerExpression : CollectionInitializerExpression { + + internal static NullCollectionInitializerExpression Instance = new NullCollectionInitializerExpression(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullCollectionInitializerExpression]"; + } + } + + public class ConditionalExpression : Expression { + + Expression condition; + + Expression trueExpression; + + Expression falseExpression; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public Expression TrueExpression { + get { + return trueExpression; + } + set { + trueExpression = value ?? Expression.Null; + if (!trueExpression.IsNull) trueExpression.Parent = this; + } + } + + public Expression FalseExpression { + get { + return falseExpression; + } + set { + falseExpression = value ?? Expression.Null; + if (!falseExpression.IsNull) falseExpression.Parent = this; + } + } + + public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) { + Condition = condition; + TrueExpression = trueExpression; + FalseExpression = falseExpression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitConditionalExpression(this, data); + } + + public override string ToString() { + return string.Format("[ConditionalExpression Condition={0} TrueExpression={1} FalseExpression={2}]", Condition, TrueExpression, FalseExpression); + } + } + + public class ConstructorDeclaration : ParametrizedNode { + + ConstructorInitializer constructorInitializer; + + BlockStatement body; + + public ConstructorInitializer ConstructorInitializer { + get { + return constructorInitializer; + } + set { + constructorInitializer = value ?? ConstructorInitializer.Null; + if (!constructorInitializer.IsNull) constructorInitializer.Parent = this; + } + } + + public BlockStatement Body { + get { + return body; + } + set { + body = value ?? BlockStatement.Null; + if (!body.IsNull) body.Parent = this; + } + } + + public ConstructorDeclaration(string name, Modifiers modifier, List parameters, List attributes) { + Name = name; + Modifier = modifier; + Parameters = parameters; + Attributes = attributes; + constructorInitializer = ConstructorInitializer.Null; + body = BlockStatement.Null; + } + + public ConstructorDeclaration(string name, Modifiers modifier, List parameters, ConstructorInitializer constructorInitializer, List attributes) { + Name = name; + Modifier = modifier; + Parameters = parameters; + ConstructorInitializer = constructorInitializer; + Attributes = attributes; + body = BlockStatement.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitConstructorDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[ConstructorDeclaration ConstructorInitializer={0} Body={1} Name={2} Parameters={" + + "3} Attributes={4} Modifier={5}]", ConstructorInitializer, Body, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class ConstructorInitializer : AbstractNode, INullable { + + ConstructorInitializerType constructorInitializerType; + + List arguments; + + public ConstructorInitializerType ConstructorInitializerType { + get { + return constructorInitializerType; + } + set { + constructorInitializerType = value; + } + } + + public List Arguments { + get { + return arguments; + } + set { + arguments = value ?? new List(); + } + } + + public ConstructorInitializer() { + arguments = new List(); + } + + public virtual bool IsNull { + get { + return false; + } + } + + public static ConstructorInitializer Null { + get { + return NullConstructorInitializer.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitConstructorInitializer(this, data); + } + + public override string ToString() { + return string.Format("[ConstructorInitializer ConstructorInitializerType={0} Arguments={1}]", ConstructorInitializerType, GetCollectionString(Arguments)); + } + } + + internal sealed class NullConstructorInitializer : ConstructorInitializer { + + internal static NullConstructorInitializer Instance = new NullConstructorInitializer(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullConstructorInitializer]"; + } + } + + public class ContinueStatement : Statement { + + ContinueType continueType; + + public ContinueType ContinueType { + get { + return continueType; + } + set { + continueType = value; + } + } + + public ContinueStatement() { + } + + public ContinueStatement(ContinueType continueType) { + ContinueType = continueType; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitContinueStatement(this, data); + } + + public override string ToString() { + return string.Format("[ContinueStatement ContinueType={0}]", ContinueType); + } + } + + public class DeclareDeclaration : ParametrizedNode { + + string alias; + + string library; + + CharsetModifier charset; + + TypeReference typeReference; + + public string Alias { + get { + return alias; + } + set { + alias = value ?? ""; + } + } + + public string Library { + get { + return library; + } + set { + library = value ?? ""; + } + } + + public CharsetModifier Charset { + get { + return charset; + } + set { + charset = value; + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public DeclareDeclaration(string name, Modifiers modifier, TypeReference typeReference, List parameters, List attributes, string library, string alias, CharsetModifier charset) { + Name = name; + Modifier = modifier; + TypeReference = typeReference; + Parameters = parameters; + Attributes = attributes; + Library = library; + Alias = alias; + Charset = charset; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDeclareDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[DeclareDeclaration Alias={0} Library={1} Charset={2} TypeReference={3} Name={4} " + + "Parameters={5} Attributes={6} Modifier={7}]", Alias, Library, Charset, TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class DefaultValueExpression : Expression { + + TypeReference typeReference; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public DefaultValueExpression(TypeReference typeReference) { + TypeReference = typeReference; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDefaultValueExpression(this, data); + } + + public override string ToString() { + return string.Format("[DefaultValueExpression TypeReference={0}]", TypeReference); + } + } + + public class DelegateDeclaration : AttributedNode { + + string name; + + TypeReference returnType; + + List parameters; + + List templates; + + public string Name { + get { + return name; + } + set { + name = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public TypeReference ReturnType { + get { + return returnType; + } + set { + returnType = value ?? TypeReference.Null; + } + } + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public List Templates { + get { + return templates; + } + set { + templates = value ?? new List(); + } + } + + public DelegateDeclaration(Modifiers modifier, List attributes) { + Modifier = modifier; + Attributes = attributes; + name = "?"; + returnType = TypeReference.Null; + parameters = new List(); + templates = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDelegateDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[DelegateDeclaration Name={0} ReturnType={1} Parameters={2} Templates={3} Attribu" + + "tes={4} Modifier={5}]", Name, ReturnType, GetCollectionString(Parameters), GetCollectionString(Templates), GetCollectionString(Attributes), Modifier); + } + } + + public class DestructorDeclaration : AttributedNode { + + string name; + + BlockStatement body; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public BlockStatement Body { + get { + return body; + } + set { + body = value ?? BlockStatement.Null; + if (!body.IsNull) body.Parent = this; + } + } + + public DestructorDeclaration(string name, Modifiers modifier, List attributes) { + Name = name; + Modifier = modifier; + Attributes = attributes; + body = BlockStatement.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDestructorDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[DestructorDeclaration Name={0} Body={1} Attributes={2} Modifier={3}]", Name, Body, GetCollectionString(Attributes), Modifier); + } + } + + public class DirectionExpression : Expression { + + FieldDirection fieldDirection; + + Expression expression; + + public FieldDirection FieldDirection { + get { + return fieldDirection; + } + set { + fieldDirection = value; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public DirectionExpression(FieldDirection fieldDirection, Expression expression) { + FieldDirection = fieldDirection; + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDirectionExpression(this, data); + } + + public override string ToString() { + return string.Format("[DirectionExpression FieldDirection={0} Expression={1}]", FieldDirection, Expression); + } + } + + public class DoLoopStatement : StatementWithEmbeddedStatement { + + Expression condition; + + ConditionType conditionType; + + ConditionPosition conditionPosition; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public ConditionType ConditionType { + get { + return conditionType; + } + set { + conditionType = value; + } + } + + public ConditionPosition ConditionPosition { + get { + return conditionPosition; + } + set { + conditionPosition = value; + } + } + + public DoLoopStatement(Expression condition, Statement embeddedStatement, ConditionType conditionType, ConditionPosition conditionPosition) { + Condition = condition; + EmbeddedStatement = embeddedStatement; + ConditionType = conditionType; + ConditionPosition = conditionPosition; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitDoLoopStatement(this, data); + } + + public override string ToString() { + return string.Format("[DoLoopStatement Condition={0} ConditionType={1} ConditionPosition={2} EmbeddedSt" + + "atement={3}]", Condition, ConditionType, ConditionPosition, EmbeddedStatement); + } + } + + public class ElseIfSection : StatementWithEmbeddedStatement { + + Expression condition; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public ElseIfSection(Expression condition, Statement embeddedStatement) { + Condition = condition; + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitElseIfSection(this, data); + } + + public override string ToString() { + return string.Format("[ElseIfSection Condition={0} EmbeddedStatement={1}]", Condition, EmbeddedStatement); + } + } + + public class EmptyStatement : Statement { + + public EmptyStatement() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEmptyStatement(this, data); + } + + public override string ToString() { + return "[EmptyStatement]"; + } + } + + public class EndStatement : Statement { + + public EndStatement() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEndStatement(this, data); + } + + public override string ToString() { + return "[EndStatement]"; + } + } + + public class EraseStatement : Statement { + + List expressions; + + public List Expressions { + get { + return expressions; + } + set { + expressions = value ?? new List(); + } + } + + public EraseStatement() { + expressions = new List(); + } + + public EraseStatement(List expressions) { + Expressions = expressions; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEraseStatement(this, data); + } + + public override string ToString() { + return string.Format("[EraseStatement Expressions={0}]", GetCollectionString(Expressions)); + } + } + + public class ErrorStatement : Statement { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public ErrorStatement(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitErrorStatement(this, data); + } + + public override string ToString() { + return string.Format("[ErrorStatement Expression={0}]", Expression); + } + } + + public class EventAddRegion : EventAddRemoveRegion { + + public EventAddRegion(List attributes) : + base(attributes) { + } + + public static EventAddRegion Null { + get { + return NullEventAddRegion.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEventAddRegion(this, data); + } + + public override string ToString() { + return string.Format("[EventAddRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + internal sealed class NullEventAddRegion : EventAddRegion { + + private NullEventAddRegion() : + base(null) { + } + + internal static NullEventAddRegion Instance = new NullEventAddRegion(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullEventAddRegion]"; + } + } + + public abstract class EventAddRemoveRegion : AttributedNode, INullable { + + BlockStatement block; + + List parameters; + + public BlockStatement Block { + get { + return block; + } + set { + block = value ?? BlockStatement.Null; + if (!block.IsNull) block.Parent = this; + } + } + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + protected EventAddRemoveRegion(List attributes) { + Attributes = attributes; + block = BlockStatement.Null; + parameters = new List(); + } + + public virtual bool IsNull { + get { + return false; + } + } + } + + public class EventDeclaration : MemberNode { + + EventAddRegion addRegion; + + EventRemoveRegion removeRegion; + + EventRaiseRegion raiseRegion; + + Location bodyStart; + + Location bodyEnd; + + Expression initializer; + + public EventAddRegion AddRegion { + get { + return addRegion; + } + set { + addRegion = value ?? EventAddRegion.Null; + } + } + + public EventRemoveRegion RemoveRegion { + get { + return removeRegion; + } + set { + removeRegion = value ?? EventRemoveRegion.Null; + } + } + + public EventRaiseRegion RaiseRegion { + get { + return raiseRegion; + } + set { + raiseRegion = value ?? EventRaiseRegion.Null; + } + } + + public Location BodyStart { + get { + return bodyStart; + } + set { + bodyStart = value; + } + } + + public Location BodyEnd { + get { + return bodyEnd; + } + set { + bodyEnd = value; + } + } + + public Expression Initializer { + get { + return initializer; + } + set { + initializer = value ?? Expression.Null; + if (!initializer.IsNull) initializer.Parent = this; + } + } + + public EventDeclaration() { + addRegion = EventAddRegion.Null; + removeRegion = EventRemoveRegion.Null; + raiseRegion = EventRaiseRegion.Null; + bodyStart = Location.Empty; + bodyEnd = Location.Empty; + initializer = Expression.Null; + } + + public bool HasRaiseRegion { + get { + return !raiseRegion.IsNull; + } + } + + public bool HasRemoveRegion { + get { + return !removeRegion.IsNull; + } + } + + public bool HasAddRegion { + get { + return !addRegion.IsNull; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEventDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[EventDeclaration AddRegion={0} RemoveRegion={1} RaiseRegion={2} BodyStart={3} Bo" + + "dyEnd={4} Initializer={5} InterfaceImplementations={6} TypeReference={7} Name={8" + + "} Parameters={9} Attributes={10} Modifier={11}]", AddRegion, RemoveRegion, RaiseRegion, BodyStart, BodyEnd, Initializer, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class EventRaiseRegion : EventAddRemoveRegion { + + public EventRaiseRegion(List attributes) : + base(attributes) { + } + + public static EventRaiseRegion Null { + get { + return NullEventRaiseRegion.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEventRaiseRegion(this, data); + } + + public override string ToString() { + return string.Format("[EventRaiseRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + internal sealed class NullEventRaiseRegion : EventRaiseRegion { + + private NullEventRaiseRegion() : + base(null) { + } + + internal static NullEventRaiseRegion Instance = new NullEventRaiseRegion(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullEventRaiseRegion]"; + } + } + + public class EventRemoveRegion : EventAddRemoveRegion { + + public EventRemoveRegion(List attributes) : + base(attributes) { + } + + public static EventRemoveRegion Null { + get { + return NullEventRemoveRegion.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitEventRemoveRegion(this, data); + } + + public override string ToString() { + return string.Format("[EventRemoveRegion Block={0} Parameters={1} Attributes={2} Modifier={3}]", Block, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + internal sealed class NullEventRemoveRegion : EventRemoveRegion { + + private NullEventRemoveRegion() : + base(null) { + } + + internal static NullEventRemoveRegion Instance = new NullEventRemoveRegion(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullEventRemoveRegion]"; + } + } + + public class ExitStatement : Statement { + + ExitType exitType; + + public ExitType ExitType { + get { + return exitType; + } + set { + exitType = value; + } + } + + public ExitStatement(ExitType exitType) { + ExitType = exitType; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitExitStatement(this, data); + } + + public override string ToString() { + return string.Format("[ExitStatement ExitType={0}]", ExitType); + } + } + + public class ExpressionStatement : Statement { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public ExpressionStatement(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitExpressionStatement(this, data); + } + + public override string ToString() { + return string.Format("[ExpressionStatement Expression={0}]", Expression); + } + } + + public class FieldDeclaration : AttributedNode { + + TypeReference typeReference; + + List fields; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public List Fields { + get { + return fields; + } + set { + fields = value ?? new List(); + } + } + + public FieldDeclaration(List attributes) { + Attributes = attributes; + typeReference = TypeReference.Null; + fields = new List(); + } + + public FieldDeclaration(List attributes, TypeReference typeReference, Modifiers modifier) { + Attributes = attributes; + TypeReference = typeReference; + Modifier = modifier; + fields = new List(); + } + + + public TypeReference GetTypeForField(int fieldIndex) + { + if (!typeReference.IsNull) { + return typeReference; + } + return ((VariableDeclaration)Fields[fieldIndex]).TypeReference; + } + + + public VariableDeclaration GetVariableDeclaration(string variableName) + { + foreach (VariableDeclaration variableDeclaration in Fields) { + if (variableDeclaration.Name == variableName) { + return variableDeclaration; + } + } + return null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitFieldDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[FieldDeclaration TypeReference={0} Fields={1} Attributes={2} Modifier={3}]", TypeReference, GetCollectionString(Fields), GetCollectionString(Attributes), Modifier); + } + } + + public class FixedStatement : StatementWithEmbeddedStatement { + + TypeReference typeReference; + + List pointerDeclarators; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public List PointerDeclarators { + get { + return pointerDeclarators; + } + set { + pointerDeclarators = value ?? new List(); + } + } + + public FixedStatement(TypeReference typeReference, List pointerDeclarators, Statement embeddedStatement) { + TypeReference = typeReference; + PointerDeclarators = pointerDeclarators; + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitFixedStatement(this, data); + } + + public override string ToString() { + return string.Format("[FixedStatement TypeReference={0} PointerDeclarators={1} EmbeddedStatement={2}]", TypeReference, GetCollectionString(PointerDeclarators), EmbeddedStatement); + } + } + + public class ForeachStatement : StatementWithEmbeddedStatement { + + TypeReference typeReference; + + string variableName; + + Expression expression; + + Expression nextExpression; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public string VariableName { + get { + return variableName; + } + set { + variableName = value ?? ""; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public Expression NextExpression { + get { + return nextExpression; + } + set { + nextExpression = value ?? Expression.Null; + if (!nextExpression.IsNull) nextExpression.Parent = this; + } + } + + public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement) { + TypeReference = typeReference; + VariableName = variableName; + Expression = expression; + EmbeddedStatement = embeddedStatement; + nextExpression = Expression.Null; + } + + public ForeachStatement(TypeReference typeReference, string variableName, Expression expression, Statement embeddedStatement, Expression nextExpression) { + TypeReference = typeReference; + VariableName = variableName; + Expression = expression; + EmbeddedStatement = embeddedStatement; + NextExpression = nextExpression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitForeachStatement(this, data); + } + + public override string ToString() { + return string.Format("[ForeachStatement TypeReference={0} VariableName={1} Expression={2} NextExpressio" + + "n={3} EmbeddedStatement={4}]", TypeReference, VariableName, Expression, NextExpression, EmbeddedStatement); + } + } + + public class ForNextStatement : StatementWithEmbeddedStatement { + + Expression start; + + Expression end; + + Expression step; + + List nextExpressions; + + TypeReference typeReference; + + string variableName; + + public Expression Start { + get { + return start; + } + set { + start = value ?? Expression.Null; + if (!start.IsNull) start.Parent = this; + } + } + + public Expression End { + get { + return end; + } + set { + end = value ?? Expression.Null; + if (!end.IsNull) end.Parent = this; + } + } + + public Expression Step { + get { + return step; + } + set { + step = value ?? Expression.Null; + if (!step.IsNull) step.Parent = this; + } + } + + public List NextExpressions { + get { + return nextExpressions; + } + set { + nextExpressions = value ?? new List(); + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public string VariableName { + get { + return variableName; + } + set { + variableName = value ?? ""; + } + } + + public ForNextStatement(TypeReference typeReference, string variableName, Expression start, Expression end, Expression step, Statement embeddedStatement, List nextExpressions) { + TypeReference = typeReference; + VariableName = variableName; + Start = start; + End = end; + Step = step; + EmbeddedStatement = embeddedStatement; + NextExpressions = nextExpressions; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitForNextStatement(this, data); + } + + public override string ToString() { + return string.Format("[ForNextStatement Start={0} End={1} Step={2} NextExpressions={3} TypeReference={4" + + "} VariableName={5} EmbeddedStatement={6}]", Start, End, Step, GetCollectionString(NextExpressions), TypeReference, VariableName, EmbeddedStatement); + } + } + + public class ForStatement : StatementWithEmbeddedStatement { + + List initializers; + + Expression condition; + + List iterator; + + public List Initializers { + get { + return initializers; + } + set { + initializers = value ?? new List(); + } + } + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public List Iterator { + get { + return iterator; + } + set { + iterator = value ?? new List(); + } + } + + public ForStatement(List initializers, Expression condition, List iterator, Statement embeddedStatement) { + Initializers = initializers; + Condition = condition; + Iterator = iterator; + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitForStatement(this, data); + } + + public override string ToString() { + return string.Format("[ForStatement Initializers={0} Condition={1} Iterator={2} EmbeddedStatement={3}]", GetCollectionString(Initializers), Condition, GetCollectionString(Iterator), EmbeddedStatement); + } + } + + public class GotoCaseStatement : Statement { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public GotoCaseStatement(Expression expression) { + Expression = expression; + } + + public bool IsDefaultCase { + get { + return expression.IsNull; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitGotoCaseStatement(this, data); + } + + public override string ToString() { + return string.Format("[GotoCaseStatement Expression={0}]", Expression); + } + } + + public class GotoStatement : Statement { + + string label; + + public string Label { + get { + return label; + } + set { + label = value ?? ""; + } + } + + public GotoStatement(string label) { + Label = label; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitGotoStatement(this, data); + } + + public override string ToString() { + return string.Format("[GotoStatement Label={0}]", Label); + } + } + + public class IdentifierExpression : Expression { + + string identifier; + + List typeArguments; + + public string Identifier { + get { + return identifier; + } + set { + identifier = value ?? ""; + } + } + + public List TypeArguments { + get { + return typeArguments; + } + set { + typeArguments = value ?? new List(); + } + } + + public IdentifierExpression(string identifier) { + Identifier = identifier; + typeArguments = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitIdentifierExpression(this, data); + } + + public override string ToString() { + return string.Format("[IdentifierExpression Identifier={0} TypeArguments={1}]", Identifier, GetCollectionString(TypeArguments)); + } + } + + public class IfElseStatement : Statement { + + Expression condition; + + List trueStatement; + + List falseStatement; + + List elseIfSections; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public List TrueStatement { + get { + return trueStatement; + } + set { + trueStatement = value ?? new List(); + } + } + + public List FalseStatement { + get { + return falseStatement; + } + set { + falseStatement = value ?? new List(); + } + } + + public List ElseIfSections { + get { + return elseIfSections; + } + set { + elseIfSections = value ?? new List(); + } + } + + public IfElseStatement(Expression condition) { + Condition = condition; + trueStatement = new List(); + falseStatement = new List(); + elseIfSections = new List(); + } + + public bool HasElseIfSections { + get { + return elseIfSections.Count > 0; + } + } + + + public IfElseStatement(Expression condition, Statement trueStatement) + : this(condition) { + this.trueStatement.Add(Statement.CheckNull(trueStatement)); + } + + + public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) + : this(condition) { + this.trueStatement.Add(Statement.CheckNull(trueStatement)); + this.falseStatement.Add(Statement.CheckNull(falseStatement)); + } + + public bool HasElseStatements { + get { + return falseStatement.Count > 0; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitIfElseStatement(this, data); + } + + public override string ToString() { + return string.Format("[IfElseStatement Condition={0} TrueStatement={1} FalseStatement={2} ElseIfSection" + + "s={3}]", Condition, GetCollectionString(TrueStatement), GetCollectionString(FalseStatement), GetCollectionString(ElseIfSections)); + } + } + + public class IndexerDeclaration : AttributedNode { + + List parameters; + + List interfaceImplementations; + + TypeReference typeReference; + + Location bodyStart; + + Location bodyEnd; + + PropertyGetRegion getRegion; + + PropertySetRegion setRegion; + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public List InterfaceImplementations { + get { + return interfaceImplementations; + } + set { + interfaceImplementations = value ?? new List(); + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public Location BodyStart { + get { + return bodyStart; + } + set { + bodyStart = value; + } + } + + public Location BodyEnd { + get { + return bodyEnd; + } + set { + bodyEnd = value; + } + } + + public PropertyGetRegion GetRegion { + get { + return getRegion; + } + set { + getRegion = value ?? PropertyGetRegion.Null; + } + } + + public PropertySetRegion SetRegion { + get { + return setRegion; + } + set { + setRegion = value ?? PropertySetRegion.Null; + } + } + + public IndexerDeclaration(Modifiers modifier, List parameters, List attributes) { + Modifier = modifier; + Parameters = parameters; + Attributes = attributes; + interfaceImplementations = new List(); + typeReference = TypeReference.Null; + bodyStart = Location.Empty; + bodyEnd = Location.Empty; + getRegion = PropertyGetRegion.Null; + setRegion = PropertySetRegion.Null; + } + + public IndexerDeclaration(TypeReference typeReference, List parameters, Modifiers modifier, List attributes) { + TypeReference = typeReference; + Parameters = parameters; + Modifier = modifier; + Attributes = attributes; + interfaceImplementations = new List(); + bodyStart = Location.Empty; + bodyEnd = Location.Empty; + getRegion = PropertyGetRegion.Null; + setRegion = PropertySetRegion.Null; + } + + public bool HasSetRegion { + get { + return !setRegion.IsNull; + } + } + + public bool HasGetRegion { + get { + return !getRegion.IsNull; + } + } + + public bool IsReadOnly { + get { + return HasGetRegion && !HasSetRegion; + } + } + + public bool IsWriteOnly { + get { + return !HasGetRegion && HasSetRegion; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitIndexerDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[IndexerDeclaration Parameters={0} InterfaceImplementations={1} TypeReference={2}" + + " BodyStart={3} BodyEnd={4} GetRegion={5} SetRegion={6} Attributes={7} Modifier={" + + "8}]", GetCollectionString(Parameters), GetCollectionString(InterfaceImplementations), TypeReference, BodyStart, BodyEnd, GetRegion, SetRegion, GetCollectionString(Attributes), Modifier); + } + } + + public class IndexerExpression : Expression { + + Expression targetObject; + + List indexes; + + public Expression TargetObject { + get { + return targetObject; + } + set { + targetObject = value ?? Expression.Null; + if (!targetObject.IsNull) targetObject.Parent = this; + } + } + + public List Indexes { + get { + return indexes; + } + set { + indexes = value ?? new List(); + } + } + + public IndexerExpression(Expression targetObject, List indexes) { + TargetObject = targetObject; + Indexes = indexes; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitIndexerExpression(this, data); + } + + public override string ToString() { + return string.Format("[IndexerExpression TargetObject={0} Indexes={1}]", TargetObject, GetCollectionString(Indexes)); + } + } + + public class InterfaceImplementation : AbstractNode { + + TypeReference interfaceType; + + string memberName; + + public TypeReference InterfaceType { + get { + return interfaceType; + } + set { + interfaceType = value ?? TypeReference.Null; + } + } + + public string MemberName { + get { + return memberName; + } + set { + memberName = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public InterfaceImplementation(TypeReference interfaceType, string memberName) { + InterfaceType = interfaceType; + MemberName = memberName; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitInterfaceImplementation(this, data); + } + + public override string ToString() { + return string.Format("[InterfaceImplementation InterfaceType={0} MemberName={1}]", InterfaceType, MemberName); + } + } + + public class InvocationExpression : Expression { + + Expression targetObject; + + List arguments; + + public Expression TargetObject { + get { + return targetObject; + } + set { + targetObject = value ?? Expression.Null; + if (!targetObject.IsNull) targetObject.Parent = this; + } + } + + public List Arguments { + get { + return arguments; + } + set { + arguments = value ?? new List(); + } + } + + public InvocationExpression(Expression targetObject) { + TargetObject = targetObject; + arguments = new List(); + } + + public InvocationExpression(Expression targetObject, List arguments) { + TargetObject = targetObject; + Arguments = arguments; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitInvocationExpression(this, data); + } + + public override string ToString() { + return string.Format("[InvocationExpression TargetObject={0} Arguments={1}]", TargetObject, GetCollectionString(Arguments)); + } + } + + public class LabelStatement : Statement { + + string label; + + public string Label { + get { + return label; + } + set { + label = value ?? ""; + } + } + + public LabelStatement(string label) { + Label = label; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitLabelStatement(this, data); + } + + public override string ToString() { + return string.Format("[LabelStatement Label={0}]", Label); + } + } + + public class LambdaExpression : Expression { + + List parameters; + + BlockStatement statementBody; + + Expression expressionBody; + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public BlockStatement StatementBody { + get { + return statementBody; + } + set { + statementBody = value ?? BlockStatement.Null; + if (!statementBody.IsNull) statementBody.Parent = this; + } + } + + public Expression ExpressionBody { + get { + return expressionBody; + } + set { + expressionBody = value ?? Expression.Null; + if (!expressionBody.IsNull) expressionBody.Parent = this; + } + } + + public LambdaExpression() { + parameters = new List(); + statementBody = BlockStatement.Null; + expressionBody = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitLambdaExpression(this, data); + } + + public override string ToString() { + return string.Format("[LambdaExpression Parameters={0} StatementBody={1} ExpressionBody={2}]", GetCollectionString(Parameters), StatementBody, ExpressionBody); + } + } + + public class LockStatement : StatementWithEmbeddedStatement { + + Expression lockExpression; + + public Expression LockExpression { + get { + return lockExpression; + } + set { + lockExpression = value ?? Expression.Null; + if (!lockExpression.IsNull) lockExpression.Parent = this; + } + } + + public LockStatement(Expression lockExpression, Statement embeddedStatement) { + LockExpression = lockExpression; + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitLockStatement(this, data); + } + + public override string ToString() { + return string.Format("[LockStatement LockExpression={0} EmbeddedStatement={1}]", LockExpression, EmbeddedStatement); + } + } + + public abstract class MemberNode : ParametrizedNode { + + List interfaceImplementations; + + TypeReference typeReference; + + public List InterfaceImplementations { + get { + return interfaceImplementations; + } + set { + interfaceImplementations = value ?? new List(); + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + protected MemberNode() { + interfaceImplementations = new List(); + typeReference = TypeReference.Null; + } + + protected MemberNode(Modifiers modifier, List attributes, string name, List parameters) { + Modifier = modifier; + Attributes = attributes; + Name = name; + Parameters = parameters; + interfaceImplementations = new List(); + typeReference = TypeReference.Null; + } + } + + public class MemberReferenceExpression : Expression { + + Expression targetObject; + + string memberName; + + List typeArguments; + + public Expression TargetObject { + get { + return targetObject; + } + set { + targetObject = value ?? Expression.Null; + if (!targetObject.IsNull) targetObject.Parent = this; + } + } + + public string MemberName { + get { + return memberName; + } + set { + memberName = value ?? ""; + } + } + + public List TypeArguments { + get { + return typeArguments; + } + set { + typeArguments = value ?? new List(); + } + } + + public MemberReferenceExpression(Expression targetObject, string memberName) { + TargetObject = targetObject; + MemberName = memberName; + typeArguments = new List(); + } + +[Obsolete] public string FieldName { get { return MemberName; } set { MemberName = value; } } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitMemberReferenceExpression(this, data); + } + + public override string ToString() { + return string.Format("[MemberReferenceExpression TargetObject={0} MemberName={1} TypeArguments={2}]", TargetObject, MemberName, GetCollectionString(TypeArguments)); + } + } + + public class MethodDeclaration : MemberNode { + + BlockStatement body; + + List handlesClause; + + List templates; + + bool isExtensionMethod; + + public BlockStatement Body { + get { + return body; + } + set { + body = value ?? BlockStatement.Null; + if (!body.IsNull) body.Parent = this; + } + } + + public List HandlesClause { + get { + return handlesClause; + } + set { + handlesClause = value ?? new List(); + } + } + + public List Templates { + get { + return templates; + } + set { + templates = value ?? new List(); + } + } + + public bool IsExtensionMethod { + get { + return isExtensionMethod; + } + set { + isExtensionMethod = value; + } + } + + public MethodDeclaration() { + body = BlockStatement.Null; + handlesClause = new List(); + templates = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitMethodDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[MethodDeclaration Body={0} HandlesClause={1} Templates={2} IsExtensionMethod={3}" + + " InterfaceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attribut" + + "es={8} Modifier={9}]", Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class NamedArgumentExpression : Expression { + + string name; + + Expression expression; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public NamedArgumentExpression(string name, Expression expression) { + Name = name; + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitNamedArgumentExpression(this, data); + } + + public override string ToString() { + return string.Format("[NamedArgumentExpression Name={0} Expression={1}]", Name, Expression); + } + } + + public class NamespaceDeclaration : AbstractNode { + + string name; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public NamespaceDeclaration(string name) { + Name = name; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitNamespaceDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[NamespaceDeclaration Name={0}]", Name); + } + } + + public class ObjectCreateExpression : Expression { + + TypeReference createType; + + List parameters; + + CollectionInitializerExpression objectInitializer; + + public TypeReference CreateType { + get { + return createType; + } + set { + createType = value ?? TypeReference.Null; + } + } + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public CollectionInitializerExpression ObjectInitializer { + get { + return objectInitializer; + } + set { + objectInitializer = value ?? CollectionInitializerExpression.Null; + if (!objectInitializer.IsNull) objectInitializer.Parent = this; + } + } + + public ObjectCreateExpression(TypeReference createType, List parameters) { + CreateType = createType; + Parameters = parameters; + objectInitializer = CollectionInitializerExpression.Null; + } + + public bool IsAnonymousType { + get { + return createType.IsNull || string.IsNullOrEmpty(createType.Type); + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitObjectCreateExpression(this, data); + } + + public override string ToString() { + return string.Format("[ObjectCreateExpression CreateType={0} Parameters={1} ObjectInitializer={2}]", CreateType, GetCollectionString(Parameters), ObjectInitializer); + } + } + + public class OnErrorStatement : StatementWithEmbeddedStatement { + + public OnErrorStatement(Statement embeddedStatement) { + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitOnErrorStatement(this, data); + } + + public override string ToString() { + return string.Format("[OnErrorStatement EmbeddedStatement={0}]", EmbeddedStatement); + } + } + + public class OperatorDeclaration : MethodDeclaration { + + ConversionType conversionType; + + List returnTypeAttributes; + + OverloadableOperatorType overloadableOperator; + + public ConversionType ConversionType { + get { + return conversionType; + } + set { + conversionType = value; + } + } + + public List ReturnTypeAttributes { + get { + return returnTypeAttributes; + } + set { + returnTypeAttributes = value ?? new List(); + } + } + + public OverloadableOperatorType OverloadableOperator { + get { + return overloadableOperator; + } + set { + overloadableOperator = value; + } + } + + public OperatorDeclaration() { + returnTypeAttributes = new List(); + } + + public bool IsConversionOperator { + get { + return conversionType != ConversionType.None; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitOperatorDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[OperatorDeclaration ConversionType={0} ReturnTypeAttributes={1} OverloadableOper" + + "ator={2} Body={3} HandlesClause={4} Templates={5} IsExtensionMethod={6} Interfac" + + "eImplementations={7} TypeReference={8} Name={9} Parameters={10} Attributes={11} " + + "Modifier={12}]", ConversionType, GetCollectionString(ReturnTypeAttributes), OverloadableOperator, Body, GetCollectionString(HandlesClause), GetCollectionString(Templates), IsExtensionMethod, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class OptionDeclaration : AbstractNode { + + OptionType optionType; + + bool optionValue; + + public OptionType OptionType { + get { + return optionType; + } + set { + optionType = value; + } + } + + public bool OptionValue { + get { + return optionValue; + } + set { + optionValue = value; + } + } + + public OptionDeclaration(OptionType optionType, bool optionValue) { + OptionType = optionType; + OptionValue = optionValue; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitOptionDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[OptionDeclaration OptionType={0} OptionValue={1}]", OptionType, OptionValue); + } + } + + public class ParameterDeclarationExpression : Expression { + + List attributes; + + string parameterName; + + TypeReference typeReference; + + ParameterModifiers paramModifier; + + Expression defaultValue; + + public List Attributes { + get { + return attributes; + } + set { + attributes = value ?? new List(); + } + } + + public string ParameterName { + get { + return parameterName; + } + set { + parameterName = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public ParameterModifiers ParamModifier { + get { + return paramModifier; + } + set { + paramModifier = value; + } + } + + public Expression DefaultValue { + get { + return defaultValue; + } + set { + defaultValue = value ?? Expression.Null; + if (!defaultValue.IsNull) defaultValue.Parent = this; + } + } + + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName) { + TypeReference = typeReference; + ParameterName = parameterName; + attributes = new List(); + defaultValue = Expression.Null; + } + + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier) { + TypeReference = typeReference; + ParameterName = parameterName; + ParamModifier = paramModifier; + attributes = new List(); + defaultValue = Expression.Null; + } + + public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParameterModifiers paramModifier, Expression defaultValue) { + TypeReference = typeReference; + ParameterName = parameterName; + ParamModifier = paramModifier; + DefaultValue = defaultValue; + attributes = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitParameterDeclarationExpression(this, data); + } + + public override string ToString() { + return string.Format("[ParameterDeclarationExpression Attributes={0} ParameterName={1} TypeReference={2" + + "} ParamModifier={3} DefaultValue={4}]", GetCollectionString(Attributes), ParameterName, TypeReference, ParamModifier, DefaultValue); + } + } + + public abstract class ParametrizedNode : AttributedNode { + + string name; + + List parameters; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + protected ParametrizedNode() { + name = ""; + parameters = new List(); + } + + protected ParametrizedNode(Modifiers modifier, List attributes, string name, List parameters) { + Modifier = modifier; + Attributes = attributes; + Name = name; + Parameters = parameters; + } + } + + public class ParenthesizedExpression : Expression { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public ParenthesizedExpression(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitParenthesizedExpression(this, data); + } + + public override string ToString() { + return string.Format("[ParenthesizedExpression Expression={0}]", Expression); + } + } + + public class PointerReferenceExpression : Expression { + + Expression targetObject; + + string identifier; + + List typeArguments; + + public Expression TargetObject { + get { + return targetObject; + } + set { + targetObject = value ?? Expression.Null; + if (!targetObject.IsNull) targetObject.Parent = this; + } + } + + public string Identifier { + get { + return identifier; + } + set { + identifier = value ?? ""; + } + } + + public List TypeArguments { + get { + return typeArguments; + } + set { + typeArguments = value ?? new List(); + } + } + + public PointerReferenceExpression(Expression targetObject, string identifier) { + TargetObject = targetObject; + Identifier = identifier; + typeArguments = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitPointerReferenceExpression(this, data); + } + + public override string ToString() { + return string.Format("[PointerReferenceExpression TargetObject={0} Identifier={1} TypeArguments={2}]", TargetObject, Identifier, GetCollectionString(TypeArguments)); + } + } + + public class PropertyDeclaration : MemberNode { + + Location bodyStart; + + Location bodyEnd; + + PropertyGetRegion getRegion; + + PropertySetRegion setRegion; + + public Location BodyStart { + get { + return bodyStart; + } + set { + bodyStart = value; + } + } + + public Location BodyEnd { + get { + return bodyEnd; + } + set { + bodyEnd = value; + } + } + + public PropertyGetRegion GetRegion { + get { + return getRegion; + } + set { + getRegion = value ?? PropertyGetRegion.Null; + } + } + + public PropertySetRegion SetRegion { + get { + return setRegion; + } + set { + setRegion = value ?? PropertySetRegion.Null; + } + } + + public PropertyDeclaration(Modifiers modifier, List attributes, string name, List parameters) { + Modifier = modifier; + Attributes = attributes; + Name = name; + Parameters = parameters; + bodyStart = Location.Empty; + bodyEnd = Location.Empty; + getRegion = PropertyGetRegion.Null; + setRegion = PropertySetRegion.Null; + } + + public bool HasSetRegion { + get { + return !setRegion.IsNull; + } + } + + public bool HasGetRegion { + get { + return !getRegion.IsNull; + } + } + + public bool IsWriteOnly { + get { + return !HasGetRegion && HasSetRegion; + } + } + + + internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List attributes) : this(modifier, attributes, name, null) + { + this.TypeReference = typeReference; + if ((modifier & Modifiers.ReadOnly) != Modifiers.ReadOnly) { + this.SetRegion = new PropertySetRegion(null, null); + } + if ((modifier & Modifiers.WriteOnly) != Modifiers.WriteOnly) { + this.GetRegion = new PropertyGetRegion(null, null); + } + } + + public bool IsReadOnly { + get { + return HasGetRegion && !HasSetRegion; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitPropertyDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[PropertyDeclaration BodyStart={0} BodyEnd={1} GetRegion={2} SetRegion={3} Interf" + + "aceImplementations={4} TypeReference={5} Name={6} Parameters={7} Attributes={8} " + + "Modifier={9}]", BodyStart, BodyEnd, GetRegion, SetRegion, GetCollectionString(InterfaceImplementations), TypeReference, Name, GetCollectionString(Parameters), GetCollectionString(Attributes), Modifier); + } + } + + public class PropertyGetRegion : PropertyGetSetRegion { + + public PropertyGetRegion(BlockStatement block, List attributes) : + base(block, attributes) { + } + + public static PropertyGetRegion Null { + get { + return NullPropertyGetRegion.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitPropertyGetRegion(this, data); + } + + public override string ToString() { + return string.Format("[PropertyGetRegion Block={0} Attributes={1} Modifier={2}]", Block, GetCollectionString(Attributes), Modifier); + } + } + + internal sealed class NullPropertyGetRegion : PropertyGetRegion { + + private NullPropertyGetRegion() : + base(null, null) { + } + + internal static NullPropertyGetRegion Instance = new NullPropertyGetRegion(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullPropertyGetRegion]"; + } + } + + public abstract class PropertyGetSetRegion : AttributedNode, INullable { + + BlockStatement block; + + public BlockStatement Block { + get { + return block; + } + set { + block = value ?? BlockStatement.Null; + if (!block.IsNull) block.Parent = this; + } + } + + protected PropertyGetSetRegion(BlockStatement block, List attributes) { + Block = block; + Attributes = attributes; + } + + public virtual bool IsNull { + get { + return false; + } + } + } + + public class PropertySetRegion : PropertyGetSetRegion { + + List parameters; + + public List Parameters { + get { + return parameters; + } + set { + parameters = value ?? new List(); + } + } + + public PropertySetRegion(BlockStatement block, List attributes) : + base(block, attributes) { + parameters = new List(); + } + + public static PropertySetRegion Null { + get { + return NullPropertySetRegion.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitPropertySetRegion(this, data); + } + + public override string ToString() { + return string.Format("[PropertySetRegion Parameters={0} Block={1} Attributes={2} Modifier={3}]", GetCollectionString(Parameters), Block, GetCollectionString(Attributes), Modifier); + } + } + + internal sealed class NullPropertySetRegion : PropertySetRegion { + + private NullPropertySetRegion() : + base(null, null) { + } + + internal static NullPropertySetRegion Instance = new NullPropertySetRegion(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullPropertySetRegion]"; + } + } + + public class QueryExpression : Expression { + + QueryExpressionFromClause fromClause; + + List fromLetWhereClauses; + + List orderings; + + QueryExpressionClause selectOrGroupClause; + + QueryExpressionIntoClause intoClause; + + public QueryExpressionFromClause FromClause { + get { + return fromClause; + } + set { + fromClause = value ?? QueryExpressionFromClause.Null; + if (!fromClause.IsNull) fromClause.Parent = this; + } + } + + public List FromLetWhereClauses { + get { + return fromLetWhereClauses; + } + set { + fromLetWhereClauses = value ?? new List(); + } + } + + public List Orderings { + get { + return orderings; + } + set { + orderings = value ?? new List(); + } + } + + public QueryExpressionClause SelectOrGroupClause { + get { + return selectOrGroupClause; + } + set { + selectOrGroupClause = value ?? QueryExpressionClause.Null; + if (!selectOrGroupClause.IsNull) selectOrGroupClause.Parent = this; + } + } + + public QueryExpressionIntoClause IntoClause { + get { + return intoClause; + } + set { + intoClause = value ?? QueryExpressionIntoClause.Null; + if (!intoClause.IsNull) intoClause.Parent = this; + } + } + + public QueryExpression() { + fromClause = QueryExpressionFromClause.Null; + fromLetWhereClauses = new List(); + orderings = new List(); + selectOrGroupClause = QueryExpressionClause.Null; + intoClause = QueryExpressionIntoClause.Null; + } + + public new static QueryExpression Null { + get { + return NullQueryExpression.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpression(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpression FromClause={0} FromLetWhereClauses={1} Orderings={2} SelectOrGro" + + "upClause={3} IntoClause={4}]", FromClause, GetCollectionString(FromLetWhereClauses), GetCollectionString(Orderings), SelectOrGroupClause, IntoClause); + } + } + + internal sealed class NullQueryExpression : QueryExpression { + + internal static NullQueryExpression Instance = new NullQueryExpression(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpression]"; + } + } + + public abstract class QueryExpressionClause : AbstractNode, INullable { + + public virtual bool IsNull { + get { + return false; + } + } + + public static QueryExpressionClause Null { + get { + return NullQueryExpressionClause.Instance; + } + } + } + + internal sealed class NullQueryExpressionClause : QueryExpressionClause { + + internal static NullQueryExpressionClause Instance = new NullQueryExpressionClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionClause]"; + } + } + + public class QueryExpressionFromClause : QueryExpressionFromOrJoinClause { + + public QueryExpressionFromClause() { + } + + public new static QueryExpressionFromClause Null { + get { + return NullQueryExpressionFromClause.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionFromClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionFromClause Type={0} Identifier={1} InExpression={2}]", Type, Identifier, InExpression); + } + } + + internal sealed class NullQueryExpressionFromClause : QueryExpressionFromClause { + + internal static NullQueryExpressionFromClause Instance = new NullQueryExpressionFromClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionFromClause]"; + } + } + + public abstract class QueryExpressionFromOrJoinClause : QueryExpressionClause { + + TypeReference type; + + string identifier; + + Expression inExpression; + + public TypeReference Type { + get { + return type; + } + set { + type = value ?? TypeReference.Null; + } + } + + public string Identifier { + get { + return identifier; + } + set { + identifier = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public Expression InExpression { + get { + return inExpression; + } + set { + inExpression = value ?? Expression.Null; + if (!inExpression.IsNull) inExpression.Parent = this; + } + } + } + + public class QueryExpressionGroupClause : QueryExpressionClause { + + Expression projection; + + Expression groupBy; + + public Expression Projection { + get { + return projection; + } + set { + projection = value ?? Expression.Null; + if (!projection.IsNull) projection.Parent = this; + } + } + + public Expression GroupBy { + get { + return groupBy; + } + set { + groupBy = value ?? Expression.Null; + if (!groupBy.IsNull) groupBy.Parent = this; + } + } + + public QueryExpressionGroupClause() { + projection = Expression.Null; + groupBy = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionGroupClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionGroupClause Projection={0} GroupBy={1}]", Projection, GroupBy); + } + } + + public class QueryExpressionIntoClause : QueryExpressionClause { + + string intoIdentifier; + + QueryExpression continuedQuery; + + public string IntoIdentifier { + get { + return intoIdentifier; + } + set { + intoIdentifier = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public QueryExpression ContinuedQuery { + get { + return continuedQuery; + } + set { + continuedQuery = value ?? QueryExpression.Null; + if (!continuedQuery.IsNull) continuedQuery.Parent = this; + } + } + + public QueryExpressionIntoClause() { + intoIdentifier = "?"; + continuedQuery = QueryExpression.Null; + } + + public new static QueryExpressionIntoClause Null { + get { + return NullQueryExpressionIntoClause.Instance; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionIntoClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionIntoClause IntoIdentifier={0} ContinuedQuery={1}]", IntoIdentifier, ContinuedQuery); + } + } + + internal sealed class NullQueryExpressionIntoClause : QueryExpressionIntoClause { + + internal static NullQueryExpressionIntoClause Instance = new NullQueryExpressionIntoClause(); + + public override bool IsNull { + get { + return true; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return null; + } + + public override string ToString() { + return "[NullQueryExpressionIntoClause]"; + } + } + + public class QueryExpressionJoinClause : QueryExpressionFromOrJoinClause { + + Expression onExpression; + + Expression equalsExpression; + + string intoIdentifier; + + public Expression OnExpression { + get { + return onExpression; + } + set { + onExpression = value ?? Expression.Null; + if (!onExpression.IsNull) onExpression.Parent = this; + } + } + + public Expression EqualsExpression { + get { + return equalsExpression; + } + set { + equalsExpression = value ?? Expression.Null; + if (!equalsExpression.IsNull) equalsExpression.Parent = this; + } + } + + public string IntoIdentifier { + get { + return intoIdentifier; + } + set { + intoIdentifier = value ?? ""; + } + } + + public QueryExpressionJoinClause() { + onExpression = Expression.Null; + equalsExpression = Expression.Null; + intoIdentifier = ""; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionJoinClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionJoinClause OnExpression={0} EqualsExpression={1} IntoIdentifier={" + + "2} Type={3} Identifier={4} InExpression={5}]", OnExpression, EqualsExpression, IntoIdentifier, Type, Identifier, InExpression); + } + } + + public class QueryExpressionLetClause : QueryExpressionClause { + + string identifier; + + Expression expression; + + public string Identifier { + get { + return identifier; + } + set { + identifier = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public QueryExpressionLetClause() { + identifier = "?"; + expression = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionLetClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionLetClause Identifier={0} Expression={1}]", Identifier, Expression); + } + } + + public class QueryExpressionOrdering : AbstractNode { + + Expression criteria; + + QueryExpressionOrderingDirection direction; + + public Expression Criteria { + get { + return criteria; + } + set { + criteria = value ?? Expression.Null; + if (!criteria.IsNull) criteria.Parent = this; + } + } + + public QueryExpressionOrderingDirection Direction { + get { + return direction; + } + set { + direction = value; + } + } + + public QueryExpressionOrdering() { + criteria = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionOrdering(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionOrdering Criteria={0} Direction={1}]", Criteria, Direction); + } + } + + public class QueryExpressionSelectClause : QueryExpressionClause { + + Expression projection; + + public Expression Projection { + get { + return projection; + } + set { + projection = value ?? Expression.Null; + if (!projection.IsNull) projection.Parent = this; + } + } + + public QueryExpressionSelectClause() { + projection = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionSelectClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionSelectClause Projection={0}]", Projection); + } + } + + public class QueryExpressionWhereClause : QueryExpressionClause { + + Expression condition; + + public Expression Condition { + get { + return condition; + } + set { + condition = value ?? Expression.Null; + if (!condition.IsNull) condition.Parent = this; + } + } + + public QueryExpressionWhereClause() { + condition = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitQueryExpressionWhereClause(this, data); + } + + public override string ToString() { + return string.Format("[QueryExpressionWhereClause Condition={0}]", Condition); + } + } + + public class RaiseEventStatement : Statement { + + string eventName; + + List arguments; + + public string EventName { + get { + return eventName; + } + set { + eventName = value ?? ""; + } + } + + public List Arguments { + get { + return arguments; + } + set { + arguments = value ?? new List(); + } + } + + public RaiseEventStatement(string eventName, List arguments) { + EventName = eventName; + Arguments = arguments; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitRaiseEventStatement(this, data); + } + + public override string ToString() { + return string.Format("[RaiseEventStatement EventName={0} Arguments={1}]", EventName, GetCollectionString(Arguments)); + } + } + + public class ReDimStatement : Statement { + + List reDimClauses; + + bool isPreserve; + + public List ReDimClauses { + get { + return reDimClauses; + } + set { + reDimClauses = value ?? new List(); + } + } + + public bool IsPreserve { + get { + return isPreserve; + } + set { + isPreserve = value; + } + } + + public ReDimStatement(bool isPreserve) { + IsPreserve = isPreserve; + reDimClauses = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitReDimStatement(this, data); + } + + public override string ToString() { + return string.Format("[ReDimStatement ReDimClauses={0} IsPreserve={1}]", GetCollectionString(ReDimClauses), IsPreserve); + } + } + + public class RemoveHandlerStatement : Statement { + + Expression eventExpression; + + Expression handlerExpression; + + public Expression EventExpression { + get { + return eventExpression; + } + set { + eventExpression = value ?? Expression.Null; + if (!eventExpression.IsNull) eventExpression.Parent = this; + } + } + + public Expression HandlerExpression { + get { + return handlerExpression; + } + set { + handlerExpression = value ?? Expression.Null; + if (!handlerExpression.IsNull) handlerExpression.Parent = this; + } + } + + public RemoveHandlerStatement(Expression eventExpression, Expression handlerExpression) { + EventExpression = eventExpression; + HandlerExpression = handlerExpression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitRemoveHandlerStatement(this, data); + } + + public override string ToString() { + return string.Format("[RemoveHandlerStatement EventExpression={0} HandlerExpression={1}]", EventExpression, HandlerExpression); + } + } + + public class ResumeStatement : Statement { + + string labelName; + + bool isResumeNext; + + public string LabelName { + get { + return labelName; + } + set { + labelName = value ?? ""; + } + } + + public bool IsResumeNext { + get { + return isResumeNext; + } + set { + isResumeNext = value; + } + } + + public ResumeStatement(bool isResumeNext) { + IsResumeNext = isResumeNext; + labelName = ""; + } + + public ResumeStatement(string labelName) { + LabelName = labelName; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitResumeStatement(this, data); + } + + public override string ToString() { + return string.Format("[ResumeStatement LabelName={0} IsResumeNext={1}]", LabelName, IsResumeNext); + } + } + + public class ReturnStatement : Statement { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public ReturnStatement(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitReturnStatement(this, data); + } + + public override string ToString() { + return string.Format("[ReturnStatement Expression={0}]", Expression); + } + } + + public class SizeOfExpression : Expression { + + TypeReference typeReference; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public SizeOfExpression(TypeReference typeReference) { + TypeReference = typeReference; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitSizeOfExpression(this, data); + } + + public override string ToString() { + return string.Format("[SizeOfExpression TypeReference={0}]", TypeReference); + } + } + + public class StackAllocExpression : Expression { + + TypeReference typeReference; + + Expression expression; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public StackAllocExpression(TypeReference typeReference, Expression expression) { + TypeReference = typeReference; + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitStackAllocExpression(this, data); + } + + public override string ToString() { + return string.Format("[StackAllocExpression TypeReference={0} Expression={1}]", TypeReference, Expression); + } + } + + public class StopStatement : Statement { + + public StopStatement() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitStopStatement(this, data); + } + + public override string ToString() { + return "[StopStatement]"; + } + } + + public class SwitchSection : BlockStatement { + + List switchLabels; + + public List SwitchLabels { + get { + return switchLabels; + } + set { + switchLabels = value ?? new List(); + } + } + + public SwitchSection() { + switchLabels = new List(); + } + + public SwitchSection(List switchLabels) { + SwitchLabels = switchLabels; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitSwitchSection(this, data); + } + + public override string ToString() { + return string.Format("[SwitchSection SwitchLabels={0}]", GetCollectionString(SwitchLabels)); + } + } + + public class SwitchStatement : Statement { + + Expression switchExpression; + + List switchSections; + + public Expression SwitchExpression { + get { + return switchExpression; + } + set { + switchExpression = value ?? Expression.Null; + if (!switchExpression.IsNull) switchExpression.Parent = this; + } + } + + public List SwitchSections { + get { + return switchSections; + } + set { + switchSections = value ?? new List(); + } + } + + public SwitchStatement(Expression switchExpression, List switchSections) { + SwitchExpression = switchExpression; + SwitchSections = switchSections; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitSwitchStatement(this, data); + } + + public override string ToString() { + return string.Format("[SwitchStatement SwitchExpression={0} SwitchSections={1}]", SwitchExpression, GetCollectionString(SwitchSections)); + } + } + + public class TemplateDefinition : AttributedNode { + + string name; + + List bases; + + public string Name { + get { + return name; + } + set { + name = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public List Bases { + get { + return bases; + } + set { + bases = value ?? new List(); + } + } + + public TemplateDefinition(string name, List attributes) { + Name = name; + Attributes = attributes; + bases = new List(); + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTemplateDefinition(this, data); + } + + public override string ToString() { + return string.Format("[TemplateDefinition Name={0} Bases={1} Attributes={2} Modifier={3}]", Name, GetCollectionString(Bases), GetCollectionString(Attributes), Modifier); + } + } + + public class ThisReferenceExpression : Expression { + + public ThisReferenceExpression() { + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitThisReferenceExpression(this, data); + } + + public override string ToString() { + return "[ThisReferenceExpression]"; + } + } + + public class ThrowStatement : Statement { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public ThrowStatement(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitThrowStatement(this, data); + } + + public override string ToString() { + return string.Format("[ThrowStatement Expression={0}]", Expression); + } + } + + public class TryCatchStatement : Statement { + + Statement statementBlock; + + List catchClauses; + + Statement finallyBlock; + + public Statement StatementBlock { + get { + return statementBlock; + } + set { + statementBlock = value ?? Statement.Null; + if (!statementBlock.IsNull) statementBlock.Parent = this; + } + } + + public List CatchClauses { + get { + return catchClauses; + } + set { + catchClauses = value ?? new List(); + } + } + + public Statement FinallyBlock { + get { + return finallyBlock; + } + set { + finallyBlock = value ?? Statement.Null; + if (!finallyBlock.IsNull) finallyBlock.Parent = this; + } + } + + public TryCatchStatement(Statement statementBlock, List catchClauses, Statement finallyBlock) { + StatementBlock = statementBlock; + CatchClauses = catchClauses; + FinallyBlock = finallyBlock; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTryCatchStatement(this, data); + } + + public override string ToString() { + return string.Format("[TryCatchStatement StatementBlock={0} CatchClauses={1} FinallyBlock={2}]", StatementBlock, GetCollectionString(CatchClauses), FinallyBlock); + } + } + + public class TypeDeclaration : AttributedNode { + + string name; + + ClassType type; + + List baseTypes; + + List templates; + + Location bodyStartLocation; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public ClassType Type { + get { + return type; + } + set { + type = value; + } + } + + public List BaseTypes { + get { + return baseTypes; + } + set { + baseTypes = value ?? new List(); + } + } + + public List Templates { + get { + return templates; + } + set { + templates = value ?? new List(); + } + } + + public Location BodyStartLocation { + get { + return bodyStartLocation; + } + set { + bodyStartLocation = value; + } + } + + public TypeDeclaration(Modifiers modifier, List attributes) { + Modifier = modifier; + Attributes = attributes; + name = ""; + baseTypes = new List(); + templates = new List(); + bodyStartLocation = Location.Empty; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTypeDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[TypeDeclaration Name={0} Type={1} BaseTypes={2} Templates={3} BodyStartLocation=" + + "{4} Attributes={5} Modifier={6}]", Name, Type, GetCollectionString(BaseTypes), GetCollectionString(Templates), BodyStartLocation, GetCollectionString(Attributes), Modifier); + } + } + + public class TypeOfExpression : Expression { + + TypeReference typeReference; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public TypeOfExpression(TypeReference typeReference) { + TypeReference = typeReference; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTypeOfExpression(this, data); + } + + public override string ToString() { + return string.Format("[TypeOfExpression TypeReference={0}]", TypeReference); + } + } + + public class TypeOfIsExpression : Expression { + + Expression expression; + + TypeReference typeReference; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public TypeOfIsExpression(Expression expression, TypeReference typeReference) { + Expression = expression; + TypeReference = typeReference; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTypeOfIsExpression(this, data); + } + + public override string ToString() { + return string.Format("[TypeOfIsExpression Expression={0} TypeReference={1}]", Expression, TypeReference); + } + } + + public class TypeReferenceExpression : Expression { + + TypeReference typeReference; + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public TypeReferenceExpression(TypeReference typeReference) { + TypeReference = typeReference; + } + +public TypeReferenceExpression(string typeName) : this(new TypeReference(typeName)) {} + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitTypeReferenceExpression(this, data); + } + + public override string ToString() { + return string.Format("[TypeReferenceExpression TypeReference={0}]", TypeReference); + } + } + + public class UnaryOperatorExpression : Expression { + + UnaryOperatorType op; + + Expression expression; + + public UnaryOperatorType Op { + get { + return op; + } + set { + op = value; + } + } + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public UnaryOperatorExpression(UnaryOperatorType op) { + Op = op; + expression = Expression.Null; + } + + public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) { + Expression = expression; + Op = op; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUnaryOperatorExpression(this, data); + } + + public override string ToString() { + return string.Format("[UnaryOperatorExpression Op={0} Expression={1}]", Op, Expression); + } + } + + public class UncheckedExpression : Expression { + + Expression expression; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public UncheckedExpression(Expression expression) { + Expression = expression; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUncheckedExpression(this, data); + } + + public override string ToString() { + return string.Format("[UncheckedExpression Expression={0}]", Expression); + } + } + + public class UncheckedStatement : Statement { + + Statement block; + + public Statement Block { + get { + return block; + } + set { + block = value ?? Statement.Null; + if (!block.IsNull) block.Parent = this; + } + } + + public UncheckedStatement(Statement block) { + Block = block; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUncheckedStatement(this, data); + } + + public override string ToString() { + return string.Format("[UncheckedStatement Block={0}]", Block); + } + } + + public class UnsafeStatement : Statement { + + Statement block; + + public Statement Block { + get { + return block; + } + set { + block = value ?? Statement.Null; + if (!block.IsNull) block.Parent = this; + } + } + + public UnsafeStatement(Statement block) { + Block = block; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUnsafeStatement(this, data); + } + + public override string ToString() { + return string.Format("[UnsafeStatement Block={0}]", Block); + } + } + + public class Using : AbstractNode { + + string name; + + TypeReference alias; + + public string Name { + get { + return name; + } + set { + name = string.IsNullOrEmpty(value) ? "?" : value; + } + } + + public TypeReference Alias { + get { + return alias; + } + set { + alias = value ?? TypeReference.Null; + } + } + + public Using(string name) { + Name = name; + alias = TypeReference.Null; + } + + public Using(string name, TypeReference alias) { + Name = name; + Alias = alias; + } + + public bool IsAlias { + get { + return !alias.IsNull; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUsing(this, data); + } + + public override string ToString() { + return string.Format("[Using Name={0} Alias={1}]", Name, Alias); + } + } + + public class UsingDeclaration : AbstractNode { + + List usings; + + public List Usings { + get { + return usings; + } + set { + usings = value ?? new List(); + } + } + + public UsingDeclaration(List usings) { + Usings = usings; + } + +public UsingDeclaration(string @namespace, TypeReference alias) { usings = new List(1); usings.Add(new Using(@namespace, alias)); } + +public UsingDeclaration(string @namespace) : this(@namespace, null) {} + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUsingDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[UsingDeclaration Usings={0}]", GetCollectionString(Usings)); + } + } + + public class UsingStatement : StatementWithEmbeddedStatement { + + Statement resourceAcquisition; + + public Statement ResourceAcquisition { + get { + return resourceAcquisition; + } + set { + resourceAcquisition = value ?? Statement.Null; + if (!resourceAcquisition.IsNull) resourceAcquisition.Parent = this; + } + } + + public UsingStatement(Statement resourceAcquisition, Statement embeddedStatement) { + ResourceAcquisition = resourceAcquisition; + EmbeddedStatement = embeddedStatement; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitUsingStatement(this, data); + } + + public override string ToString() { + return string.Format("[UsingStatement ResourceAcquisition={0} EmbeddedStatement={1}]", ResourceAcquisition, EmbeddedStatement); + } + } + + public class VariableDeclaration : AbstractNode { + + string name; + + Expression initializer; + + TypeReference typeReference; + + Expression fixedArrayInitialization; + + public string Name { + get { + return name; + } + set { + name = value ?? ""; + } + } + + public Expression Initializer { + get { + return initializer; + } + set { + initializer = value ?? Expression.Null; + if (!initializer.IsNull) initializer.Parent = this; + } + } + + public TypeReference TypeReference { + get { + return typeReference; + } + set { + typeReference = value ?? TypeReference.Null; + } + } + + public Expression FixedArrayInitialization { + get { + return fixedArrayInitialization; + } + set { + fixedArrayInitialization = value ?? Expression.Null; + if (!fixedArrayInitialization.IsNull) fixedArrayInitialization.Parent = this; + } + } + + public VariableDeclaration(string name) { + Name = name; + initializer = Expression.Null; + typeReference = TypeReference.Null; + fixedArrayInitialization = Expression.Null; + } + + public VariableDeclaration(string name, Expression initializer) { + Name = name; + Initializer = initializer; + typeReference = TypeReference.Null; + fixedArrayInitialization = Expression.Null; + } + + public VariableDeclaration(string name, Expression initializer, TypeReference typeReference) { + Name = name; + Initializer = initializer; + TypeReference = typeReference; + fixedArrayInitialization = Expression.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitVariableDeclaration(this, data); + } + + public override string ToString() { + return string.Format("[VariableDeclaration Name={0} Initializer={1} TypeReference={2} FixedArrayInitial" + + "ization={3}]", Name, Initializer, TypeReference, FixedArrayInitialization); + } + } + + public class WithStatement : Statement { + + Expression expression; + + BlockStatement body; + + public Expression Expression { + get { + return expression; + } + set { + expression = value ?? Expression.Null; + if (!expression.IsNull) expression.Parent = this; + } + } + + public BlockStatement Body { + get { + return body; + } + set { + body = value ?? BlockStatement.Null; + if (!body.IsNull) body.Parent = this; + } + } + + public WithStatement(Expression expression) { + Expression = expression; + body = BlockStatement.Null; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitWithStatement(this, data); + } + + public override string ToString() { + return string.Format("[WithStatement Expression={0} Body={1}]", Expression, Body); + } + } + + public class YieldStatement : Statement { + + Statement statement; + + public Statement Statement { + get { + return statement; + } + set { + statement = value ?? Statement.Null; + if (!statement.IsNull) statement.Parent = this; + } + } + + public YieldStatement(Statement statement) { + Statement = statement; + } + + public bool IsYieldBreak { + get { + return statement is BreakStatement; + } + } + + public bool IsYieldReturn { + get { + return statement is ReturnStatement; + } + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) { + return visitor.VisitYieldStatement(this, data); + } + + public override string ToString() { + return string.Format("[YieldStatement Statement={0}]", Statement); + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/INode.cs b/lib/NRefactory/Project/Src/Ast/INode.cs new file mode 100644 index 000000000..044731a42 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/INode.cs @@ -0,0 +1,55 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.Ast +{ + public interface INode + { + INode Parent { + get; + set; + } + + List Children { + get; + } + + Location StartLocation { + get; + set; + } + + Location EndLocation { + get; + set; + } + + object UserData { + get; + set; + } + + /// + /// Visits all children + /// + /// The visitor to accept + /// Additional data for the visitor + /// The paremeter + object AcceptChildren(IAstVisitor visitor, object data); + + /// + /// Accept the visitor + /// + /// The visitor to accept + /// Additional data for the visitor + /// The value the visitor returns after the visit + object AcceptVisitor(IAstVisitor visitor, object data); + } +} diff --git a/lib/NRefactory/Project/Src/Ast/INullable.cs b/lib/NRefactory/Project/Src/Ast/INullable.cs new file mode 100644 index 000000000..b484e85ba --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/INullable.cs @@ -0,0 +1,16 @@ +// +// +// +// +// $Revision$ +// + +namespace ICSharpCode.NRefactory.Ast +{ + public interface INullable + { + bool IsNull { + get; + } + } +} diff --git a/lib/NRefactory/Project/Src/Ast/TypeReference.cs b/lib/NRefactory/Project/Src/Ast/TypeReference.cs new file mode 100644 index 000000000..0ed0b1395 --- /dev/null +++ b/lib/NRefactory/Project/Src/Ast/TypeReference.cs @@ -0,0 +1,431 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text; + +namespace ICSharpCode.NRefactory.Ast +{ + public class TypeReference : AbstractNode, INullable, ICloneable + { + public static readonly TypeReference StructConstraint = new TypeReference("constraint: struct"); + public static readonly TypeReference ClassConstraint = new TypeReference("constraint: class"); + public static readonly TypeReference NewConstraint = new TypeReference("constraint: new"); + + string type = ""; + string systemType = ""; + int pointerNestingLevel; + int[] rankSpecifier; + List genericTypes = new List(); + bool isGlobal; + + #region Static primitive type list + static Dictionary types = new Dictionary(); + static Dictionary vbtypes = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + static Dictionary typesReverse = new Dictionary(); + static Dictionary vbtypesReverse = new Dictionary(); + + static TypeReference() + { + // C# types + types.Add("bool", "System.Boolean"); + types.Add("byte", "System.Byte"); + types.Add("char", "System.Char"); + types.Add("decimal", "System.Decimal"); + types.Add("double", "System.Double"); + types.Add("float", "System.Single"); + types.Add("int", "System.Int32"); + types.Add("long", "System.Int64"); + types.Add("object", "System.Object"); + types.Add("sbyte", "System.SByte"); + types.Add("short", "System.Int16"); + types.Add("string", "System.String"); + types.Add("uint", "System.UInt32"); + types.Add("ulong", "System.UInt64"); + types.Add("ushort", "System.UInt16"); + types.Add("void", "System.Void"); + + // VB.NET types + vbtypes.Add("Boolean", "System.Boolean"); + vbtypes.Add("Byte", "System.Byte"); + vbtypes.Add("SByte", "System.SByte"); + vbtypes.Add("Date", "System.DateTime"); + vbtypes.Add("Char", "System.Char"); + vbtypes.Add("Decimal", "System.Decimal"); + vbtypes.Add("Double", "System.Double"); + vbtypes.Add("Single", "System.Single"); + vbtypes.Add("Integer", "System.Int32"); + vbtypes.Add("Long", "System.Int64"); + vbtypes.Add("UInteger","System.UInt32"); + vbtypes.Add("ULong", "System.UInt64"); + vbtypes.Add("Object", "System.Object"); + vbtypes.Add("Short", "System.Int16"); + vbtypes.Add("UShort", "System.UInt16"); + vbtypes.Add("String", "System.String"); + + foreach (KeyValuePair pair in types) { + typesReverse.Add(pair.Value, pair.Key); + } + foreach (KeyValuePair pair in vbtypes) { + vbtypesReverse.Add(pair.Value, pair.Key); + } + } + + /// + /// Gets a shortname=>full name dictionary of C# types. + /// + public static IDictionary PrimitiveTypesCSharp { + get { return types; } + } + + /// + /// Gets a shortname=>full name dictionary of VB types. + /// + public static IDictionary PrimitiveTypesVB { + get { return vbtypes; } + } + + /// + /// Gets a full name=>shortname dictionary of C# types. + /// + public static IDictionary PrimitiveTypesCSharpReverse { + get { return typesReverse; } + } + + /// + /// Gets a full name=>shortname dictionary of VB types. + /// + public static IDictionary PrimitiveTypesVBReverse { + get { return vbtypesReverse; } + } + + + static string GetSystemType(string type) + { + if (types == null) return type; + + string systemType; + if (types.TryGetValue(type, out systemType)) { + return systemType; + } + if (vbtypes.TryGetValue(type, out systemType)) { + return systemType; + } + return type; + } + #endregion + + object ICloneable.Clone() + { + return this.Clone(); + } + + public virtual TypeReference Clone() + { + TypeReference c = new TypeReference(type, systemType); + CopyFields(this, c); + return c; + } + + /// + /// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag + /// from to . + /// + /// + /// If already contains generics, the new generics are appended to the list. + /// + protected static void CopyFields(TypeReference from, TypeReference to) + { + to.pointerNestingLevel = from.pointerNestingLevel; + if (from.rankSpecifier != null) { + to.rankSpecifier = (int[])from.rankSpecifier.Clone(); + } + foreach (TypeReference r in from.genericTypes) { + to.genericTypes.Add(r.Clone()); + } + to.isGlobal = from.isGlobal; + } + + public string Type { + get { + return type; + } + set { + Debug.Assert(value != null); + type = value; + systemType = GetSystemType(type); + } + } + + /// + /// Removes the last identifier from the type. + /// e.g. "System.String.Length" becomes "System.String" or + /// "System.Collections.IEnumerable(of string).Current" becomes "System.Collections.IEnumerable(of string)" + /// This is used for explicit interface implementation in VB. + /// + public static string StripLastIdentifierFromType(ref TypeReference tr) + { + if (tr is InnerClassTypeReference && ((InnerClassTypeReference)tr).Type.IndexOf('.') < 0) { + string ident = ((InnerClassTypeReference)tr).Type; + tr = ((InnerClassTypeReference)tr).BaseType; + return ident; + } else { + int pos = tr.Type.LastIndexOf('.'); + if (pos < 0) + return tr.Type; + string ident = tr.Type.Substring(pos + 1); + tr.Type = tr.Type.Substring(0, pos); + return ident; + } + } + + public string SystemType { + get { + return systemType; + } + } + + public int PointerNestingLevel { + get { + return pointerNestingLevel; + } + set { + Debug.Assert(this.IsNull == false); + pointerNestingLevel = value; + } + } + + /// + /// The rank of the array type. + /// For "object[]", this is { 0 }; for "object[,]", it is {1}. + /// For "object[,][,,][]", it is {1, 2, 0}. + /// For non-array types, this property is null or {}. + /// + public int[] RankSpecifier { + get { + return rankSpecifier; + } + set { + Debug.Assert(this.IsNull == false); + rankSpecifier = value; + } + } + + public List GenericTypes { + get { + return genericTypes; + } + } + + public bool IsArrayType { + get { + return rankSpecifier != null && rankSpecifier.Length > 0; + } + } + + public static TypeReference CheckNull(TypeReference typeReference) + { + return typeReference ?? NullTypeReference.Instance; + } + + public static TypeReference Null { + get { + return NullTypeReference.Instance; + } + } + + public virtual bool IsNull { + get { + return false; + } + } + + /// + /// Gets/Sets if the type reference had a "global::" prefix. + /// + public bool IsGlobal { + get { + return isGlobal; + } + set { + isGlobal = value; + } + } + + public TypeReference(string type) + { + this.Type = type; + } + + public TypeReference(string type, string systemType) + { + this.type = type; + this.systemType = systemType; + } + + public TypeReference(string type, List genericTypes) : this(type) + { + if (genericTypes != null) { + this.genericTypes = genericTypes; + } + } + + public TypeReference(string type, int[] rankSpecifier) : this(type, 0, rankSpecifier) + { + } + + public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier) : this(type, pointerNestingLevel, rankSpecifier, null) + { + } + + public TypeReference(string type, int pointerNestingLevel, int[] rankSpecifier, List genericTypes) + { + Debug.Assert(type != null); + this.type = type; + this.systemType = GetSystemType(type); + this.pointerNestingLevel = pointerNestingLevel; + this.rankSpecifier = rankSpecifier; + if (genericTypes != null) { + this.genericTypes = genericTypes; + } + } + + protected TypeReference() + {} + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitTypeReference(this, data); + } + + public override string ToString() + { + StringBuilder b = new StringBuilder(type); + if (genericTypes != null && genericTypes.Count > 0) { + b.Append('<'); + for (int i = 0; i < genericTypes.Count; i++) { + if (i > 0) b.Append(','); + b.Append(genericTypes[i].ToString()); + } + b.Append('>'); + } + if (pointerNestingLevel > 0) { + b.Append('*', pointerNestingLevel); + } + if (IsArrayType) { + foreach (int rank in rankSpecifier) { + b.Append('['); + if (rank < 0) + b.Append('`', -rank); + else + b.Append(',', rank); + b.Append(']'); + } + } + return b.ToString(); + } + + public static bool AreEqualReferences(TypeReference a, TypeReference b) + { + if (a == b) return true; + if (a == null || b == null) return false; + if (a is InnerClassTypeReference) a = ((InnerClassTypeReference)a).CombineToNormalTypeReference(); + if (b is InnerClassTypeReference) b = ((InnerClassTypeReference)b).CombineToNormalTypeReference(); + if (a.systemType != b.systemType) return false; + if (a.pointerNestingLevel != b.pointerNestingLevel) return false; + if (a.IsArrayType != b.IsArrayType) return false; + if (a.IsArrayType) { + if (a.rankSpecifier.Length != b.rankSpecifier.Length) return false; + for (int i = 0; i < a.rankSpecifier.Length; i++) { + if (a.rankSpecifier[i] != b.rankSpecifier[i]) return false; + } + } + if (a.genericTypes.Count != b.genericTypes.Count) return false; + for (int i = 0; i < a.genericTypes.Count; i++) { + if (!AreEqualReferences(a.genericTypes[i], b.genericTypes[i])) + return false; + } + return true; + } + } + + internal sealed class NullTypeReference : TypeReference + { + public static readonly NullTypeReference Instance = new NullTypeReference(); + public override bool IsNull { + get { + return true; + } + } + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return null; + } + + public override string ToString() + { + return String.Format("[NullTypeReference]"); + } + } + + /// + /// We need this special type reference for cases like + /// OuterClass(Of T1).InnerClass(Of T2) (in expression or type context) + /// or Dictionary(Of String, NamespaceStruct).KeyCollection (in type context, otherwise it's a + /// MemberReferenceExpression) + /// + public class InnerClassTypeReference: TypeReference + { + TypeReference baseType; + + public TypeReference BaseType { + get { return baseType; } + set { baseType = value; } + } + + public override TypeReference Clone() + { + InnerClassTypeReference c = new InnerClassTypeReference(baseType.Clone(), Type, GenericTypes); + CopyFields(this, c); + return c; + } + + public InnerClassTypeReference(TypeReference outerClass, string innerType, List innerGenericTypes) + : base(innerType, innerGenericTypes) + { + this.baseType = outerClass; + } + + public override object AcceptVisitor(IAstVisitor visitor, object data) + { + return visitor.VisitInnerClassTypeReference(this, data); + } + + /// + /// Creates a type reference where all type parameters are specified for the innermost class. + /// Namespace.OuterClass(of string).InnerClass(of integer).InnerInnerClass + /// becomes Namespace.OuterClass.InnerClass.InnerInnerClass(of string, integer) + /// + public TypeReference CombineToNormalTypeReference() + { + TypeReference tr = (baseType is InnerClassTypeReference) + ? ((InnerClassTypeReference)baseType).CombineToNormalTypeReference() + : baseType.Clone(); + CopyFields(this, tr); + tr.Type += "." + Type; + return tr; + } + + public override string ToString() + { + return "[InnerClassTypeReference: (" + baseType.ToString() + ")." + base.ToString() + "]"; + } + } +} diff --git a/lib/NRefactory/Project/Src/EnvironmentInformationProvider.cs b/lib/NRefactory/Project/Src/EnvironmentInformationProvider.cs new file mode 100644 index 000000000..b57d06a27 --- /dev/null +++ b/lib/NRefactory/Project/Src/EnvironmentInformationProvider.cs @@ -0,0 +1,26 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + public interface IEnvironmentInformationProvider + { + bool HasField(string fullTypeName, int typeParameterCount, string fieldName); + } + + sealed class DummyEnvironmentInformationProvider : IEnvironmentInformationProvider + { + internal static readonly IEnvironmentInformationProvider Instance = new DummyEnvironmentInformationProvider(); + + public bool HasField(string fullTypeName, int typeParameterCount, string fieldName) + { + return false; + } + } +} diff --git a/lib/NRefactory/Project/Src/IAstVisitor.cs b/lib/NRefactory/Project/Src/IAstVisitor.cs new file mode 100644 index 000000000..b1ccb8433 --- /dev/null +++ b/lib/NRefactory/Project/Src/IAstVisitor.cs @@ -0,0 +1,240 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:2.0.50727.1433 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace ICSharpCode.NRefactory { + using System; + using ICSharpCode.NRefactory.Ast; + + + public interface IAstVisitor { + + object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data); + + object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data); + + object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data); + + object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data); + + object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data); + + object VisitAttribute(ICSharpCode.NRefactory.Ast.Attribute attribute, object data); + + object VisitAttributeSection(AttributeSection attributeSection, object data); + + object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data); + + object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data); + + object VisitBlockStatement(BlockStatement blockStatement, object data); + + object VisitBreakStatement(BreakStatement breakStatement, object data); + + object VisitCaseLabel(CaseLabel caseLabel, object data); + + object VisitCastExpression(CastExpression castExpression, object data); + + object VisitCatchClause(CatchClause catchClause, object data); + + object VisitCheckedExpression(CheckedExpression checkedExpression, object data); + + object VisitCheckedStatement(CheckedStatement checkedStatement, object data); + + object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data); + + object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data); + + object VisitCompilationUnit(CompilationUnit compilationUnit, object data); + + object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data); + + object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data); + + object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data); + + object VisitContinueStatement(ContinueStatement continueStatement, object data); + + object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data); + + object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data); + + object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data); + + object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data); + + object VisitDirectionExpression(DirectionExpression directionExpression, object data); + + object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data); + + object VisitElseIfSection(ElseIfSection elseIfSection, object data); + + object VisitEmptyStatement(EmptyStatement emptyStatement, object data); + + object VisitEndStatement(EndStatement endStatement, object data); + + object VisitEraseStatement(EraseStatement eraseStatement, object data); + + object VisitErrorStatement(ErrorStatement errorStatement, object data); + + object VisitEventAddRegion(EventAddRegion eventAddRegion, object data); + + object VisitEventDeclaration(EventDeclaration eventDeclaration, object data); + + object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data); + + object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data); + + object VisitExitStatement(ExitStatement exitStatement, object data); + + object VisitExpressionStatement(ExpressionStatement expressionStatement, object data); + + object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data); + + object VisitFixedStatement(FixedStatement fixedStatement, object data); + + object VisitForeachStatement(ForeachStatement foreachStatement, object data); + + object VisitForNextStatement(ForNextStatement forNextStatement, object data); + + object VisitForStatement(ForStatement forStatement, object data); + + object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data); + + object VisitGotoStatement(GotoStatement gotoStatement, object data); + + object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data); + + object VisitIfElseStatement(IfElseStatement ifElseStatement, object data); + + object VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, object data); + + object VisitIndexerExpression(IndexerExpression indexerExpression, object data); + + object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data); + + object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data); + + object VisitInvocationExpression(InvocationExpression invocationExpression, object data); + + object VisitLabelStatement(LabelStatement labelStatement, object data); + + object VisitLambdaExpression(LambdaExpression lambdaExpression, object data); + + object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data); + + object VisitLockStatement(LockStatement lockStatement, object data); + + object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data); + + object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data); + + object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data); + + object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data); + + object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data); + + object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data); + + object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data); + + object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data); + + object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data); + + object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data); + + object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data); + + object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data); + + object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data); + + object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data); + + object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data); + + object VisitQueryExpression(QueryExpression queryExpression, object data); + + object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data); + + object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data); + + object VisitQueryExpressionIntoClause(QueryExpressionIntoClause queryExpressionIntoClause, object data); + + object VisitQueryExpressionJoinClause(QueryExpressionJoinClause queryExpressionJoinClause, object data); + + object VisitQueryExpressionLetClause(QueryExpressionLetClause queryExpressionLetClause, object data); + + object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data); + + object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data); + + object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data); + + object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data); + + object VisitReDimStatement(ReDimStatement reDimStatement, object data); + + object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data); + + object VisitResumeStatement(ResumeStatement resumeStatement, object data); + + object VisitReturnStatement(ReturnStatement returnStatement, object data); + + object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data); + + object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data); + + object VisitStopStatement(StopStatement stopStatement, object data); + + object VisitSwitchSection(SwitchSection switchSection, object data); + + object VisitSwitchStatement(SwitchStatement switchStatement, object data); + + object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data); + + object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data); + + object VisitThrowStatement(ThrowStatement throwStatement, object data); + + object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data); + + object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data); + + object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data); + + object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data); + + object VisitTypeReference(TypeReference typeReference, object data); + + object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data); + + object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data); + + object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data); + + object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data); + + object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data); + + object VisitUsing(Using @using, object data); + + object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data); + + object VisitUsingStatement(UsingStatement usingStatement, object data); + + object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data); + + object VisitWithStatement(WithStatement withStatement, object data); + + object VisitYieldStatement(YieldStatement yieldStatement, object data); + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/AbstractLexer.cs b/lib/NRefactory/Project/Src/Lexer/AbstractLexer.cs new file mode 100644 index 000000000..2416b980d --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/AbstractLexer.cs @@ -0,0 +1,297 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Text; + +namespace ICSharpCode.NRefactory.Parser +{ + /// + /// This is the base class for the C# and VB.NET lexer + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1708:IdentifiersShouldDifferByMoreThanCase")] + public abstract class AbstractLexer : ILexer + { + TextReader reader; + int col = 1; + int line = 1; + + [CLSCompliant(false)] + protected Errors errors = new Errors(); + + protected Token lastToken = null; + protected Token curToken = null; + protected Token peekToken = null; + + string[] specialCommentTags = null; + protected Hashtable specialCommentHash = null; + List tagComments = new List(); + protected StringBuilder sb = new StringBuilder(); + [CLSCompliant(false)] + protected SpecialTracker specialTracker = new SpecialTracker(); + + // used for the original value of strings (with escape sequences). + protected StringBuilder originalValue = new StringBuilder(); + + bool skipAllComments = false; + + public bool SkipAllComments { + get { + return skipAllComments; + } + set { + skipAllComments = value; + } + } + + protected int Line { + get { + return line; + } + } + protected int Col { + get { + return col; + } + } + protected int ReaderRead() + { + ++col; + return reader.Read(); + } + protected int ReaderPeek() + { + return reader.Peek(); + } + + public Errors Errors { + get { + return errors; + } + } + + /// + /// Returns the comments that had been read and containing tag key words. + /// + public List TagComments { + get { + return tagComments; + } + } + + public SpecialTracker SpecialTracker { + get { + return specialTracker; + } + } + + /// + /// Special comment tags are tags like TODO, HACK or UNDONE which are read by the lexer and stored in . + /// + public string[] SpecialCommentTags { + get { + return specialCommentTags; + } + set { + specialCommentTags = value; + specialCommentHash = null; + if (specialCommentTags != null && specialCommentTags.Length > 0) { + specialCommentHash = new Hashtable(); + foreach (string str in specialCommentTags) { + specialCommentHash.Add(str, null); + } + } + } + } + + /// + /// The current Token. + /// + public Token Token { + get { +// Console.WriteLine("Call to Token"); + return lastToken; + } + } + + /// + /// The next Token (The after call) . + /// + public Token LookAhead { + get { +// Console.WriteLine("Call to LookAhead"); + return curToken; + } + } + + /// + /// Constructor for the abstract lexer class. + /// + protected AbstractLexer(TextReader reader) + { + this.reader = reader; + } + + #region System.IDisposable interface implementation + public virtual void Dispose() + { + reader.Close(); + reader = null; + errors = null; + lastToken = curToken = peekToken = null; + specialCommentHash = null; + tagComments = null; + sb = originalValue = null; + } + #endregion + + /// + /// Must be called before a peek operation. + /// + public void StartPeek() + { + peekToken = curToken; + } + + /// + /// Gives back the next token. A second call to Peek() gives the next token after the last call for Peek() and so on. + /// + /// An object. + public Token Peek() + { +// Console.WriteLine("Call to Peek"); + if (peekToken.next == null) { + peekToken.next = Next(); + specialTracker.InformToken(peekToken.next.kind); + } + peekToken = peekToken.next; + return peekToken; + } + + /// + /// Reads the next token and gives it back. + /// + /// An object. + public virtual Token NextToken() + { + if (curToken == null) { + curToken = Next(); + specialTracker.InformToken(curToken.kind); + //Console.WriteLine(ICSharpCode.NRefactory.Parser.CSharp.Tokens.GetTokenString(curToken.kind) + " -- " + curToken.val + "(" + curToken.kind + ")"); + return curToken; + } + + lastToken = curToken; + + if (curToken.next == null) { + curToken.next = Next(); + if (curToken.next != null) { + specialTracker.InformToken(curToken.next.kind); + } + } + + curToken = curToken.next; + //Console.WriteLine(ICSharpCode.NRefactory.Parser.CSharp.Tokens.GetTokenString(curToken.kind) + " -- " + curToken.val + "(" + curToken.kind + ")"); + return curToken; + } + + protected abstract Token Next(); + + protected static bool IsIdentifierPart(int ch) + { + if (ch == 95) return true; // 95 = '_' + if (ch == -1) return false; + return char.IsLetterOrDigit((char)ch); // accept unicode letters + } + + protected static bool IsHex(char digit) + { + return Char.IsDigit(digit) || ('A' <= digit && digit <= 'F') || ('a' <= digit && digit <= 'f'); + } + + protected int GetHexNumber(char digit) + { + if (Char.IsDigit(digit)) { + return digit - '0'; + } + if ('A' <= digit && digit <= 'F') { + return digit - 'A' + 0xA; + } + if ('a' <= digit && digit <= 'f') { + return digit - 'a' + 0xA; + } + errors.Error(line, col, String.Format("Invalid hex number '" + digit + "'")); + return 0; + } + + protected bool WasLineEnd(char ch) + { + // Handle MS-DOS or MacOS line ends. + if (ch == '\r') { + if (reader.Peek() == '\n') { // MS-DOS line end '\r\n' + ch = (char)reader.Read(); + ++col; + } else { // assume MacOS line end which is '\r' + ch = '\n'; + } + } + return ch == '\n'; + } + + protected bool HandleLineEnd(char ch) + { + if (WasLineEnd(ch)) { + ++line; + col = 1; + return true; + } + return false; + } + + protected void SkipToEndOfLine() + { + int nextChar; + while ((nextChar = reader.Read()) != -1) { + if (HandleLineEnd((char)nextChar)) { + break; + } + } + } + + protected string ReadToEndOfLine() + { + sb.Length = 0; + int nextChar; + while ((nextChar = reader.Read()) != -1) { + char ch = (char)nextChar; + + // Return read string, if EOL is reached + if (HandleLineEnd(ch)) { + return sb.ToString(); + } + + sb.Append(ch); + } + + // Got EOF before EOL + string retStr = sb.ToString(); + col += retStr.Length; + return retStr; + } + + /// + /// Skips to the end of the current code block. + /// For this, the lexer must have read the next token AFTER the token opening the + /// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead). + /// After the call, Lexer.LookAhead will be the block-closing token. + /// + public abstract void SkipCurrentBlock(int targetToken); + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/BuildKeywords.pl b/lib/NRefactory/Project/Src/Lexer/BuildKeywords.pl new file mode 100644 index 000000000..21c09339f --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/BuildKeywords.pl @@ -0,0 +1,340 @@ +#!/bin/perl + +# File names +$keyword_file = "KeywordList.txt"; +$keywords_outfile = "Keywords.cs"; +$tokens_outfile = "Tokens.cs"; +$unittests_outfile = "LexerTests.cs"; +$ATGTokensSection = "ATGTokensSection.gen"; + +#read infile +print "\n"; +print "Reading keyword definition from '$keyword_file'.\n"; +open(DAT, $keyword_file) || die("Could not open file '$keyword_file': $!"); +@raw_data=; +close(DAT); +print "done.\n"; + +#analyse infile +print "starting analysation ... this could take a few minutes.\n"; + +foreach (@raw_data) { + if ($_=~/^\s*\$(\w+)\s*=\s*(\S+)\s*$/) { + #properties form: $PROPERTY = "VALUE" + $properties{$1} = $2; + } elsif ($_=~/^\s*(\w+)\s*=\s*(\S+)\s*$/) { + #special characters form: name = "VALUE" + $specialCharLookup{$2} = $1; + $special_chars[$#special_chars + 1] = $1; + $special_values[$#special_values + 1] = $2; + } elsif ($_=~/^\s*\"(\S+)\s*\"\s*$/) { + #special keywords form: "VALUE" + $keywords[$#keywords + 1] = $1; + } elsif ($_=~/^\s*(\w+)\s*\((.*)\)\s*$/) { + $sets[$#sets + 1] = $1; + #Split set values (comma separated list) + $_ = $2; + @vals = split/\s*,\s*/; + + push @$setValues, [@vals]; + } elsif ($_=~/^\s*(\w+)\s*$/) { + #special terminal classes form: name + $terminals[$#terminals + 1] = $1 + } elsif ($_=~/^\s*(#.*)?$/) { + #ignore empty line + } else { + print "unknown line: $_"; + } +} + + +for ($i=0; $i <= $#keywords; $i++) { + $upperKeywords[$i] = uc $keywords[$i]; +} +sort (ascend @upperKeywords); + + +sort (ascend @keywords); +print "done.\n"; + +#write output +print "writing output files.\nIf your computer doesn’t respond, then press \"Ctrl-Alt-Delete\"\n"; +print "\n"; +&write_keywordfile; +print "\n"; +&write_tokensfile; +print "\n"; +&write_atgtokensfile; +print "\n"; +&write_unittests; +print "finished.\n"; + +sub write_keywordfile +{ + print " ->Generating Keywords class to file '$keywords_outfile'\n"; + open(DAT,">$keywords_outfile") || die("Cannot Open File"); + print DAT "// this file was autogenerated by a tool.\n"; + print DAT "using System;\n"; + print DAT "\n"; + print DAT "namespace " . $properties{'Namespace'} . "\n"; + print DAT "{\n"; + print DAT "\tpublic static class Keywords\n"; + print DAT "\t{\n"; + print DAT "\t\tstatic readonly string[] keywordList = {\n"; + if ($properties{'UpperCaseKeywords'} eq "True") { + for ($i=0; $i <= $#upperKeywords; $i++) { + print DAT "\t\t\t\"$upperKeywords[$i]\""; + if ($i + 1 <= $#upperKeywords) { + print DAT ","; + } + print DAT "\n"; + } + } else { + for ($i=0; $i <= $#keywords; $i++) { + print DAT "\t\t\t\"$keywords[$i]\""; + if ($i + 1 <= $#keywords) { + print DAT ","; + } + print DAT "\n"; + } + } + + print DAT "\t\t};\n"; + print DAT "\t\t\n"; + if ($properties{'UpperCaseKeywords'} eq "True") { + print DAT "\t\tstatic LookupTable keywords = new LookupTable(false);\n"; + } else { + print DAT "\t\tstatic LookupTable keywords = new LookupTable(true);\n"; + } + + print DAT "\t\t\n"; + print DAT "\t\tstatic Keywords()\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tfor (int i = 0; i < keywordList.Length; ++i) {\n"; + print DAT "\t\t\t\tkeywords[keywordList[i]] = i + Tokens." . ucfirst $keywords[0] . ";\n"; + print DAT "\t\t\t}\n"; + print DAT "\t\t}\n"; + print DAT "\t\t\n"; + print DAT "\t\tpublic static int GetToken(string keyword)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\treturn keywords[keyword];\n"; + print DAT "\t\t}\n"; + print DAT "\t\t\n"; + print DAT "\t\tpublic static bool IsNonIdentifierKeyword(string word)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tint token = GetToken(word);\n"; + print DAT "\t\t\tif (token < 0)\n"; + print DAT "\t\t\t\treturn false;\n"; + print DAT "\t\t\treturn !Tokens.IdentifierTokens[token];\n"; + print DAT "\t\t}\n"; + print DAT "\t}\n"; + print DAT "}\n"; + close(DAT); + print " ->done.\n"; +} + +sub write_token { + $formattedString = sprintf("%-20s", ucfirst $tokenName); + if (($tokenName eq "GetType") or ($tokenName eq "equals")) { + print DAT "\t\tnew public const int $formattedString = $tokenValue;\n"; + } else { + print DAT "\t\tpublic const int $formattedString = $tokenValue;\n"; + } + $tokenValue++; + +} + +sub print_list { + local ($j, $k, $max, $index); + + $index = $_[0]; + $max = $#{$setValues->[$index]}; + + for ($j=0; $j <= $max; $j++) { + $_ = $setValues->[$index][$j]; + if (/\"(\w+)\"/) { # Keywords + print DAT ucfirst $1; + } elsif (/\"(\W+)\"/) { # special chars + print DAT $specialCharLookup{$_}; + } elsif (/@(\w+)/) { # @otherList + for ($k=0; $k <= $#sets; $k++) { + if ($sets[$k] eq $1) { + print_list($k); + } + } + } else { + print DAT $_; + } + + if ($j + 1 <= $max) { + print DAT ", "; + } + } +} + + +sub write_tokensfile { + print " ->Generating Tokens class to file '$tokens_outfile'\n"; + open(DAT,">$tokens_outfile") || die("Cannot Open File"); + print DAT "// this file was autogenerated by a tool.\n"; + print DAT "using System;\n"; + print DAT "using System.Collections;\n"; + print DAT "\n"; + print DAT "namespace " . $properties{'Namespace'} . "\n"; + print DAT "{\n"; + print DAT "\tpublic static class Tokens\n"; + print DAT "\t{\n"; + $tokenValue = 0; + + print DAT "\t\t// ----- terminal classes -----\n"; + foreach (@terminals) { + $tokenName = $_; + write_token(); + } + print DAT "\n"; + print DAT "\t\t// ----- special character -----\n"; + foreach (@special_chars) { + $tokenName = $_; + write_token(); + } + print DAT "\n"; + print DAT "\t\t// ----- keywords -----\n"; + foreach (@keywords) { + $tokenName = $_; + write_token(); + } + print DAT "\n"; + + print DAT "\t\tpublic const int MaxToken = " . $tokenValue . ";\n"; + + #write sets. + if ($#sets > 0) { + print DAT "\t\tstatic BitArray NewSet(params int[] values)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tBitArray bitArray = new BitArray(MaxToken);\n"; + print DAT "\t\t\tforeach (int val in values) {\n"; + print DAT "\t\t\tbitArray[val] = true;\n"; + print DAT "\t\t\t}\n"; + print DAT "\t\t\treturn bitArray;\n"; + print DAT "\t\t}\n"; + for ($i=0; $i <= $#sets; $i++) { + print DAT "\t\tpublic static BitArray ". $sets[$i] . " = NewSet("; + print_list($i); + print DAT ");\n"; + } + print DAT "\n"; + } + + #write token number --> string function. + print DAT "\t\tstatic string[] tokenList = new string[] {\n"; + print DAT "\t\t\t// ----- terminal classes -----\n"; + foreach (@terminals) { + print DAT "\t\t\t\"<$_>\",\n"; + } + print DAT "\t\t\t// ----- special character -----\n"; + foreach (@special_values) { + print DAT "\t\t\t$_,\n"; + } + print DAT "\t\t\t// ----- keywords -----\n"; + foreach (@keywords) { + print DAT "\t\t\t\"$_\",\n"; + } + print DAT "\t\t};\n"; + + + print DAT "\t\tpublic static string GetTokenString(int token)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tif (token >= 0 && token < tokenList.Length) {\n"; + print DAT "\t\t\t\treturn tokenList[token];\n"; + print DAT "\t\t\t}\n"; + print DAT "\t\t\tthrow new System.NotSupportedException(\"Unknown token:\" + token);\n"; + print DAT "\t\t}\n"; + print DAT "\t}\n"; + + + + print DAT "}\n"; + close(DAT); + print " ->done.\n"; +} + +sub write_unittests { + open(DAT,">$unittests_outfile") || die("Cannot Open File"); + print DAT "using System;\n"; + print DAT "using System.IO;\n"; + print DAT "using NUnit.Framework;\n"; + print DAT "using ICSharpCode.NRefactory.Parser;\n"; + print DAT "using ICSharpCode.NRefactory.PrettyPrinter;\n"; + + print DAT "\n"; + print DAT "namespace ICSharpCode.NRefactory.Tests.Lexer\n"; + print DAT "{\n"; + print DAT "\t[TestFixture]\n"; + print DAT "\tpublic sealed class LexerTests\n"; + print DAT "\t{\n"; + print DAT "\t\tILexer GenerateLexer(StringReader sr)\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\treturn ParserFactory.CreateLexer(SupportedLanguage.CSharp, sr);\n"; + print DAT "\t\t}\n\n"; + + for ($i=0; $i <= $#special_values; $i++) { + + print DAT "\t\t[Test]\n"; + print DAT "\t\tpublic void Test" . $special_chars[$i] ."()\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tILexer lexer = GenerateLexer(new StringReader(" . $special_values[$i] . "));\n"; + print DAT "\t\t\tAssert.AreEqual(Tokens." . $special_chars[$i] . ", lexer.NextToken().kind);\n"; + print DAT "\t\t}\n\n"; + + } + + foreach (@keywords) { + print DAT "\t\t[Test()]\n"; + print DAT "\t\tpublic void Test" . ucfirst $_ ."()\n"; + print DAT "\t\t{\n"; + print DAT "\t\t\tILexer lexer = GenerateLexer(new StringReader(\"" . $_ . "\"));\n"; + print DAT "\t\t\tAssert.AreEqual(Tokens." . ucfirst $_ . ", lexer.NextToken().kind);\n"; + print DAT "\t\t}\n"; + } + + print DAT "\t}\n"; + print DAT "}\n"; + + + close(DAT); +} + +sub write_atgtokensfile { + print " ->Generating ATG TOKENS section and writing it to file '$ATGTokensSection'\n"; + open(DAT,">$ATGTokensSection") || die("Cannot Open File"); + print DAT "/* START AUTOGENERATED TOKENS SECTION */\n"; + print DAT "TOKENS\n"; + + print DAT "\t/* ----- terminal classes ----- */\n"; + print DAT "\t/* EOF is 0 */\n"; + foreach $term (@terminals) { + if ($term eq "EOF") { + } elsif ($term eq "Identifier") { + print DAT "\tident\n"; + } else { + print DAT "\t$term\n"; + } + + } + + print DAT "\n"; + print DAT "\t/* ----- special character ----- */\n"; + foreach (@special_values) { + print DAT "\t$_\n"; + } + print DAT "\n"; + print DAT "\t/* ----- keywords ----- */\n"; + foreach (@keywords) { + print DAT "\t\"$_\"\n"; + } + + print DAT "/* END AUTOGENERATED TOKENS SECTION */\n"; + close(DAT); + print " ->done.\n"; +} + diff --git a/lib/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt b/lib/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt new file mode 100644 index 000000000..0e21274cc --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/CSharp/KeywordList.txt @@ -0,0 +1,215 @@ +# this list is used for autogeneration of: +# - Keywords.cs +# - Tokens.cs +# - ATGTokensSection.txt - the TOKENS section of the ATG file + +# use BuildKeywords to generate the different lists. + +$Namespace=ICSharpCode.NRefactory.Parser.CSharp +$UpperCaseKeywords=False + +# TERMINAL_CLASSES +EOF +Identifier +Literal + +# SPECIAL_CHARACTERS +Assign = "=" +Plus = "+" +Minus = "-" +Times = "*" +Div = "/" +Mod = "%" + +Colon = ":" +DoubleColon = "::" +Semicolon = ";" +Question = "?" +DoubleQuestion = "??" +Comma = "," +Dot = "." + +OpenCurlyBrace = "{" +CloseCurlyBrace = "}" + +OpenSquareBracket = "[" +CloseSquareBracket = "]" + +OpenParenthesis = "(" +CloseParenthesis = ")" + +GreaterThan = ">" +LessThan = "<" + +Not = "!" +LogicalAnd = "&&" +LogicalOr = "||" + +BitwiseComplement = "~" +BitwiseAnd = "&" +BitwiseOr = "|" +Xor = "^" + +Increment = "++" +Decrement = "--" +Equal = "==" +NotEqual = "!=" +GreaterEqual = ">=" +LessEqual = "<=" + +ShiftLeft = "<<" +#Removed because of generics +#ShiftRight = ">>" + +PlusAssign = "+=" +MinusAssign = "-=" +TimesAssign = "*=" +DivAssign = "/=" +ModAssign = "%=" +BitwiseAndAssign = "&=" +BitwiseOrAssign = "|=" +XorAssign = "^=" +ShiftLeftAssign = "<<=" +#Removed because of generics +#ShiftRightAssign = ">>=" +Pointer = "->" +LambdaArrow = "=>" + +# Keywordlist +"abstract" +"as" +"base" +"bool" +"break" +"byte" +"case" +"catch" +"char" +"checked" +"class" +"const" +"continue" +"decimal" +"default" +"delegate" +"do" +"double" +"else" +"enum" +"event" +"explicit" +"extern" +"false" +"finally" +"fixed" +"float" +"for" +"foreach" +"goto" +"if" +"implicit" +"in" +"int" +"interface" +"internal" +"is" +"lock" +"long" +"namespace" +"new" +"null" +"object" +"operator" +"out" +"override" +"params" +"private" +"protected" +"public" +"readonly" +"ref" +"return" +"sbyte" +"sealed" +"short" +"sizeof" +"stackalloc" +"static" +"string" +"struct" +"switch" +"this" +"throw" +"true" +"try" +"typeof" +"uint" +"ulong" +"unchecked" +"unsafe" +"ushort" +"using" +"virtual" +"void" +"volatile" +"while" + +# Context dependent keywords. +"partial" +"where" +"get" +"set" +"add" +"remove" +"yield" +"select" +"group" +"by" +"into" +"from" +"ascending" +"descending" +"orderby" +"let" +"join" +"on" +"equals" + +#Sets + +# When changing IdentifierTokens, ensure you also change the "Identifier" production in cs.ATG +IdentifierTokens(Identifier, "partial", "where", "get", "set", "add", "remove", "yield", "select", "group", "by", "into", "from", "ascending", "descending", "orderby", "let", "join", "on", "equals") + +OverloadableUnaryOp("-", "!", "~", "++", "--", "true", "false") +OverloadableBinaryOp("+", "-", "*", "/", "%", "&", "|", "^", "<<", "==", "!=", ">", "<", ">=", "<=") + +TypeKW("char", "bool", "object", "string", "sbyte", "byte", "short", "ushort", "int", "uint", "long", "ulong", "float", "double", "decimal") +UnaryHead("+", "-", "!", "~", "*", "++", "--", "&") +AssnStartOp("+", "-", "!", "~", "*") +CastFollower(@SimpleTypeName, Literal, "(", "~", "!", @ExpressionStart) +AssgnOps("=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "<<=") +UnaryOp("+", "-", "!", "~", "*", "++", "--", "&") +TypeDeclarationKW("class", "interface", "struct", "enum", "delegate") +# for §7.5.4.2 "Grammar ambiguities" disambiguation for F(G(7)) +GenericFollower("(", ")", "]", "}", ":", ";", Comma, ".", "?", "==", "!=") + +ValidInsideTypeName(@IdentifierTokens, @TypeKW, "<", ">", ".", "?", "[", Comma, "]", "*", "::") + +# Keywords for keyword-code-completion +KCCClassModifiers("abstract", "sealed", "static", "unsafe", "partial") +KCCTypeDeclarationStart("public", "internal", @TypeDeclarationKW, @KCCClassModifiers) +KCCMemberVisibilityModifiers("protected", "private", "public", "internal") +SimpleTypeName(@TypeKW, @IdentifierTokens, "void") +GlobalLevel("namespace", "using", @KCCTypeDeclarationStart) +ExpressionStart("base", "delegate", "false", "new", "null", "sizeof", "this", "true", "typeof", "checked", "unchecked", "from") +ExpressionContent("as", "is", "out", "ref", "in") +# interfaces cannot have inner classes etc., the only keyword (expect for type names) that may appear in them is "event" +InterfaceLevel("event") +TypeLevel(@KCCTypeDeclarationStart, @KCCMemberVisibilityModifiers, "const", "event", "explicit", "extern", "fixed", "implicit", "new", "operator", "override", "readonly", "virtual", "volatile") +StatementStart(@ExpressionStart, @ExpressionContent, "break", "case", "catch", "checked", "unchecked", "const", "continue", "default", "do", "else", "finally", "fixed", "for", "foreach", "goto", "if", "lock", "return", "stackalloc", "switch", "throw", "try", "unsafe", "using", "while", "yield") +QueryExpressionClauseStart("from", "let", "where", "join", "orderby", "group", "select") +InPropertyDeclaration(@KCCMemberVisibilityModifiers, "get", "set") +InEventDeclaration("add", "remove") + +# unused: where +# "by", "into", "ascending", "descending", "on", "equals" diff --git a/lib/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs b/lib/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs new file mode 100644 index 000000000..b5cedcab8 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/CSharp/Keywords.cs @@ -0,0 +1,129 @@ +// this file was autogenerated by a tool. +using System; + +namespace ICSharpCode.NRefactory.Parser.CSharp +{ + public static class Keywords + { + static readonly string[] keywordList = { + "abstract", + "as", + "base", + "bool", + "break", + "byte", + "case", + "catch", + "char", + "checked", + "class", + "const", + "continue", + "decimal", + "default", + "delegate", + "do", + "double", + "else", + "enum", + "event", + "explicit", + "extern", + "false", + "finally", + "fixed", + "float", + "for", + "foreach", + "goto", + "if", + "implicit", + "in", + "int", + "interface", + "internal", + "is", + "lock", + "long", + "namespace", + "new", + "null", + "object", + "operator", + "out", + "override", + "params", + "private", + "protected", + "public", + "readonly", + "ref", + "return", + "sbyte", + "sealed", + "short", + "sizeof", + "stackalloc", + "static", + "string", + "struct", + "switch", + "this", + "throw", + "true", + "try", + "typeof", + "uint", + "ulong", + "unchecked", + "unsafe", + "ushort", + "using", + "virtual", + "void", + "volatile", + "while", + "partial", + "where", + "get", + "set", + "add", + "remove", + "yield", + "select", + "group", + "by", + "into", + "from", + "ascending", + "descending", + "orderby", + "let", + "join", + "on", + "equals" + }; + + static LookupTable keywords = new LookupTable(true); + + static Keywords() + { + for (int i = 0; i < keywordList.Length; ++i) { + keywords[keywordList[i]] = i + Tokens.Abstract; + } + } + + public static int GetToken(string keyword) + { + return keywords[keyword]; + } + + public static bool IsNonIdentifierKeyword(string word) + { + int token = GetToken(word); + if (token < 0) + return false; + return !Tokens.IdentifierTokens[token]; + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs b/lib/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs new file mode 100644 index 000000000..434c14288 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs @@ -0,0 +1,978 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Globalization; +using System.IO; +using System.Text; + +namespace ICSharpCode.NRefactory.Parser.CSharp +{ + internal sealed class Lexer : AbstractLexer + { + public Lexer(TextReader reader) : base(reader) + { + } + + void ReadPreProcessingDirective() + { + Location start = new Location(Col - 1, Line); + + // skip spaces between # and the directive + while (ReaderPeek() == ' ') + ReaderRead(); + + bool canBeKeyword; + string directive = ReadIdent('#', out canBeKeyword); + string argument = ReadToEndOfLine(); + this.specialTracker.AddPreprocessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y)); + } + + protected override Token Next() + { + int nextChar; + char ch; + bool hadLineEnd = false; + if (Line == 1 && Col == 1) hadLineEnd = true; // beginning of document + + while ((nextChar = ReaderRead()) != -1) { + Token token; + + switch (nextChar) { + case ' ': + case '\t': + continue; + case '\r': + case '\n': + if (hadLineEnd) { + // second line end before getting to a token + // -> here was a blank line + specialTracker.AddEndOfLine(new Location(Col, Line)); + } + HandleLineEnd((char)nextChar); + hadLineEnd = true; + continue; + case '/': + int peek = ReaderPeek(); + if (peek == '/' || peek == '*') { + ReadComment(); + continue; + } else { + token = ReadOperator('/'); + } + break; + case '#': + ReadPreProcessingDirective(); + continue; + case '"': + token = ReadString(); + break; + case '\'': + token = ReadChar(); + break; + case '@': + int next = ReaderRead(); + if (next == -1) { + errors.Error(Line, Col, String.Format("EOF after @")); + continue; + } else { + int x = Col - 1; + int y = Line; + ch = (char)next; + if (ch == '"') { + token = ReadVerbatimString(); + } else if (Char.IsLetterOrDigit(ch) || ch == '_') { + bool canBeKeyword; + token = new Token(Tokens.Identifier, x - 1, y, ReadIdent(ch, out canBeKeyword)); + } else { + errors.Error(y, x, String.Format("Unexpected char in Lexer.Next() : {0}", ch)); + continue; + } + } + break; + default: + ch = (char)nextChar; + if (Char.IsLetter(ch) || ch == '_' || ch == '\\') { + int x = Col - 1; // Col was incremented above, but we want the start of the identifier + int y = Line; + bool canBeKeyword; + string s = ReadIdent(ch, out canBeKeyword); + if (canBeKeyword) { + int keyWordToken = Keywords.GetToken(s); + if (keyWordToken >= 0) { + return new Token(keyWordToken, x, y, s); + } + } + return new Token(Tokens.Identifier, x, y, s); + } else if (Char.IsDigit(ch)) { + token = ReadDigit(ch, Col - 1); + } else { + token = ReadOperator(ch); + } + break; + } + + // try error recovery (token = null -> continue with next char) + if (token != null) { + return token; + } + } + + return new Token(Tokens.EOF, Col, Line, String.Empty); + } + + // The C# compiler has a fixed size length therefore we'll use a fixed size char array for identifiers + // it's also faster than using a string builder. + const int MAX_IDENTIFIER_LENGTH = 512; + char[] identBuffer = new char[MAX_IDENTIFIER_LENGTH]; + + string ReadIdent(char ch, out bool canBeKeyword) + { + int peek; + int curPos = 0; + canBeKeyword = true; + while (true) { + if (ch == '\\') { + peek = ReaderPeek(); + if (peek != 'u' && peek != 'U') { + errors.Error(Line, Col, "Identifiers can only contain unicode escape sequences"); + } + canBeKeyword = false; + string surrogatePair; + ReadEscapeSequence(out ch, out surrogatePair); + if (surrogatePair != null) { + if (!char.IsLetterOrDigit(surrogatePair, 0)) { + errors.Error(Line, Col, "Unicode escape sequences in identifiers cannot be used to represent characters that are invalid in identifiers"); + } + for (int i = 0; i < surrogatePair.Length - 1; i++) { + if (curPos < MAX_IDENTIFIER_LENGTH) { + identBuffer[curPos++] = surrogatePair[i]; + } + } + ch = surrogatePair[surrogatePair.Length - 1]; + } else { + if (!IsIdentifierPart(ch)) { + errors.Error(Line, Col, "Unicode escape sequences in identifiers cannot be used to represent characters that are invalid in identifiers"); + } + } + } + + if (curPos < MAX_IDENTIFIER_LENGTH) { + identBuffer[curPos++] = ch; + } else { + errors.Error(Line, Col, String.Format("Identifier too long")); + while (IsIdentifierPart(ReaderPeek())) { + ReaderRead(); + } + break; + } + peek = ReaderPeek(); + if (IsIdentifierPart(peek) || peek == '\\') { + ch = (char)ReaderRead(); + } else { + break; + } + } + return new String(identBuffer, 0, curPos); + } + + Token ReadDigit(char ch, int x) + { + unchecked { // prevent exception when ReaderPeek() = -1 is cast to char + int y = Line; + sb.Length = 0; + sb.Append(ch); + string prefix = null; + string suffix = null; + + bool ishex = false; + bool isunsigned = false; + bool islong = false; + bool isfloat = false; + bool isdouble = false; + bool isdecimal = false; + + char peek = (char)ReaderPeek(); + + if (ch == '.') { + isdouble = true; + + while (Char.IsDigit((char)ReaderPeek())) { // read decimal digits beyond the dot + sb.Append((char)ReaderRead()); + } + peek = (char)ReaderPeek(); + } else if (ch == '0' && (peek == 'x' || peek == 'X')) { + ReaderRead(); // skip 'x' + sb.Length = 0; // Remove '0' from 0x prefix from the stringvalue + while (IsHex((char)ReaderPeek())) { + sb.Append((char)ReaderRead()); + } + if (sb.Length == 0) { + sb.Append('0'); // dummy value to prevent exception + errors.Error(y, x, "Invalid hexadecimal integer literal"); + } + ishex = true; + prefix = "0x"; + peek = (char)ReaderPeek(); + } else { + while (Char.IsDigit((char)ReaderPeek())) { + sb.Append((char)ReaderRead()); + } + peek = (char)ReaderPeek(); + } + + Token nextToken = null; // if we accidently read a 'dot' + if (peek == '.') { // read floating point number + ReaderRead(); + peek = (char)ReaderPeek(); + if (!Char.IsDigit(peek)) { + nextToken = new Token(Tokens.Dot, Col - 1, Line); + peek = '.'; + } else { + isdouble = true; // double is default + if (ishex) { + errors.Error(y, x, String.Format("No hexadecimal floating point values allowed")); + } + sb.Append('.'); + + while (Char.IsDigit((char)ReaderPeek())) { // read decimal digits beyond the dot + sb.Append((char)ReaderRead()); + } + peek = (char)ReaderPeek(); + } + } + + if (peek == 'e' || peek == 'E') { // read exponent + isdouble = true; + sb.Append((char)ReaderRead()); + peek = (char)ReaderPeek(); + if (peek == '-' || peek == '+') { + sb.Append((char)ReaderRead()); + } + while (Char.IsDigit((char)ReaderPeek())) { // read exponent value + sb.Append((char)ReaderRead()); + } + isunsigned = true; + peek = (char)ReaderPeek(); + } + + if (peek == 'f' || peek == 'F') { // float value + ReaderRead(); + suffix = "f"; + isfloat = true; + } else if (peek == 'd' || peek == 'D') { // double type suffix (obsolete, double is default) + ReaderRead(); + suffix = "d"; + isdouble = true; + } else if (peek == 'm' || peek == 'M') { // decimal value + ReaderRead(); + suffix = "m"; + isdecimal = true; + } else if (!isdouble) { + if (peek == 'u' || peek == 'U') { + ReaderRead(); + suffix = "u"; + isunsigned = true; + peek = (char)ReaderPeek(); + } + + if (peek == 'l' || peek == 'L') { + ReaderRead(); + peek = (char)ReaderPeek(); + islong = true; + if (!isunsigned && (peek == 'u' || peek == 'U')) { + ReaderRead(); + suffix = "Lu"; + isunsigned = true; + } else { + suffix = isunsigned ? "uL" : "L"; + } + } + } + + string digit = sb.ToString(); + string stringValue = prefix + digit + suffix; + + if (isfloat) { + float num; + if (float.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { + return new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse float {0}", digit)); + return new Token(Tokens.Literal, x, y, stringValue, 0f); + } + } + if (isdecimal) { + decimal num; + if (decimal.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { + return new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse decimal {0}", digit)); + return new Token(Tokens.Literal, x, y, stringValue, 0m); + } + } + if (isdouble) { + double num; + if (double.TryParse(digit, NumberStyles.Any, CultureInfo.InvariantCulture, out num)) { + return new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse double {0}", digit)); + return new Token(Tokens.Literal, x, y, stringValue, 0d); + } + } + + // Try to determine a parsable value using ranges. + ulong result; + if (ishex) { + if (!ulong.TryParse(digit, NumberStyles.HexNumber, null, out result)) { + errors.Error(y, x, String.Format("Can't parse hexadecimal constant {0}", digit)); + return new Token(Tokens.Literal, x, y, stringValue.ToString(), 0); + } + } else { + if (!ulong.TryParse(digit, NumberStyles.Integer, null, out result)) { + errors.Error(y, x, String.Format("Can't parse integral constant {0}", digit)); + return new Token(Tokens.Literal, x, y, stringValue.ToString(), 0); + } + } + + if (result > long.MaxValue) { + islong = true; + isunsigned = true; + } else if (result > uint.MaxValue) { + islong = true; + } else if (islong == false && result > int.MaxValue) { + isunsigned = true; + } + + Token token; + + if (islong) { + if (isunsigned) { + ulong num; + if (ulong.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { + token = new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse unsigned long {0}", digit)); + token = new Token(Tokens.Literal, x, y, stringValue, 0UL); + } + } else { + long num; + if (long.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { + token = new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse long {0}", digit)); + token = new Token(Tokens.Literal, x, y, stringValue, 0L); + } + } + } else { + if (isunsigned) { + uint num; + if (uint.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { + token = new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse unsigned int {0}", digit)); + token = new Token(Tokens.Literal, x, y, stringValue, (uint)0); + } + } else { + int num; + if (int.TryParse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number, CultureInfo.InvariantCulture, out num)) { + token = new Token(Tokens.Literal, x, y, stringValue, num); + } else { + errors.Error(y, x, String.Format("Can't parse int {0}", digit)); + token = new Token(Tokens.Literal, x, y, stringValue, 0); + } + } + } + token.next = nextToken; + return token; + } + } + + Token ReadString() + { + int x = Col - 1; + int y = Line; + + sb.Length = 0; + originalValue.Length = 0; + originalValue.Append('"'); + bool doneNormally = false; + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + + if (ch == '"') { + doneNormally = true; + originalValue.Append('"'); + break; + } + + if (ch == '\\') { + originalValue.Append('\\'); + string surrogatePair; + originalValue.Append(ReadEscapeSequence(out ch, out surrogatePair)); + if (surrogatePair != null) { + sb.Append(surrogatePair); + } else { + sb.Append(ch); + } + } else if (ch == '\n') { + HandleLineEnd(ch); // ensure line numbers are still correct after the error + errors.Error(y, x, String.Format("No new line is allowed inside a string literal")); + break; + } else { + originalValue.Append(ch); + sb.Append(ch); + } + } + + if (!doneNormally) { + errors.Error(y, x, String.Format("End of file reached inside string literal")); + } + + return new Token(Tokens.Literal, x, y, originalValue.ToString(), sb.ToString()); + } + + Token ReadVerbatimString() + { + sb.Length = 0; + originalValue.Length = 0; + originalValue.Append("@\""); + int x = Col - 2; // @ and " already read + int y = Line; + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + + if (ch == '"') { + if (ReaderPeek() != '"') { + originalValue.Append('"'); + break; + } + originalValue.Append("\"\""); + sb.Append('"'); + ReaderRead(); + } else if (HandleLineEnd(ch)) { + sb.Append("\r\n"); + originalValue.Append("\r\n"); + } else { + sb.Append(ch); + originalValue.Append(ch); + } + } + + if (nextChar == -1) { + errors.Error(y, x, String.Format("End of file reached inside verbatim string literal")); + } + + return new Token(Tokens.Literal, x, y, originalValue.ToString(), sb.ToString()); + } + + char[] escapeSequenceBuffer = new char[12]; + + /// + /// reads an escape sequence + /// + /// The character represented by the escape sequence, + /// or '\0' if there was an error or the escape sequence represents a character that + /// can be represented only be a suggorate pair + /// Null, except when the character represented + /// by the escape sequence can only be represented by a surrogate pair (then the string + /// contains the surrogate pair) + /// The escape sequence + string ReadEscapeSequence(out char ch, out string surrogatePair) + { + surrogatePair = null; + + int nextChar = ReaderRead(); + if (nextChar == -1) { + errors.Error(Line, Col, String.Format("End of file reached inside escape sequence")); + ch = '\0'; + return String.Empty; + } + int number; + char c = (char)nextChar; + int curPos = 1; + escapeSequenceBuffer[0] = c; + switch (c) { + case '\'': + ch = '\''; + break; + case '\"': + ch = '\"'; + break; + case '\\': + ch = '\\'; + break; + case '0': + ch = '\0'; + break; + case 'a': + ch = '\a'; + break; + case 'b': + ch = '\b'; + break; + case 'f': + ch = '\f'; + break; + case 'n': + ch = '\n'; + break; + case 'r': + ch = '\r'; + break; + case 't': + ch = '\t'; + break; + case 'v': + ch = '\v'; + break; + case 'u': + case 'x': + // 16 bit unicode character + c = (char)ReaderRead(); + number = GetHexNumber(c); + escapeSequenceBuffer[curPos++] = c; + + if (number < 0) { + errors.Error(Line, Col - 1, String.Format("Invalid char in literal : {0}", c)); + } + for (int i = 0; i < 3; ++i) { + if (IsHex((char)ReaderPeek())) { + c = (char)ReaderRead(); + int idx = GetHexNumber(c); + escapeSequenceBuffer[curPos++] = c; + number = 16 * number + idx; + } else { + break; + } + } + ch = (char)number; + break; + case 'U': + // 32 bit unicode character + number = 0; + for (int i = 0; i < 8; ++i) { + if (IsHex((char)ReaderPeek())) { + c = (char)ReaderRead(); + int idx = GetHexNumber(c); + escapeSequenceBuffer[curPos++] = c; + number = 16 * number + idx; + } else { + errors.Error(Line, Col - 1, String.Format("Invalid char in literal : {0}", (char)ReaderPeek())); + break; + } + } + if (number > 0xffff) { + ch = '\0'; + surrogatePair = char.ConvertFromUtf32(number); + } else { + ch = (char)number; + } + break; + default: + errors.Error(Line, Col, String.Format("Unexpected escape sequence : {0}", c)); + ch = '\0'; + break; + } + return new String(escapeSequenceBuffer, 0, curPos); + } + + Token ReadChar() + { + int x = Col - 1; + int y = Line; + int nextChar = ReaderRead(); + if (nextChar == -1) { + errors.Error(y, x, String.Format("End of file reached inside character literal")); + return null; + } + char ch = (char)nextChar; + char chValue = ch; + string escapeSequence = String.Empty; + if (ch == '\\') { + string surrogatePair; + escapeSequence = ReadEscapeSequence(out chValue, out surrogatePair); + if (surrogatePair != null) { + errors.Error(y, x, String.Format("The unicode character must be represented by a surrogate pair and does not fit into a System.Char")); + } + } + + unchecked { + if ((char)ReaderRead() != '\'') { + errors.Error(y, x, String.Format("Char not terminated")); + } + } + return new Token(Tokens.Literal, x, y, "'" + ch + escapeSequence + "'", chValue); + } + + Token ReadOperator(char ch) + { + int x = Col - 1; + int y = Line; + switch (ch) { + case '+': + switch (ReaderPeek()) { + case '+': + ReaderRead(); + return new Token(Tokens.Increment, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.PlusAssign, x, y); + } + return new Token(Tokens.Plus, x, y); + case '-': + switch (ReaderPeek()) { + case '-': + ReaderRead(); + return new Token(Tokens.Decrement, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.MinusAssign, x, y); + case '>': + ReaderRead(); + return new Token(Tokens.Pointer, x, y); + } + return new Token(Tokens.Minus, x, y); + case '*': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.TimesAssign, x, y); + default: + break; + } + return new Token(Tokens.Times, x, y); + case '/': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.DivAssign, x, y); + } + return new Token(Tokens.Div, x, y); + case '%': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.ModAssign, x, y); + } + return new Token(Tokens.Mod, x, y); + case '&': + switch (ReaderPeek()) { + case '&': + ReaderRead(); + return new Token(Tokens.LogicalAnd, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.BitwiseAndAssign, x, y); + } + return new Token(Tokens.BitwiseAnd, x, y); + case '|': + switch (ReaderPeek()) { + case '|': + ReaderRead(); + return new Token(Tokens.LogicalOr, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.BitwiseOrAssign, x, y); + } + return new Token(Tokens.BitwiseOr, x, y); + case '^': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.XorAssign, x, y); + default: + break; + } + return new Token(Tokens.Xor, x, y); + case '!': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.NotEqual, x, y); + } + return new Token(Tokens.Not, x, y); + case '~': + return new Token(Tokens.BitwiseComplement, x, y); + case '=': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.Equal, x, y); + case '>': + ReaderRead(); + return new Token(Tokens.LambdaArrow, x, y); + } + return new Token(Tokens.Assign, x, y); + case '<': + switch (ReaderPeek()) { + case '<': + ReaderRead(); + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.ShiftLeftAssign, x, y); + default: + break; + } + return new Token(Tokens.ShiftLeft, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.LessEqual, x, y); + } + return new Token(Tokens.LessThan, x, y); + case '>': + switch (ReaderPeek()) { + // Removed because of generics: +// case '>': +// ReaderRead(); +// if (ReaderPeek() != -1) { +// switch ((char)ReaderPeek()) { +// case '=': +// ReaderRead(); +// return new Token(Tokens.ShiftRightAssign, x, y); +// default: +// break; +// } +// } +// return new Token(Tokens.ShiftRight, x, y); + case '=': + ReaderRead(); + return new Token(Tokens.GreaterEqual, x, y); + } + return new Token(Tokens.GreaterThan, x, y); + case '?': + if (ReaderPeek() == '?') { + ReaderRead(); + return new Token(Tokens.DoubleQuestion, x, y); + } + return new Token(Tokens.Question, x, y); + case ';': + return new Token(Tokens.Semicolon, x, y); + case ':': + if (ReaderPeek() == ':') { + ReaderRead(); + return new Token(Tokens.DoubleColon, x, y); + } + return new Token(Tokens.Colon, x, y); + case ',': + return new Token(Tokens.Comma, x, y); + case '.': + // Prevent OverflowException when ReaderPeek returns -1 + int tmp = ReaderPeek(); + if (tmp > 0 && Char.IsDigit((char)tmp)) { + return ReadDigit('.', Col - 1); + } + return new Token(Tokens.Dot, x, y); + case ')': + return new Token(Tokens.CloseParenthesis, x, y); + case '(': + return new Token(Tokens.OpenParenthesis, x, y); + case ']': + return new Token(Tokens.CloseSquareBracket, x, y); + case '[': + return new Token(Tokens.OpenSquareBracket, x, y); + case '}': + return new Token(Tokens.CloseCurlyBrace, x, y); + case '{': + return new Token(Tokens.OpenCurlyBrace, x, y); + default: + return null; + } + } + + void ReadComment() + { + switch (ReaderRead()) { + case '*': + ReadMultiLineComment(); + break; + case '/': + if (ReaderPeek() == '/') { + ReaderRead(); + ReadSingleLineComment(CommentType.Documentation); + } else { + ReadSingleLineComment(CommentType.SingleLine); + } + break; + default: + errors.Error(Line, Col, String.Format("Error while reading comment")); + break; + } + } + + string ReadCommentToEOL() + { + if (specialCommentHash == null) { + return ReadToEndOfLine(); + } + sb.Length = 0; + StringBuilder curWord = new StringBuilder(); + + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + + if (HandleLineEnd(ch)) { + break; + } + + sb.Append(ch); + if (IsIdentifierPart(nextChar)) { + curWord.Append(ch); + } else { + string tag = curWord.ToString(); + curWord.Length = 0; + if (specialCommentHash.ContainsKey(tag)) { + Location p = new Location(Col, Line); + string comment = ch + ReadToEndOfLine(); + this.TagComments.Add(new TagComment(tag, comment, p, new Location(Col, Line))); + sb.Append(comment); + break; + } + } + } + return sb.ToString(); + } + + void ReadSingleLineComment(CommentType commentType) + { + if (this.SkipAllComments) { + SkipToEndOfLine(); + } else { + specialTracker.StartComment(commentType, new Location(Col, Line)); + specialTracker.AddString(ReadCommentToEOL()); + specialTracker.FinishComment(new Location(Col, Line)); + } + } + + void ReadMultiLineComment() + { + int nextChar; + if (this.SkipAllComments) { + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + if (ch == '*' && ReaderPeek() == '/') { + ReaderRead(); + return; + } else { + HandleLineEnd(ch); + } + } + } else { + specialTracker.StartComment(CommentType.Block, new Location(Col, Line)); + + // sc* = special comment handling (TO DO markers) + string scTag = null; // is set to non-null value when we are inside a comment marker + StringBuilder scCurWord = new StringBuilder(); // current word, (scTag == null) or comment (when scTag != null) + Location scStartLocation = Location.Empty; + + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + + if (HandleLineEnd(ch)) { + if (scTag != null) { + this.TagComments.Add(new TagComment(scTag, scCurWord.ToString(), scStartLocation, new Location(Col, Line))); + scTag = null; + } + scCurWord.Length = 0; + specialTracker.AddString(Environment.NewLine); + continue; + } + + // End of multiline comment reached ? + if (ch == '*' && ReaderPeek() == '/') { + if (scTag != null) { + this.TagComments.Add(new TagComment(scTag, scCurWord.ToString(), scStartLocation, new Location(Col, Line))); + } + ReaderRead(); + specialTracker.FinishComment(new Location(Col, Line)); + return; + } + specialTracker.AddChar(ch); + if (scTag != null || IsIdentifierPart(ch)) { + scCurWord.Append(ch); + } else { + if (specialCommentHash != null && specialCommentHash.ContainsKey(scCurWord.ToString())) { + scTag = scCurWord.ToString(); + scStartLocation = new Location(Col, Line); + } + scCurWord.Length = 0; + } + } + specialTracker.FinishComment(new Location(Col, Line)); + } + // Reached EOF before end of multiline comment. + errors.Error(Line, Col, String.Format("Reached EOF before the end of a multiline comment")); + } + + /// + /// Skips to the end of the current code block. + /// For this, the lexer must have read the next token AFTER the token opening the + /// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead). + /// After the call, Lexer.LookAhead will be the block-closing token. + /// + public override void SkipCurrentBlock(int targetToken) + { + int braceCount = 0; + while (curToken != null) { + if (curToken.kind == Tokens.OpenCurlyBrace) { + ++braceCount; + } else if (curToken.kind == Tokens.CloseCurlyBrace) { + if (--braceCount < 0) + return; + } + lastToken = curToken; + curToken = curToken.next; + } + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + switch (nextChar) { + case '{': + braceCount++; + break; + case '}': + if (--braceCount < 0) { + curToken = new Token(Tokens.CloseCurlyBrace, Col - 1, Line); + return; + } + break; + case '/': + int peek = ReaderPeek(); + if (peek == '/' || peek == '*') { + ReadComment(); + } + break; + case '#': + ReadPreProcessingDirective(); + break; + case '"': + ReadString(); + break; + case '\'': + ReadChar(); + break; + case '\r': + case '\n': + HandleLineEnd((char)nextChar); + break; + case '@': + int next = ReaderRead(); + if (next == -1) { + errors.Error(Line, Col, String.Format("EOF after @")); + } else if (next == '"') { + ReadVerbatimString(); + } + break; + } + } + curToken = new Token(Tokens.EOF, Col, Line); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs b/lib/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs new file mode 100644 index 000000000..05142245e --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/CSharp/Tokens.cs @@ -0,0 +1,353 @@ +// this file was autogenerated by a tool. +using System; +using System.Collections; + +namespace ICSharpCode.NRefactory.Parser.CSharp +{ + public static class Tokens + { + // ----- terminal classes ----- + public const int EOF = 0; + public const int Identifier = 1; + public const int Literal = 2; + + // ----- special character ----- + public const int Assign = 3; + public const int Plus = 4; + public const int Minus = 5; + public const int Times = 6; + public const int Div = 7; + public const int Mod = 8; + public const int Colon = 9; + public const int DoubleColon = 10; + public const int Semicolon = 11; + public const int Question = 12; + public const int DoubleQuestion = 13; + public const int Comma = 14; + public const int Dot = 15; + public const int OpenCurlyBrace = 16; + public const int CloseCurlyBrace = 17; + public const int OpenSquareBracket = 18; + public const int CloseSquareBracket = 19; + public const int OpenParenthesis = 20; + public const int CloseParenthesis = 21; + public const int GreaterThan = 22; + public const int LessThan = 23; + public const int Not = 24; + public const int LogicalAnd = 25; + public const int LogicalOr = 26; + public const int BitwiseComplement = 27; + public const int BitwiseAnd = 28; + public const int BitwiseOr = 29; + public const int Xor = 30; + public const int Increment = 31; + public const int Decrement = 32; + public const int Equal = 33; + public const int NotEqual = 34; + public const int GreaterEqual = 35; + public const int LessEqual = 36; + public const int ShiftLeft = 37; + public const int PlusAssign = 38; + public const int MinusAssign = 39; + public const int TimesAssign = 40; + public const int DivAssign = 41; + public const int ModAssign = 42; + public const int BitwiseAndAssign = 43; + public const int BitwiseOrAssign = 44; + public const int XorAssign = 45; + public const int ShiftLeftAssign = 46; + public const int Pointer = 47; + public const int LambdaArrow = 48; + + // ----- keywords ----- + public const int Abstract = 49; + public const int As = 50; + public const int Base = 51; + public const int Bool = 52; + public const int Break = 53; + public const int Byte = 54; + public const int Case = 55; + public const int Catch = 56; + public const int Char = 57; + public const int Checked = 58; + public const int Class = 59; + public const int Const = 60; + public const int Continue = 61; + public const int Decimal = 62; + public const int Default = 63; + public const int Delegate = 64; + public const int Do = 65; + public const int Double = 66; + public const int Else = 67; + public const int Enum = 68; + public const int Event = 69; + public const int Explicit = 70; + public const int Extern = 71; + public const int False = 72; + public const int Finally = 73; + public const int Fixed = 74; + public const int Float = 75; + public const int For = 76; + public const int Foreach = 77; + public const int Goto = 78; + public const int If = 79; + public const int Implicit = 80; + public const int In = 81; + public const int Int = 82; + public const int Interface = 83; + public const int Internal = 84; + public const int Is = 85; + public const int Lock = 86; + public const int Long = 87; + public const int Namespace = 88; + public const int New = 89; + public const int Null = 90; + public const int Object = 91; + public const int Operator = 92; + public const int Out = 93; + public const int Override = 94; + public const int Params = 95; + public const int Private = 96; + public const int Protected = 97; + public const int Public = 98; + public const int Readonly = 99; + public const int Ref = 100; + public const int Return = 101; + public const int Sbyte = 102; + public const int Sealed = 103; + public const int Short = 104; + public const int Sizeof = 105; + public const int Stackalloc = 106; + public const int Static = 107; + public const int String = 108; + public const int Struct = 109; + public const int Switch = 110; + public const int This = 111; + public const int Throw = 112; + public const int True = 113; + public const int Try = 114; + public const int Typeof = 115; + public const int Uint = 116; + public const int Ulong = 117; + public const int Unchecked = 118; + public const int Unsafe = 119; + public const int Ushort = 120; + public const int Using = 121; + public const int Virtual = 122; + public const int Void = 123; + public const int Volatile = 124; + public const int While = 125; + public const int Partial = 126; + public const int Where = 127; + public const int Get = 128; + public const int Set = 129; + public const int Add = 130; + public const int Remove = 131; + public const int Yield = 132; + public const int Select = 133; + public const int Group = 134; + public const int By = 135; + public const int Into = 136; + public const int From = 137; + public const int Ascending = 138; + public const int Descending = 139; + public const int Orderby = 140; + public const int Let = 141; + public const int Join = 142; + public const int On = 143; + new public const int Equals = 144; + + public const int MaxToken = 145; + static BitArray NewSet(params int[] values) + { + BitArray bitArray = new BitArray(MaxToken); + foreach (int val in values) { + bitArray[val] = true; + } + return bitArray; + } + public static BitArray IdentifierTokens = NewSet(Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby, Let, Join, On, Equals); + public static BitArray OverloadableUnaryOp = NewSet(Minus, Not, BitwiseComplement, Increment, Decrement, True, False); + public static BitArray OverloadableBinaryOp = NewSet(Plus, Minus, Times, Div, Mod, BitwiseAnd, BitwiseOr, Xor, ShiftLeft, Equal, NotEqual, GreaterThan, LessThan, GreaterEqual, LessEqual); + public static BitArray TypeKW = NewSet(Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal); + public static BitArray UnaryHead = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd); + public static BitArray AssnStartOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times); + public static BitArray CastFollower = NewSet(Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal, Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby, Let, Join, On, Equals, Void, Literal, OpenParenthesis, BitwiseComplement, Not, Base, Delegate, False, New, Null, Sizeof, This, True, Typeof, Checked, Unchecked, From); + public static BitArray AssgnOps = NewSet(Assign, PlusAssign, MinusAssign, TimesAssign, DivAssign, ModAssign, BitwiseAndAssign, BitwiseOrAssign, ShiftLeftAssign); + public static BitArray UnaryOp = NewSet(Plus, Minus, Not, BitwiseComplement, Times, Increment, Decrement, BitwiseAnd); + public static BitArray TypeDeclarationKW = NewSet(Class, Interface, Struct, Enum, Delegate); + public static BitArray GenericFollower = NewSet(OpenParenthesis, CloseParenthesis, CloseSquareBracket, CloseCurlyBrace, Colon, Semicolon, Comma, Dot, Question, Equal, NotEqual); + public static BitArray ValidInsideTypeName = NewSet(Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby, Let, Join, On, Equals, Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal, LessThan, GreaterThan, Dot, Question, OpenSquareBracket, Comma, CloseSquareBracket, Times, DoubleColon); + public static BitArray KCCClassModifiers = NewSet(Abstract, Sealed, Static, Unsafe, Partial); + public static BitArray KCCTypeDeclarationStart = NewSet(Public, Internal, Class, Interface, Struct, Enum, Delegate, Abstract, Sealed, Static, Unsafe, Partial); + public static BitArray KCCMemberVisibilityModifiers = NewSet(Protected, Private, Public, Internal); + public static BitArray SimpleTypeName = NewSet(Char, Bool, Object, String, Sbyte, Byte, Short, Ushort, Int, Uint, Long, Ulong, Float, Double, Decimal, Identifier, Partial, Where, Get, Set, Add, Remove, Yield, Select, Group, By, Into, From, Ascending, Descending, Orderby, Let, Join, On, Equals, Void); + public static BitArray GlobalLevel = NewSet(Namespace, Using, Public, Internal, Class, Interface, Struct, Enum, Delegate, Abstract, Sealed, Static, Unsafe, Partial); + public static BitArray ExpressionStart = NewSet(Base, Delegate, False, New, Null, Sizeof, This, True, Typeof, Checked, Unchecked, From); + public static BitArray ExpressionContent = NewSet(As, Is, Out, Ref, In); + public static BitArray InterfaceLevel = NewSet(Event); + public static BitArray TypeLevel = NewSet(Public, Internal, Class, Interface, Struct, Enum, Delegate, Abstract, Sealed, Static, Unsafe, Partial, Protected, Private, Public, Internal, Const, Event, Explicit, Extern, Fixed, Implicit, New, Operator, Override, Readonly, Virtual, Volatile); + public static BitArray StatementStart = NewSet(Base, Delegate, False, New, Null, Sizeof, This, True, Typeof, Checked, Unchecked, From, As, Is, Out, Ref, In, Break, Case, Catch, Checked, Unchecked, Const, Continue, Default, Do, Else, Finally, Fixed, For, Foreach, Goto, If, Lock, Return, Stackalloc, Switch, Throw, Try, Unsafe, Using, While, Yield); + public static BitArray QueryExpressionClauseStart = NewSet(From, Let, Where, Join, Orderby, Group, Select); + public static BitArray InPropertyDeclaration = NewSet(Protected, Private, Public, Internal, Get, Set); + public static BitArray InEventDeclaration = NewSet(Add, Remove); + + static string[] tokenList = new string[] { + // ----- terminal classes ----- + "", + "", + "", + // ----- special character ----- + "=", + "+", + "-", + "*", + "/", + "%", + ":", + "::", + ";", + "?", + "??", + ",", + ".", + "{", + "}", + "[", + "]", + "(", + ")", + ">", + "<", + "!", + "&&", + "||", + "~", + "&", + "|", + "^", + "++", + "--", + "==", + "!=", + ">=", + "<=", + "<<", + "+=", + "-=", + "*=", + "/=", + "%=", + "&=", + "|=", + "^=", + "<<=", + "->", + "=>", + // ----- keywords ----- + "abstract", + "as", + "base", + "bool", + "break", + "byte", + "case", + "catch", + "char", + "checked", + "class", + "const", + "continue", + "decimal", + "default", + "delegate", + "do", + "double", + "else", + "enum", + "event", + "explicit", + "extern", + "false", + "finally", + "fixed", + "float", + "for", + "foreach", + "goto", + "if", + "implicit", + "in", + "int", + "interface", + "internal", + "is", + "lock", + "long", + "namespace", + "new", + "null", + "object", + "operator", + "out", + "override", + "params", + "private", + "protected", + "public", + "readonly", + "ref", + "return", + "sbyte", + "sealed", + "short", + "sizeof", + "stackalloc", + "static", + "string", + "struct", + "switch", + "this", + "throw", + "true", + "try", + "typeof", + "uint", + "ulong", + "unchecked", + "unsafe", + "ushort", + "using", + "virtual", + "void", + "volatile", + "while", + "partial", + "where", + "get", + "set", + "add", + "remove", + "yield", + "select", + "group", + "by", + "into", + "from", + "ascending", + "descending", + "orderby", + "let", + "join", + "on", + "equals", + }; + public static string GetTokenString(int token) + { + if (token >= 0 && token < tokenList.Length) { + return tokenList[token]; + } + throw new System.NotSupportedException("Unknown token:" + token); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/ILexer.cs b/lib/NRefactory/Project/Src/Lexer/ILexer.cs new file mode 100644 index 000000000..9cc36a65c --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/ILexer.cs @@ -0,0 +1,86 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory.Parser +{ + /// + /// Lexer interface + /// + public interface ILexer : IDisposable + { + Errors Errors { + get; + } + + /// + /// The current Token. + /// + Token Token { + get; + } + + /// + /// The next Token (The after call) . + /// + Token LookAhead { + get; + } + + /// + /// Special comment tags are tags like TODO, HACK or UNDONE which are read by the lexer and stored in . + /// + string[] SpecialCommentTags { + get; + set; + } + + /// + /// Gets/Sets if the lexer should skip adding comments to the special tracker. Set this + /// property to true to improve lexing performance. + /// + bool SkipAllComments { + get; + set; + } + + /// + /// Returns the comments that had been read and containing tag key words. + /// + List TagComments { + get; + } + + SpecialTracker SpecialTracker { + get; + } + + void StartPeek(); + + /// + /// Gives back the next token. A second call to Peek() gives the next token after the last call for Peek() and so on. + /// + /// An object. + Token Peek(); + + /// + /// Reads the next token and gives it back. + /// + /// An object. + Token NextToken(); + + /// + /// Skips to the end of the current code block. + /// For this, the lexer must have read the next token AFTER the token opening the + /// block (so that Lexer.Token is the block-opening token, not Lexer.LookAhead). + /// After the call, Lexer.LookAhead will be the block-closing token. + /// + void SkipCurrentBlock(int targetToken); + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/LookupTable.cs b/lib/NRefactory/Project/Src/Lexer/LookupTable.cs new file mode 100644 index 000000000..674cfb24f --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/LookupTable.cs @@ -0,0 +1,120 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Globalization; + +namespace ICSharpCode.NRefactory.Parser +{ + /// + /// This class implements a keyword map. It implements a digital search trees (tries) to find + /// a word. + /// + internal class LookupTable + { + Node root = new Node(-1, null); + bool casesensitive; + int length; + + /// + /// The number of elements in the table + /// + public int Count { + get { + return length; + } + } + + /// + /// Inserts an int in the tree, under keyword + /// + public int this[string keyword] { + get { + Node next = root; + + if (!casesensitive) { + keyword = keyword.ToUpper(CultureInfo.InvariantCulture); + } + + for (int i = 0; i < keyword.Length; ++i) { + int index = ((int)keyword[i]) % 256; + next = next.leaf[index]; + + if (next == null) { + return -1; + } + + if (keyword == next.word) { + return next.val; + } + } + return -1; + } + set { + Node node = root; + Node next = root; + + if (!casesensitive) { + keyword = keyword.ToUpper(CultureInfo.InvariantCulture); + } + + ++length; + + // insert word into the tree + for (int i = 0; i < keyword.Length; ++i) { + int index = ((int)keyword[i]) % 256; // index of curchar + bool d = keyword[i] == '\\'; + + next = next.leaf[index]; // get node to this index + + if (next == null) { // no node created -> insert word here + node.leaf[index] = new Node(value, keyword); + break; + } + + if (next.word != null && next.word.Length != i) { // node there, take node content and insert them again + string tmpword = next.word; // this word will be inserted 1 level deeper (better, don't need too much + int tmpval = next.val; // string comparisons for finding.) + next.val = -1; + next.word = null; + this[tmpword] = tmpval; + } + + if (i == keyword.Length - 1) { // end of keyword reached, insert node there, if a node was here it was + next.word = keyword; // reinserted, if it has the same length (keyword EQUALS this word) it will be overwritten + next.val = value; + break; + } + + node = next; + } + } + } + + /// + /// Creates a new instance of + /// + public LookupTable(bool casesensitive) + { + this.casesensitive = casesensitive; + } + + class Node + { + public Node(int val, string word) + { + this.word = word; + this.val = val; + } + + public string word; + public int val; + + public Node[] leaf = new Node[256]; + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/BlankLine.cs b/lib/NRefactory/Project/Src/Lexer/Special/BlankLine.cs new file mode 100644 index 000000000..e21240b09 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/BlankLine.cs @@ -0,0 +1,23 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + public class BlankLine : AbstractSpecial + { + public BlankLine(Location point) : base(point) + { + } + + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/Comment.cs b/lib/NRefactory/Project/Src/Lexer/Special/Comment.cs new file mode 100644 index 000000000..faabd2d8b --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/Comment.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + public class Comment : AbstractSpecial + { + CommentType commentType; + string comment; + + public CommentType CommentType { + get { + return commentType; + } + set { + commentType = value; + } + } + + public string CommentText { + get { + return comment; + } + set { + comment = value; + } + } + + public Comment(CommentType commentType, string comment, Location startPosition, Location endPosition) + : base(startPosition, endPosition) + { + this.commentType = commentType; + this.comment = comment; + } + + public override string ToString() + { + return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]", + GetType().Name, CommentType, CommentText, StartPosition, EndPosition); + } + + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/CommentType.cs b/lib/NRefactory/Project/Src/Lexer/Special/CommentType.cs new file mode 100644 index 000000000..1454ffc7b --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/CommentType.cs @@ -0,0 +1,18 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + public enum CommentType + { + Block, + SingleLine, + Documentation + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/ISpecial.cs b/lib/NRefactory/Project/Src/Lexer/Special/ISpecial.cs new file mode 100644 index 000000000..e002566e9 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/ISpecial.cs @@ -0,0 +1,73 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + /// + /// Interface for all specials. + /// + public interface ISpecial + { + Location StartPosition { get; } + Location EndPosition { get; } + + object AcceptVisitor(ISpecialVisitor visitor, object data); + } + + public interface ISpecialVisitor + { + object Visit(ISpecial special, object data); + object Visit(BlankLine special, object data); + object Visit(Comment special, object data); + object Visit(PreprocessingDirective special, object data); + } + + public abstract class AbstractSpecial : ISpecial + { + public abstract object AcceptVisitor(ISpecialVisitor visitor, object data); + + Location startPosition, endPosition; + + protected AbstractSpecial(Location position) + { + this.startPosition = position; + this.endPosition = position; + } + + protected AbstractSpecial(Location startPosition, Location endPosition) + { + this.startPosition = startPosition; + this.endPosition = endPosition; + } + + public Location StartPosition { + get { + return startPosition; + } + set { + startPosition = value; + } + } + + public Location EndPosition { + get { + return endPosition; + } + set { + endPosition = value; + } + } + + public override string ToString() + { + return String.Format("[{0}: Start = {1}, End = {2}]", + GetType().Name, StartPosition, EndPosition); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs b/lib/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs new file mode 100644 index 000000000..c65f537c1 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs @@ -0,0 +1,122 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; + +namespace ICSharpCode.NRefactory +{ + public class PreprocessingDirective : AbstractSpecial + { + public static void VBToCSharp(IList list) + { + for (int i = 0; i < list.Count; ++i) { + if (list[i] is PreprocessingDirective) + list[i] = VBToCSharp((PreprocessingDirective)list[i]); + } + } + + public static PreprocessingDirective VBToCSharp(PreprocessingDirective dir) + { + string cmd = dir.Cmd; + string arg = dir.Arg; + if (cmd.Equals("#End", StringComparison.InvariantCultureIgnoreCase)) { + if (arg.ToLowerInvariant().StartsWith("region")) { + cmd = "#endregion"; + arg = ""; + } else if ("if".Equals(arg, StringComparison.InvariantCultureIgnoreCase)) { + cmd = "#endif"; + arg = ""; + } + } else if (cmd.Equals("#Region", StringComparison.InvariantCultureIgnoreCase)) { + cmd = "#region"; + } else if (cmd.Equals("#If", StringComparison.InvariantCultureIgnoreCase)) { + cmd = "#if"; + if (arg.ToLowerInvariant().EndsWith(" then")) + arg = arg.Substring(0, arg.Length - 5); + } + return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition); + } + + public static void CSharpToVB(List list) + { + for (int i = 0; i < list.Count; ++i) { + if (list[i] is PreprocessingDirective) + list[i] = CSharpToVB((PreprocessingDirective)list[i]); + } + } + + public static PreprocessingDirective CSharpToVB(PreprocessingDirective dir) + { + string cmd = dir.Cmd; + string arg = dir.Arg; + switch (cmd) { + case "#region": + cmd = "#Region"; + if (!arg.StartsWith("\"")) { + arg = "\"" + arg.Trim() + "\""; + } + break; + case "#endregion": + cmd = "#End"; + arg = "Region"; + break; + case "#endif": + cmd = "#End"; + arg = "If"; + break; + case "#if": + arg += " Then"; + break; + } + if (cmd.Length > 1) { + cmd = cmd.Substring(0, 2).ToUpperInvariant() + cmd.Substring(2); + } + return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition); + } + + string cmd; + string arg; + + public string Cmd { + get { + return cmd; + } + set { + cmd = value ?? string.Empty; + } + } + + public string Arg { + get { + return arg; + } + set { + arg = value ?? string.Empty; + } + } + + public override string ToString() + { + return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]", + Cmd, + Arg); + } + + public PreprocessingDirective(string cmd, string arg, Location start, Location end) + : base(start, end) + { + this.Cmd = cmd; + this.Arg = arg; + } + + public override object AcceptVisitor(ISpecialVisitor visitor, object data) + { + return visitor.Visit(this, data); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs b/lib/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs new file mode 100644 index 000000000..b14d3682e --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs @@ -0,0 +1,76 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Text; + +namespace ICSharpCode.NRefactory.Parser +{ + public class SpecialTracker + { + List currentSpecials = new List(); + + CommentType currentCommentType; + StringBuilder sb = new StringBuilder(); + Location startPosition; + + public List CurrentSpecials { + get { + return currentSpecials; + } + } + + public void InformToken(int kind) + { + + } + + /// + /// Gets the specials from the SpecialTracker and resets the lists. + /// + public List RetrieveSpecials() + { + List tmp = currentSpecials; + currentSpecials = new List(); + return tmp; + } + + public void AddEndOfLine(Location point) + { + currentSpecials.Add(new BlankLine(point)); + } + + public void AddPreprocessingDirective(string cmd, string arg, Location start, Location end) + { + currentSpecials.Add(new PreprocessingDirective(cmd, arg, start, end)); + } + + // used for comment tracking + public void StartComment(CommentType commentType, Location startPosition) + { + this.currentCommentType = commentType; + this.startPosition = startPosition; + this.sb.Length = 0; + } + + public void AddChar(char c) + { + sb.Append(c); + } + + public void AddString(string s) + { + sb.Append(s); + } + + public void FinishComment(Location endPosition) + { + currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), startPosition, endPosition)); + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Special/TagComment.cs b/lib/NRefactory/Project/Src/Lexer/Special/TagComment.cs new file mode 100644 index 000000000..54c76f254 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Special/TagComment.cs @@ -0,0 +1,33 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Parser +{ + /// + /// Description of TagComment. + /// + public class TagComment : Comment + { + string tag; + + public string Tag { + get { + return tag; + } + set { + tag = value; + } + } + + public TagComment(string tag, string comment, Location startPosition, Location endPosition) : base(CommentType.SingleLine, comment, startPosition, endPosition) + { + this.tag = tag; + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/Token.cs b/lib/NRefactory/Project/Src/Lexer/Token.cs new file mode 100644 index 000000000..f7b0f5407 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/Token.cs @@ -0,0 +1,64 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory.Parser +{ + public class Token + { + public int kind; + + public int col; + public int line; + + public object literalValue; + public string val; + public Token next; + + public Location EndLocation { + get { + return new Location(val == null ? col + 1 : col + val.Length, line); + } + } + public Location Location { + get { + return new Location(col, line); + } + } + + public Token(int kind) : this(kind, 0, 0) + { + } + + public Token(int kind, int col, int line) : this (kind, col, line, null) + { + } + + public Token(int kind, int col, int line, string val) : this(kind, col, line, val, null) + { + } + + public Token(int kind, int col, int line, string val, object literalValue) + { + this.kind = kind; + this.col = col; + this.line = line; + this.val = val; + this.literalValue = literalValue; + } + + public override string ToString() + { + return string.Format("[C# {0}/VB {1} line={2} col={3} val={4}]", + CSharp.Tokens.GetTokenString(kind), + VB.Tokens.GetTokenString(kind), + line, col, val); + + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt b/lib/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt new file mode 100644 index 000000000..c308b2f78 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/VBNet/KeywordList.txt @@ -0,0 +1,241 @@ +# this list is used for autogeneration of: +# - Keywords.cs +# - Tokens.cs +# - ATGTokensSection.txt - the TOKENS section of the ATG file + +# use BuildKeywords to generate the different lists. + +$Namespace=ICSharpCode.NRefactory.Parser.VB +$UpperCaseKeywords=True + +# TERMINAL_CLASSES +EOF +EOL +Identifier +LiteralString +LiteralCharacter +LiteralInteger +LiteralDouble +LiteralSingle +LiteralDecimal +LiteralDate + +# SPECIAL_CHARACTERS +Dot = "." +Assign = "=" +Comma = "," +Colon =":" +Plus = "+" +Minus = "-" +Times = "*" +Div ="/" +DivInteger = "\\" +ConcatString = "&" +Power = "^" +# Question mark is not needed by VB8, but we use it inside the IDE +QuestionMark = "?" + +OpenCurlyBrace = "{" +CloseCurlyBrace = "}" + +OpenParenthesis = "(" +CloseParenthesis = ")" + +GreaterThan = ">" +LessThan = "<" + +NotEqual = "<>" +GreaterEqual = ">=" +LessEqual = "<=" + +ShiftLeft = "<<" +ShiftRight = ">>" + +PlusAssign = "+=" +PowerAssign = "^=" +MinusAssign = "-=" +TimesAssign = "*=" +DivAssign = "/=" +DivIntegerAssign = "\\=" +ShiftLeftAssign = "<<=" +ShiftRightAssign = ">>=" +ConcatStringAssign = "&=" + +# keywords according to the spec: +# Keywordlist +"AddHandler" +"AddressOf" +"Alias" +"And" +"AndAlso" +"Ansi" +"As" +"Assembly" +"Auto" +"Binary" +"Boolean" +"ByRef" +"Byte" +"ByVal" +"Call" +"Case" +"Catch" +"CBool" +"CByte" +"CChar" +"CDate" +"CDbl" +"CDec" +"Char" +"CInt" +"Class" +"CLng" +"CObj" +"Compare" +"Const" +"CShort" +"CSng" +"CStr" +"CType" +"Date" +"Decimal" +"Declare" +"Default" +"Delegate" +"Dim" +"DirectCast" +"Do" +"Double" +"Each" +"Else" +"ElseIf" +"End" +"EndIf" +"Enum" +"Erase" +"Error" +"Event" +"Exit" +"Explicit" +"False" +"Finally" +"For" +"Friend" +"Function" +"Get" +"GetType" +"GoSub" +"GoTo" +"Handles" +"If" +"Implements" +"Imports" +"In" +"Inherits" +"Integer" +"Interface" +"Is" +"Let" +"Lib" +"Like" +"Long" +"Loop" +"Me" +"Mod" +"Module" +"MustInherit" +"MustOverride" +"MyBase" +"MyClass" +"Namespace" +"New" +"Next" +"Not" +"Nothing" +"NotInheritable" +"NotOverridable" +"Object" +"Off" +"On" +"Option" +"Optional" +"Or" +"OrElse" +"Overloads" +"Overridable" +"Overrides" +"ParamArray" +"Preserve" +"Private" +"Property" +"Protected" +"Public" +"RaiseEvent" +"ReadOnly" +"ReDim" +"RemoveHandler" +"Resume" +"Return" +"Select" +"Set" +"Shadows" +"Shared" +"Short" +"Single" +"Static" +"Step" +"Stop" +"Strict" +"String" +"Structure" +"Sub" +"SyncLock" +"Text" +"Then" +"Throw" +"To" +"True" +"Try" +"TypeOf" +"Unicode" +"Until" +"Variant" +"Wend" +"When" +"While" +"With" +"WithEvents" +"WriteOnly" +"Xor" +# Rem never gets passed to the parser because it is handled by the lexer, but it still +# has to be in the keyword list for the output formatter +"Rem" + +# VB.NET 2.0 Keywords: +"Continue" +"Operator" +"Using" +"IsNot" +# Note: IsTrue and IsFalse are 'NOT' keywords they're only valid in Operator declarations (like get/set/value are no C# 'keywords') +"SByte" +"UInteger" +"ULong" +"UShort" +"CSByte" +"CUShort" +"CUInt" +"CULng" +"Global" +"TryCast" +"Of" +"Narrowing" +"Widening" +"Partial" +"Custom" + +#Sets +Null("Nothing") +BlockSucc("Case", "Catch", "Else", "ElseIf", "End", "Finally", "Loop", "Next") + +# List of keywords that are valid identifiers, must be the same as the "Identifier" production in VBNET.ATG +IdentifierTokens("Text", "Binary", "Compare", "Assembly", "Ansi", "Auto", "Preserve", "Unicode", "Until", "Explicit", "Off") diff --git a/lib/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs b/lib/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs new file mode 100644 index 000000000..76374886f --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/VBNet/Keywords.cs @@ -0,0 +1,197 @@ +// this file was autogenerated by a tool. +using System; + +namespace ICSharpCode.NRefactory.Parser.VB +{ + public static class Keywords + { + static readonly string[] keywordList = { + "ADDHANDLER", + "ADDRESSOF", + "ALIAS", + "AND", + "ANDALSO", + "ANSI", + "AS", + "ASSEMBLY", + "AUTO", + "BINARY", + "BOOLEAN", + "BYREF", + "BYTE", + "BYVAL", + "CALL", + "CASE", + "CATCH", + "CBOOL", + "CBYTE", + "CCHAR", + "CDATE", + "CDBL", + "CDEC", + "CHAR", + "CINT", + "CLASS", + "CLNG", + "COBJ", + "COMPARE", + "CONST", + "CSHORT", + "CSNG", + "CSTR", + "CTYPE", + "DATE", + "DECIMAL", + "DECLARE", + "DEFAULT", + "DELEGATE", + "DIM", + "DIRECTCAST", + "DO", + "DOUBLE", + "EACH", + "ELSE", + "ELSEIF", + "END", + "ENDIF", + "ENUM", + "ERASE", + "ERROR", + "EVENT", + "EXIT", + "EXPLICIT", + "FALSE", + "FINALLY", + "FOR", + "FRIEND", + "FUNCTION", + "GET", + "GETTYPE", + "GOSUB", + "GOTO", + "HANDLES", + "IF", + "IMPLEMENTS", + "IMPORTS", + "IN", + "INHERITS", + "INTEGER", + "INTERFACE", + "IS", + "LET", + "LIB", + "LIKE", + "LONG", + "LOOP", + "ME", + "MOD", + "MODULE", + "MUSTINHERIT", + "MUSTOVERRIDE", + "MYBASE", + "MYCLASS", + "NAMESPACE", + "NEW", + "NEXT", + "NOT", + "NOTHING", + "NOTINHERITABLE", + "NOTOVERRIDABLE", + "OBJECT", + "OFF", + "ON", + "OPTION", + "OPTIONAL", + "OR", + "ORELSE", + "OVERLOADS", + "OVERRIDABLE", + "OVERRIDES", + "PARAMARRAY", + "PRESERVE", + "PRIVATE", + "PROPERTY", + "PROTECTED", + "PUBLIC", + "RAISEEVENT", + "READONLY", + "REDIM", + "REMOVEHANDLER", + "RESUME", + "RETURN", + "SELECT", + "SET", + "SHADOWS", + "SHARED", + "SHORT", + "SINGLE", + "STATIC", + "STEP", + "STOP", + "STRICT", + "STRING", + "STRUCTURE", + "SUB", + "SYNCLOCK", + "TEXT", + "THEN", + "THROW", + "TO", + "TRUE", + "TRY", + "TYPEOF", + "UNICODE", + "UNTIL", + "VARIANT", + "WEND", + "WHEN", + "WHILE", + "WITH", + "WITHEVENTS", + "WRITEONLY", + "XOR", + "REM", + "CONTINUE", + "OPERATOR", + "USING", + "ISNOT", + "SBYTE", + "UINTEGER", + "ULONG", + "USHORT", + "CSBYTE", + "CUSHORT", + "CUINT", + "CULNG", + "GLOBAL", + "TRYCAST", + "OF", + "NARROWING", + "WIDENING", + "PARTIAL", + "CUSTOM" + }; + + static LookupTable keywords = new LookupTable(false); + + static Keywords() + { + for (int i = 0; i < keywordList.Length; ++i) { + keywords[keywordList[i]] = i + Tokens.AddHandler; + } + } + + public static int GetToken(string keyword) + { + return keywords[keyword]; + } + + public static bool IsNonIdentifierKeyword(string word) + { + int token = GetToken(word); + if (token < 0) + return false; + return !Tokens.IdentifierTokens[token]; + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs b/lib/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs new file mode 100644 index 000000000..5caa09dc2 --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs @@ -0,0 +1,731 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Globalization; +using System.IO; +using System.Text; + +namespace ICSharpCode.NRefactory.Parser.VB +{ + internal sealed class Lexer : AbstractLexer + { + bool lineEnd = true; + + public Lexer(TextReader reader) : base(reader) + { + } + + public override Token NextToken() + { + if (curToken == null) { // first call of NextToken() + curToken = Next(); + specialTracker.InformToken(curToken.kind); + //Console.WriteLine("Tok:" + Tokens.GetTokenString(curToken.kind) + " --- " + curToken.val); + return curToken; + } + + lastToken = curToken; + + if (curToken.next == null) { + curToken.next = Next(); + specialTracker.InformToken(curToken.next.kind); + } + + curToken = curToken.next; + + if (curToken.kind == Tokens.EOF && !(lastToken.kind == Tokens.EOL)) { // be sure that before EOF there is an EOL token + curToken = new Token(Tokens.EOL, curToken.col, curToken.line, "\n"); + specialTracker.InformToken(curToken.kind); + curToken.next = new Token(Tokens.EOF, curToken.col, curToken.line, "\n"); + specialTracker.InformToken(curToken.next.kind); + } + //Console.WriteLine("Tok:" + Tokens.GetTokenString(curToken.kind) + " --- " + curToken.val); + return curToken; + } + + protected override Token Next() + { + unchecked { + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + if (Char.IsWhiteSpace(ch)) { + int x = Col - 1; + int y = Line; + if (HandleLineEnd(ch)) { + if (lineEnd) { + // second line end before getting to a token + // -> here was a blank line + specialTracker.AddEndOfLine(new Location(x, y)); + } else { + lineEnd = true; + return new Token(Tokens.EOL, x, y); + } + } + continue; + } + if (ch == '_') { + if (ReaderPeek() == -1) { + errors.Error(Line, Col, String.Format("No EOF expected after _")); + return new Token(Tokens.EOF); + } + if (!Char.IsWhiteSpace((char)ReaderPeek())) { + int x = Col - 1; + int y = Line; + string s = ReadIdent('_'); + lineEnd = false; + return new Token(Tokens.Identifier, x, y, s); + } + ch = (char)ReaderRead(); + + bool oldLineEnd = lineEnd; + lineEnd = false; + while (Char.IsWhiteSpace(ch)) { + if (HandleLineEnd(ch)) { + lineEnd = true; + break; + } + if (ReaderPeek() != -1) { + ch = (char)ReaderRead(); + } else { + errors.Error(Line, Col, String.Format("No EOF expected after _")); + return new Token(Tokens.EOF); + } + } + if (!lineEnd) { + errors.Error(Line, Col, String.Format("Return expected")); + } + lineEnd = oldLineEnd; + continue; + } + + if (ch == '#') { + while (Char.IsWhiteSpace((char)ReaderPeek())) { + ReaderRead(); + } + if (Char.IsDigit((char)ReaderPeek())) { + int x = Col - 1; + int y = Line; + string s = ReadDate(); + DateTime time = new DateTime(1, 1, 1, 0, 0, 0); + try { + time = DateTime.Parse(s, System.Globalization.CultureInfo.InvariantCulture, DateTimeStyles.NoCurrentDateDefault); + } catch (Exception e) { + errors.Error(Line, Col, String.Format("Invalid date time {0}", e)); + } + return new Token(Tokens.LiteralDate, x, y, s, time); + } else { + ReadPreprocessorDirective(); + continue; + } + } + + if (ch == '[') { // Identifier + lineEnd = false; + if (ReaderPeek() == -1) { + errors.Error(Line, Col, String.Format("Identifier expected")); + } + ch = (char)ReaderRead(); + if (ch == ']' || Char.IsWhiteSpace(ch)) { + errors.Error(Line, Col, String.Format("Identifier expected")); + } + int x = Col - 1; + int y = Line; + string s = ReadIdent(ch); + if (ReaderPeek() == -1) { + errors.Error(Line, Col, String.Format("']' expected")); + } + ch = (char)ReaderRead(); + if (!(ch == ']')) { + errors.Error(Line, Col, String.Format("']' expected")); + } + return new Token(Tokens.Identifier, x, y, s); + } + if (Char.IsLetter(ch)) { + int x = Col - 1; + int y = Line; + string s = ReadIdent(ch); + int keyWordToken = Keywords.GetToken(s); + if (keyWordToken >= 0) { + lineEnd = false; + return new Token(keyWordToken, x, y, s); + } + + // handle 'REM' comments + if (s.Equals("REM", StringComparison.InvariantCultureIgnoreCase)) { + ReadComment(); + if (!lineEnd) { + lineEnd = true; + return new Token(Tokens.EOL, Col, Line, "\n"); + } + continue; + } + + lineEnd = false; + return new Token(Tokens.Identifier, x, y, s); + + } + if (Char.IsDigit(ch)) { + lineEnd = false; + return ReadDigit(ch, Col - 1); + } + if (ch == '&') { + lineEnd = false; + if (ReaderPeek() == -1) { + return ReadOperator('&'); + } + ch = (char)ReaderPeek(); + if (Char.ToUpper(ch, CultureInfo.InvariantCulture) == 'H' || Char.ToUpper(ch, CultureInfo.InvariantCulture) == 'O') { + return ReadDigit('&', Col - 1); + } + return ReadOperator('&'); + } + if (ch == '\'' || ch == '\u2018' || ch == '\u2019') { + int x = Col - 1; + int y = Line; + ReadComment(); + if (!lineEnd) { + lineEnd = true; + return new Token(Tokens.EOL, x, y, "\n"); + } + continue; + } + if (ch == '"') { + lineEnd = false; + int x = Col - 1; + int y = Line; + string s = ReadString(); + if (ReaderPeek() != -1 && (ReaderPeek() == 'C' || ReaderPeek() == 'c')) { + ReaderRead(); + if (s.Length != 1) { + errors.Error(Line, Col, String.Format("Chars can only have Length 1 ")); + } + if (s.Length == 0) { + s = "\0"; + } + return new Token(Tokens.LiteralCharacter, x, y, '"' + s + "\"C", s[0]); + } + return new Token(Tokens.LiteralString, x, y, '"' + s + '"', s); + } + Token token = ReadOperator(ch); + if (token != null) { + lineEnd = false; + return token; + } + errors.Error(Line, Col, String.Format("Unknown char({0}) which can't be read", ch)); + } + + return new Token(Tokens.EOF); + } + } + + string ReadIdent(char ch) + { + sb.Length = 0; + sb.Append(ch); + int peek; + while ((peek = ReaderPeek()) != -1 && (Char.IsLetterOrDigit(ch = (char)peek) || ch == '_')) { + ReaderRead(); + sb.Append(ch.ToString()); + } + if (peek == -1) { + return sb.ToString(); + } + + if ("%&@!#$".IndexOf((char)peek) != -1) { + ReaderRead(); + } + return sb.ToString(); + } + + char PeekUpperChar() + { + return Char.ToUpper((char)ReaderPeek(), CultureInfo.InvariantCulture); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1818:DoNotConcatenateStringsInsideLoops")] + Token ReadDigit(char ch, int x) + { + sb.Length = 0; + sb.Append(ch); + + int y = Line; + string digit = ""; + if (ch != '&') { + digit += ch; + } + + bool ishex = false; + bool isokt = false; + bool issingle = false; + bool isdouble = false; + bool isdecimal = false; + + if (ReaderPeek() == -1) { + if (ch == '&') { + errors.Error(Line, Col, String.Format("digit expected")); + } + return new Token(Tokens.LiteralInteger, x, y, sb.ToString() ,ch - '0'); + } + if (ch == '.') { + if (Char.IsDigit((char)ReaderPeek())) { + isdouble = true; // double is default + if (ishex || isokt) { + errors.Error(Line, Col, String.Format("No hexadecimal or oktadecimal floating point values allowed")); + } + while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())){ // read decimal digits beyond the dot + digit += (char)ReaderRead(); + } + } + } else if (ch == '&' && PeekUpperChar() == 'H') { + const string hex = "0123456789ABCDEF"; + sb.Append((char)ReaderRead()); // skip 'H' + while (ReaderPeek() != -1 && hex.IndexOf(PeekUpperChar()) != -1) { + ch = (char)ReaderRead(); + sb.Append(ch); + digit += Char.ToUpper(ch, CultureInfo.InvariantCulture); + } + ishex = true; + } else if (ReaderPeek() != -1 && ch == '&' && PeekUpperChar() == 'O') { + const string okt = "01234567"; + sb.Append((char)ReaderRead()); // skip 'O' + while (ReaderPeek() != -1 && okt.IndexOf(PeekUpperChar()) != -1) { + ch = (char)ReaderRead(); + sb.Append(ch); + digit += Char.ToUpper(ch, CultureInfo.InvariantCulture); + } + isokt = true; + } else { + while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) { + ch = (char)ReaderRead();; + digit += ch; + sb.Append(ch); + } + } + + if (digit.Length == 0) { + errors.Error(Line, Col, String.Format("digit expected")); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); + } + + if (ReaderPeek() != -1 && ("%&SILU".IndexOf(PeekUpperChar()) != -1 || ishex || isokt)) { + ch = (char)ReaderPeek(); + sb.Append(ch); + ch = Char.ToUpper(ch, CultureInfo.InvariantCulture); + bool unsigned = ch == 'U'; + if (unsigned) { + ReaderRead(); // read the U + ch = (char)ReaderPeek(); + sb.Append(ch); + ch = Char.ToUpper(ch, CultureInfo.InvariantCulture); + if (ch != 'I' && ch != 'L' && ch != 'S') { + errors.Error(Line, Col, "Invalid type character: U" + ch); + } + } + try { + if (isokt) { + ReaderRead(); + ulong number = 0L; + for (int i = 0; i < digit.Length; ++i) { + number = number * 8 + digit[i] - '0'; + } + if (ch == 'S') { + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ushort)number); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (short)number); + } else if (ch == '%' || ch == 'I') { + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (uint)number); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (int)number); + } else if (ch == '&' || ch == 'L') { + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (ulong)number); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), (long)number); + } else { + if (number > uint.MaxValue) { + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number)); + } else { + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number)); + } + } + } + if (ch == 'S') { + ReaderRead(); + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt16.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int16.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + } else if (ch == '%' || ch == 'I') { + ReaderRead(); + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt32.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + } else if (ch == '&' || ch == 'L') { + ReaderRead(); + if (unsigned) + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), UInt64.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + else + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + } else if (ishex) { + ulong number = UInt64.Parse(digit, NumberStyles.HexNumber); + if (number > uint.MaxValue) { + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((long)number)); + } else { + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), unchecked((int)number)); + } + } + } catch (OverflowException ex) { + errors.Error(Line, Col, ex.Message); + return new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); + } + } + Token nextToken = null; // if we accedently read a 'dot' + if (!isdouble && ReaderPeek() == '.') { // read floating point number + ReaderRead(); + if (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) { + isdouble = true; // double is default + if (ishex || isokt) { + errors.Error(Line, Col, String.Format("No hexadecimal or oktadecimal floating point values allowed")); + } + digit += '.'; + while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())){ // read decimal digits beyond the dot + digit += (char)ReaderRead(); + } + } else { + nextToken = new Token(Tokens.Dot, Col - 1, Line); + } + } + + if (ReaderPeek() != -1 && PeekUpperChar() == 'E') { // read exponent + isdouble = true; + digit += (char)ReaderRead(); + if (ReaderPeek() != -1 && (ReaderPeek() == '-' || ReaderPeek() == '+')) { + digit += (char)ReaderRead(); + } + while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) { // read exponent value + digit += (char)ReaderRead(); + } + } + + if (ReaderPeek() != -1) { + switch (PeekUpperChar()) { + case 'R': + case '#': + ReaderRead(); + isdouble = true; + break; + case 'D': + case '@': + ReaderRead(); + isdecimal = true; + break; + case 'F': + case '!': + ReaderRead(); + issingle = true; + break; + } + } + + try { + if (issingle) { + return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), Single.Parse(digit, CultureInfo.InvariantCulture)); + } + if (isdecimal) { + return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), Decimal.Parse(digit, NumberStyles.Currency | NumberStyles.AllowExponent, CultureInfo.InvariantCulture)); + } + if (isdouble) { + return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), Double.Parse(digit, CultureInfo.InvariantCulture)); + } + } catch (FormatException) { + errors.Error(Line, Col, String.Format("{0} is not a parseable number", digit)); + if (issingle) + return new Token(Tokens.LiteralSingle, x, y, sb.ToString(), 0f); + if (isdecimal) + return new Token(Tokens.LiteralDecimal, x, y, sb.ToString(), 0m); + if (isdouble) + return new Token(Tokens.LiteralDouble, x, y, sb.ToString(), 0.0); + } + Token token; + try { + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int32.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + } catch (Exception) { + try { + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), Int64.Parse(digit, ishex ? NumberStyles.HexNumber : NumberStyles.Number)); + } catch (FormatException) { + errors.Error(Line, Col, String.Format("{0} is not a parseable number", digit)); + // fallback, when nothing helps :) + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); + } catch (OverflowException) { + errors.Error(Line, Col, String.Format("{0} is too long for a integer literal", digit)); + // fallback, when nothing helps :) + token = new Token(Tokens.LiteralInteger, x, y, sb.ToString(), 0); + } + } + token.next = nextToken; + return token; + } + + void ReadPreprocessorDirective() + { + Location start = new Location(Col - 1, Line); + string directive = ReadIdent('#'); + string argument = ReadToEndOfLine(); + this.specialTracker.AddPreprocessingDirective(directive, argument.Trim(), start, new Location(start.X + directive.Length + argument.Length, start.Y)); + } + + string ReadDate() + { + char ch = '\0'; + sb.Length = 0; + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + ch = (char)nextChar; + if (ch == '#') { + break; + } else if (ch == '\n') { + errors.Error(Line, Col, String.Format("No return allowed inside Date literal")); + } else { + sb.Append(ch); + } + } + if (ch != '#') { + errors.Error(Line, Col, String.Format("End of File reached before Date literal terminated")); + } + return sb.ToString(); + } + + string ReadString() + { + char ch = '\0'; + sb.Length = 0; + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + ch = (char)nextChar; + if (ch == '"') { + if (ReaderPeek() != -1 && ReaderPeek() == '"') { + sb.Append('"'); + ReaderRead(); + } else { + break; + } + } else if (ch == '\n') { + errors.Error(Line, Col, String.Format("No return allowed inside String literal")); + } else { + sb.Append(ch); + } + } + if (ch != '"') { + errors.Error(Line, Col, String.Format("End of File reached before String terminated ")); + } + return sb.ToString(); + } + + void ReadComment() + { + Location startPos = new Location(Col, Line); + sb.Length = 0; + StringBuilder curWord = specialCommentHash != null ? new StringBuilder() : null; + int missingApostrophes = 2; // no. of ' missing until it is a documentation comment + int nextChar; + while ((nextChar = ReaderRead()) != -1) { + char ch = (char)nextChar; + + if (HandleLineEnd(ch)) { + break; + } + + sb.Append(ch); + + if (missingApostrophes > 0) { + if (ch == '\'' || ch == '\u2018' || ch == '\u2019') { + if (--missingApostrophes == 0) { + specialTracker.StartComment(CommentType.Documentation, startPos); + sb.Length = 0; + } + } else { + specialTracker.StartComment(CommentType.SingleLine, startPos); + missingApostrophes = 0; + } + } + + if (specialCommentHash != null) { + if (Char.IsLetter(ch)) { + curWord.Append(ch); + } else { + string tag = curWord.ToString(); + curWord.Length = 0; + if (specialCommentHash.ContainsKey(tag)) { + Location p = new Location(Col, Line); + string comment = ch + ReadToEndOfLine(); + this.TagComments.Add(new TagComment(tag, comment, p, new Location(Col, Line))); + sb.Append(comment); + break; + } + } + } + } + if (missingApostrophes > 0) { + specialTracker.StartComment(CommentType.SingleLine, startPos); + } + specialTracker.AddString(sb.ToString()); + specialTracker.FinishComment(new Location(Col, Line)); + } + + Token ReadOperator(char ch) + { + int x = Col - 1; + int y = Line; + switch(ch) { + case '+': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.PlusAssign, x, y); + default: + break; + } + return new Token(Tokens.Plus, x, y); + case '-': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.MinusAssign, x, y); + default: + break; + } + return new Token(Tokens.Minus, x, y); + case '*': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.TimesAssign, x, y); + default: + break; + } + return new Token(Tokens.Times, x, y, "*"); + case '/': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.DivAssign, x, y); + default: + break; + } + return new Token(Tokens.Div, x, y); + case '\\': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.DivIntegerAssign, x, y); + default: + break; + } + return new Token(Tokens.DivInteger, x, y); + case '&': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.ConcatStringAssign, x, y); + default: + break; + } + return new Token(Tokens.ConcatString, x, y); + case '^': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.PowerAssign, x, y); + default: + break; + } + return new Token(Tokens.Power, x, y); + case ':': + return new Token(Tokens.Colon, x, y); + case '=': + return new Token(Tokens.Assign, x, y); + case '<': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.LessEqual, x, y); + case '>': + ReaderRead(); + return new Token(Tokens.NotEqual, x, y); + case '<': + ReaderRead(); + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.ShiftLeftAssign, x, y); + default: + break; + } + return new Token(Tokens.ShiftLeft, x, y); + } + return new Token(Tokens.LessThan, x, y); + case '>': + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.GreaterEqual, x, y); + case '>': + ReaderRead(); + if (ReaderPeek() != -1) { + switch (ReaderPeek()) { + case '=': + ReaderRead(); + return new Token(Tokens.ShiftRightAssign, x, y); + default: + break; + } + } + return new Token(Tokens.ShiftRight, x, y); + } + return new Token(Tokens.GreaterThan, x, y); + case ',': + return new Token(Tokens.Comma, x, y); + case '.': + // Prevent OverflowException when Peek returns -1 + int tmp = ReaderPeek(); + if (tmp > 0 && Char.IsDigit((char)tmp)) { + return ReadDigit('.', Col); + } + return new Token(Tokens.Dot, x, y); + case '(': + return new Token(Tokens.OpenParenthesis, x, y); + case ')': + return new Token(Tokens.CloseParenthesis, x, y); + case '{': + return new Token(Tokens.OpenCurlyBrace, x, y); + case '}': + return new Token(Tokens.CloseCurlyBrace, x, y); + case '?': + return new Token(Tokens.QuestionMark, x, y); + } + return null; + } + + public override void SkipCurrentBlock(int targetToken) + { + int lastKind = -1; + int kind = base.lastToken.kind; + while (kind != Tokens.EOF && + !(lastKind == Tokens.End && kind == targetToken)) + { + lastKind = kind; + NextToken(); + kind = lastToken.kind; + } + } + } +} diff --git a/lib/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs b/lib/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs new file mode 100644 index 000000000..51e1847bd --- /dev/null +++ b/lib/NRefactory/Project/Src/Lexer/VBNet/Tokens.cs @@ -0,0 +1,453 @@ +// this file was autogenerated by a tool. +using System; +using System.Collections; + +namespace ICSharpCode.NRefactory.Parser.VB +{ + public static class Tokens + { + // ----- terminal classes ----- + public const int EOF = 0; + public const int EOL = 1; + public const int Identifier = 2; + public const int LiteralString = 3; + public const int LiteralCharacter = 4; + public const int LiteralInteger = 5; + public const int LiteralDouble = 6; + public const int LiteralSingle = 7; + public const int LiteralDecimal = 8; + public const int LiteralDate = 9; + + // ----- special character ----- + public const int Dot = 10; + public const int Assign = 11; + public const int Comma = 12; + public const int Colon = 13; + public const int Plus = 14; + public const int Minus = 15; + public const int Times = 16; + public const int Div = 17; + public const int DivInteger = 18; + public const int ConcatString = 19; + public const int Power = 20; + public const int QuestionMark = 21; + public const int OpenCurlyBrace = 22; + public const int CloseCurlyBrace = 23; + public const int OpenParenthesis = 24; + public const int CloseParenthesis = 25; + public const int GreaterThan = 26; + public const int LessThan = 27; + public const int NotEqual = 28; + public const int GreaterEqual = 29; + public const int LessEqual = 30; + public const int ShiftLeft = 31; + public const int ShiftRight = 32; + public const int PlusAssign = 33; + public const int PowerAssign = 34; + public const int MinusAssign = 35; + public const int TimesAssign = 36; + public const int DivAssign = 37; + public const int DivIntegerAssign = 38; + public const int ShiftLeftAssign = 39; + public const int ShiftRightAssign = 40; + public const int ConcatStringAssign = 41; + + // ----- keywords ----- + public const int AddHandler = 42; + public const int AddressOf = 43; + public const int Alias = 44; + public const int And = 45; + public const int AndAlso = 46; + public const int Ansi = 47; + public const int As = 48; + public const int Assembly = 49; + public const int Auto = 50; + public const int Binary = 51; + public const int Boolean = 52; + public const int ByRef = 53; + public const int Byte = 54; + public const int ByVal = 55; + public const int Call = 56; + public const int Case = 57; + public const int Catch = 58; + public const int CBool = 59; + public const int CByte = 60; + public const int CChar = 61; + public const int CDate = 62; + public const int CDbl = 63; + public const int CDec = 64; + public const int Char = 65; + public const int CInt = 66; + public const int Class = 67; + public const int CLng = 68; + public const int CObj = 69; + public const int Compare = 70; + public const int Const = 71; + public const int CShort = 72; + public const int CSng = 73; + public const int CStr = 74; + public const int CType = 75; + public const int Date = 76; + public const int Decimal = 77; + public const int Declare = 78; + public const int Default = 79; + public const int Delegate = 80; + public const int Dim = 81; + public const int DirectCast = 82; + public const int Do = 83; + public const int Double = 84; + public const int Each = 85; + public const int Else = 86; + public const int ElseIf = 87; + public const int End = 88; + public const int EndIf = 89; + public const int Enum = 90; + public const int Erase = 91; + public const int Error = 92; + public const int Event = 93; + public const int Exit = 94; + public const int Explicit = 95; + public const int False = 96; + public const int Finally = 97; + public const int For = 98; + public const int Friend = 99; + public const int Function = 100; + public const int Get = 101; + new public const int GetType = 102; + public const int GoSub = 103; + public const int GoTo = 104; + public const int Handles = 105; + public const int If = 106; + public const int Implements = 107; + public const int Imports = 108; + public const int In = 109; + public const int Inherits = 110; + public const int Integer = 111; + public const int Interface = 112; + public const int Is = 113; + public const int Let = 114; + public const int Lib = 115; + public const int Like = 116; + public const int Long = 117; + public const int Loop = 118; + public const int Me = 119; + public const int Mod = 120; + public const int Module = 121; + public const int MustInherit = 122; + public const int MustOverride = 123; + public const int MyBase = 124; + public const int MyClass = 125; + public const int Namespace = 126; + public const int New = 127; + public const int Next = 128; + public const int Not = 129; + public const int Nothing = 130; + public const int NotInheritable = 131; + public const int NotOverridable = 132; + public const int Object = 133; + public const int Off = 134; + public const int On = 135; + public const int Option = 136; + public const int Optional = 137; + public const int Or = 138; + public const int OrElse = 139; + public const int Overloads = 140; + public const int Overridable = 141; + public const int Overrides = 142; + public const int ParamArray = 143; + public const int Preserve = 144; + public const int Private = 145; + public const int Property = 146; + public const int Protected = 147; + public const int Public = 148; + public const int RaiseEvent = 149; + public const int ReadOnly = 150; + public const int ReDim = 151; + public const int RemoveHandler = 152; + public const int Resume = 153; + public const int Return = 154; + public const int Select = 155; + public const int Set = 156; + public const int Shadows = 157; + public const int Shared = 158; + public const int Short = 159; + public const int Single = 160; + public const int Static = 161; + public const int Step = 162; + public const int Stop = 163; + public const int Strict = 164; + public const int String = 165; + public const int Structure = 166; + public const int Sub = 167; + public const int SyncLock = 168; + public const int Text = 169; + public const int Then = 170; + public const int Throw = 171; + public const int To = 172; + public const int True = 173; + public const int Try = 174; + public const int TypeOf = 175; + public const int Unicode = 176; + public const int Until = 177; + public const int Variant = 178; + public const int Wend = 179; + public const int When = 180; + public const int While = 181; + public const int With = 182; + public const int WithEvents = 183; + public const int WriteOnly = 184; + public const int Xor = 185; + public const int Rem = 186; + public const int Continue = 187; + public const int Operator = 188; + public const int Using = 189; + public const int IsNot = 190; + public const int SByte = 191; + public const int UInteger = 192; + public const int ULong = 193; + public const int UShort = 194; + public const int CSByte = 195; + public const int CUShort = 196; + public const int CUInt = 197; + public const int CULng = 198; + public const int Global = 199; + public const int TryCast = 200; + public const int Of = 201; + public const int Narrowing = 202; + public const int Widening = 203; + public const int Partial = 204; + public const int Custom = 205; + + public const int MaxToken = 206; + static BitArray NewSet(params int[] values) + { + BitArray bitArray = new BitArray(MaxToken); + foreach (int val in values) { + bitArray[val] = true; + } + return bitArray; + } + public static BitArray Null = NewSet(Nothing); + public static BitArray BlockSucc = NewSet(Case, Catch, Else, ElseIf, End, Finally, Loop, Next); + public static BitArray IdentifierTokens = NewSet(Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Explicit, Off); + + static string[] tokenList = new string[] { + // ----- terminal classes ----- + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + // ----- special character ----- + ".", + "=", + ",", + ":", + "+", + "-", + "*", + "/", + "\\", + "&", + "^", + "?", + "{", + "}", + "(", + ")", + ">", + "<", + "<>", + ">=", + "<=", + "<<", + ">>", + "+=", + "^=", + "-=", + "*=", + "/=", + "\\=", + "<<=", + ">>=", + "&=", + // ----- keywords ----- + "AddHandler", + "AddressOf", + "Alias", + "And", + "AndAlso", + "Ansi", + "As", + "Assembly", + "Auto", + "Binary", + "Boolean", + "ByRef", + "Byte", + "ByVal", + "Call", + "Case", + "Catch", + "CBool", + "CByte", + "CChar", + "CDate", + "CDbl", + "CDec", + "Char", + "CInt", + "Class", + "CLng", + "CObj", + "Compare", + "Const", + "CShort", + "CSng", + "CStr", + "CType", + "Date", + "Decimal", + "Declare", + "Default", + "Delegate", + "Dim", + "DirectCast", + "Do", + "Double", + "Each", + "Else", + "ElseIf", + "End", + "EndIf", + "Enum", + "Erase", + "Error", + "Event", + "Exit", + "Explicit", + "False", + "Finally", + "For", + "Friend", + "Function", + "Get", + "GetType", + "GoSub", + "GoTo", + "Handles", + "If", + "Implements", + "Imports", + "In", + "Inherits", + "Integer", + "Interface", + "Is", + "Let", + "Lib", + "Like", + "Long", + "Loop", + "Me", + "Mod", + "Module", + "MustInherit", + "MustOverride", + "MyBase", + "MyClass", + "Namespace", + "New", + "Next", + "Not", + "Nothing", + "NotInheritable", + "NotOverridable", + "Object", + "Off", + "On", + "Option", + "Optional", + "Or", + "OrElse", + "Overloads", + "Overridable", + "Overrides", + "ParamArray", + "Preserve", + "Private", + "Property", + "Protected", + "Public", + "RaiseEvent", + "ReadOnly", + "ReDim", + "RemoveHandler", + "Resume", + "Return", + "Select", + "Set", + "Shadows", + "Shared", + "Short", + "Single", + "Static", + "Step", + "Stop", + "Strict", + "String", + "Structure", + "Sub", + "SyncLock", + "Text", + "Then", + "Throw", + "To", + "True", + "Try", + "TypeOf", + "Unicode", + "Until", + "Variant", + "Wend", + "When", + "While", + "With", + "WithEvents", + "WriteOnly", + "Xor", + "Rem", + "Continue", + "Operator", + "Using", + "IsNot", + "SByte", + "UInteger", + "ULong", + "UShort", + "CSByte", + "CUShort", + "CUInt", + "CULng", + "Global", + "TryCast", + "Of", + "Narrowing", + "Widening", + "Partial", + "Custom", + }; + public static string GetTokenString(int token) + { + if (token >= 0 && token < tokenList.Length) { + return tokenList[token]; + } + throw new System.NotSupportedException("Unknown token:" + token); + } + } +} diff --git a/lib/NRefactory/Project/Src/Location.cs b/lib/NRefactory/Project/Src/Location.cs new file mode 100644 index 000000000..75539013f --- /dev/null +++ b/lib/NRefactory/Project/Src/Location.cs @@ -0,0 +1,125 @@ +// +// +// +// +// $Revision$ +// + +using System; + +namespace ICSharpCode.NRefactory +{ + /// + /// A line/column position. + /// NRefactory lines/columns are counting from one. + /// + public struct Location : IComparable, IEquatable + { + public static readonly Location Empty = new Location(-1, -1); + + public Location(int column, int line) + { + x = column; + y = line; + } + + int x, y; + + public int X { + get { return x; } + set { x = value; } + } + + public int Y { + get { return y; } + set { y = value; } + } + + public int Line { + get { return y; } + set { y = value; } + } + + public int Column { + get { return x; } + set { x = value; } + } + + public bool IsEmpty { + get { + return x <= 0 && y <= 0; + } + } + + public override string ToString() + { + return string.Format("(Line {1}, Col {0})", this.x, this.y); + } + + public override int GetHashCode() + { + return unchecked (87 * x.GetHashCode() ^ y.GetHashCode()); + } + + public override bool Equals(object obj) + { + if (!(obj is Location)) return false; + return (Location)obj == this; + } + + public bool Equals(Location other) + { + return this == other; + } + + public static bool operator ==(Location a, Location b) + { + return a.x == b.x && a.y == b.y; + } + + public static bool operator !=(Location a, Location b) + { + return a.x != b.x || a.y != b.y; + } + + public static bool operator <(Location a, Location b) + { + if (a.y < b.y) + return true; + else if (a.y == b.y) + return a.x < b.x; + else + return false; + } + + public static bool operator >(Location a, Location b) + { + if (a.y > b.y) + return true; + else if (a.y == b.y) + return a.x > b.x; + else + return false; + } + + public static bool operator <=(Location a, Location b) + { + return !(a > b); + } + + public static bool operator >=(Location a, Location b) + { + return !(a < b); + } + + public int CompareTo(Location other) + { + if (this == other) + return 0; + if (this < other) + return -1; + else + return 1; + } + } +} diff --git a/lib/NRefactory/Project/Src/OperatorPrecedence.cs b/lib/NRefactory/Project/Src/OperatorPrecedence.cs new file mode 100644 index 000000000..e4074143c --- /dev/null +++ b/lib/NRefactory/Project/Src/OperatorPrecedence.cs @@ -0,0 +1,88 @@ +// +// +// +// +// $Revision: 2644$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory +{ + /// + /// Stores the operator precedences for the output visitor. + /// + static class OperatorPrecedence + { + static readonly Dictionary vbDict = MakePrecedenceTable( + new BinaryOperatorType[] { BinaryOperatorType.Power }, + new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide }, + new BinaryOperatorType[] { BinaryOperatorType.DivideInteger }, + new BinaryOperatorType[] { BinaryOperatorType.Modulus }, + new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract }, + new BinaryOperatorType[] { BinaryOperatorType.Concat }, + new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight }, + new BinaryOperatorType[] { + BinaryOperatorType.Equality, BinaryOperatorType.InEquality, + BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual, + BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual, + BinaryOperatorType.ReferenceEquality, BinaryOperatorType.ReferenceInequality, + BinaryOperatorType.Like + }, + new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.BitwiseAnd }, + new BinaryOperatorType[] { BinaryOperatorType.LogicalOr, BinaryOperatorType.BitwiseOr }, + new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr } + ); + + static readonly Dictionary csharpDict = MakePrecedenceTable( + new BinaryOperatorType[] { BinaryOperatorType.Multiply, BinaryOperatorType.Divide, BinaryOperatorType.Modulus }, + new BinaryOperatorType[] { BinaryOperatorType.Add, BinaryOperatorType.Subtract }, + new BinaryOperatorType[] { BinaryOperatorType.ShiftLeft, BinaryOperatorType.ShiftRight }, + new BinaryOperatorType[] { + BinaryOperatorType.LessThan, BinaryOperatorType.LessThanOrEqual, + BinaryOperatorType.GreaterThan, BinaryOperatorType.GreaterThanOrEqual, + }, + new BinaryOperatorType[] { BinaryOperatorType.Equality, BinaryOperatorType.InEquality }, + new BinaryOperatorType[] { BinaryOperatorType.BitwiseAnd }, + new BinaryOperatorType[] { BinaryOperatorType.ExclusiveOr }, + new BinaryOperatorType[] { BinaryOperatorType.BitwiseOr }, + new BinaryOperatorType[] { BinaryOperatorType.LogicalAnd, BinaryOperatorType.LogicalOr }, + new BinaryOperatorType[] { BinaryOperatorType.NullCoalescing } + ); + + // create a dictionary operator->precedence (higher value = higher precedence) + static Dictionary MakePrecedenceTable(params BinaryOperatorType[][] input) + { + Dictionary dict = new Dictionary(); + for (int i = 0; i < input.Length; i++) { + foreach (BinaryOperatorType op in input[i]) { + dict.Add(op, input.Length - i); + } + } + return dict; + } + + public static int ComparePrecedenceVB(BinaryOperatorType op1, BinaryOperatorType op2) + { + int p1 = GetOperatorPrecedence(vbDict, op1); + int p2 = GetOperatorPrecedence(vbDict, op2); + return p1.CompareTo(p2); + } + + public static int ComparePrecedenceCSharp(BinaryOperatorType op1, BinaryOperatorType op2) + { + int p1 = GetOperatorPrecedence(vbDict, op1); + int p2 = GetOperatorPrecedence(vbDict, op2); + return p1.CompareTo(p2); + } + + static int GetOperatorPrecedence(Dictionary dict, BinaryOperatorType op) + { + int p; + dict.TryGetValue(op, out p); + return p; + } + } +} diff --git a/lib/NRefactory/Project/Src/Parser/AbstractParser.cs b/lib/NRefactory/Project/Src/Parser/AbstractParser.cs new file mode 100644 index 000000000..221222b33 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/AbstractParser.cs @@ -0,0 +1,109 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Parser +{ + public abstract class AbstractParser : IParser + { + protected const int MinErrDist = 2; + protected const string ErrMsgFormat = "-- line {0} col {1}: {2}"; // 0=line, 1=column, 2=text + + + private Errors errors; + private ILexer lexer; + + protected int errDist = MinErrDist; + + [CLSCompliant(false)] + protected CompilationUnit compilationUnit; + + bool parseMethodContents = true; + + public bool ParseMethodBodies { + get { + return parseMethodContents; + } + set { + parseMethodContents = value; + } + } + + public ILexer Lexer { + get { + return lexer; + } + } + + public Errors Errors { + get { + return errors; + } + } + + public CompilationUnit CompilationUnit { + get { + return compilationUnit; + } + } + + internal AbstractParser(ILexer lexer) + { + this.errors = lexer.Errors; + this.lexer = lexer; + errors.SynErr = new ErrorCodeProc(SynErr); + } + + public abstract void Parse(); + + public abstract Expression ParseExpression(); + public abstract BlockStatement ParseBlock(); + public abstract List ParseTypeMembers(); + + protected abstract void SynErr(int line, int col, int errorNumber); + + protected void SynErr(int n) + { + if (errDist >= MinErrDist) { + errors.SynErr(lexer.LookAhead.line, lexer.LookAhead.col, n); + } + errDist = 0; + } + + protected void SemErr(string msg) + { + if (errDist >= MinErrDist) { + errors.Error(lexer.Token.line, lexer.Token.col, msg); + } + errDist = 0; + } + + protected void Expect(int n) + { + if (lexer.LookAhead.kind == n) { + lexer.NextToken(); + } else { + SynErr(n); + } + } + + #region System.IDisposable interface implementation + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")] + public void Dispose() + { + errors = null; + if (lexer != null) { + lexer.Dispose(); + } + lexer = null; + } + #endregion + } +} diff --git a/lib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs b/lib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs new file mode 100644 index 000000000..d01a48949 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/CSharp/CSharpParser.cs @@ -0,0 +1,598 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Text; +using System.Diagnostics; + +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Parser.CSharp +{ + internal sealed partial class Parser : AbstractParser + { + Lexer lexer; + + public Parser(ILexer lexer) : base(lexer) + { + this.lexer = (Lexer)lexer; + // due to anonymous methods, we always need a compilation unit, so + // create it in the constructor + compilationUnit = new CompilationUnit(); + } + + StringBuilder qualidentBuilder = new StringBuilder(); + + Token t { + [System.Diagnostics.DebuggerStepThrough] + get { + return lexer.Token; + } + } + + Token la { + [System.Diagnostics.DebuggerStepThrough] + get { + return lexer.LookAhead; + } + } + + public void Error(string s) + { + if (errDist >= MinErrDist) { + this.Errors.Error(la.line, la.col, s); + } + errDist = 0; + } + + public override Expression ParseExpression() + { + lexer.NextToken(); + Expression expr; + Expr(out expr); + // SEMICOLON HACK : without a trailing semicolon, parsing expressions does not work correctly + if (la.kind == Tokens.Semicolon) lexer.NextToken(); + Expect(Tokens.EOF); + return expr; + } + + public override BlockStatement ParseBlock() + { + lexer.NextToken(); + compilationUnit = new CompilationUnit(); + + BlockStatement blockStmt = new BlockStatement(); + blockStmt.StartLocation = la.Location; + compilationUnit.BlockStart(blockStmt); + + while (la.kind != Tokens.EOF) { + Token oldLa = la; + Statement(); + if (la == oldLa) { + // did not advance lexer position, we cannot parse this as a statement block + return null; + } + } + + compilationUnit.BlockEnd(); + Expect(Tokens.EOF); + return blockStmt; + } + + public override List ParseTypeMembers() + { + lexer.NextToken(); + compilationUnit = new CompilationUnit(); + + TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null); + compilationUnit.BlockStart(newType); + ClassBody(); + compilationUnit.BlockEnd(); + Expect(Tokens.EOF); + return newType.Children; + } + + // Begin ISTypeCast + bool IsTypeCast() + { + if (la.kind != Tokens.OpenParenthesis) { + return false; + } + if (IsSimpleTypeCast()) { + return true; + } + return GuessTypeCast(); + } + + // "(" ( typeKW [ "[" {","} "]" | "*" ] | void ( "[" {","} "]" | "*" ) ) ")" + // only for built-in types, all others use GuessTypeCast! + bool IsSimpleTypeCast () + { + // assert: la.kind == _lpar + lexer.StartPeek(); + Token pt = lexer.Peek(); + + if (!IsTypeKWForTypeCast(ref pt)) { + return false; + } + if (pt.kind == Tokens.Question) // TODO: check if IsTypeKWForTypeCast doesn't already to this + pt = lexer.Peek(); + return pt.kind == Tokens.CloseParenthesis; + } + + /* !!! Proceeds from current peek position !!! */ + bool IsTypeKWForTypeCast(ref Token pt) + { + if (Tokens.TypeKW[pt.kind]) { + pt = lexer.Peek(); + return IsPointerOrDims(ref pt) && SkipQuestionMark(ref pt); + } else if (pt.kind == Tokens.Void) { + pt = lexer.Peek(); + return IsPointerOrDims(ref pt); + } + return false; + } + + /* !!! Proceeds from current peek position !!! */ + bool IsTypeNameOrKWForTypeCast(ref Token pt) + { + if (Tokens.TypeKW[pt.kind] || pt.kind == Tokens.Void) + return IsTypeKWForTypeCast(ref pt); + else + return IsTypeNameForTypeCast(ref pt); + } + + // TypeName = ident [ "::" ident ] { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } ["?"] PointerOrDims + /* !!! Proceeds from current peek position !!! */ + bool IsTypeNameForTypeCast(ref Token pt) + { + // ident + if (!IsIdentifierToken(pt)) { + return false; + } + pt = Peek(); + // "::" ident + if (pt.kind == Tokens.DoubleColon) { + pt = Peek(); + if (!IsIdentifierToken(pt)) { + return false; + } + pt = Peek(); + } + // { ["<" TypeNameOrKW { "," TypeNameOrKW } ">" ] "." ident } + while (true) { + if (pt.kind == Tokens.LessThan) { + do { + pt = Peek(); + if (!IsTypeNameOrKWForTypeCast(ref pt)) { + return false; + } + } while (pt.kind == Tokens.Comma); + if (pt.kind != Tokens.GreaterThan) { + return false; + } + pt = Peek(); + } + if (pt.kind != Tokens.Dot) + break; + pt = Peek(); + if (pt.kind != Tokens.Identifier) { + return false; + } + pt = Peek(); + } + // ["?"] + if (pt.kind == Tokens.Question) { + pt = Peek(); + } + if (pt.kind == Tokens.Times || pt.kind == Tokens.OpenSquareBracket) { + return IsPointerOrDims(ref pt); + } + return true; + } + + // "(" TypeName ")" castFollower + bool GuessTypeCast () + { + // assert: la.kind == _lpar + StartPeek(); + Token pt = Peek(); + + if (!IsTypeNameForTypeCast(ref pt)) { + return false; + } + + // ")" + if (pt.kind != Tokens.CloseParenthesis) { + return false; + } + // check successor + pt = Peek(); + return Tokens.CastFollower[pt.kind]; + } + // END IsTypeCast + + // Gets if the token is a possible token for an expression start + // Is used to determine if "a is Type ? token" a the start of a ternary + // expression or a type test for Nullable + bool IsPossibleExpressionStart(int token) + { + return Tokens.CastFollower[token] || Tokens.UnaryOp[token]; + } + + // ( { [TypeNameOrKWForTypeCast] ident "," } ) + bool IsLambdaExpression() + { + if (la.kind != Tokens.OpenParenthesis) { + return false; + } + StartPeek(); + Token pt = Peek(); + while (pt.kind != Tokens.CloseParenthesis) { + if (!IsTypeNameOrKWForTypeCast(ref pt)) { + return false; + } + if (IsIdentifierToken(pt)) { + // make ident optional: if implicitly typed lambda arguments are used, IsTypeNameForTypeCast + // has already accepted the identifier + pt = Peek(); + } + if (pt.kind == Tokens.CloseParenthesis) { + break; + } + // require comma between parameters: + if (pt.kind == Tokens.Comma) { + pt = Peek(); + } else { + return false; + } + } + pt = Peek(); + return pt.kind == Tokens.LambdaArrow; + } + + /* Checks whether the next sequences of tokens is a qualident * + * and returns the qualident string */ + /* !!! Proceeds from current peek position !!! */ + bool IsQualident(ref Token pt, out string qualident) + { + if (IsIdentifierToken(pt)) { + qualidentBuilder.Length = 0; qualidentBuilder.Append(pt.val); + pt = Peek(); + while (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) { + pt = Peek(); + if (!IsIdentifierToken(pt)) { + qualident = String.Empty; + return false; + } + qualidentBuilder.Append('.'); + qualidentBuilder.Append(pt.val); + pt = Peek(); + } + qualident = qualidentBuilder.ToString(); + return true; + } + qualident = String.Empty; + return false; + } + + /* Skips generic type extensions */ + /* !!! Proceeds from current peek position !!! */ + + /* skip: { "*" | "[" { "," } "]" } */ + /* !!! Proceeds from current peek position !!! */ + bool IsPointerOrDims (ref Token pt) + { + for (;;) { + if (pt.kind == Tokens.OpenSquareBracket) { + do pt = Peek(); + while (pt.kind == Tokens.Comma); + if (pt.kind != Tokens.CloseSquareBracket) return false; + } else if (pt.kind != Tokens.Times) break; + pt = Peek(); + } + return true; + } + + /* Return the n-th token after the current lookahead token */ + void StartPeek() + { + lexer.StartPeek(); + } + + Token Peek() + { + return lexer.Peek(); + } + + Token Peek (int n) + { + lexer.StartPeek(); + Token x = la; + while (n > 0) { + x = lexer.Peek(); + n--; + } + return x; + } + + /*-----------------------------------------------------------------* + * Resolver routines to resolve LL(1) conflicts: * * + * These resolution routine return a boolean value that indicates * + * whether the alternative at hand shall be choosen or not. * + * They are used in IF ( ... ) expressions. * + *-----------------------------------------------------------------*/ + + /* True, if ident is followed by "=" */ + bool IdentAndAsgn () + { + return IsIdentifierToken(la) && Peek(1).kind == Tokens.Assign; + } + + bool IdentAndDoubleColon () + { + return IsIdentifierToken(la) && Peek(1).kind == Tokens.DoubleColon; + } + + bool IsAssignment () { return IdentAndAsgn(); } + + /* True, if ident is followed by ",", "=", "[" or ";" */ + bool IsVarDecl () { + int peek = Peek(1).kind; + return IsIdentifierToken(la) && + (peek == Tokens.Comma || peek == Tokens.Assign || peek == Tokens.Semicolon || peek == Tokens.OpenSquareBracket); + } + + /* True, if the comma is not a trailing one, * + * like the last one in: a, b, c, */ + bool NotFinalComma () { + int peek = Peek(1).kind; + return la.kind == Tokens.Comma && + peek != Tokens.CloseCurlyBrace && peek != Tokens.CloseSquareBracket; + } + + /* True, if "void" is followed by "*" */ + bool NotVoidPointer () { + return la.kind == Tokens.Void && Peek(1).kind != Tokens.Times; + } + + /* True, if "checked" or "unchecked" are followed by "{" */ + bool UnCheckedAndLBrace () { + return la.kind == Tokens.Checked || la.kind == Tokens.Unchecked && + Peek(1).kind == Tokens.OpenCurlyBrace; + } + + /* True, if "." is followed by an ident */ + bool DotAndIdent () { + return la.kind == Tokens.Dot && IsIdentifierToken(Peek(1)); + } + + /* True, if ident is followed by ":" */ + bool IdentAndColon () { + return IsIdentifierToken(la) && Peek(1).kind == Tokens.Colon; + } + + bool IsLabel () { return IdentAndColon(); } + + /* True, if ident is followed by "(" */ + bool IdentAndLPar () { + return IsIdentifierToken(la) && Peek(1).kind == Tokens.OpenParenthesis; + } + + /* True, if "catch" is followed by "(" */ + bool CatchAndLPar () { + return la.kind == Tokens.Catch && Peek(1).kind == Tokens.OpenParenthesis; + } + bool IsTypedCatch () { return CatchAndLPar(); } + + /* True, if "[" is followed by the ident "assembly" */ + bool IsGlobalAttrTarget () { + Token pt = Peek(1); + return la.kind == Tokens.OpenSquareBracket && + IsIdentifierToken(pt) && (pt.val == "assembly" || pt.val == "module"); + } + + /* True, if "[" is followed by "," or "]" */ + bool LBrackAndCommaOrRBrack () { + int peek = Peek(1).kind; + return la.kind == Tokens.OpenSquareBracket && + (peek == Tokens.Comma || peek == Tokens.CloseSquareBracket); + } + + /* True, if "[" is followed by "," or "]" */ + /* or if the current token is "*" */ + bool TimesOrLBrackAndCommaOrRBrack () { + return la.kind == Tokens.Times || LBrackAndCommaOrRBrack(); + } + bool IsPointerOrDims () { return TimesOrLBrackAndCommaOrRBrack(); } + bool IsPointer () { return la.kind == Tokens.Times; } + + + bool SkipGeneric(ref Token pt) + { + if (pt.kind == Tokens.LessThan) { + do { + pt = Peek(); + if (!IsTypeNameOrKWForTypeCast(ref pt)) return false; + } while (pt.kind == Tokens.Comma); + if (pt.kind != Tokens.GreaterThan) return false; + pt = Peek(); + } + return true; + } + bool SkipQuestionMark(ref Token pt) + { + if (pt.kind == Tokens.Question) { + pt = Peek(); + } + return true; + } + + /* True, if lookahead is a primitive type keyword, or */ + /* if it is a type declaration followed by an ident */ + bool IsLocalVarDecl () { + if (IsYieldStatement()) { + return false; + } + if ((Tokens.TypeKW[la.kind] && Peek(1).kind != Tokens.Dot) || la.kind == Tokens.Void) { + return true; + } + + StartPeek(); + Token pt = la; + return IsTypeNameOrKWForTypeCast(ref pt) && IsIdentifierToken(pt); + } + + /* True if lookahead is a type argument list (<...>) followed by + * one of "( ) ] } : ; , . ? == !=" */ + bool IsGenericInSimpleNameOrMemberAccess() + { + Token t = la; + if (t.kind != Tokens.LessThan) return false; + StartPeek(); + return SkipGeneric(ref t) && Tokens.GenericFollower[t.kind]; + } + + bool IsExplicitInterfaceImplementation() + { + StartPeek(); + Token pt = la; + pt = Peek(); + if (pt.kind == Tokens.Dot || pt.kind == Tokens.DoubleColon) + return true; + if (pt.kind == Tokens.LessThan) { + if (SkipGeneric(ref pt)) + return pt.kind == Tokens.Dot; + } + return false; + } + + /* True, if lookahead ident is "yield" and than follows a break or return */ + bool IsYieldStatement () { + return la.kind == Tokens.Yield && (Peek(1).kind == Tokens.Return || Peek(1).kind == Tokens.Break); + } + + /* True, if lookahead is a local attribute target specifier, * + * i.e. one of "event", "return", "field", "method", * + * "module", "param", "property", or "type" */ + bool IsLocalAttrTarget () { + int cur = la.kind; + string val = la.val; + + return (cur == Tokens.Event || cur == Tokens.Return || + (Tokens.IdentifierTokens[cur] && + (val == "field" || val == "method" || val == "module" || + val == "param" || val == "property" || val == "type"))) && + Peek(1).kind == Tokens.Colon; + } + + bool IsShiftRight() + { + Token next = Peek(1); + // TODO : Add col test (seems not to work, lexer bug...) : && la.col == next.col - 1 + return (la.kind == Tokens.GreaterThan && next.kind == Tokens.GreaterThan); + } + + bool IsGenericExpression(Expression expr) + { + if (expr is IdentifierExpression) + return ((IdentifierExpression)expr).TypeArguments.Count > 0; + else if (expr is MemberReferenceExpression) + return ((MemberReferenceExpression)expr).TypeArguments.Count > 0; + else + return false; + } + + bool ShouldConvertTargetExpressionToTypeReference(Expression targetExpr) + { + if (targetExpr is IdentifierExpression) + return ((IdentifierExpression)targetExpr).TypeArguments.Count > 0; + else if (targetExpr is MemberReferenceExpression) + return ((MemberReferenceExpression)targetExpr).TypeArguments.Count > 0; + else + return false; + } + + TypeReference GetTypeReferenceFromExpression(Expression expr) + { + if (expr is TypeReferenceExpression) + return (expr as TypeReferenceExpression).TypeReference; + + IdentifierExpression ident = expr as IdentifierExpression; + if (ident != null) { + return new TypeReference(ident.Identifier, ident.TypeArguments); + } + + MemberReferenceExpression member = expr as MemberReferenceExpression; + if (member != null) { + TypeReference targetType = GetTypeReferenceFromExpression(member.TargetObject); + if (targetType != null) { + if (targetType.GenericTypes.Count == 0 && targetType.IsArrayType == false) { + TypeReference tr = new TypeReference(targetType.Type + "." + member.MemberName, member.TypeArguments); + tr.IsGlobal = targetType.IsGlobal; + return tr; + } else { + return new InnerClassTypeReference(targetType, member.MemberName, member.TypeArguments); + } + } + } + return null; + } + + bool IsMostNegativeIntegerWithoutTypeSuffix() + { + Token token = la; + if (token.kind == Tokens.Literal) { + return token.val == "2147483648" || token.val == "9223372036854775808"; + } else { + return false; + } + } + + bool LastExpressionIsUnaryMinus(System.Collections.ArrayList expressions) + { + if (expressions.Count == 0) return false; + UnaryOperatorExpression uoe = expressions[expressions.Count - 1] as UnaryOperatorExpression; + if (uoe != null) { + return uoe.Op == UnaryOperatorType.Minus; + } else { + return false; + } + } + + bool StartOfQueryExpression() + { + if (la.kind == Tokens.From) { + Token p = Peek(1); + if (IsIdentifierToken(p) || Tokens.TypeKW[p.kind]) + return true; + } + return false; + } + + static bool IsIdentifierToken(Token tk) + { + return Tokens.IdentifierTokens[tk.kind]; + } + + /// + /// Adds a child item to a collection stored in the parent node. + /// Also set's the item's parent to . + /// Does nothing if item is null. + /// + static void SafeAdd(INode parent, List list, T item) where T : class, INode + { + Debug.Assert(parent != null); + Debug.Assert((parent is INullable) ? !(parent as INullable).IsNull : true); + if (item != null) { + list.Add(item); + item.Parent = parent; + } + } + } +} diff --git a/lib/NRefactory/Project/Src/Parser/CSharp/Parser.cs b/lib/NRefactory/Project/Src/Parser/CSharp/Parser.cs new file mode 100644 index 000000000..8b0816ceb --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/CSharp/Parser.cs @@ -0,0 +1,6129 @@ + +#line 1 "cs.ATG" +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Text; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Ast; +using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute; +using Types = ICSharpCode.NRefactory.Ast.ClassType; +/* + Parser.frame file for NRefactory. + */ +using System; +using System.Reflection; + +namespace ICSharpCode.NRefactory.Parser.CSharp { + + + +partial class Parser : AbstractParser +{ + const int maxT = 145; + + const bool T = true; + const bool x = false; + + +#line 18 "cs.ATG" + + +/* + +*/ + + void CS() { + +#line 179 "cs.ATG" + lexer.NextToken(); /* get the first token */ + while (la.kind == 121) { + UsingDirective(); + } + while ( +#line 182 "cs.ATG" +IsGlobalAttrTarget()) { + GlobalAttributeSection(); + } + while (StartOf(1)) { + NamespaceMemberDecl(); + } + Expect(0); + } + + void UsingDirective() { + +#line 189 "cs.ATG" + string qualident = null; TypeReference aliasedType = null; + + Expect(121); + +#line 192 "cs.ATG" + Location startPos = t.Location; + Qualident( +#line 193 "cs.ATG" +out qualident); + if (la.kind == 3) { + lexer.NextToken(); + NonArrayType( +#line 194 "cs.ATG" +out aliasedType); + } + Expect(11); + +#line 196 "cs.ATG" + if (qualident != null && qualident.Length > 0) { + INode node; + if (aliasedType != null) { + node = new UsingDeclaration(qualident, aliasedType); + } else { + node = new UsingDeclaration(qualident); + } + node.StartLocation = startPos; + node.EndLocation = t.EndLocation; + compilationUnit.AddChild(node); + } + + } + + void GlobalAttributeSection() { + Expect(18); + +#line 212 "cs.ATG" + Location startPos = t.Location; + Identifier(); + +#line 213 "cs.ATG" + if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (assembly or module) expected"); + string attributeTarget = t.val; + List attributes = new List(); + ASTAttribute attribute; + + Expect(9); + Attribute( +#line 218 "cs.ATG" +out attribute); + +#line 218 "cs.ATG" + attributes.Add(attribute); + while ( +#line 219 "cs.ATG" +NotFinalComma()) { + Expect(14); + Attribute( +#line 219 "cs.ATG" +out attribute); + +#line 219 "cs.ATG" + attributes.Add(attribute); + } + if (la.kind == 14) { + lexer.NextToken(); + } + Expect(19); + +#line 221 "cs.ATG" + AttributeSection section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + compilationUnit.AddChild(section); + + } + + void NamespaceMemberDecl() { + +#line 322 "cs.ATG" + AttributeSection section; + List attributes = new List(); + ModifierList m = new ModifierList(); + string qualident; + + if (la.kind == 88) { + lexer.NextToken(); + +#line 328 "cs.ATG" + Location startPos = t.Location; + Qualident( +#line 329 "cs.ATG" +out qualident); + +#line 329 "cs.ATG" + INode node = new NamespaceDeclaration(qualident); + node.StartLocation = startPos; + compilationUnit.AddChild(node); + compilationUnit.BlockStart(node); + + Expect(16); + while (la.kind == 121) { + UsingDirective(); + } + while (StartOf(1)) { + NamespaceMemberDecl(); + } + Expect(17); + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 338 "cs.ATG" + node.EndLocation = t.EndLocation; + compilationUnit.BlockEnd(); + + } else if (StartOf(2)) { + while (la.kind == 18) { + AttributeSection( +#line 342 "cs.ATG" +out section); + +#line 342 "cs.ATG" + attributes.Add(section); + } + while (StartOf(3)) { + TypeModifier( +#line 343 "cs.ATG" +m); + } + TypeDecl( +#line 344 "cs.ATG" +m, attributes); + } else SynErr(146); + } + + void Qualident( +#line 468 "cs.ATG" +out string qualident) { + Identifier(); + +#line 470 "cs.ATG" + qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); + while ( +#line 471 "cs.ATG" +DotAndIdent()) { + Expect(15); + Identifier(); + +#line 471 "cs.ATG" + qualidentBuilder.Append('.'); + qualidentBuilder.Append(t.val); + + } + +#line 474 "cs.ATG" + qualident = qualidentBuilder.ToString(); + } + + void NonArrayType( +#line 583 "cs.ATG" +out TypeReference type) { + +#line 585 "cs.ATG" + string name; + int pointer = 0; + type = null; + + if (StartOf(4)) { + ClassType( +#line 590 "cs.ATG" +out type, false); + } else if (StartOf(5)) { + SimpleType( +#line 591 "cs.ATG" +out name); + +#line 591 "cs.ATG" + type = new TypeReference(name); + } else if (la.kind == 123) { + lexer.NextToken(); + Expect(6); + +#line 592 "cs.ATG" + pointer = 1; type = new TypeReference("void"); + } else SynErr(147); + if (la.kind == 12) { + NullableQuestionMark( +#line 595 "cs.ATG" +ref type); + } + while ( +#line 597 "cs.ATG" +IsPointer()) { + Expect(6); + +#line 598 "cs.ATG" + ++pointer; + } + +#line 600 "cs.ATG" + if (type != null) { type.PointerNestingLevel = pointer; } + } + + void Identifier() { + switch (la.kind) { + case 1: { + lexer.NextToken(); + break; + } + case 126: { + lexer.NextToken(); + break; + } + case 127: { + lexer.NextToken(); + break; + } + case 128: { + lexer.NextToken(); + break; + } + case 129: { + lexer.NextToken(); + break; + } + case 130: { + lexer.NextToken(); + break; + } + case 131: { + lexer.NextToken(); + break; + } + case 132: { + lexer.NextToken(); + break; + } + case 133: { + lexer.NextToken(); + break; + } + case 134: { + lexer.NextToken(); + break; + } + case 135: { + lexer.NextToken(); + break; + } + case 136: { + lexer.NextToken(); + break; + } + case 137: { + lexer.NextToken(); + break; + } + case 138: { + lexer.NextToken(); + break; + } + case 139: { + lexer.NextToken(); + break; + } + case 140: { + lexer.NextToken(); + break; + } + case 141: { + lexer.NextToken(); + break; + } + case 142: { + lexer.NextToken(); + break; + } + case 143: { + lexer.NextToken(); + break; + } + case 144: { + lexer.NextToken(); + break; + } + default: SynErr(148); break; + } + } + + void Attribute( +#line 231 "cs.ATG" +out ASTAttribute attribute) { + +#line 232 "cs.ATG" + string qualident; + string alias = null; + + +#line 236 "cs.ATG" + Location startPos = la.Location; + if ( +#line 237 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); + +#line 238 "cs.ATG" + alias = t.val; + Expect(10); + } + Qualident( +#line 241 "cs.ATG" +out qualident); + +#line 242 "cs.ATG" + List positional = new List(); + List named = new List(); + string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident; + + if (la.kind == 20) { + AttributeArguments( +#line 246 "cs.ATG" +positional, named); + } + +#line 247 "cs.ATG" + attribute = new ASTAttribute(name, positional, named); + attribute.StartLocation = startPos; + attribute.EndLocation = t.EndLocation; + + } + + void AttributeArguments( +#line 253 "cs.ATG" +List positional, List named) { + +#line 255 "cs.ATG" + bool nameFound = false; + string name = ""; + Expression expr; + + Expect(20); + if (StartOf(6)) { + if ( +#line 263 "cs.ATG" +IsAssignment()) { + +#line 263 "cs.ATG" + nameFound = true; + Identifier(); + +#line 264 "cs.ATG" + name = t.val; + Expect(3); + } + Expr( +#line 266 "cs.ATG" +out expr); + +#line 266 "cs.ATG" + if (expr != null) {if(name == "") positional.Add(expr); + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + + while (la.kind == 14) { + lexer.NextToken(); + if ( +#line 274 "cs.ATG" +IsAssignment()) { + +#line 274 "cs.ATG" + nameFound = true; + Identifier(); + +#line 275 "cs.ATG" + name = t.val; + Expect(3); + } else if (StartOf(6)) { + +#line 277 "cs.ATG" + if (nameFound) Error("no positional argument after named argument"); + } else SynErr(149); + Expr( +#line 278 "cs.ATG" +out expr); + +#line 278 "cs.ATG" + if (expr != null) { if(name == "") positional.Add(expr); + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + + } + } + Expect(21); + } + + void Expr( +#line 1726 "cs.ATG" +out Expression expr) { + +#line 1727 "cs.ATG" + expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; + +#line 1729 "cs.ATG" + Location startLocation = la.Location; + UnaryExpr( +#line 1730 "cs.ATG" +out expr); + if (StartOf(7)) { + AssignmentOperator( +#line 1733 "cs.ATG" +out op); + Expr( +#line 1733 "cs.ATG" +out expr1); + +#line 1733 "cs.ATG" + expr = new AssignmentExpression(expr, op, expr1); + } else if ( +#line 1734 "cs.ATG" +la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) { + AssignmentOperator( +#line 1735 "cs.ATG" +out op); + Expr( +#line 1735 "cs.ATG" +out expr1); + +#line 1735 "cs.ATG" + expr = new AssignmentExpression(expr, op, expr1); + } else if (StartOf(8)) { + ConditionalOrExpr( +#line 1737 "cs.ATG" +ref expr); + if (la.kind == 13) { + lexer.NextToken(); + Expr( +#line 1738 "cs.ATG" +out expr1); + +#line 1738 "cs.ATG" + expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); + } + if (la.kind == 12) { + lexer.NextToken(); + Expr( +#line 1739 "cs.ATG" +out expr1); + Expect(9); + Expr( +#line 1739 "cs.ATG" +out expr2); + +#line 1739 "cs.ATG" + expr = new ConditionalExpression(expr, expr1, expr2); + } + } else SynErr(150); + +#line 1742 "cs.ATG" + if (expr != null) { + expr.StartLocation = startLocation; + expr.EndLocation = t.EndLocation; + } + + } + + void AttributeSection( +#line 287 "cs.ATG" +out AttributeSection section) { + +#line 289 "cs.ATG" + string attributeTarget = ""; + List attributes = new List(); + ASTAttribute attribute; + + + Expect(18); + +#line 295 "cs.ATG" + Location startPos = t.Location; + if ( +#line 296 "cs.ATG" +IsLocalAttrTarget()) { + if (la.kind == 69) { + lexer.NextToken(); + +#line 297 "cs.ATG" + attributeTarget = "event"; + } else if (la.kind == 101) { + lexer.NextToken(); + +#line 298 "cs.ATG" + attributeTarget = "return"; + } else { + Identifier(); + +#line 299 "cs.ATG" + if (t.val != "field" && t.val != "method" && + t.val != "param" && + t.val != "property" && t.val != "type") + Error("attribute target specifier (field, event, method, param, property, return or type) expected"); + attributeTarget = t.val; + + } + Expect(9); + } + Attribute( +#line 308 "cs.ATG" +out attribute); + +#line 308 "cs.ATG" + attributes.Add(attribute); + while ( +#line 309 "cs.ATG" +NotFinalComma()) { + Expect(14); + Attribute( +#line 309 "cs.ATG" +out attribute); + +#line 309 "cs.ATG" + attributes.Add(attribute); + } + if (la.kind == 14) { + lexer.NextToken(); + } + Expect(19); + +#line 311 "cs.ATG" + section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + + } + + void TypeModifier( +#line 670 "cs.ATG" +ModifierList m) { + switch (la.kind) { + case 89: { + lexer.NextToken(); + +#line 672 "cs.ATG" + m.Add(Modifiers.New, t.Location); + break; + } + case 98: { + lexer.NextToken(); + +#line 673 "cs.ATG" + m.Add(Modifiers.Public, t.Location); + break; + } + case 97: { + lexer.NextToken(); + +#line 674 "cs.ATG" + m.Add(Modifiers.Protected, t.Location); + break; + } + case 84: { + lexer.NextToken(); + +#line 675 "cs.ATG" + m.Add(Modifiers.Internal, t.Location); + break; + } + case 96: { + lexer.NextToken(); + +#line 676 "cs.ATG" + m.Add(Modifiers.Private, t.Location); + break; + } + case 119: { + lexer.NextToken(); + +#line 677 "cs.ATG" + m.Add(Modifiers.Unsafe, t.Location); + break; + } + case 49: { + lexer.NextToken(); + +#line 678 "cs.ATG" + m.Add(Modifiers.Abstract, t.Location); + break; + } + case 103: { + lexer.NextToken(); + +#line 679 "cs.ATG" + m.Add(Modifiers.Sealed, t.Location); + break; + } + case 107: { + lexer.NextToken(); + +#line 680 "cs.ATG" + m.Add(Modifiers.Static, t.Location); + break; + } + case 126: { + lexer.NextToken(); + +#line 681 "cs.ATG" + m.Add(Modifiers.Partial, t.Location); + break; + } + default: SynErr(151); break; + } + } + + void TypeDecl( +#line 347 "cs.ATG" +ModifierList m, List attributes) { + +#line 349 "cs.ATG" + TypeReference type; + List names; + List p = new List(); + string name; + List templates; + + if (la.kind == 59) { + +#line 355 "cs.ATG" + m.Check(Modifiers.Classes); + lexer.NextToken(); + +#line 356 "cs.ATG" + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + + newType.Type = Types.Class; + + Identifier(); + +#line 364 "cs.ATG" + newType.Name = t.val; + if (la.kind == 23) { + TypeParameterList( +#line 367 "cs.ATG" +templates); + } + if (la.kind == 9) { + ClassBase( +#line 369 "cs.ATG" +out names); + +#line 369 "cs.ATG" + newType.BaseTypes = names; + } + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 372 "cs.ATG" +templates); + } + +#line 374 "cs.ATG" + newType.BodyStartLocation = t.EndLocation; + Expect(16); + ClassBody(); + Expect(17); + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 378 "cs.ATG" + newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + + } else if (StartOf(9)) { + +#line 381 "cs.ATG" + m.Check(Modifiers.StructsInterfacesEnumsDelegates); + if (la.kind == 109) { + lexer.NextToken(); + +#line 382 "cs.ATG" + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + newType.StartLocation = m.GetDeclarationLocation(t.Location); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.Type = Types.Struct; + + Identifier(); + +#line 389 "cs.ATG" + newType.Name = t.val; + if (la.kind == 23) { + TypeParameterList( +#line 392 "cs.ATG" +templates); + } + if (la.kind == 9) { + StructInterfaces( +#line 394 "cs.ATG" +out names); + +#line 394 "cs.ATG" + newType.BaseTypes = names; + } + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 397 "cs.ATG" +templates); + } + +#line 400 "cs.ATG" + newType.BodyStartLocation = t.EndLocation; + StructBody(); + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 402 "cs.ATG" + newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + + } else if (la.kind == 83) { + lexer.NextToken(); + +#line 406 "cs.ATG" + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = Types.Interface; + + Identifier(); + +#line 413 "cs.ATG" + newType.Name = t.val; + if (la.kind == 23) { + TypeParameterList( +#line 416 "cs.ATG" +templates); + } + if (la.kind == 9) { + InterfaceBase( +#line 418 "cs.ATG" +out names); + +#line 418 "cs.ATG" + newType.BaseTypes = names; + } + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 421 "cs.ATG" +templates); + } + +#line 423 "cs.ATG" + newType.BodyStartLocation = t.EndLocation; + InterfaceBody(); + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 425 "cs.ATG" + newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + + } else if (la.kind == 68) { + lexer.NextToken(); + +#line 429 "cs.ATG" + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = Types.Enum; + + Identifier(); + +#line 435 "cs.ATG" + newType.Name = t.val; + if (la.kind == 9) { + lexer.NextToken(); + IntegralType( +#line 436 "cs.ATG" +out name); + +#line 436 "cs.ATG" + newType.BaseTypes.Add(new TypeReference(name)); + } + +#line 438 "cs.ATG" + newType.BodyStartLocation = t.EndLocation; + EnumBody(); + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 440 "cs.ATG" + newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + + } else { + lexer.NextToken(); + +#line 444 "cs.ATG" + DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); + templates = delegateDeclr.Templates; + delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); + + if ( +#line 448 "cs.ATG" +NotVoidPointer()) { + Expect(123); + +#line 448 "cs.ATG" + delegateDeclr.ReturnType = new TypeReference("void", 0, null); + } else if (StartOf(10)) { + Type( +#line 449 "cs.ATG" +out type); + +#line 449 "cs.ATG" + delegateDeclr.ReturnType = type; + } else SynErr(152); + Identifier(); + +#line 451 "cs.ATG" + delegateDeclr.Name = t.val; + if (la.kind == 23) { + TypeParameterList( +#line 454 "cs.ATG" +templates); + } + Expect(20); + if (StartOf(11)) { + FormalParameterList( +#line 456 "cs.ATG" +p); + +#line 456 "cs.ATG" + delegateDeclr.Parameters = p; + } + Expect(21); + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 460 "cs.ATG" +templates); + } + Expect(11); + +#line 462 "cs.ATG" + delegateDeclr.EndLocation = t.Location; + compilationUnit.AddChild(delegateDeclr); + + } + } else SynErr(153); + } + + void TypeParameterList( +#line 2291 "cs.ATG" +List templates) { + +#line 2293 "cs.ATG" + AttributeSection section; + List attributes = new List(); + + Expect(23); + while (la.kind == 18) { + AttributeSection( +#line 2297 "cs.ATG" +out section); + +#line 2297 "cs.ATG" + attributes.Add(section); + } + Identifier(); + +#line 2298 "cs.ATG" + templates.Add(new TemplateDefinition(t.val, attributes)); + while (la.kind == 14) { + lexer.NextToken(); + while (la.kind == 18) { + AttributeSection( +#line 2299 "cs.ATG" +out section); + +#line 2299 "cs.ATG" + attributes.Add(section); + } + Identifier(); + +#line 2300 "cs.ATG" + templates.Add(new TemplateDefinition(t.val, attributes)); + } + Expect(22); + } + + void ClassBase( +#line 477 "cs.ATG" +out List names) { + +#line 479 "cs.ATG" + TypeReference typeRef; + names = new List(); + + Expect(9); + ClassType( +#line 483 "cs.ATG" +out typeRef, false); + +#line 483 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + while (la.kind == 14) { + lexer.NextToken(); + TypeName( +#line 484 "cs.ATG" +out typeRef, false); + +#line 484 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + } + } + + void TypeParameterConstraintsClause( +#line 2304 "cs.ATG" +List templates) { + +#line 2305 "cs.ATG" + string name = ""; TypeReference type; + Expect(127); + Identifier(); + +#line 2308 "cs.ATG" + name = t.val; + Expect(9); + TypeParameterConstraintsClauseBase( +#line 2310 "cs.ATG" +out type); + +#line 2311 "cs.ATG" + TemplateDefinition td = null; + foreach (TemplateDefinition d in templates) { + if (d.Name == name) { + td = d; + break; + } + } + if ( td != null && type != null) { td.Bases.Add(type); } + + while (la.kind == 14) { + lexer.NextToken(); + TypeParameterConstraintsClauseBase( +#line 2320 "cs.ATG" +out type); + +#line 2321 "cs.ATG" + td = null; + foreach (TemplateDefinition d in templates) { + if (d.Name == name) { + td = d; + break; + } + } + if ( td != null && type != null) { td.Bases.Add(type); } + + } + } + + void ClassBody() { + +#line 488 "cs.ATG" + AttributeSection section; + while (StartOf(12)) { + +#line 490 "cs.ATG" + List attributes = new List(); + ModifierList m = new ModifierList(); + + while (!(StartOf(13))) {SynErr(154); lexer.NextToken(); } + while (la.kind == 18) { + AttributeSection( +#line 494 "cs.ATG" +out section); + +#line 494 "cs.ATG" + attributes.Add(section); + } + MemberModifiers( +#line 495 "cs.ATG" +m); + ClassMemberDecl( +#line 496 "cs.ATG" +m, attributes); + } + } + + void StructInterfaces( +#line 500 "cs.ATG" +out List names) { + +#line 502 "cs.ATG" + TypeReference typeRef; + names = new List(); + + Expect(9); + TypeName( +#line 506 "cs.ATG" +out typeRef, false); + +#line 506 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + while (la.kind == 14) { + lexer.NextToken(); + TypeName( +#line 507 "cs.ATG" +out typeRef, false); + +#line 507 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + } + } + + void StructBody() { + +#line 511 "cs.ATG" + AttributeSection section; + Expect(16); + while (StartOf(14)) { + +#line 514 "cs.ATG" + List attributes = new List(); + ModifierList m = new ModifierList(); + + while (la.kind == 18) { + AttributeSection( +#line 517 "cs.ATG" +out section); + +#line 517 "cs.ATG" + attributes.Add(section); + } + MemberModifiers( +#line 518 "cs.ATG" +m); + StructMemberDecl( +#line 519 "cs.ATG" +m, attributes); + } + Expect(17); + } + + void InterfaceBase( +#line 524 "cs.ATG" +out List names) { + +#line 526 "cs.ATG" + TypeReference typeRef; + names = new List(); + + Expect(9); + TypeName( +#line 530 "cs.ATG" +out typeRef, false); + +#line 530 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + while (la.kind == 14) { + lexer.NextToken(); + TypeName( +#line 531 "cs.ATG" +out typeRef, false); + +#line 531 "cs.ATG" + if (typeRef != null) { names.Add(typeRef); } + } + } + + void InterfaceBody() { + Expect(16); + while (StartOf(15)) { + while (!(StartOf(16))) {SynErr(155); lexer.NextToken(); } + InterfaceMemberDecl(); + } + Expect(17); + } + + void IntegralType( +#line 692 "cs.ATG" +out string name) { + +#line 692 "cs.ATG" + name = ""; + switch (la.kind) { + case 102: { + lexer.NextToken(); + +#line 694 "cs.ATG" + name = "sbyte"; + break; + } + case 54: { + lexer.NextToken(); + +#line 695 "cs.ATG" + name = "byte"; + break; + } + case 104: { + lexer.NextToken(); + +#line 696 "cs.ATG" + name = "short"; + break; + } + case 120: { + lexer.NextToken(); + +#line 697 "cs.ATG" + name = "ushort"; + break; + } + case 82: { + lexer.NextToken(); + +#line 698 "cs.ATG" + name = "int"; + break; + } + case 116: { + lexer.NextToken(); + +#line 699 "cs.ATG" + name = "uint"; + break; + } + case 87: { + lexer.NextToken(); + +#line 700 "cs.ATG" + name = "long"; + break; + } + case 117: { + lexer.NextToken(); + +#line 701 "cs.ATG" + name = "ulong"; + break; + } + case 57: { + lexer.NextToken(); + +#line 702 "cs.ATG" + name = "char"; + break; + } + default: SynErr(156); break; + } + } + + void EnumBody() { + +#line 540 "cs.ATG" + FieldDeclaration f; + Expect(16); + if (StartOf(17)) { + EnumMemberDecl( +#line 543 "cs.ATG" +out f); + +#line 543 "cs.ATG" + compilationUnit.AddChild(f); + while ( +#line 544 "cs.ATG" +NotFinalComma()) { + Expect(14); + EnumMemberDecl( +#line 545 "cs.ATG" +out f); + +#line 545 "cs.ATG" + compilationUnit.AddChild(f); + } + if (la.kind == 14) { + lexer.NextToken(); + } + } + Expect(17); + } + + void Type( +#line 551 "cs.ATG" +out TypeReference type) { + TypeWithRestriction( +#line 553 "cs.ATG" +out type, true, false); + } + + void FormalParameterList( +#line 614 "cs.ATG" +List parameter) { + +#line 617 "cs.ATG" + ParameterDeclarationExpression p; + AttributeSection section; + List attributes = new List(); + + while (la.kind == 18) { + AttributeSection( +#line 622 "cs.ATG" +out section); + +#line 622 "cs.ATG" + attributes.Add(section); + } + if (StartOf(18)) { + FixedParameter( +#line 624 "cs.ATG" +out p); + +#line 624 "cs.ATG" + bool paramsFound = false; + p.Attributes = attributes; + parameter.Add(p); + + while (la.kind == 14) { + lexer.NextToken(); + +#line 629 "cs.ATG" + attributes = new List(); if (paramsFound) Error("params array must be at end of parameter list"); + while (la.kind == 18) { + AttributeSection( +#line 630 "cs.ATG" +out section); + +#line 630 "cs.ATG" + attributes.Add(section); + } + if (StartOf(18)) { + FixedParameter( +#line 632 "cs.ATG" +out p); + +#line 632 "cs.ATG" + p.Attributes = attributes; parameter.Add(p); + } else if (la.kind == 95) { + ParameterArray( +#line 633 "cs.ATG" +out p); + +#line 633 "cs.ATG" + paramsFound = true; p.Attributes = attributes; parameter.Add(p); + } else SynErr(157); + } + } else if (la.kind == 95) { + ParameterArray( +#line 636 "cs.ATG" +out p); + +#line 636 "cs.ATG" + p.Attributes = attributes; parameter.Add(p); + } else SynErr(158); + } + + void ClassType( +#line 684 "cs.ATG" +out TypeReference typeRef, bool canBeUnbound) { + +#line 685 "cs.ATG" + TypeReference r; typeRef = null; + if (StartOf(19)) { + TypeName( +#line 687 "cs.ATG" +out r, canBeUnbound); + +#line 687 "cs.ATG" + typeRef = r; + } else if (la.kind == 91) { + lexer.NextToken(); + +#line 688 "cs.ATG" + typeRef = new TypeReference("object"); + } else if (la.kind == 108) { + lexer.NextToken(); + +#line 689 "cs.ATG" + typeRef = new TypeReference("string"); + } else SynErr(159); + } + + void TypeName( +#line 2234 "cs.ATG" +out TypeReference typeRef, bool canBeUnbound) { + +#line 2235 "cs.ATG" + List typeArguments = null; + string alias = null; + string qualident; + + if ( +#line 2240 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); + +#line 2241 "cs.ATG" + alias = t.val; + Expect(10); + } + Qualident( +#line 2244 "cs.ATG" +out qualident); + if (la.kind == 23) { + TypeArgumentList( +#line 2245 "cs.ATG" +out typeArguments, canBeUnbound); + } + +#line 2247 "cs.ATG" + if (alias == null) { + typeRef = new TypeReference(qualident, typeArguments); + } else if (alias == "global") { + typeRef = new TypeReference(qualident, typeArguments); + typeRef.IsGlobal = true; + } else { + typeRef = new TypeReference(alias + "." + qualident, typeArguments); + } + + while ( +#line 2256 "cs.ATG" +DotAndIdent()) { + Expect(15); + +#line 2257 "cs.ATG" + typeArguments = null; + Qualident( +#line 2258 "cs.ATG" +out qualident); + if (la.kind == 23) { + TypeArgumentList( +#line 2259 "cs.ATG" +out typeArguments, canBeUnbound); + } + +#line 2260 "cs.ATG" + typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); + } + } + + void MemberModifiers( +#line 705 "cs.ATG" +ModifierList m) { + while (StartOf(20)) { + switch (la.kind) { + case 49: { + lexer.NextToken(); + +#line 708 "cs.ATG" + m.Add(Modifiers.Abstract, t.Location); + break; + } + case 71: { + lexer.NextToken(); + +#line 709 "cs.ATG" + m.Add(Modifiers.Extern, t.Location); + break; + } + case 84: { + lexer.NextToken(); + +#line 710 "cs.ATG" + m.Add(Modifiers.Internal, t.Location); + break; + } + case 89: { + lexer.NextToken(); + +#line 711 "cs.ATG" + m.Add(Modifiers.New, t.Location); + break; + } + case 94: { + lexer.NextToken(); + +#line 712 "cs.ATG" + m.Add(Modifiers.Override, t.Location); + break; + } + case 96: { + lexer.NextToken(); + +#line 713 "cs.ATG" + m.Add(Modifiers.Private, t.Location); + break; + } + case 97: { + lexer.NextToken(); + +#line 714 "cs.ATG" + m.Add(Modifiers.Protected, t.Location); + break; + } + case 98: { + lexer.NextToken(); + +#line 715 "cs.ATG" + m.Add(Modifiers.Public, t.Location); + break; + } + case 99: { + lexer.NextToken(); + +#line 716 "cs.ATG" + m.Add(Modifiers.ReadOnly, t.Location); + break; + } + case 103: { + lexer.NextToken(); + +#line 717 "cs.ATG" + m.Add(Modifiers.Sealed, t.Location); + break; + } + case 107: { + lexer.NextToken(); + +#line 718 "cs.ATG" + m.Add(Modifiers.Static, t.Location); + break; + } + case 74: { + lexer.NextToken(); + +#line 719 "cs.ATG" + m.Add(Modifiers.Fixed, t.Location); + break; + } + case 119: { + lexer.NextToken(); + +#line 720 "cs.ATG" + m.Add(Modifiers.Unsafe, t.Location); + break; + } + case 122: { + lexer.NextToken(); + +#line 721 "cs.ATG" + m.Add(Modifiers.Virtual, t.Location); + break; + } + case 124: { + lexer.NextToken(); + +#line 722 "cs.ATG" + m.Add(Modifiers.Volatile, t.Location); + break; + } + case 126: { + lexer.NextToken(); + +#line 723 "cs.ATG" + m.Add(Modifiers.Partial, t.Location); + break; + } + } + } + } + + void ClassMemberDecl( +#line 1032 "cs.ATG" +ModifierList m, List attributes) { + +#line 1033 "cs.ATG" + Statement stmt = null; + if (StartOf(21)) { + StructMemberDecl( +#line 1035 "cs.ATG" +m, attributes); + } else if (la.kind == 27) { + +#line 1036 "cs.ATG" + m.Check(Modifiers.Destructors); Location startPos = t.Location; + lexer.NextToken(); + Identifier(); + +#line 1037 "cs.ATG" + DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); + d.Modifier = m.Modifier; + d.StartLocation = m.GetDeclarationLocation(startPos); + + Expect(20); + Expect(21); + +#line 1041 "cs.ATG" + d.EndLocation = t.EndLocation; + if (la.kind == 16) { + Block( +#line 1041 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(160); + +#line 1042 "cs.ATG" + d.Body = (BlockStatement)stmt; + compilationUnit.AddChild(d); + + } else SynErr(161); + } + + void StructMemberDecl( +#line 727 "cs.ATG" +ModifierList m, List attributes) { + +#line 729 "cs.ATG" + string qualident = null; + TypeReference type; + Expression expr; + List p = new List(); + Statement stmt = null; + List variableDeclarators = new List(); + List templates = new List(); + TypeReference explicitInterface = null; + bool isExtensionMethod = false; + + if (la.kind == 60) { + +#line 740 "cs.ATG" + m.Check(Modifiers.Constants); + lexer.NextToken(); + +#line 741 "cs.ATG" + Location startPos = t.Location; + Type( +#line 742 "cs.ATG" +out type); + Identifier(); + +#line 742 "cs.ATG" + FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); + fd.StartLocation = m.GetDeclarationLocation(startPos); + VariableDeclaration f = new VariableDeclaration(t.val); + fd.Fields.Add(f); + + Expect(3); + Expr( +#line 747 "cs.ATG" +out expr); + +#line 747 "cs.ATG" + f.Initializer = expr; + while (la.kind == 14) { + lexer.NextToken(); + Identifier(); + +#line 748 "cs.ATG" + f = new VariableDeclaration(t.val); + fd.Fields.Add(f); + + Expect(3); + Expr( +#line 751 "cs.ATG" +out expr); + +#line 751 "cs.ATG" + f.Initializer = expr; + } + Expect(11); + +#line 752 "cs.ATG" + fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); + } else if ( +#line 756 "cs.ATG" +NotVoidPointer()) { + +#line 756 "cs.ATG" + m.Check(Modifiers.PropertysEventsMethods); + Expect(123); + +#line 757 "cs.ATG" + Location startPos = t.Location; + if ( +#line 758 "cs.ATG" +IsExplicitInterfaceImplementation()) { + TypeName( +#line 759 "cs.ATG" +out explicitInterface, false); + +#line 760 "cs.ATG" + if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { + qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); + } + } else if (StartOf(19)) { + Identifier(); + +#line 763 "cs.ATG" + qualident = t.val; + } else SynErr(162); + if (la.kind == 23) { + TypeParameterList( +#line 766 "cs.ATG" +templates); + } + Expect(20); + if (la.kind == 111) { + lexer.NextToken(); + +#line 769 "cs.ATG" + isExtensionMethod = true; /* C# 3.0 */ + } + if (StartOf(11)) { + FormalParameterList( +#line 770 "cs.ATG" +p); + } + Expect(21); + +#line 771 "cs.ATG" + MethodDeclaration methodDeclaration = new MethodDeclaration { + Name = qualident, + Modifier = m.Modifier, + TypeReference = new TypeReference("void"), + Parameters = p, + Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation, + Templates = templates, + IsExtensionMethod = isExtensionMethod + }; + if (explicitInterface != null) + methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + compilationUnit.AddChild(methodDeclaration); + compilationUnit.BlockStart(methodDeclaration); + + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 789 "cs.ATG" +templates); + } + if (la.kind == 16) { + Block( +#line 791 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(163); + +#line 791 "cs.ATG" + compilationUnit.BlockEnd(); + methodDeclaration.Body = (BlockStatement)stmt; + + } else if (la.kind == 69) { + +#line 795 "cs.ATG" + m.Check(Modifiers.PropertysEventsMethods); + lexer.NextToken(); + +#line 797 "cs.ATG" + EventDeclaration eventDecl = new EventDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + StartLocation = t.Location + }; + compilationUnit.AddChild(eventDecl); + compilationUnit.BlockStart(eventDecl); + EventAddRegion addBlock = null; + EventRemoveRegion removeBlock = null; + + Type( +#line 807 "cs.ATG" +out type); + +#line 807 "cs.ATG" + eventDecl.TypeReference = type; + if ( +#line 808 "cs.ATG" +IsExplicitInterfaceImplementation()) { + TypeName( +#line 809 "cs.ATG" +out explicitInterface, false); + +#line 810 "cs.ATG" + qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); + +#line 811 "cs.ATG" + eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + } else if (StartOf(19)) { + Identifier(); + +#line 813 "cs.ATG" + qualident = t.val; + } else SynErr(164); + +#line 815 "cs.ATG" + eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; + if (la.kind == 3) { + lexer.NextToken(); + Expr( +#line 816 "cs.ATG" +out expr); + +#line 816 "cs.ATG" + eventDecl.Initializer = expr; + } + if (la.kind == 16) { + lexer.NextToken(); + +#line 817 "cs.ATG" + eventDecl.BodyStart = t.Location; + EventAccessorDecls( +#line 818 "cs.ATG" +out addBlock, out removeBlock); + Expect(17); + +#line 819 "cs.ATG" + eventDecl.BodyEnd = t.EndLocation; + } + if (la.kind == 11) { + lexer.NextToken(); + } + +#line 822 "cs.ATG" + compilationUnit.BlockEnd(); + eventDecl.AddRegion = addBlock; + eventDecl.RemoveRegion = removeBlock; + + } else if ( +#line 828 "cs.ATG" +IdentAndLPar()) { + +#line 828 "cs.ATG" + m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); + Identifier(); + +#line 829 "cs.ATG" + string name = t.val; Location startPos = t.Location; + Expect(20); + if (StartOf(11)) { + +#line 829 "cs.ATG" + m.Check(Modifiers.Constructors); + FormalParameterList( +#line 830 "cs.ATG" +p); + } + Expect(21); + +#line 832 "cs.ATG" + ConstructorInitializer init = null; + if (la.kind == 9) { + +#line 833 "cs.ATG" + m.Check(Modifiers.Constructors); + ConstructorInitializer( +#line 834 "cs.ATG" +out init); + } + +#line 836 "cs.ATG" + ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes); + cd.StartLocation = startPos; + cd.EndLocation = t.EndLocation; + + if (la.kind == 16) { + Block( +#line 841 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(165); + +#line 841 "cs.ATG" + cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); + } else if (la.kind == 70 || la.kind == 80) { + +#line 844 "cs.ATG" + m.Check(Modifiers.Operators); + if (m.isNone) Error("at least one modifier must be set"); + bool isImplicit = true; + Location startPos = Location.Empty; + + if (la.kind == 80) { + lexer.NextToken(); + +#line 849 "cs.ATG" + startPos = t.Location; + } else { + lexer.NextToken(); + +#line 849 "cs.ATG" + isImplicit = false; startPos = t.Location; + } + Expect(92); + Type( +#line 850 "cs.ATG" +out type); + +#line 850 "cs.ATG" + TypeReference operatorType = type; + Expect(20); + Type( +#line 851 "cs.ATG" +out type); + Identifier(); + +#line 851 "cs.ATG" + string varName = t.val; + Expect(21); + +#line 852 "cs.ATG" + Location endPos = t.Location; + if (la.kind == 16) { + Block( +#line 853 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + +#line 853 "cs.ATG" + stmt = null; + } else SynErr(166); + +#line 856 "cs.ATG" + List parameters = new List(); + parameters.Add(new ParameterDeclarationExpression(type, varName)); + OperatorDeclaration operatorDeclaration = new OperatorDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + Parameters = parameters, + TypeReference = operatorType, + ConversionType = isImplicit ? ConversionType.Implicit : ConversionType.Explicit, + Body = (BlockStatement)stmt, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = endPos + }; + compilationUnit.AddChild(operatorDeclaration); + + } else if (StartOf(22)) { + TypeDecl( +#line 873 "cs.ATG" +m, attributes); + } else if (StartOf(10)) { + Type( +#line 875 "cs.ATG" +out type); + +#line 875 "cs.ATG" + Location startPos = t.Location; + if (la.kind == 92) { + +#line 877 "cs.ATG" + OverloadableOperatorType op; + m.Check(Modifiers.Operators); + if (m.isNone) Error("at least one modifier must be set"); + + lexer.NextToken(); + OverloadableOperator( +#line 881 "cs.ATG" +out op); + +#line 881 "cs.ATG" + TypeReference firstType, secondType = null; string secondName = null; + Expect(20); + Type( +#line 882 "cs.ATG" +out firstType); + Identifier(); + +#line 882 "cs.ATG" + string firstName = t.val; + if (la.kind == 14) { + lexer.NextToken(); + Type( +#line 883 "cs.ATG" +out secondType); + Identifier(); + +#line 883 "cs.ATG" + secondName = t.val; + } else if (la.kind == 21) { + } else SynErr(167); + +#line 891 "cs.ATG" + Location endPos = t.Location; + Expect(21); + if (la.kind == 16) { + Block( +#line 892 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(168); + +#line 894 "cs.ATG" + List parameters = new List(); + parameters.Add(new ParameterDeclarationExpression(firstType, firstName)); + if (secondType != null) { + parameters.Add(new ParameterDeclarationExpression(secondType, secondName)); + } + OperatorDeclaration operatorDeclaration = new OperatorDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + Parameters = parameters, + TypeReference = type, + OverloadableOperator = op, + Body = (BlockStatement)stmt, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = endPos + }; + compilationUnit.AddChild(operatorDeclaration); + + } else if ( +#line 913 "cs.ATG" +IsVarDecl()) { + +#line 914 "cs.ATG" + m.Check(Modifiers.Fields); + FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); + fd.StartLocation = m.GetDeclarationLocation(startPos); + + if ( +#line 918 "cs.ATG" +m.Contains(Modifiers.Fixed)) { + VariableDeclarator( +#line 919 "cs.ATG" +variableDeclarators); + Expect(18); + Expr( +#line 921 "cs.ATG" +out expr); + +#line 921 "cs.ATG" + if (variableDeclarators.Count > 0) + variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; + Expect(19); + while (la.kind == 14) { + lexer.NextToken(); + VariableDeclarator( +#line 925 "cs.ATG" +variableDeclarators); + Expect(18); + Expr( +#line 927 "cs.ATG" +out expr); + +#line 927 "cs.ATG" + if (variableDeclarators.Count > 0) + variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; + Expect(19); + } + } else if (StartOf(19)) { + VariableDeclarator( +#line 932 "cs.ATG" +variableDeclarators); + while (la.kind == 14) { + lexer.NextToken(); + VariableDeclarator( +#line 933 "cs.ATG" +variableDeclarators); + } + } else SynErr(169); + Expect(11); + +#line 935 "cs.ATG" + fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); + } else if (la.kind == 111) { + +#line 938 "cs.ATG" + m.Check(Modifiers.Indexers); + lexer.NextToken(); + Expect(18); + FormalParameterList( +#line 939 "cs.ATG" +p); + Expect(19); + +#line 939 "cs.ATG" + Location endLocation = t.EndLocation; + Expect(16); + +#line 940 "cs.ATG" + IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); + indexer.StartLocation = startPos; + indexer.EndLocation = endLocation; + indexer.BodyStart = t.Location; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + AccessorDecls( +#line 947 "cs.ATG" +out getRegion, out setRegion); + Expect(17); + +#line 948 "cs.ATG" + indexer.BodyEnd = t.EndLocation; + indexer.GetRegion = getRegion; + indexer.SetRegion = setRegion; + compilationUnit.AddChild(indexer); + + } else if ( +#line 953 "cs.ATG" +IsIdentifierToken(la)) { + if ( +#line 954 "cs.ATG" +IsExplicitInterfaceImplementation()) { + TypeName( +#line 955 "cs.ATG" +out explicitInterface, false); + +#line 956 "cs.ATG" + if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { + qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); + } + } else if (StartOf(19)) { + Identifier(); + +#line 959 "cs.ATG" + qualident = t.val; + } else SynErr(170); + +#line 961 "cs.ATG" + Location qualIdentEndLocation = t.EndLocation; + if (la.kind == 16 || la.kind == 20 || la.kind == 23) { + if (la.kind == 20 || la.kind == 23) { + +#line 965 "cs.ATG" + m.Check(Modifiers.PropertysEventsMethods); + if (la.kind == 23) { + TypeParameterList( +#line 967 "cs.ATG" +templates); + } + Expect(20); + if (la.kind == 111) { + lexer.NextToken(); + +#line 969 "cs.ATG" + isExtensionMethod = true; + } + if (StartOf(11)) { + FormalParameterList( +#line 970 "cs.ATG" +p); + } + Expect(21); + +#line 972 "cs.ATG" + MethodDeclaration methodDeclaration = new MethodDeclaration { + Name = qualident, + Modifier = m.Modifier, + TypeReference = type, + Parameters = p, + Attributes = attributes + }; + if (explicitInterface != null) + methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); + methodDeclaration.EndLocation = t.EndLocation; + methodDeclaration.IsExtensionMethod = isExtensionMethod; + methodDeclaration.Templates = templates; + compilationUnit.AddChild(methodDeclaration); + + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 987 "cs.ATG" +templates); + } + if (la.kind == 16) { + Block( +#line 988 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(171); + +#line 988 "cs.ATG" + methodDeclaration.Body = (BlockStatement)stmt; + } else { + lexer.NextToken(); + +#line 991 "cs.ATG" + PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes); + if (explicitInterface != null) + pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + pDecl.StartLocation = m.GetDeclarationLocation(startPos); + pDecl.EndLocation = qualIdentEndLocation; + pDecl.BodyStart = t.Location; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + AccessorDecls( +#line 1000 "cs.ATG" +out getRegion, out setRegion); + Expect(17); + +#line 1002 "cs.ATG" + pDecl.GetRegion = getRegion; + pDecl.SetRegion = setRegion; + pDecl.BodyEnd = t.EndLocation; + compilationUnit.AddChild(pDecl); + + } + } else if (la.kind == 15) { + +#line 1010 "cs.ATG" + m.Check(Modifiers.Indexers); + lexer.NextToken(); + Expect(111); + Expect(18); + FormalParameterList( +#line 1011 "cs.ATG" +p); + Expect(19); + +#line 1012 "cs.ATG" + IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); + indexer.StartLocation = m.GetDeclarationLocation(startPos); + indexer.EndLocation = t.EndLocation; + if (explicitInterface != null) + indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this")); + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + Expect(16); + +#line 1020 "cs.ATG" + Location bodyStart = t.Location; + AccessorDecls( +#line 1021 "cs.ATG" +out getRegion, out setRegion); + Expect(17); + +#line 1022 "cs.ATG" + indexer.BodyStart = bodyStart; + indexer.BodyEnd = t.EndLocation; + indexer.GetRegion = getRegion; + indexer.SetRegion = setRegion; + compilationUnit.AddChild(indexer); + + } else SynErr(172); + } else SynErr(173); + } else SynErr(174); + } + + void InterfaceMemberDecl() { + +#line 1049 "cs.ATG" + TypeReference type; + + AttributeSection section; + Modifiers mod = Modifiers.None; + List attributes = new List(); + List parameters = new List(); + string name; + PropertyGetRegion getBlock; + PropertySetRegion setBlock; + Location startLocation = new Location(-1, -1); + List templates = new List(); + + while (la.kind == 18) { + AttributeSection( +#line 1062 "cs.ATG" +out section); + +#line 1062 "cs.ATG" + attributes.Add(section); + } + if (la.kind == 89) { + lexer.NextToken(); + +#line 1063 "cs.ATG" + mod = Modifiers.New; startLocation = t.Location; + } + if ( +#line 1066 "cs.ATG" +NotVoidPointer()) { + Expect(123); + +#line 1066 "cs.ATG" + if (startLocation.X == -1) startLocation = t.Location; + Identifier(); + +#line 1067 "cs.ATG" + name = t.val; + if (la.kind == 23) { + TypeParameterList( +#line 1068 "cs.ATG" +templates); + } + Expect(20); + if (StartOf(11)) { + FormalParameterList( +#line 1069 "cs.ATG" +parameters); + } + Expect(21); + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 1070 "cs.ATG" +templates); + } + Expect(11); + +#line 1072 "cs.ATG" + MethodDeclaration md = new MethodDeclaration { + Name = name, Modifier = mod, TypeReference = new TypeReference("void"), + Parameters = parameters, Attributes = attributes, Templates = templates, + StartLocation = startLocation, EndLocation = t.EndLocation + }; + compilationUnit.AddChild(md); + + } else if (StartOf(23)) { + if (StartOf(10)) { + Type( +#line 1080 "cs.ATG" +out type); + +#line 1080 "cs.ATG" + if (startLocation.X == -1) startLocation = t.Location; + if (StartOf(19)) { + Identifier(); + +#line 1082 "cs.ATG" + name = t.val; Location qualIdentEndLocation = t.EndLocation; + if (la.kind == 20 || la.kind == 23) { + if (la.kind == 23) { + TypeParameterList( +#line 1086 "cs.ATG" +templates); + } + Expect(20); + if (StartOf(11)) { + FormalParameterList( +#line 1087 "cs.ATG" +parameters); + } + Expect(21); + while (la.kind == 127) { + TypeParameterConstraintsClause( +#line 1089 "cs.ATG" +templates); + } + Expect(11); + +#line 1090 "cs.ATG" + MethodDeclaration md = new MethodDeclaration { + Name = name, Modifier = mod, TypeReference = type, + Parameters = parameters, Attributes = attributes, Templates = templates, + StartLocation = startLocation, EndLocation = t.EndLocation + }; + compilationUnit.AddChild(md); + + } else if (la.kind == 16) { + +#line 1098 "cs.ATG" + PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); + lexer.NextToken(); + +#line 1099 "cs.ATG" + Location bodyStart = t.Location; + InterfaceAccessors( +#line 1099 "cs.ATG" +out getBlock, out setBlock); + Expect(17); + +#line 1099 "cs.ATG" + pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; + } else SynErr(175); + } else if (la.kind == 111) { + lexer.NextToken(); + Expect(18); + FormalParameterList( +#line 1102 "cs.ATG" +parameters); + Expect(19); + +#line 1102 "cs.ATG" + Location bracketEndLocation = t.EndLocation; + +#line 1102 "cs.ATG" + IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); + Expect(16); + +#line 1103 "cs.ATG" + Location bodyStart = t.Location; + InterfaceAccessors( +#line 1103 "cs.ATG" +out getBlock, out setBlock); + Expect(17); + +#line 1103 "cs.ATG" + id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation; + } else SynErr(176); + } else { + lexer.NextToken(); + +#line 1106 "cs.ATG" + if (startLocation.X == -1) startLocation = t.Location; + Type( +#line 1107 "cs.ATG" +out type); + Identifier(); + +#line 1108 "cs.ATG" + EventDeclaration ed = new EventDeclaration { + TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes + }; + compilationUnit.AddChild(ed); + + Expect(11); + +#line 1113 "cs.ATG" + ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; + } + } else SynErr(177); + } + + void EnumMemberDecl( +#line 1118 "cs.ATG" +out FieldDeclaration f) { + +#line 1120 "cs.ATG" + Expression expr = null; + List attributes = new List(); + AttributeSection section = null; + VariableDeclaration varDecl = null; + + while (la.kind == 18) { + AttributeSection( +#line 1126 "cs.ATG" +out section); + +#line 1126 "cs.ATG" + attributes.Add(section); + } + Identifier(); + +#line 1127 "cs.ATG" + f = new FieldDeclaration(attributes); + varDecl = new VariableDeclaration(t.val); + f.Fields.Add(varDecl); + f.StartLocation = t.Location; + + if (la.kind == 3) { + lexer.NextToken(); + Expr( +#line 1132 "cs.ATG" +out expr); + +#line 1132 "cs.ATG" + varDecl.Initializer = expr; + } + } + + void TypeWithRestriction( +#line 556 "cs.ATG" +out TypeReference type, bool allowNullable, bool canBeUnbound) { + +#line 558 "cs.ATG" + string name; + int pointer = 0; + type = null; + + if (StartOf(4)) { + ClassType( +#line 563 "cs.ATG" +out type, canBeUnbound); + } else if (StartOf(5)) { + SimpleType( +#line 564 "cs.ATG" +out name); + +#line 564 "cs.ATG" + type = new TypeReference(name); + } else if (la.kind == 123) { + lexer.NextToken(); + Expect(6); + +#line 565 "cs.ATG" + pointer = 1; type = new TypeReference("void"); + } else SynErr(178); + +#line 566 "cs.ATG" + List r = new List(); + if ( +#line 568 "cs.ATG" +allowNullable && la.kind == Tokens.Question) { + NullableQuestionMark( +#line 568 "cs.ATG" +ref type); + } + while ( +#line 570 "cs.ATG" +IsPointerOrDims()) { + +#line 570 "cs.ATG" + int i = 0; + if (la.kind == 6) { + lexer.NextToken(); + +#line 571 "cs.ATG" + ++pointer; + } else if (la.kind == 18) { + lexer.NextToken(); + while (la.kind == 14) { + lexer.NextToken(); + +#line 572 "cs.ATG" + ++i; + } + Expect(19); + +#line 572 "cs.ATG" + r.Add(i); + } else SynErr(179); + } + +#line 575 "cs.ATG" + if (type != null) { + type.RankSpecifier = r.ToArray(); + type.PointerNestingLevel = pointer; + } + + } + + void SimpleType( +#line 603 "cs.ATG" +out string name) { + +#line 604 "cs.ATG" + name = String.Empty; + if (StartOf(24)) { + IntegralType( +#line 606 "cs.ATG" +out name); + } else if (la.kind == 75) { + lexer.NextToken(); + +#line 607 "cs.ATG" + name = "float"; + } else if (la.kind == 66) { + lexer.NextToken(); + +#line 608 "cs.ATG" + name = "double"; + } else if (la.kind == 62) { + lexer.NextToken(); + +#line 609 "cs.ATG" + name = "decimal"; + } else if (la.kind == 52) { + lexer.NextToken(); + +#line 610 "cs.ATG" + name = "bool"; + } else SynErr(180); + } + + void NullableQuestionMark( +#line 2265 "cs.ATG" +ref TypeReference typeRef) { + +#line 2266 "cs.ATG" + List typeArguments = new List(1); + Expect(12); + +#line 2270 "cs.ATG" + if (typeRef != null) typeArguments.Add(typeRef); + typeRef = new TypeReference("System.Nullable", typeArguments); + + } + + void FixedParameter( +#line 640 "cs.ATG" +out ParameterDeclarationExpression p) { + +#line 642 "cs.ATG" + TypeReference type; + ParameterModifiers mod = ParameterModifiers.In; + Location start = t.Location; + + if (la.kind == 93 || la.kind == 100) { + if (la.kind == 100) { + lexer.NextToken(); + +#line 648 "cs.ATG" + mod = ParameterModifiers.Ref; + } else { + lexer.NextToken(); + +#line 649 "cs.ATG" + mod = ParameterModifiers.Out; + } + } + Type( +#line 651 "cs.ATG" +out type); + Identifier(); + +#line 651 "cs.ATG" + p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; + } + + void ParameterArray( +#line 654 "cs.ATG" +out ParameterDeclarationExpression p) { + +#line 655 "cs.ATG" + TypeReference type; + Expect(95); + Type( +#line 657 "cs.ATG" +out type); + Identifier(); + +#line 657 "cs.ATG" + p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); + } + + void AccessorModifiers( +#line 660 "cs.ATG" +out ModifierList m) { + +#line 661 "cs.ATG" + m = new ModifierList(); + if (la.kind == 96) { + lexer.NextToken(); + +#line 663 "cs.ATG" + m.Add(Modifiers.Private, t.Location); + } else if (la.kind == 97) { + lexer.NextToken(); + +#line 664 "cs.ATG" + m.Add(Modifiers.Protected, t.Location); + if (la.kind == 84) { + lexer.NextToken(); + +#line 665 "cs.ATG" + m.Add(Modifiers.Internal, t.Location); + } + } else if (la.kind == 84) { + lexer.NextToken(); + +#line 666 "cs.ATG" + m.Add(Modifiers.Internal, t.Location); + if (la.kind == 97) { + lexer.NextToken(); + +#line 667 "cs.ATG" + m.Add(Modifiers.Protected, t.Location); + } + } else SynErr(181); + } + + void Block( +#line 1251 "cs.ATG" +out Statement stmt) { + Expect(16); + +#line 1253 "cs.ATG" + BlockStatement blockStmt = new BlockStatement(); + blockStmt.StartLocation = t.Location; + compilationUnit.BlockStart(blockStmt); + if (!ParseMethodBodies) lexer.SkipCurrentBlock(0); + + while (StartOf(25)) { + Statement(); + } + Expect(17); + +#line 1260 "cs.ATG" + stmt = blockStmt; + blockStmt.EndLocation = t.EndLocation; + compilationUnit.BlockEnd(); + + } + + void EventAccessorDecls( +#line 1189 "cs.ATG" +out EventAddRegion addBlock, out EventRemoveRegion removeBlock) { + +#line 1190 "cs.ATG" + AttributeSection section; + List attributes = new List(); + Statement stmt; + addBlock = null; + removeBlock = null; + + while (la.kind == 18) { + AttributeSection( +#line 1197 "cs.ATG" +out section); + +#line 1197 "cs.ATG" + attributes.Add(section); + } + if (la.kind == 130) { + +#line 1199 "cs.ATG" + addBlock = new EventAddRegion(attributes); + AddAccessorDecl( +#line 1200 "cs.ATG" +out stmt); + +#line 1200 "cs.ATG" + attributes = new List(); addBlock.Block = (BlockStatement)stmt; + while (la.kind == 18) { + AttributeSection( +#line 1201 "cs.ATG" +out section); + +#line 1201 "cs.ATG" + attributes.Add(section); + } + RemoveAccessorDecl( +#line 1202 "cs.ATG" +out stmt); + +#line 1202 "cs.ATG" + removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; + } else if (la.kind == 131) { + RemoveAccessorDecl( +#line 1204 "cs.ATG" +out stmt); + +#line 1204 "cs.ATG" + removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List(); + while (la.kind == 18) { + AttributeSection( +#line 1205 "cs.ATG" +out section); + +#line 1205 "cs.ATG" + attributes.Add(section); + } + AddAccessorDecl( +#line 1206 "cs.ATG" +out stmt); + +#line 1206 "cs.ATG" + addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; + } else SynErr(182); + } + + void ConstructorInitializer( +#line 1280 "cs.ATG" +out ConstructorInitializer ci) { + +#line 1281 "cs.ATG" + Expression expr; ci = new ConstructorInitializer(); + Expect(9); + if (la.kind == 51) { + lexer.NextToken(); + +#line 1285 "cs.ATG" + ci.ConstructorInitializerType = ConstructorInitializerType.Base; + } else if (la.kind == 111) { + lexer.NextToken(); + +#line 1286 "cs.ATG" + ci.ConstructorInitializerType = ConstructorInitializerType.This; + } else SynErr(183); + Expect(20); + if (StartOf(26)) { + Argument( +#line 1289 "cs.ATG" +out expr); + +#line 1289 "cs.ATG" + if (expr != null) { ci.Arguments.Add(expr); } + while (la.kind == 14) { + lexer.NextToken(); + Argument( +#line 1289 "cs.ATG" +out expr); + +#line 1289 "cs.ATG" + if (expr != null) { ci.Arguments.Add(expr); } + } + } + Expect(21); + } + + void OverloadableOperator( +#line 1301 "cs.ATG" +out OverloadableOperatorType op) { + +#line 1302 "cs.ATG" + op = OverloadableOperatorType.None; + switch (la.kind) { + case 4: { + lexer.NextToken(); + +#line 1304 "cs.ATG" + op = OverloadableOperatorType.Add; + break; + } + case 5: { + lexer.NextToken(); + +#line 1305 "cs.ATG" + op = OverloadableOperatorType.Subtract; + break; + } + case 24: { + lexer.NextToken(); + +#line 1307 "cs.ATG" + op = OverloadableOperatorType.Not; + break; + } + case 27: { + lexer.NextToken(); + +#line 1308 "cs.ATG" + op = OverloadableOperatorType.BitNot; + break; + } + case 31: { + lexer.NextToken(); + +#line 1310 "cs.ATG" + op = OverloadableOperatorType.Increment; + break; + } + case 32: { + lexer.NextToken(); + +#line 1311 "cs.ATG" + op = OverloadableOperatorType.Decrement; + break; + } + case 113: { + lexer.NextToken(); + +#line 1313 "cs.ATG" + op = OverloadableOperatorType.IsTrue; + break; + } + case 72: { + lexer.NextToken(); + +#line 1314 "cs.ATG" + op = OverloadableOperatorType.IsFalse; + break; + } + case 6: { + lexer.NextToken(); + +#line 1316 "cs.ATG" + op = OverloadableOperatorType.Multiply; + break; + } + case 7: { + lexer.NextToken(); + +#line 1317 "cs.ATG" + op = OverloadableOperatorType.Divide; + break; + } + case 8: { + lexer.NextToken(); + +#line 1318 "cs.ATG" + op = OverloadableOperatorType.Modulus; + break; + } + case 28: { + lexer.NextToken(); + +#line 1320 "cs.ATG" + op = OverloadableOperatorType.BitwiseAnd; + break; + } + case 29: { + lexer.NextToken(); + +#line 1321 "cs.ATG" + op = OverloadableOperatorType.BitwiseOr; + break; + } + case 30: { + lexer.NextToken(); + +#line 1322 "cs.ATG" + op = OverloadableOperatorType.ExclusiveOr; + break; + } + case 37: { + lexer.NextToken(); + +#line 1324 "cs.ATG" + op = OverloadableOperatorType.ShiftLeft; + break; + } + case 33: { + lexer.NextToken(); + +#line 1325 "cs.ATG" + op = OverloadableOperatorType.Equality; + break; + } + case 34: { + lexer.NextToken(); + +#line 1326 "cs.ATG" + op = OverloadableOperatorType.InEquality; + break; + } + case 23: { + lexer.NextToken(); + +#line 1327 "cs.ATG" + op = OverloadableOperatorType.LessThan; + break; + } + case 35: { + lexer.NextToken(); + +#line 1328 "cs.ATG" + op = OverloadableOperatorType.GreaterThanOrEqual; + break; + } + case 36: { + lexer.NextToken(); + +#line 1329 "cs.ATG" + op = OverloadableOperatorType.LessThanOrEqual; + break; + } + case 22: { + lexer.NextToken(); + +#line 1330 "cs.ATG" + op = OverloadableOperatorType.GreaterThan; + if (la.kind == 22) { + lexer.NextToken(); + +#line 1330 "cs.ATG" + op = OverloadableOperatorType.ShiftRight; + } + break; + } + default: SynErr(184); break; + } + } + + void VariableDeclarator( +#line 1244 "cs.ATG" +List fieldDeclaration) { + +#line 1245 "cs.ATG" + Expression expr = null; + Identifier(); + +#line 1247 "cs.ATG" + VariableDeclaration f = new VariableDeclaration(t.val); + if (la.kind == 3) { + lexer.NextToken(); + VariableInitializer( +#line 1248 "cs.ATG" +out expr); + +#line 1248 "cs.ATG" + f.Initializer = expr; + } + +#line 1248 "cs.ATG" + fieldDeclaration.Add(f); + } + + void AccessorDecls( +#line 1136 "cs.ATG" +out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { + +#line 1138 "cs.ATG" + List attributes = new List(); + AttributeSection section; + getBlock = null; + setBlock = null; + ModifierList modifiers = null; + + while (la.kind == 18) { + AttributeSection( +#line 1145 "cs.ATG" +out section); + +#line 1145 "cs.ATG" + attributes.Add(section); + } + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { + AccessorModifiers( +#line 1146 "cs.ATG" +out modifiers); + } + if (la.kind == 128) { + GetAccessorDecl( +#line 1148 "cs.ATG" +out getBlock, attributes); + +#line 1149 "cs.ATG" + if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } + if (StartOf(27)) { + +#line 1150 "cs.ATG" + attributes = new List(); modifiers = null; + while (la.kind == 18) { + AttributeSection( +#line 1151 "cs.ATG" +out section); + +#line 1151 "cs.ATG" + attributes.Add(section); + } + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { + AccessorModifiers( +#line 1152 "cs.ATG" +out modifiers); + } + SetAccessorDecl( +#line 1153 "cs.ATG" +out setBlock, attributes); + +#line 1154 "cs.ATG" + if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } + } + } else if (la.kind == 129) { + SetAccessorDecl( +#line 1157 "cs.ATG" +out setBlock, attributes); + +#line 1158 "cs.ATG" + if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } + if (StartOf(28)) { + +#line 1159 "cs.ATG" + attributes = new List(); modifiers = null; + while (la.kind == 18) { + AttributeSection( +#line 1160 "cs.ATG" +out section); + +#line 1160 "cs.ATG" + attributes.Add(section); + } + if (la.kind == 84 || la.kind == 96 || la.kind == 97) { + AccessorModifiers( +#line 1161 "cs.ATG" +out modifiers); + } + GetAccessorDecl( +#line 1162 "cs.ATG" +out getBlock, attributes); + +#line 1163 "cs.ATG" + if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } + } + } else if (StartOf(19)) { + Identifier(); + +#line 1165 "cs.ATG" + Error("get or set accessor declaration expected"); + } else SynErr(185); + } + + void InterfaceAccessors( +#line 1210 "cs.ATG" +out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { + +#line 1212 "cs.ATG" + AttributeSection section; + List attributes = new List(); + getBlock = null; setBlock = null; + PropertyGetSetRegion lastBlock = null; + + while (la.kind == 18) { + AttributeSection( +#line 1218 "cs.ATG" +out section); + +#line 1218 "cs.ATG" + attributes.Add(section); + } + +#line 1219 "cs.ATG" + Location startLocation = la.Location; + if (la.kind == 128) { + lexer.NextToken(); + +#line 1221 "cs.ATG" + getBlock = new PropertyGetRegion(null, attributes); + } else if (la.kind == 129) { + lexer.NextToken(); + +#line 1222 "cs.ATG" + setBlock = new PropertySetRegion(null, attributes); + } else SynErr(186); + Expect(11); + +#line 1225 "cs.ATG" + if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } + if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; } + attributes = new List(); + if (la.kind == 18 || la.kind == 128 || la.kind == 129) { + while (la.kind == 18) { + AttributeSection( +#line 1229 "cs.ATG" +out section); + +#line 1229 "cs.ATG" + attributes.Add(section); + } + +#line 1230 "cs.ATG" + startLocation = la.Location; + if (la.kind == 128) { + lexer.NextToken(); + +#line 1232 "cs.ATG" + if (getBlock != null) Error("get already declared"); + else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } + + } else if (la.kind == 129) { + lexer.NextToken(); + +#line 1235 "cs.ATG" + if (setBlock != null) Error("set already declared"); + else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } + + } else SynErr(187); + Expect(11); + +#line 1240 "cs.ATG" + if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } + } + } + + void GetAccessorDecl( +#line 1169 "cs.ATG" +out PropertyGetRegion getBlock, List attributes) { + +#line 1170 "cs.ATG" + Statement stmt = null; + Expect(128); + +#line 1173 "cs.ATG" + Location startLocation = t.Location; + if (la.kind == 16) { + Block( +#line 1174 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(188); + +#line 1175 "cs.ATG" + getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); + +#line 1176 "cs.ATG" + getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; + } + + void SetAccessorDecl( +#line 1179 "cs.ATG" +out PropertySetRegion setBlock, List attributes) { + +#line 1180 "cs.ATG" + Statement stmt = null; + Expect(129); + +#line 1183 "cs.ATG" + Location startLocation = t.Location; + if (la.kind == 16) { + Block( +#line 1184 "cs.ATG" +out stmt); + } else if (la.kind == 11) { + lexer.NextToken(); + } else SynErr(189); + +#line 1185 "cs.ATG" + setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); + +#line 1186 "cs.ATG" + setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; + } + + void AddAccessorDecl( +#line 1266 "cs.ATG" +out Statement stmt) { + +#line 1267 "cs.ATG" + stmt = null; + Expect(130); + Block( +#line 1270 "cs.ATG" +out stmt); + } + + void RemoveAccessorDecl( +#line 1273 "cs.ATG" +out Statement stmt) { + +#line 1274 "cs.ATG" + stmt = null; + Expect(131); + Block( +#line 1277 "cs.ATG" +out stmt); + } + + void VariableInitializer( +#line 1293 "cs.ATG" +out Expression initializerExpression) { + +#line 1294 "cs.ATG" + TypeReference type = null; Expression expr = null; initializerExpression = null; + if (StartOf(6)) { + Expr( +#line 1296 "cs.ATG" +out initializerExpression); + } else if (la.kind == 16) { + CollectionInitializer( +#line 1297 "cs.ATG" +out initializerExpression); + } else if (la.kind == 106) { + lexer.NextToken(); + Type( +#line 1298 "cs.ATG" +out type); + Expect(18); + Expr( +#line 1298 "cs.ATG" +out expr); + Expect(19); + +#line 1298 "cs.ATG" + initializerExpression = new StackAllocExpression(type, expr); + } else SynErr(190); + } + + void Statement() { + +#line 1439 "cs.ATG" + TypeReference type; + Expression expr; + Statement stmt = null; + Location startPos = la.Location; + + while (!(StartOf(29))) {SynErr(191); lexer.NextToken(); } + if ( +#line 1448 "cs.ATG" +IsLabel()) { + Identifier(); + +#line 1448 "cs.ATG" + compilationUnit.AddChild(new LabelStatement(t.val)); + Expect(9); + Statement(); + } else if (la.kind == 60) { + lexer.NextToken(); + Type( +#line 1451 "cs.ATG" +out type); + +#line 1451 "cs.ATG" + LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; + Identifier(); + +#line 1452 "cs.ATG" + ident = t.val; + Expect(3); + Expr( +#line 1453 "cs.ATG" +out expr); + +#line 1453 "cs.ATG" + var.Variables.Add(new VariableDeclaration(ident, expr)); + while (la.kind == 14) { + lexer.NextToken(); + Identifier(); + +#line 1454 "cs.ATG" + ident = t.val; + Expect(3); + Expr( +#line 1454 "cs.ATG" +out expr); + +#line 1454 "cs.ATG" + var.Variables.Add(new VariableDeclaration(ident, expr)); + } + Expect(11); + +#line 1455 "cs.ATG" + compilationUnit.AddChild(var); + } else if ( +#line 1458 "cs.ATG" +IsLocalVarDecl()) { + LocalVariableDecl( +#line 1458 "cs.ATG" +out stmt); + Expect(11); + +#line 1458 "cs.ATG" + compilationUnit.AddChild(stmt); + } else if (StartOf(30)) { + EmbeddedStatement( +#line 1460 "cs.ATG" +out stmt); + +#line 1460 "cs.ATG" + compilationUnit.AddChild(stmt); + } else SynErr(192); + +#line 1466 "cs.ATG" + if (stmt != null) { + stmt.StartLocation = startPos; + stmt.EndLocation = t.EndLocation; + } + + } + + void Argument( +#line 1333 "cs.ATG" +out Expression argumentexpr) { + +#line 1335 "cs.ATG" + Expression expr; + FieldDirection fd = FieldDirection.None; + + if (la.kind == 93 || la.kind == 100) { + if (la.kind == 100) { + lexer.NextToken(); + +#line 1340 "cs.ATG" + fd = FieldDirection.Ref; + } else { + lexer.NextToken(); + +#line 1341 "cs.ATG" + fd = FieldDirection.Out; + } + } + Expr( +#line 1343 "cs.ATG" +out expr); + +#line 1344 "cs.ATG" + argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; + } + + void CollectionInitializer( +#line 1364 "cs.ATG" +out Expression outExpr) { + +#line 1366 "cs.ATG" + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); + + Expect(16); + +#line 1370 "cs.ATG" + initializer.StartLocation = t.Location; + if (StartOf(31)) { + VariableInitializer( +#line 1371 "cs.ATG" +out expr); + +#line 1372 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + while ( +#line 1373 "cs.ATG" +NotFinalComma()) { + Expect(14); + VariableInitializer( +#line 1374 "cs.ATG" +out expr); + +#line 1375 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + } + if (la.kind == 14) { + lexer.NextToken(); + } + } + Expect(17); + +#line 1379 "cs.ATG" + initializer.EndLocation = t.Location; outExpr = initializer; + } + + void AssignmentOperator( +#line 1347 "cs.ATG" +out AssignmentOperatorType op) { + +#line 1348 "cs.ATG" + op = AssignmentOperatorType.None; + if (la.kind == 3) { + lexer.NextToken(); + +#line 1350 "cs.ATG" + op = AssignmentOperatorType.Assign; + } else if (la.kind == 38) { + lexer.NextToken(); + +#line 1351 "cs.ATG" + op = AssignmentOperatorType.Add; + } else if (la.kind == 39) { + lexer.NextToken(); + +#line 1352 "cs.ATG" + op = AssignmentOperatorType.Subtract; + } else if (la.kind == 40) { + lexer.NextToken(); + +#line 1353 "cs.ATG" + op = AssignmentOperatorType.Multiply; + } else if (la.kind == 41) { + lexer.NextToken(); + +#line 1354 "cs.ATG" + op = AssignmentOperatorType.Divide; + } else if (la.kind == 42) { + lexer.NextToken(); + +#line 1355 "cs.ATG" + op = AssignmentOperatorType.Modulus; + } else if (la.kind == 43) { + lexer.NextToken(); + +#line 1356 "cs.ATG" + op = AssignmentOperatorType.BitwiseAnd; + } else if (la.kind == 44) { + lexer.NextToken(); + +#line 1357 "cs.ATG" + op = AssignmentOperatorType.BitwiseOr; + } else if (la.kind == 45) { + lexer.NextToken(); + +#line 1358 "cs.ATG" + op = AssignmentOperatorType.ExclusiveOr; + } else if (la.kind == 46) { + lexer.NextToken(); + +#line 1359 "cs.ATG" + op = AssignmentOperatorType.ShiftLeft; + } else if ( +#line 1360 "cs.ATG" +la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) { + Expect(22); + Expect(35); + +#line 1361 "cs.ATG" + op = AssignmentOperatorType.ShiftRight; + } else SynErr(193); + } + + void CollectionOrObjectInitializer( +#line 1382 "cs.ATG" +out Expression outExpr) { + +#line 1384 "cs.ATG" + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); + + Expect(16); + +#line 1388 "cs.ATG" + initializer.StartLocation = t.Location; + if (StartOf(31)) { + ObjectPropertyInitializerOrVariableInitializer( +#line 1389 "cs.ATG" +out expr); + +#line 1390 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + while ( +#line 1391 "cs.ATG" +NotFinalComma()) { + Expect(14); + ObjectPropertyInitializerOrVariableInitializer( +#line 1392 "cs.ATG" +out expr); + +#line 1393 "cs.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + } + if (la.kind == 14) { + lexer.NextToken(); + } + } + Expect(17); + +#line 1397 "cs.ATG" + initializer.EndLocation = t.Location; outExpr = initializer; + } + + void ObjectPropertyInitializerOrVariableInitializer( +#line 1400 "cs.ATG" +out Expression expr) { + +#line 1401 "cs.ATG" + expr = null; + if ( +#line 1403 "cs.ATG" +IdentAndAsgn()) { + Identifier(); + +#line 1405 "cs.ATG" + NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null); + nae.StartLocation = t.Location; + Expression r = null; + Expect(3); + if (la.kind == 16) { + CollectionOrObjectInitializer( +#line 1409 "cs.ATG" +out r); + } else if (StartOf(31)) { + VariableInitializer( +#line 1410 "cs.ATG" +out r); + } else SynErr(194); + +#line 1411 "cs.ATG" + nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; + } else if (StartOf(31)) { + VariableInitializer( +#line 1413 "cs.ATG" +out expr); + } else SynErr(195); + } + + void LocalVariableDecl( +#line 1417 "cs.ATG" +out Statement stmt) { + +#line 1419 "cs.ATG" + TypeReference type; + VariableDeclaration var = null; + LocalVariableDeclaration localVariableDeclaration; + + Type( +#line 1424 "cs.ATG" +out type); + +#line 1424 "cs.ATG" + localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; + LocalVariableDeclarator( +#line 1425 "cs.ATG" +out var); + +#line 1425 "cs.ATG" + localVariableDeclaration.Variables.Add(var); + while (la.kind == 14) { + lexer.NextToken(); + LocalVariableDeclarator( +#line 1426 "cs.ATG" +out var); + +#line 1426 "cs.ATG" + localVariableDeclaration.Variables.Add(var); + } + +#line 1427 "cs.ATG" + stmt = localVariableDeclaration; + } + + void LocalVariableDeclarator( +#line 1430 "cs.ATG" +out VariableDeclaration var) { + +#line 1431 "cs.ATG" + Expression expr = null; + Identifier(); + +#line 1433 "cs.ATG" + var = new VariableDeclaration(t.val); + if (la.kind == 3) { + lexer.NextToken(); + VariableInitializer( +#line 1434 "cs.ATG" +out expr); + +#line 1434 "cs.ATG" + var.Initializer = expr; + } + } + + void EmbeddedStatement( +#line 1473 "cs.ATG" +out Statement statement) { + +#line 1475 "cs.ATG" + TypeReference type = null; + Expression expr = null; + Statement embeddedStatement = null; + statement = null; + + +#line 1481 "cs.ATG" + Location startLocation = la.Location; + if (la.kind == 16) { + Block( +#line 1483 "cs.ATG" +out statement); + } else if (la.kind == 11) { + lexer.NextToken(); + +#line 1486 "cs.ATG" + statement = new EmptyStatement(); + } else if ( +#line 1489 "cs.ATG" +UnCheckedAndLBrace()) { + +#line 1489 "cs.ATG" + Statement block; bool isChecked = true; + if (la.kind == 58) { + lexer.NextToken(); + } else if (la.kind == 118) { + lexer.NextToken(); + +#line 1490 "cs.ATG" + isChecked = false; + } else SynErr(196); + Block( +#line 1491 "cs.ATG" +out block); + +#line 1491 "cs.ATG" + statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); + } else if (la.kind == 79) { + IfStatement( +#line 1494 "cs.ATG" +out statement); + } else if (la.kind == 110) { + lexer.NextToken(); + +#line 1496 "cs.ATG" + List switchSections = new List(); + Expect(20); + Expr( +#line 1497 "cs.ATG" +out expr); + Expect(21); + Expect(16); + SwitchSections( +#line 1498 "cs.ATG" +switchSections); + Expect(17); + +#line 1499 "cs.ATG" + statement = new SwitchStatement(expr, switchSections); + } else if (la.kind == 125) { + lexer.NextToken(); + Expect(20); + Expr( +#line 1502 "cs.ATG" +out expr); + Expect(21); + EmbeddedStatement( +#line 1503 "cs.ATG" +out embeddedStatement); + +#line 1504 "cs.ATG" + statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); + } else if (la.kind == 65) { + lexer.NextToken(); + EmbeddedStatement( +#line 1506 "cs.ATG" +out embeddedStatement); + Expect(125); + Expect(20); + Expr( +#line 1507 "cs.ATG" +out expr); + Expect(21); + Expect(11); + +#line 1508 "cs.ATG" + statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); + } else if (la.kind == 76) { + lexer.NextToken(); + +#line 1510 "cs.ATG" + List initializer = null; List iterator = null; + Expect(20); + if (StartOf(6)) { + ForInitializer( +#line 1511 "cs.ATG" +out initializer); + } + Expect(11); + if (StartOf(6)) { + Expr( +#line 1512 "cs.ATG" +out expr); + } + Expect(11); + if (StartOf(6)) { + ForIterator( +#line 1513 "cs.ATG" +out iterator); + } + Expect(21); + EmbeddedStatement( +#line 1514 "cs.ATG" +out embeddedStatement); + +#line 1514 "cs.ATG" + statement = new ForStatement(initializer, expr, iterator, embeddedStatement); + } else if (la.kind == 77) { + lexer.NextToken(); + Expect(20); + Type( +#line 1516 "cs.ATG" +out type); + Identifier(); + +#line 1516 "cs.ATG" + string varName = t.val; + Expect(81); + Expr( +#line 1517 "cs.ATG" +out expr); + Expect(21); + EmbeddedStatement( +#line 1518 "cs.ATG" +out embeddedStatement); + +#line 1519 "cs.ATG" + statement = new ForeachStatement(type, varName , expr, embeddedStatement); + } else if (la.kind == 53) { + lexer.NextToken(); + Expect(11); + +#line 1522 "cs.ATG" + statement = new BreakStatement(); + } else if (la.kind == 61) { + lexer.NextToken(); + Expect(11); + +#line 1523 "cs.ATG" + statement = new ContinueStatement(); + } else if (la.kind == 78) { + GotoStatement( +#line 1524 "cs.ATG" +out statement); + } else if ( +#line 1526 "cs.ATG" +IsYieldStatement()) { + Expect(132); + if (la.kind == 101) { + lexer.NextToken(); + Expr( +#line 1527 "cs.ATG" +out expr); + +#line 1527 "cs.ATG" + statement = new YieldStatement(new ReturnStatement(expr)); + } else if (la.kind == 53) { + lexer.NextToken(); + +#line 1528 "cs.ATG" + statement = new YieldStatement(new BreakStatement()); + } else SynErr(197); + Expect(11); + } else if (la.kind == 101) { + lexer.NextToken(); + if (StartOf(6)) { + Expr( +#line 1531 "cs.ATG" +out expr); + } + Expect(11); + +#line 1531 "cs.ATG" + statement = new ReturnStatement(expr); + } else if (la.kind == 112) { + lexer.NextToken(); + if (StartOf(6)) { + Expr( +#line 1532 "cs.ATG" +out expr); + } + Expect(11); + +#line 1532 "cs.ATG" + statement = new ThrowStatement(expr); + } else if (StartOf(6)) { + StatementExpr( +#line 1535 "cs.ATG" +out statement); + while (!(la.kind == 0 || la.kind == 11)) {SynErr(198); lexer.NextToken(); } + Expect(11); + } else if (la.kind == 114) { + TryStatement( +#line 1538 "cs.ATG" +out statement); + } else if (la.kind == 86) { + lexer.NextToken(); + Expect(20); + Expr( +#line 1541 "cs.ATG" +out expr); + Expect(21); + EmbeddedStatement( +#line 1542 "cs.ATG" +out embeddedStatement); + +#line 1542 "cs.ATG" + statement = new LockStatement(expr, embeddedStatement); + } else if (la.kind == 121) { + +#line 1545 "cs.ATG" + Statement resourceAcquisitionStmt = null; + lexer.NextToken(); + Expect(20); + ResourceAcquisition( +#line 1547 "cs.ATG" +out resourceAcquisitionStmt); + Expect(21); + EmbeddedStatement( +#line 1548 "cs.ATG" +out embeddedStatement); + +#line 1548 "cs.ATG" + statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); + } else if (la.kind == 119) { + lexer.NextToken(); + Block( +#line 1551 "cs.ATG" +out embeddedStatement); + +#line 1551 "cs.ATG" + statement = new UnsafeStatement(embeddedStatement); + } else if (la.kind == 74) { + lexer.NextToken(); + Expect(20); + Type( +#line 1554 "cs.ATG" +out type); + +#line 1554 "cs.ATG" + if (type == null || type.PointerNestingLevel == 0) Error("can only fix pointer types"); + List pointerDeclarators = new List(1); + + Identifier(); + +#line 1557 "cs.ATG" + string identifier = t.val; + Expect(3); + Expr( +#line 1558 "cs.ATG" +out expr); + +#line 1558 "cs.ATG" + pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); + while (la.kind == 14) { + lexer.NextToken(); + Identifier(); + +#line 1560 "cs.ATG" + identifier = t.val; + Expect(3); + Expr( +#line 1561 "cs.ATG" +out expr); + +#line 1561 "cs.ATG" + pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); + } + Expect(21); + EmbeddedStatement( +#line 1563 "cs.ATG" +out embeddedStatement); + +#line 1563 "cs.ATG" + statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); + } else SynErr(199); + +#line 1565 "cs.ATG" + if (statement != null) { + statement.StartLocation = startLocation; + statement.EndLocation = t.EndLocation; + } + + } + + void IfStatement( +#line 1572 "cs.ATG" +out Statement statement) { + +#line 1574 "cs.ATG" + Expression expr = null; + Statement embeddedStatement = null; + statement = null; + + Expect(79); + Expect(20); + Expr( +#line 1580 "cs.ATG" +out expr); + Expect(21); + EmbeddedStatement( +#line 1581 "cs.ATG" +out embeddedStatement); + +#line 1582 "cs.ATG" + Statement elseStatement = null; + if (la.kind == 67) { + lexer.NextToken(); + EmbeddedStatement( +#line 1583 "cs.ATG" +out elseStatement); + } + +#line 1584 "cs.ATG" + statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); + +#line 1585 "cs.ATG" + if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) { + /* else if-section (otherwise we would have a BlockStatment) */ + (statement as IfElseStatement).ElseIfSections.Add( + new ElseIfSection((elseStatement as IfElseStatement).Condition, + (elseStatement as IfElseStatement).TrueStatement[0])); + (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections); + (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement; + } + + } + + void SwitchSections( +#line 1615 "cs.ATG" +List switchSections) { + +#line 1617 "cs.ATG" + SwitchSection switchSection = new SwitchSection(); + CaseLabel label; + + SwitchLabel( +#line 1621 "cs.ATG" +out label); + +#line 1621 "cs.ATG" + if (label != null) { switchSection.SwitchLabels.Add(label); } + +#line 1622 "cs.ATG" + compilationUnit.BlockStart(switchSection); + while (StartOf(32)) { + if (la.kind == 55 || la.kind == 63) { + SwitchLabel( +#line 1624 "cs.ATG" +out label); + +#line 1625 "cs.ATG" + if (label != null) { + if (switchSection.Children.Count > 0) { + // open new section + compilationUnit.BlockEnd(); switchSections.Add(switchSection); + switchSection = new SwitchSection(); + compilationUnit.BlockStart(switchSection); + } + switchSection.SwitchLabels.Add(label); + } + + } else { + Statement(); + } + } + +#line 1637 "cs.ATG" + compilationUnit.BlockEnd(); switchSections.Add(switchSection); + } + + void ForInitializer( +#line 1596 "cs.ATG" +out List initializer) { + +#line 1598 "cs.ATG" + Statement stmt; + initializer = new List(); + + if ( +#line 1602 "cs.ATG" +IsLocalVarDecl()) { + LocalVariableDecl( +#line 1602 "cs.ATG" +out stmt); + +#line 1602 "cs.ATG" + initializer.Add(stmt); + } else if (StartOf(6)) { + StatementExpr( +#line 1603 "cs.ATG" +out stmt); + +#line 1603 "cs.ATG" + initializer.Add(stmt); + while (la.kind == 14) { + lexer.NextToken(); + StatementExpr( +#line 1603 "cs.ATG" +out stmt); + +#line 1603 "cs.ATG" + initializer.Add(stmt); + } + } else SynErr(200); + } + + void ForIterator( +#line 1606 "cs.ATG" +out List iterator) { + +#line 1608 "cs.ATG" + Statement stmt; + iterator = new List(); + + StatementExpr( +#line 1612 "cs.ATG" +out stmt); + +#line 1612 "cs.ATG" + iterator.Add(stmt); + while (la.kind == 14) { + lexer.NextToken(); + StatementExpr( +#line 1612 "cs.ATG" +out stmt); + +#line 1612 "cs.ATG" + iterator.Add(stmt); + } + } + + void GotoStatement( +#line 1690 "cs.ATG" +out Statement stmt) { + +#line 1691 "cs.ATG" + Expression expr; stmt = null; + Expect(78); + if (StartOf(19)) { + Identifier(); + +#line 1695 "cs.ATG" + stmt = new GotoStatement(t.val); + Expect(11); + } else if (la.kind == 55) { + lexer.NextToken(); + Expr( +#line 1696 "cs.ATG" +out expr); + Expect(11); + +#line 1696 "cs.ATG" + stmt = new GotoCaseStatement(expr); + } else if (la.kind == 63) { + lexer.NextToken(); + Expect(11); + +#line 1697 "cs.ATG" + stmt = new GotoCaseStatement(null); + } else SynErr(201); + } + + void StatementExpr( +#line 1717 "cs.ATG" +out Statement stmt) { + +#line 1718 "cs.ATG" + Expression expr; + Expr( +#line 1720 "cs.ATG" +out expr); + +#line 1723 "cs.ATG" + stmt = new ExpressionStatement(expr); + } + + void TryStatement( +#line 1647 "cs.ATG" +out Statement tryStatement) { + +#line 1649 "cs.ATG" + Statement blockStmt = null, finallyStmt = null; + List catchClauses = null; + + Expect(114); + Block( +#line 1653 "cs.ATG" +out blockStmt); + if (la.kind == 56) { + CatchClauses( +#line 1655 "cs.ATG" +out catchClauses); + if (la.kind == 73) { + lexer.NextToken(); + Block( +#line 1655 "cs.ATG" +out finallyStmt); + } + } else if (la.kind == 73) { + lexer.NextToken(); + Block( +#line 1656 "cs.ATG" +out finallyStmt); + } else SynErr(202); + +#line 1659 "cs.ATG" + tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); + + } + + void ResourceAcquisition( +#line 1701 "cs.ATG" +out Statement stmt) { + +#line 1703 "cs.ATG" + stmt = null; + Expression expr; + + if ( +#line 1708 "cs.ATG" +IsLocalVarDecl()) { + LocalVariableDecl( +#line 1708 "cs.ATG" +out stmt); + } else if (StartOf(6)) { + Expr( +#line 1709 "cs.ATG" +out expr); + +#line 1713 "cs.ATG" + stmt = new ExpressionStatement(expr); + } else SynErr(203); + } + + void SwitchLabel( +#line 1640 "cs.ATG" +out CaseLabel label) { + +#line 1641 "cs.ATG" + Expression expr = null; label = null; + if (la.kind == 55) { + lexer.NextToken(); + Expr( +#line 1643 "cs.ATG" +out expr); + Expect(9); + +#line 1643 "cs.ATG" + label = new CaseLabel(expr); + } else if (la.kind == 63) { + lexer.NextToken(); + Expect(9); + +#line 1644 "cs.ATG" + label = new CaseLabel(); + } else SynErr(204); + } + + void CatchClauses( +#line 1664 "cs.ATG" +out List catchClauses) { + +#line 1666 "cs.ATG" + catchClauses = new List(); + + Expect(56); + +#line 1669 "cs.ATG" + string identifier; + Statement stmt; + TypeReference typeRef; + + if (la.kind == 16) { + Block( +#line 1675 "cs.ATG" +out stmt); + +#line 1675 "cs.ATG" + catchClauses.Add(new CatchClause(stmt)); + } else if (la.kind == 20) { + lexer.NextToken(); + ClassType( +#line 1677 "cs.ATG" +out typeRef, false); + +#line 1677 "cs.ATG" + identifier = null; + if (StartOf(19)) { + Identifier(); + +#line 1678 "cs.ATG" + identifier = t.val; + } + Expect(21); + Block( +#line 1679 "cs.ATG" +out stmt); + +#line 1680 "cs.ATG" + catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); + while ( +#line 1681 "cs.ATG" +IsTypedCatch()) { + Expect(56); + Expect(20); + ClassType( +#line 1681 "cs.ATG" +out typeRef, false); + +#line 1681 "cs.ATG" + identifier = null; + if (StartOf(19)) { + Identifier(); + +#line 1682 "cs.ATG" + identifier = t.val; + } + Expect(21); + Block( +#line 1683 "cs.ATG" +out stmt); + +#line 1684 "cs.ATG" + catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); + } + if (la.kind == 56) { + lexer.NextToken(); + Block( +#line 1686 "cs.ATG" +out stmt); + +#line 1686 "cs.ATG" + catchClauses.Add(new CatchClause(stmt)); + } + } else SynErr(205); + } + + void UnaryExpr( +#line 1750 "cs.ATG" +out Expression uExpr) { + +#line 1752 "cs.ATG" + TypeReference type = null; + Expression expr = null; + ArrayList expressions = new ArrayList(); + uExpr = null; + + while (StartOf(33) || +#line 1774 "cs.ATG" +IsTypeCast()) { + if (la.kind == 4) { + lexer.NextToken(); + +#line 1761 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); + } else if (la.kind == 5) { + lexer.NextToken(); + +#line 1762 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); + } else if (la.kind == 24) { + lexer.NextToken(); + +#line 1763 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); + } else if (la.kind == 27) { + lexer.NextToken(); + +#line 1764 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); + } else if (la.kind == 6) { + lexer.NextToken(); + +#line 1765 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); + } else if (la.kind == 31) { + lexer.NextToken(); + +#line 1766 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); + } else if (la.kind == 32) { + lexer.NextToken(); + +#line 1767 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); + } else if (la.kind == 28) { + lexer.NextToken(); + +#line 1768 "cs.ATG" + expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); + } else { + Expect(20); + Type( +#line 1774 "cs.ATG" +out type); + Expect(21); + +#line 1774 "cs.ATG" + expressions.Add(new CastExpression(type)); + } + } + if ( +#line 1779 "cs.ATG" +LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix()) { + Expect(2); + +#line 1782 "cs.ATG" + expressions.RemoveAt(expressions.Count - 1); + if (t.literalValue is uint) { + expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString()); + } else if (t.literalValue is ulong) { + expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString()); + } else { + throw new Exception("t.literalValue must be uint or ulong"); + } + + } else if (StartOf(34)) { + PrimaryExpr( +#line 1791 "cs.ATG" +out expr); + } else SynErr(206); + +#line 1793 "cs.ATG" + for (int i = 0; i < expressions.Count; ++i) { + Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr; + if (expressions[i] is CastExpression) { + ((CastExpression)expressions[i]).Expression = nextExpression; + } else { + ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression; + } + } + if (expressions.Count > 0) { + uExpr = (Expression)expressions[0]; + } else { + uExpr = expr; + } + + } + + void ConditionalOrExpr( +#line 2105 "cs.ATG" +ref Expression outExpr) { + +#line 2106 "cs.ATG" + Expression expr; + ConditionalAndExpr( +#line 2108 "cs.ATG" +ref outExpr); + while (la.kind == 26) { + lexer.NextToken(); + UnaryExpr( +#line 2108 "cs.ATG" +out expr); + ConditionalAndExpr( +#line 2108 "cs.ATG" +ref expr); + +#line 2108 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); + } + } + + void PrimaryExpr( +#line 1810 "cs.ATG" +out Expression pexpr) { + +#line 1812 "cs.ATG" + TypeReference type = null; + Expression expr; + pexpr = null; + + +#line 1817 "cs.ATG" + Location startLocation = la.Location; + if (la.kind == 113) { + lexer.NextToken(); + +#line 1819 "cs.ATG" + pexpr = new PrimitiveExpression(true, "true"); + } else if (la.kind == 72) { + lexer.NextToken(); + +#line 1820 "cs.ATG" + pexpr = new PrimitiveExpression(false, "false"); + } else if (la.kind == 90) { + lexer.NextToken(); + +#line 1821 "cs.ATG" + pexpr = new PrimitiveExpression(null, "null"); + } else if (la.kind == 2) { + lexer.NextToken(); + +#line 1822 "cs.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + } else if ( +#line 1823 "cs.ATG" +StartOfQueryExpression()) { + QueryExpression( +#line 1824 "cs.ATG" +out pexpr); + } else if ( +#line 1825 "cs.ATG" +IdentAndDoubleColon()) { + Identifier(); + +#line 1826 "cs.ATG" + type = new TypeReference(t.val); + Expect(10); + +#line 1827 "cs.ATG" + pexpr = new TypeReferenceExpression(type); + Identifier(); + +#line 1828 "cs.ATG" + if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); + } else if (StartOf(19)) { + Identifier(); + +#line 1832 "cs.ATG" + pexpr = new IdentifierExpression(t.val); + if (la.kind == 48 || +#line 1835 "cs.ATG" +IsGenericInSimpleNameOrMemberAccess()) { + if (la.kind == 48) { + ShortedLambdaExpression( +#line 1834 "cs.ATG" +(IdentifierExpression)pexpr, out pexpr); + } else { + +#line 1836 "cs.ATG" + List typeList; + TypeArgumentList( +#line 1837 "cs.ATG" +out typeList, false); + +#line 1838 "cs.ATG" + ((IdentifierExpression)pexpr).TypeArguments = typeList; + } + } + } else if ( +#line 1840 "cs.ATG" +IsLambdaExpression()) { + LambdaExpression( +#line 1841 "cs.ATG" +out pexpr); + } else if (la.kind == 20) { + lexer.NextToken(); + Expr( +#line 1844 "cs.ATG" +out expr); + Expect(21); + +#line 1844 "cs.ATG" + pexpr = new ParenthesizedExpression(expr); + } else if (StartOf(35)) { + +#line 1847 "cs.ATG" + string val = null; + switch (la.kind) { + case 52: { + lexer.NextToken(); + +#line 1848 "cs.ATG" + val = "bool"; + break; + } + case 54: { + lexer.NextToken(); + +#line 1849 "cs.ATG" + val = "byte"; + break; + } + case 57: { + lexer.NextToken(); + +#line 1850 "cs.ATG" + val = "char"; + break; + } + case 62: { + lexer.NextToken(); + +#line 1851 "cs.ATG" + val = "decimal"; + break; + } + case 66: { + lexer.NextToken(); + +#line 1852 "cs.ATG" + val = "double"; + break; + } + case 75: { + lexer.NextToken(); + +#line 1853 "cs.ATG" + val = "float"; + break; + } + case 82: { + lexer.NextToken(); + +#line 1854 "cs.ATG" + val = "int"; + break; + } + case 87: { + lexer.NextToken(); + +#line 1855 "cs.ATG" + val = "long"; + break; + } + case 91: { + lexer.NextToken(); + +#line 1856 "cs.ATG" + val = "object"; + break; + } + case 102: { + lexer.NextToken(); + +#line 1857 "cs.ATG" + val = "sbyte"; + break; + } + case 104: { + lexer.NextToken(); + +#line 1858 "cs.ATG" + val = "short"; + break; + } + case 108: { + lexer.NextToken(); + +#line 1859 "cs.ATG" + val = "string"; + break; + } + case 116: { + lexer.NextToken(); + +#line 1860 "cs.ATG" + val = "uint"; + break; + } + case 117: { + lexer.NextToken(); + +#line 1861 "cs.ATG" + val = "ulong"; + break; + } + case 120: { + lexer.NextToken(); + +#line 1862 "cs.ATG" + val = "ushort"; + break; + } + } + MemberAccess( +#line 1864 "cs.ATG" +out pexpr, new TypeReferenceExpression(val) { StartLocation = t.Location, EndLocation = t.EndLocation } ); + } else if (la.kind == 111) { + lexer.NextToken(); + +#line 1867 "cs.ATG" + pexpr = new ThisReferenceExpression(); + } else if (la.kind == 51) { + lexer.NextToken(); + +#line 1869 "cs.ATG" + pexpr = new BaseReferenceExpression(); + } else if (la.kind == 89) { + NewExpression( +#line 1872 "cs.ATG" +out pexpr); + } else if (la.kind == 115) { + lexer.NextToken(); + Expect(20); + if ( +#line 1876 "cs.ATG" +NotVoidPointer()) { + Expect(123); + +#line 1876 "cs.ATG" + type = new TypeReference("void"); + } else if (StartOf(10)) { + TypeWithRestriction( +#line 1877 "cs.ATG" +out type, true, true); + } else SynErr(207); + Expect(21); + +#line 1879 "cs.ATG" + pexpr = new TypeOfExpression(type); + } else if (la.kind == 63) { + lexer.NextToken(); + Expect(20); + Type( +#line 1881 "cs.ATG" +out type); + Expect(21); + +#line 1881 "cs.ATG" + pexpr = new DefaultValueExpression(type); + } else if (la.kind == 105) { + lexer.NextToken(); + Expect(20); + Type( +#line 1882 "cs.ATG" +out type); + Expect(21); + +#line 1882 "cs.ATG" + pexpr = new SizeOfExpression(type); + } else if (la.kind == 58) { + lexer.NextToken(); + Expect(20); + Expr( +#line 1883 "cs.ATG" +out expr); + Expect(21); + +#line 1883 "cs.ATG" + pexpr = new CheckedExpression(expr); + } else if (la.kind == 118) { + lexer.NextToken(); + Expect(20); + Expr( +#line 1884 "cs.ATG" +out expr); + Expect(21); + +#line 1884 "cs.ATG" + pexpr = new UncheckedExpression(expr); + } else if (la.kind == 64) { + lexer.NextToken(); + AnonymousMethodExpr( +#line 1885 "cs.ATG" +out expr); + +#line 1885 "cs.ATG" + pexpr = expr; + } else SynErr(208); + +#line 1887 "cs.ATG" + if (pexpr != null) { + pexpr.StartLocation = startLocation; + pexpr.EndLocation = t.EndLocation; + } + + while (StartOf(36)) { + if (la.kind == 31 || la.kind == 32) { + +#line 1893 "cs.ATG" + startLocation = la.Location; + if (la.kind == 31) { + lexer.NextToken(); + +#line 1895 "cs.ATG" + pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); + } else if (la.kind == 32) { + lexer.NextToken(); + +#line 1896 "cs.ATG" + pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); + } else SynErr(209); + } else if (la.kind == 47) { + PointerMemberAccess( +#line 1899 "cs.ATG" +out pexpr, pexpr); + } else if (la.kind == 15) { + MemberAccess( +#line 1900 "cs.ATG" +out pexpr, pexpr); + } else if (la.kind == 20) { + lexer.NextToken(); + +#line 1903 "cs.ATG" + List parameters = new List(); + if (StartOf(26)) { + Argument( +#line 1904 "cs.ATG" +out expr); + +#line 1904 "cs.ATG" + if (expr != null) {parameters.Add(expr);} + while (la.kind == 14) { + lexer.NextToken(); + Argument( +#line 1905 "cs.ATG" +out expr); + +#line 1905 "cs.ATG" + if (expr != null) {parameters.Add(expr);} + } + } + Expect(21); + +#line 1908 "cs.ATG" + pexpr = new InvocationExpression(pexpr, parameters); + } else { + +#line 1911 "cs.ATG" + List indices = new List(); + + lexer.NextToken(); + Expr( +#line 1913 "cs.ATG" +out expr); + +#line 1913 "cs.ATG" + if (expr != null) { indices.Add(expr); } + while (la.kind == 14) { + lexer.NextToken(); + Expr( +#line 1914 "cs.ATG" +out expr); + +#line 1914 "cs.ATG" + if (expr != null) { indices.Add(expr); } + } + Expect(19); + +#line 1915 "cs.ATG" + pexpr = new IndexerExpression(pexpr, indices); + +#line 1917 "cs.ATG" + if (pexpr != null) { + pexpr.StartLocation = startLocation; + pexpr.EndLocation = t.EndLocation; + } + + } + } + } + + void QueryExpression( +#line 2341 "cs.ATG" +out Expression outExpr) { + +#line 2342 "cs.ATG" + QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; + QueryExpressionFromClause fromClause; + + QueryExpressionFromClause( +#line 2346 "cs.ATG" +out fromClause); + +#line 2346 "cs.ATG" + q.FromClause = fromClause; + QueryExpressionBody( +#line 2347 "cs.ATG" +q); + +#line 2348 "cs.ATG" + q.EndLocation = t.EndLocation; + } + + void ShortedLambdaExpression( +#line 2030 "cs.ATG" +IdentifierExpression ident, out Expression pexpr) { + +#line 2031 "cs.ATG" + LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; + Expect(48); + +#line 2036 "cs.ATG" + lambda.StartLocation = ident.StartLocation; + lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); + lambda.Parameters[0].StartLocation = ident.StartLocation; + lambda.Parameters[0].EndLocation = ident.EndLocation; + + LambdaExpressionBody( +#line 2041 "cs.ATG" +lambda); + } + + void TypeArgumentList( +#line 2275 "cs.ATG" +out List types, bool canBeUnbound) { + +#line 2277 "cs.ATG" + types = new List(); + TypeReference type = null; + + Expect(23); + if ( +#line 2282 "cs.ATG" +canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) { + +#line 2283 "cs.ATG" + types.Add(TypeReference.Null); + while (la.kind == 14) { + lexer.NextToken(); + +#line 2284 "cs.ATG" + types.Add(TypeReference.Null); + } + } else if (StartOf(10)) { + Type( +#line 2285 "cs.ATG" +out type); + +#line 2285 "cs.ATG" + if (type != null) { types.Add(type); } + while (la.kind == 14) { + lexer.NextToken(); + Type( +#line 2286 "cs.ATG" +out type); + +#line 2286 "cs.ATG" + if (type != null) { types.Add(type); } + } + } else SynErr(210); + Expect(22); + } + + void LambdaExpression( +#line 2010 "cs.ATG" +out Expression outExpr) { + +#line 2012 "cs.ATG" + LambdaExpression lambda = new LambdaExpression(); + lambda.StartLocation = la.Location; + ParameterDeclarationExpression p; + outExpr = lambda; + + Expect(20); + if (StartOf(10)) { + LambdaExpressionParameter( +#line 2020 "cs.ATG" +out p); + +#line 2020 "cs.ATG" + if (p != null) lambda.Parameters.Add(p); + while (la.kind == 14) { + lexer.NextToken(); + LambdaExpressionParameter( +#line 2022 "cs.ATG" +out p); + +#line 2022 "cs.ATG" + if (p != null) lambda.Parameters.Add(p); + } + } + Expect(21); + Expect(48); + LambdaExpressionBody( +#line 2027 "cs.ATG" +lambda); + } + + void MemberAccess( +#line 1925 "cs.ATG" +out Expression expr, Expression target) { + +#line 1926 "cs.ATG" + List typeList; + +#line 1928 "cs.ATG" + if (ShouldConvertTargetExpressionToTypeReference(target)) { + TypeReference type = GetTypeReferenceFromExpression(target); + if (type != null) { + target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation }; + } + } + t.val = ""; // required for TypeReferenceExpressionTests.StandaloneIntReferenceExpression hack + + Expect(15); + Identifier(); + +#line 1938 "cs.ATG" + expr = new MemberReferenceExpression(target, t.val); + if ( +#line 1939 "cs.ATG" +IsGenericInSimpleNameOrMemberAccess()) { + TypeArgumentList( +#line 1940 "cs.ATG" +out typeList, false); + +#line 1941 "cs.ATG" + ((MemberReferenceExpression)expr).TypeArguments = typeList; + } + } + + void NewExpression( +#line 1957 "cs.ATG" +out Expression pexpr) { + +#line 1958 "cs.ATG" + pexpr = null; + List parameters = new List(); + TypeReference type = null; + Expression expr; + + Expect(89); + if (StartOf(10)) { + NonArrayType( +#line 1965 "cs.ATG" +out type); + } + if (la.kind == 16 || la.kind == 20) { + if (la.kind == 20) { + +#line 1971 "cs.ATG" + ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); + lexer.NextToken(); + +#line 1972 "cs.ATG" + if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); + if (StartOf(26)) { + Argument( +#line 1973 "cs.ATG" +out expr); + +#line 1973 "cs.ATG" + if (expr != null) { parameters.Add(expr); } + while (la.kind == 14) { + lexer.NextToken(); + Argument( +#line 1974 "cs.ATG" +out expr); + +#line 1974 "cs.ATG" + if (expr != null) { parameters.Add(expr); } + } + } + Expect(21); + +#line 1976 "cs.ATG" + pexpr = oce; + if (la.kind == 16) { + CollectionOrObjectInitializer( +#line 1977 "cs.ATG" +out expr); + +#line 1977 "cs.ATG" + oce.ObjectInitializer = (CollectionInitializerExpression)expr; + } + } else { + +#line 1978 "cs.ATG" + ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); + CollectionOrObjectInitializer( +#line 1979 "cs.ATG" +out expr); + +#line 1979 "cs.ATG" + oce.ObjectInitializer = (CollectionInitializerExpression)expr; + +#line 1980 "cs.ATG" + pexpr = oce; + } + } else if (la.kind == 18) { + lexer.NextToken(); + +#line 1985 "cs.ATG" + ArrayCreateExpression ace = new ArrayCreateExpression(type); + /* we must not change RankSpecifier on the null type reference*/ + if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); } + pexpr = ace; + int dims = 0; List ranks = new List(); + + if (la.kind == 14 || la.kind == 19) { + while (la.kind == 14) { + lexer.NextToken(); + +#line 1992 "cs.ATG" + dims += 1; + } + Expect(19); + +#line 1993 "cs.ATG" + ranks.Add(dims); dims = 0; + while (la.kind == 18) { + lexer.NextToken(); + while (la.kind == 14) { + lexer.NextToken(); + +#line 1994 "cs.ATG" + ++dims; + } + Expect(19); + +#line 1994 "cs.ATG" + ranks.Add(dims); dims = 0; + } + +#line 1995 "cs.ATG" + ace.CreateType.RankSpecifier = ranks.ToArray(); + CollectionInitializer( +#line 1996 "cs.ATG" +out expr); + +#line 1996 "cs.ATG" + ace.ArrayInitializer = (CollectionInitializerExpression)expr; + } else if (StartOf(6)) { + Expr( +#line 1997 "cs.ATG" +out expr); + +#line 1997 "cs.ATG" + if (expr != null) parameters.Add(expr); + while (la.kind == 14) { + lexer.NextToken(); + +#line 1998 "cs.ATG" + dims += 1; + Expr( +#line 1999 "cs.ATG" +out expr); + +#line 1999 "cs.ATG" + if (expr != null) parameters.Add(expr); + } + Expect(19); + +#line 2001 "cs.ATG" + ranks.Add(dims); ace.Arguments = parameters; dims = 0; + while (la.kind == 18) { + lexer.NextToken(); + while (la.kind == 14) { + lexer.NextToken(); + +#line 2002 "cs.ATG" + ++dims; + } + Expect(19); + +#line 2002 "cs.ATG" + ranks.Add(dims); dims = 0; + } + +#line 2003 "cs.ATG" + ace.CreateType.RankSpecifier = ranks.ToArray(); + if (la.kind == 16) { + CollectionInitializer( +#line 2004 "cs.ATG" +out expr); + +#line 2004 "cs.ATG" + ace.ArrayInitializer = (CollectionInitializerExpression)expr; + } + } else SynErr(211); + } else SynErr(212); + } + + void AnonymousMethodExpr( +#line 2072 "cs.ATG" +out Expression outExpr) { + +#line 2074 "cs.ATG" + AnonymousMethodExpression expr = new AnonymousMethodExpression(); + expr.StartLocation = t.Location; + BlockStatement stmt; + List p = new List(); + outExpr = expr; + + if (la.kind == 20) { + lexer.NextToken(); + if (StartOf(11)) { + FormalParameterList( +#line 2083 "cs.ATG" +p); + +#line 2083 "cs.ATG" + expr.Parameters = p; + } + Expect(21); + +#line 2085 "cs.ATG" + expr.HasParameterList = true; + } + BlockInsideExpression( +#line 2087 "cs.ATG" +out stmt); + +#line 2087 "cs.ATG" + expr.Body = stmt; + +#line 2088 "cs.ATG" + expr.EndLocation = t.Location; + } + + void PointerMemberAccess( +#line 1945 "cs.ATG" +out Expression expr, Expression target) { + +#line 1946 "cs.ATG" + List typeList; + Expect(47); + Identifier(); + +#line 1950 "cs.ATG" + expr = new PointerReferenceExpression(target, t.val); + if ( +#line 1951 "cs.ATG" +IsGenericInSimpleNameOrMemberAccess()) { + TypeArgumentList( +#line 1952 "cs.ATG" +out typeList, false); + +#line 1953 "cs.ATG" + ((MemberReferenceExpression)expr).TypeArguments = typeList; + } + } + + void LambdaExpressionParameter( +#line 2044 "cs.ATG" +out ParameterDeclarationExpression p) { + +#line 2045 "cs.ATG" + Location start = la.Location; p = null; + TypeReference type; + + if ( +#line 2049 "cs.ATG" +Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) { + Identifier(); + +#line 2051 "cs.ATG" + p = new ParameterDeclarationExpression(null, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + + } else if (StartOf(10)) { + Type( +#line 2054 "cs.ATG" +out type); + Identifier(); + +#line 2056 "cs.ATG" + p = new ParameterDeclarationExpression(type, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + + } else SynErr(213); + } + + void LambdaExpressionBody( +#line 2062 "cs.ATG" +LambdaExpression lambda) { + +#line 2063 "cs.ATG" + Expression expr; BlockStatement stmt; + if (la.kind == 16) { + BlockInsideExpression( +#line 2066 "cs.ATG" +out stmt); + +#line 2066 "cs.ATG" + lambda.StatementBody = stmt; + } else if (StartOf(6)) { + Expr( +#line 2067 "cs.ATG" +out expr); + +#line 2067 "cs.ATG" + lambda.ExpressionBody = expr; + } else SynErr(214); + +#line 2069 "cs.ATG" + lambda.EndLocation = t.EndLocation; + } + + void BlockInsideExpression( +#line 2091 "cs.ATG" +out BlockStatement outStmt) { + +#line 2092 "cs.ATG" + Statement stmt = null; outStmt = null; + +#line 2096 "cs.ATG" + if (compilationUnit != null) { + Block( +#line 2097 "cs.ATG" +out stmt); + +#line 2097 "cs.ATG" + outStmt = (BlockStatement)stmt; + +#line 2098 "cs.ATG" + } else { + Expect(16); + +#line 2100 "cs.ATG" + lexer.SkipCurrentBlock(0); + Expect(17); + +#line 2102 "cs.ATG" + } + } + + void ConditionalAndExpr( +#line 2111 "cs.ATG" +ref Expression outExpr) { + +#line 2112 "cs.ATG" + Expression expr; + InclusiveOrExpr( +#line 2114 "cs.ATG" +ref outExpr); + while (la.kind == 25) { + lexer.NextToken(); + UnaryExpr( +#line 2114 "cs.ATG" +out expr); + InclusiveOrExpr( +#line 2114 "cs.ATG" +ref expr); + +#line 2114 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); + } + } + + void InclusiveOrExpr( +#line 2117 "cs.ATG" +ref Expression outExpr) { + +#line 2118 "cs.ATG" + Expression expr; + ExclusiveOrExpr( +#line 2120 "cs.ATG" +ref outExpr); + while (la.kind == 29) { + lexer.NextToken(); + UnaryExpr( +#line 2120 "cs.ATG" +out expr); + ExclusiveOrExpr( +#line 2120 "cs.ATG" +ref expr); + +#line 2120 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); + } + } + + void ExclusiveOrExpr( +#line 2123 "cs.ATG" +ref Expression outExpr) { + +#line 2124 "cs.ATG" + Expression expr; + AndExpr( +#line 2126 "cs.ATG" +ref outExpr); + while (la.kind == 30) { + lexer.NextToken(); + UnaryExpr( +#line 2126 "cs.ATG" +out expr); + AndExpr( +#line 2126 "cs.ATG" +ref expr); + +#line 2126 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); + } + } + + void AndExpr( +#line 2129 "cs.ATG" +ref Expression outExpr) { + +#line 2130 "cs.ATG" + Expression expr; + EqualityExpr( +#line 2132 "cs.ATG" +ref outExpr); + while (la.kind == 28) { + lexer.NextToken(); + UnaryExpr( +#line 2132 "cs.ATG" +out expr); + EqualityExpr( +#line 2132 "cs.ATG" +ref expr); + +#line 2132 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); + } + } + + void EqualityExpr( +#line 2135 "cs.ATG" +ref Expression outExpr) { + +#line 2137 "cs.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + RelationalExpr( +#line 2141 "cs.ATG" +ref outExpr); + while (la.kind == 33 || la.kind == 34) { + if (la.kind == 34) { + lexer.NextToken(); + +#line 2144 "cs.ATG" + op = BinaryOperatorType.InEquality; + } else { + lexer.NextToken(); + +#line 2145 "cs.ATG" + op = BinaryOperatorType.Equality; + } + UnaryExpr( +#line 2147 "cs.ATG" +out expr); + RelationalExpr( +#line 2147 "cs.ATG" +ref expr); + +#line 2147 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void RelationalExpr( +#line 2151 "cs.ATG" +ref Expression outExpr) { + +#line 2153 "cs.ATG" + TypeReference type; + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + ShiftExpr( +#line 2158 "cs.ATG" +ref outExpr); + while (StartOf(37)) { + if (StartOf(38)) { + if (la.kind == 23) { + lexer.NextToken(); + +#line 2160 "cs.ATG" + op = BinaryOperatorType.LessThan; + } else if (la.kind == 22) { + lexer.NextToken(); + +#line 2161 "cs.ATG" + op = BinaryOperatorType.GreaterThan; + } else if (la.kind == 36) { + lexer.NextToken(); + +#line 2162 "cs.ATG" + op = BinaryOperatorType.LessThanOrEqual; + } else if (la.kind == 35) { + lexer.NextToken(); + +#line 2163 "cs.ATG" + op = BinaryOperatorType.GreaterThanOrEqual; + } else SynErr(215); + UnaryExpr( +#line 2165 "cs.ATG" +out expr); + ShiftExpr( +#line 2166 "cs.ATG" +ref expr); + +#line 2167 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } else { + if (la.kind == 85) { + lexer.NextToken(); + TypeWithRestriction( +#line 2170 "cs.ATG" +out type, false, false); + if ( +#line 2171 "cs.ATG" +la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { + NullableQuestionMark( +#line 2172 "cs.ATG" +ref type); + } + +#line 2173 "cs.ATG" + outExpr = new TypeOfIsExpression(outExpr, type); + } else if (la.kind == 50) { + lexer.NextToken(); + TypeWithRestriction( +#line 2175 "cs.ATG" +out type, false, false); + if ( +#line 2176 "cs.ATG" +la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) { + NullableQuestionMark( +#line 2177 "cs.ATG" +ref type); + } + +#line 2178 "cs.ATG" + outExpr = new CastExpression(type, outExpr, CastType.TryCast); + } else SynErr(216); + } + } + } + + void ShiftExpr( +#line 2183 "cs.ATG" +ref Expression outExpr) { + +#line 2185 "cs.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + AdditiveExpr( +#line 2189 "cs.ATG" +ref outExpr); + while (la.kind == 37 || +#line 2192 "cs.ATG" +IsShiftRight()) { + if (la.kind == 37) { + lexer.NextToken(); + +#line 2191 "cs.ATG" + op = BinaryOperatorType.ShiftLeft; + } else { + Expect(22); + Expect(22); + +#line 2193 "cs.ATG" + op = BinaryOperatorType.ShiftRight; + } + UnaryExpr( +#line 2196 "cs.ATG" +out expr); + AdditiveExpr( +#line 2196 "cs.ATG" +ref expr); + +#line 2196 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void AdditiveExpr( +#line 2200 "cs.ATG" +ref Expression outExpr) { + +#line 2202 "cs.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + MultiplicativeExpr( +#line 2206 "cs.ATG" +ref outExpr); + while (la.kind == 4 || la.kind == 5) { + if (la.kind == 4) { + lexer.NextToken(); + +#line 2209 "cs.ATG" + op = BinaryOperatorType.Add; + } else { + lexer.NextToken(); + +#line 2210 "cs.ATG" + op = BinaryOperatorType.Subtract; + } + UnaryExpr( +#line 2212 "cs.ATG" +out expr); + MultiplicativeExpr( +#line 2212 "cs.ATG" +ref expr); + +#line 2212 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void MultiplicativeExpr( +#line 2216 "cs.ATG" +ref Expression outExpr) { + +#line 2218 "cs.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + while (la.kind == 6 || la.kind == 7 || la.kind == 8) { + if (la.kind == 6) { + lexer.NextToken(); + +#line 2224 "cs.ATG" + op = BinaryOperatorType.Multiply; + } else if (la.kind == 7) { + lexer.NextToken(); + +#line 2225 "cs.ATG" + op = BinaryOperatorType.Divide; + } else { + lexer.NextToken(); + +#line 2226 "cs.ATG" + op = BinaryOperatorType.Modulus; + } + UnaryExpr( +#line 2228 "cs.ATG" +out expr); + +#line 2228 "cs.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void TypeParameterConstraintsClauseBase( +#line 2332 "cs.ATG" +out TypeReference type) { + +#line 2333 "cs.ATG" + TypeReference t; type = null; + if (la.kind == 109) { + lexer.NextToken(); + +#line 2335 "cs.ATG" + type = TypeReference.StructConstraint; + } else if (la.kind == 59) { + lexer.NextToken(); + +#line 2336 "cs.ATG" + type = TypeReference.ClassConstraint; + } else if (la.kind == 89) { + lexer.NextToken(); + Expect(20); + Expect(21); + +#line 2337 "cs.ATG" + type = TypeReference.NewConstraint; + } else if (StartOf(10)) { + Type( +#line 2338 "cs.ATG" +out t); + +#line 2338 "cs.ATG" + type = t; + } else SynErr(217); + } + + void QueryExpressionFromClause( +#line 2351 "cs.ATG" +out QueryExpressionFromClause fc) { + +#line 2352 "cs.ATG" + fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location; + + Expect(137); + QueryExpressionFromOrJoinClause( +#line 2356 "cs.ATG" +fc); + +#line 2357 "cs.ATG" + fc.EndLocation = t.EndLocation; + } + + void QueryExpressionBody( +#line 2387 "cs.ATG" +QueryExpression q) { + +#line 2388 "cs.ATG" + QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause; + QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause; + QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause; + QueryExpressionIntoClause intoClause; + + while (StartOf(39)) { + if (la.kind == 137) { + QueryExpressionFromClause( +#line 2394 "cs.ATG" +out fromClause); + +#line 2394 "cs.ATG" + SafeAdd(q, q.FromLetWhereClauses, fromClause); + } else if (la.kind == 127) { + QueryExpressionWhereClause( +#line 2395 "cs.ATG" +out whereClause); + +#line 2395 "cs.ATG" + SafeAdd(q, q.FromLetWhereClauses, whereClause); + } else if (la.kind == 141) { + QueryExpressionLetClause( +#line 2396 "cs.ATG" +out letClause); + +#line 2396 "cs.ATG" + SafeAdd(q, q.FromLetWhereClauses, letClause); + } else { + QueryExpressionJoinClause( +#line 2397 "cs.ATG" +out joinClause); + +#line 2397 "cs.ATG" + SafeAdd(q, q.FromLetWhereClauses, joinClause); + } + } + if (la.kind == 140) { + QueryExpressionOrderByClause( +#line 2399 "cs.ATG" +q); + } + if (la.kind == 133) { + QueryExpressionSelectClause( +#line 2400 "cs.ATG" +out selectClause); + +#line 2400 "cs.ATG" + q.SelectOrGroupClause = selectClause; + } else if (la.kind == 134) { + QueryExpressionGroupClause( +#line 2401 "cs.ATG" +out groupClause); + +#line 2401 "cs.ATG" + q.SelectOrGroupClause = groupClause; + } else SynErr(218); + if (la.kind == 136) { + QueryExpressionIntoClause( +#line 2403 "cs.ATG" +out intoClause); + +#line 2403 "cs.ATG" + q.IntoClause = intoClause; + } + } + + void QueryExpressionFromOrJoinClause( +#line 2377 "cs.ATG" +QueryExpressionFromOrJoinClause fjc) { + +#line 2378 "cs.ATG" + TypeReference type; Expression expr; + +#line 2380 "cs.ATG" + fjc.Type = null; + if ( +#line 2381 "cs.ATG" +IsLocalVarDecl()) { + Type( +#line 2381 "cs.ATG" +out type); + +#line 2381 "cs.ATG" + fjc.Type = type; + } + Identifier(); + +#line 2382 "cs.ATG" + fjc.Identifier = t.val; + Expect(81); + Expr( +#line 2384 "cs.ATG" +out expr); + +#line 2384 "cs.ATG" + fjc.InExpression = expr; + } + + void QueryExpressionJoinClause( +#line 2360 "cs.ATG" +out QueryExpressionJoinClause jc) { + +#line 2361 "cs.ATG" + jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location; + Expression expr; + + Expect(142); + QueryExpressionFromOrJoinClause( +#line 2366 "cs.ATG" +jc); + Expect(143); + Expr( +#line 2368 "cs.ATG" +out expr); + +#line 2368 "cs.ATG" + jc.OnExpression = expr; + Expect(144); + Expr( +#line 2370 "cs.ATG" +out expr); + +#line 2370 "cs.ATG" + jc.EqualsExpression = expr; + if (la.kind == 136) { + lexer.NextToken(); + Identifier(); + +#line 2372 "cs.ATG" + jc.IntoIdentifier = t.val; + } + +#line 2374 "cs.ATG" + jc.EndLocation = t.EndLocation; + } + + void QueryExpressionWhereClause( +#line 2406 "cs.ATG" +out QueryExpressionWhereClause wc) { + +#line 2407 "cs.ATG" + Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; + Expect(127); + Expr( +#line 2410 "cs.ATG" +out expr); + +#line 2410 "cs.ATG" + wc.Condition = expr; + +#line 2411 "cs.ATG" + wc.EndLocation = t.EndLocation; + } + + void QueryExpressionLetClause( +#line 2414 "cs.ATG" +out QueryExpressionLetClause wc) { + +#line 2415 "cs.ATG" + Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location; + Expect(141); + Identifier(); + +#line 2418 "cs.ATG" + wc.Identifier = t.val; + Expect(3); + Expr( +#line 2420 "cs.ATG" +out expr); + +#line 2420 "cs.ATG" + wc.Expression = expr; + +#line 2421 "cs.ATG" + wc.EndLocation = t.EndLocation; + } + + void QueryExpressionOrderByClause( +#line 2424 "cs.ATG" +QueryExpression q) { + +#line 2425 "cs.ATG" + QueryExpressionOrdering ordering; + Expect(140); + QueryExpressionOrderingClause( +#line 2428 "cs.ATG" +out ordering); + +#line 2428 "cs.ATG" + SafeAdd(q, q.Orderings, ordering); + while (la.kind == 14) { + lexer.NextToken(); + QueryExpressionOrderingClause( +#line 2430 "cs.ATG" +out ordering); + +#line 2430 "cs.ATG" + SafeAdd(q, q.Orderings, ordering); + } + } + + void QueryExpressionSelectClause( +#line 2444 "cs.ATG" +out QueryExpressionSelectClause sc) { + +#line 2445 "cs.ATG" + Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; + Expect(133); + Expr( +#line 2448 "cs.ATG" +out expr); + +#line 2448 "cs.ATG" + sc.Projection = expr; + +#line 2449 "cs.ATG" + sc.EndLocation = t.EndLocation; + } + + void QueryExpressionGroupClause( +#line 2452 "cs.ATG" +out QueryExpressionGroupClause gc) { + +#line 2453 "cs.ATG" + Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; + Expect(134); + Expr( +#line 2456 "cs.ATG" +out expr); + +#line 2456 "cs.ATG" + gc.Projection = expr; + Expect(135); + Expr( +#line 2458 "cs.ATG" +out expr); + +#line 2458 "cs.ATG" + gc.GroupBy = expr; + +#line 2459 "cs.ATG" + gc.EndLocation = t.EndLocation; + } + + void QueryExpressionIntoClause( +#line 2462 "cs.ATG" +out QueryExpressionIntoClause ic) { + +#line 2463 "cs.ATG" + ic = new QueryExpressionIntoClause(); ic.StartLocation = la.Location; + Expect(136); + Identifier(); + +#line 2466 "cs.ATG" + ic.IntoIdentifier = t.val; + +#line 2467 "cs.ATG" + ic.ContinuedQuery = new QueryExpression(); + +#line 2468 "cs.ATG" + ic.ContinuedQuery.StartLocation = la.Location; + QueryExpressionBody( +#line 2469 "cs.ATG" +ic.ContinuedQuery); + +#line 2470 "cs.ATG" + ic.ContinuedQuery.EndLocation = t.EndLocation; + +#line 2471 "cs.ATG" + ic.EndLocation = t.EndLocation; + } + + void QueryExpressionOrderingClause( +#line 2434 "cs.ATG" +out QueryExpressionOrdering ordering) { + +#line 2435 "cs.ATG" + Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; + Expr( +#line 2437 "cs.ATG" +out expr); + +#line 2437 "cs.ATG" + ordering.Criteria = expr; + if (la.kind == 138 || la.kind == 139) { + if (la.kind == 138) { + lexer.NextToken(); + +#line 2438 "cs.ATG" + ordering.Direction = QueryExpressionOrderingDirection.Ascending; + } else { + lexer.NextToken(); + +#line 2439 "cs.ATG" + ordering.Direction = QueryExpressionOrderingDirection.Descending; + } + } + +#line 2441 "cs.ATG" + ordering.EndLocation = t.EndLocation; + } + + + + public override void Parse() + { + CS(); + + } + + protected override void SynErr(int line, int col, int errorNumber) + { + string s; + switch (errorNumber) { + case 0: s = "EOF expected"; break; + case 1: s = "ident expected"; break; + case 2: s = "Literal expected"; break; + case 3: s = "\"=\" expected"; break; + case 4: s = "\"+\" expected"; break; + case 5: s = "\"-\" expected"; break; + case 6: s = "\"*\" expected"; break; + case 7: s = "\"/\" expected"; break; + case 8: s = "\"%\" expected"; break; + case 9: s = "\":\" expected"; break; + case 10: s = "\"::\" expected"; break; + case 11: s = "\";\" expected"; break; + case 12: s = "\"?\" expected"; break; + case 13: s = "\"??\" expected"; break; + case 14: s = "\",\" expected"; break; + case 15: s = "\".\" expected"; break; + case 16: s = "\"{\" expected"; break; + case 17: s = "\"}\" expected"; break; + case 18: s = "\"[\" expected"; break; + case 19: s = "\"]\" expected"; break; + case 20: s = "\"(\" expected"; break; + case 21: s = "\")\" expected"; break; + case 22: s = "\">\" expected"; break; + case 23: s = "\"<\" expected"; break; + case 24: s = "\"!\" expected"; break; + case 25: s = "\"&&\" expected"; break; + case 26: s = "\"||\" expected"; break; + case 27: s = "\"~\" expected"; break; + case 28: s = "\"&\" expected"; break; + case 29: s = "\"|\" expected"; break; + case 30: s = "\"^\" expected"; break; + case 31: s = "\"++\" expected"; break; + case 32: s = "\"--\" expected"; break; + case 33: s = "\"==\" expected"; break; + case 34: s = "\"!=\" expected"; break; + case 35: s = "\">=\" expected"; break; + case 36: s = "\"<=\" expected"; break; + case 37: s = "\"<<\" expected"; break; + case 38: s = "\"+=\" expected"; break; + case 39: s = "\"-=\" expected"; break; + case 40: s = "\"*=\" expected"; break; + case 41: s = "\"/=\" expected"; break; + case 42: s = "\"%=\" expected"; break; + case 43: s = "\"&=\" expected"; break; + case 44: s = "\"|=\" expected"; break; + case 45: s = "\"^=\" expected"; break; + case 46: s = "\"<<=\" expected"; break; + case 47: s = "\"->\" expected"; break; + case 48: s = "\"=>\" expected"; break; + case 49: s = "\"abstract\" expected"; break; + case 50: s = "\"as\" expected"; break; + case 51: s = "\"base\" expected"; break; + case 52: s = "\"bool\" expected"; break; + case 53: s = "\"break\" expected"; break; + case 54: s = "\"byte\" expected"; break; + case 55: s = "\"case\" expected"; break; + case 56: s = "\"catch\" expected"; break; + case 57: s = "\"char\" expected"; break; + case 58: s = "\"checked\" expected"; break; + case 59: s = "\"class\" expected"; break; + case 60: s = "\"const\" expected"; break; + case 61: s = "\"continue\" expected"; break; + case 62: s = "\"decimal\" expected"; break; + case 63: s = "\"default\" expected"; break; + case 64: s = "\"delegate\" expected"; break; + case 65: s = "\"do\" expected"; break; + case 66: s = "\"double\" expected"; break; + case 67: s = "\"else\" expected"; break; + case 68: s = "\"enum\" expected"; break; + case 69: s = "\"event\" expected"; break; + case 70: s = "\"explicit\" expected"; break; + case 71: s = "\"extern\" expected"; break; + case 72: s = "\"false\" expected"; break; + case 73: s = "\"finally\" expected"; break; + case 74: s = "\"fixed\" expected"; break; + case 75: s = "\"float\" expected"; break; + case 76: s = "\"for\" expected"; break; + case 77: s = "\"foreach\" expected"; break; + case 78: s = "\"goto\" expected"; break; + case 79: s = "\"if\" expected"; break; + case 80: s = "\"implicit\" expected"; break; + case 81: s = "\"in\" expected"; break; + case 82: s = "\"int\" expected"; break; + case 83: s = "\"interface\" expected"; break; + case 84: s = "\"internal\" expected"; break; + case 85: s = "\"is\" expected"; break; + case 86: s = "\"lock\" expected"; break; + case 87: s = "\"long\" expected"; break; + case 88: s = "\"namespace\" expected"; break; + case 89: s = "\"new\" expected"; break; + case 90: s = "\"null\" expected"; break; + case 91: s = "\"object\" expected"; break; + case 92: s = "\"operator\" expected"; break; + case 93: s = "\"out\" expected"; break; + case 94: s = "\"override\" expected"; break; + case 95: s = "\"params\" expected"; break; + case 96: s = "\"private\" expected"; break; + case 97: s = "\"protected\" expected"; break; + case 98: s = "\"public\" expected"; break; + case 99: s = "\"readonly\" expected"; break; + case 100: s = "\"ref\" expected"; break; + case 101: s = "\"return\" expected"; break; + case 102: s = "\"sbyte\" expected"; break; + case 103: s = "\"sealed\" expected"; break; + case 104: s = "\"short\" expected"; break; + case 105: s = "\"sizeof\" expected"; break; + case 106: s = "\"stackalloc\" expected"; break; + case 107: s = "\"static\" expected"; break; + case 108: s = "\"string\" expected"; break; + case 109: s = "\"struct\" expected"; break; + case 110: s = "\"switch\" expected"; break; + case 111: s = "\"this\" expected"; break; + case 112: s = "\"throw\" expected"; break; + case 113: s = "\"true\" expected"; break; + case 114: s = "\"try\" expected"; break; + case 115: s = "\"typeof\" expected"; break; + case 116: s = "\"uint\" expected"; break; + case 117: s = "\"ulong\" expected"; break; + case 118: s = "\"unchecked\" expected"; break; + case 119: s = "\"unsafe\" expected"; break; + case 120: s = "\"ushort\" expected"; break; + case 121: s = "\"using\" expected"; break; + case 122: s = "\"virtual\" expected"; break; + case 123: s = "\"void\" expected"; break; + case 124: s = "\"volatile\" expected"; break; + case 125: s = "\"while\" expected"; break; + case 126: s = "\"partial\" expected"; break; + case 127: s = "\"where\" expected"; break; + case 128: s = "\"get\" expected"; break; + case 129: s = "\"set\" expected"; break; + case 130: s = "\"add\" expected"; break; + case 131: s = "\"remove\" expected"; break; + case 132: s = "\"yield\" expected"; break; + case 133: s = "\"select\" expected"; break; + case 134: s = "\"group\" expected"; break; + case 135: s = "\"by\" expected"; break; + case 136: s = "\"into\" expected"; break; + case 137: s = "\"from\" expected"; break; + case 138: s = "\"ascending\" expected"; break; + case 139: s = "\"descending\" expected"; break; + case 140: s = "\"orderby\" expected"; break; + case 141: s = "\"let\" expected"; break; + case 142: s = "\"join\" expected"; break; + case 143: s = "\"on\" expected"; break; + case 144: s = "\"equals\" expected"; break; + case 145: s = "??? expected"; break; + case 146: s = "invalid NamespaceMemberDecl"; break; + case 147: s = "invalid NonArrayType"; break; + case 148: s = "invalid Identifier"; break; + case 149: s = "invalid AttributeArguments"; break; + case 150: s = "invalid Expr"; break; + case 151: s = "invalid TypeModifier"; break; + case 152: s = "invalid TypeDecl"; break; + case 153: s = "invalid TypeDecl"; break; + case 154: s = "this symbol not expected in ClassBody"; break; + case 155: s = "this symbol not expected in InterfaceBody"; break; + case 156: s = "invalid IntegralType"; break; + case 157: s = "invalid FormalParameterList"; break; + case 158: s = "invalid FormalParameterList"; break; + case 159: s = "invalid ClassType"; break; + case 160: s = "invalid ClassMemberDecl"; break; + case 161: s = "invalid ClassMemberDecl"; break; + case 162: s = "invalid StructMemberDecl"; break; + case 163: s = "invalid StructMemberDecl"; break; + case 164: s = "invalid StructMemberDecl"; break; + case 165: s = "invalid StructMemberDecl"; break; + case 166: s = "invalid StructMemberDecl"; break; + case 167: s = "invalid StructMemberDecl"; break; + case 168: s = "invalid StructMemberDecl"; break; + case 169: s = "invalid StructMemberDecl"; break; + case 170: s = "invalid StructMemberDecl"; break; + case 171: s = "invalid StructMemberDecl"; break; + case 172: s = "invalid StructMemberDecl"; break; + case 173: s = "invalid StructMemberDecl"; break; + case 174: s = "invalid StructMemberDecl"; break; + case 175: s = "invalid InterfaceMemberDecl"; break; + case 176: s = "invalid InterfaceMemberDecl"; break; + case 177: s = "invalid InterfaceMemberDecl"; break; + case 178: s = "invalid TypeWithRestriction"; break; + case 179: s = "invalid TypeWithRestriction"; break; + case 180: s = "invalid SimpleType"; break; + case 181: s = "invalid AccessorModifiers"; break; + case 182: s = "invalid EventAccessorDecls"; break; + case 183: s = "invalid ConstructorInitializer"; break; + case 184: s = "invalid OverloadableOperator"; break; + case 185: s = "invalid AccessorDecls"; break; + case 186: s = "invalid InterfaceAccessors"; break; + case 187: s = "invalid InterfaceAccessors"; break; + case 188: s = "invalid GetAccessorDecl"; break; + case 189: s = "invalid SetAccessorDecl"; break; + case 190: s = "invalid VariableInitializer"; break; + case 191: s = "this symbol not expected in Statement"; break; + case 192: s = "invalid Statement"; break; + case 193: s = "invalid AssignmentOperator"; break; + case 194: s = "invalid ObjectPropertyInitializerOrVariableInitializer"; break; + case 195: s = "invalid ObjectPropertyInitializerOrVariableInitializer"; break; + case 196: s = "invalid EmbeddedStatement"; break; + case 197: s = "invalid EmbeddedStatement"; break; + case 198: s = "this symbol not expected in EmbeddedStatement"; break; + case 199: s = "invalid EmbeddedStatement"; break; + case 200: s = "invalid ForInitializer"; break; + case 201: s = "invalid GotoStatement"; break; + case 202: s = "invalid TryStatement"; break; + case 203: s = "invalid ResourceAcquisition"; break; + case 204: s = "invalid SwitchLabel"; break; + case 205: s = "invalid CatchClauses"; break; + case 206: s = "invalid UnaryExpr"; break; + case 207: s = "invalid PrimaryExpr"; break; + case 208: s = "invalid PrimaryExpr"; break; + case 209: s = "invalid PrimaryExpr"; break; + case 210: s = "invalid TypeArgumentList"; break; + case 211: s = "invalid NewExpression"; break; + case 212: s = "invalid NewExpression"; break; + case 213: s = "invalid LambdaExpressionParameter"; break; + case 214: s = "invalid LambdaExpressionBody"; break; + case 215: s = "invalid RelationalExpr"; break; + case 216: s = "invalid RelationalExpr"; break; + case 217: s = "invalid TypeParameterConstraintsClauseBase"; break; + case 218: s = "invalid QueryExpressionBody"; break; + + default: s = "error " + errorNumber; break; + } + this.Errors.Error(line, col, s); + } + + private bool StartOf(int s) + { + return set[s, lexer.LookAhead.kind]; + } + + static bool[,] set = { + {T,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,T,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,T,T,x, x,T,T,T, T,T,T,T, T,T,T,x, T,T,T,T, T,x,T,T, T,T,T,T, T,x,T,T, T,x,T,T, x,T,T,T, x,x,T,x, T,T,T,T, x,T,T,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, T,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,x,x, T,T,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,T,x, T,T,x,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,T, T,T,T,T, T,T,x,T, T,T,T,T, T,T,T,T, T,T,T,T, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, x,T,T,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,T,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,T,x,T, x,x,x,x, T,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,x,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,x,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,T, x,x,T,T, x,x,x,x, T,x,T,T, T,x,x,T, x,T,x,T, x,x,T,x, T,T,T,T, x,x,T,T, T,x,x,T, T,T,x,x, x,x,x,x, T,T,x,T, T,x,T,T, T,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,T,x,x, x,x,x,x, T,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,x, x,x,T,x, T,T,T,T, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,T, T,x,T,x, T,x,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,T,T, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,T,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,T, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,T,T,x, T,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,T,x,x, x,x,x,x, T,x,T,x, T,T,x,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {T,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,T,T,x, T,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,T,T,x, x,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,T,x, T,T,T,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,T,T,x, T,T,T,x, x,x,x,T, x,x,x,x, T,x,x,x, T,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, x,T,T,x, T,T,T,T, T,T,T,x, x,x,x,x, T,x,T,T, T,T,T,T, x,x,T,x, x,x,T,T, x,T,T,T, x,x,x,x, x,x,x,x, x,T,T,x, T,T,x,x, T,x,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,T, T,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,T,x, x,T,T,x, x,x,T,T, T,x,T,x, x,x,x,x, T,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,T,x, T,T,x,x, T,x,x,T, x,T,x,T, T,T,T,x, T,x,x,x, x,x,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,T,T,T, T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,T,x,x, x,x,T,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,T,x, x,x,x,T, x,x,x,T, x,x,x,x, x,x,x,x, x,x,T,x, T,x,x,x, T,x,x,x, x,x,x,x, T,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,T,x,x, x,T,T,x, x,x,x} + + }; +} // end Parser + +} \ No newline at end of file diff --git a/lib/NRefactory/Project/Src/Parser/CSharp/cs.ATG b/lib/NRefactory/Project/Src/Parser/CSharp/cs.ATG new file mode 100644 index 000000000..e6af8f0ae --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/CSharp/cs.ATG @@ -0,0 +1,2501 @@ +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Text; +using ICSharpCode.NRefactory.Parser; +using ICSharpCode.NRefactory.Ast; +using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute; +using Types = ICSharpCode.NRefactory.Ast.ClassType; + +COMPILER CS /* AW 2002-12-30 renamed from CompilationUnit to CS */ + + +/*------------------------------------------------------------------------* + *----- LEXER TOKEN LIST ------------------------------------------------* + *------------------------------------------------------------------------*/ + +/* START AUTOGENERATED TOKENS SECTION */ +TOKENS + /* ----- terminal classes ----- */ + /* EOF is 0 */ + ident + Literal + + /* ----- special character ----- */ + "=" + "+" + "-" + "*" + "/" + "%" + ":" + "::" + ";" + "?" + "??" + "," + "." + "{" + "}" + "[" + "]" + "(" + ")" + ">" + "<" + "!" + "&&" + "||" + "~" + "&" + "|" + "^" + "++" + "--" + "==" + "!=" + ">=" + "<=" + "<<" + "+=" + "-=" + "*=" + "/=" + "%=" + "&=" + "|=" + "^=" + "<<=" + "->" + "=>" + + /* ----- keywords ----- */ + "abstract" + "as" + "base" + "bool" + "break" + "byte" + "case" + "catch" + "char" + "checked" + "class" + "const" + "continue" + "decimal" + "default" + "delegate" + "do" + "double" + "else" + "enum" + "event" + "explicit" + "extern" + "false" + "finally" + "fixed" + "float" + "for" + "foreach" + "goto" + "if" + "implicit" + "in" + "int" + "interface" + "internal" + "is" + "lock" + "long" + "namespace" + "new" + "null" + "object" + "operator" + "out" + "override" + "params" + "private" + "protected" + "public" + "readonly" + "ref" + "return" + "sbyte" + "sealed" + "short" + "sizeof" + "stackalloc" + "static" + "string" + "struct" + "switch" + "this" + "throw" + "true" + "try" + "typeof" + "uint" + "ulong" + "unchecked" + "unsafe" + "ushort" + "using" + "virtual" + "void" + "volatile" + "while" + "partial" + "where" + "get" + "set" + "add" + "remove" + "yield" + "select" + "group" + "by" + "into" + "from" + "ascending" + "descending" + "orderby" + "let" + "join" + "on" + "equals" +/* END AUTOGENERATED TOKENS SECTION */ + +/*------------------------------------------------------------------------* + *----- PARSER -----------------------------------------------------------* + *------------------------------------------------------------------------*/ + +PRODUCTIONS + +/*--- compilation unit: */ +CS +(. lexer.NextToken(); /* get the first token */ .) += + { UsingDirective } + { IF (IsGlobalAttrTarget()) GlobalAttributeSection } + { NamespaceMemberDecl } + EOF +. + +UsingDirective +(. + string qualident = null; TypeReference aliasedType = null; +.) += + "using" (. Location startPos = t.Location; .) + Qualident + [ "=" NonArrayType ] + ";" (. + if (qualident != null && qualident.Length > 0) { + INode node; + if (aliasedType != null) { + node = new UsingDeclaration(qualident, aliasedType); + } else { + node = new UsingDeclaration(qualident); + } + node.StartLocation = startPos; + node.EndLocation = t.EndLocation; + compilationUnit.AddChild(node); + } + .) +. + +GlobalAttributeSection += + "[" (. Location startPos = t.Location; .) Identifier + (. if (t.val != "assembly" && t.val != "module") Error("global attribute target specifier (assembly or module) expected"); + string attributeTarget = t.val; + List attributes = new List(); + ASTAttribute attribute; + .) + ":" Attribute (. attributes.Add(attribute); .) + { IF (NotFinalComma()) "," Attribute (. attributes.Add(attribute); .)} + [ "," ] + "]" (. AttributeSection section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + compilationUnit.AddChild(section); + .) +. + +Attribute +(. string qualident; + string alias = null; +.) += + (. Location startPos = la.Location; .) + [ IF (IdentAndDoubleColon()) + Identifier (. alias = t.val; .) + "::" + ] + Qualident + (. List positional = new List(); + List named = new List(); + string name = (alias != null && alias != "global") ? alias + "." + qualident : qualident; + .) + [ AttributeArguments ] + (. attribute = new ASTAttribute(name, positional, named); + attribute.StartLocation = startPos; + attribute.EndLocation = t.EndLocation; + .) +. + +AttributeArguments positional, List named> +(. + bool nameFound = false; + string name = ""; + Expression expr; +.) += + "(" + [ + [ + IF (IsAssignment()) (. nameFound = true; .) + Identifier (. name = t.val; .) + "=" + ] Expr (. if (expr != null) {if(name == "") positional.Add(expr); + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + .) + + { + "," + ( + IF (IsAssignment()) (. nameFound = true; .) + Identifier (. name = t.val; .) + "=" + | /*Empty*/ (. if (nameFound) Error("no positional argument after named argument"); .) + ) Expr (. if (expr != null) { if(name == "") positional.Add(expr); + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + .) + } + ] + ")" +. + +AttributeSection +(. + string attributeTarget = ""; + List attributes = new List(); + ASTAttribute attribute; + +.) += + "[" (. Location startPos = t.Location; .) /*--- attribute target specifier: */ + [ IF (IsLocalAttrTarget()) + ( "event" (. attributeTarget = "event";.) + | "return" (. attributeTarget = "return";.) + | Identifier (. if (t.val != "field" && t.val != "method" && + t.val != "param" && + t.val != "property" && t.val != "type") + Error("attribute target specifier (field, event, method, param, property, return or type) expected"); + attributeTarget = t.val; + .) + ) ":" + ] + /*--- attribute list: */ + Attribute (. attributes.Add(attribute); .) + { IF (NotFinalComma()) "," Attribute (. attributes.Add(attribute); .)} + [ "," ] + "]" (. section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + .) +. + +NamespaceMemberDecl +(. + AttributeSection section; + List attributes = new List(); + ModifierList m = new ModifierList(); + string qualident; +.) += /*--- namespace declaration: */ + "namespace" (. Location startPos = t.Location; .) + Qualident (. INode node = new NamespaceDeclaration(qualident); + node.StartLocation = startPos; + compilationUnit.AddChild(node); + compilationUnit.BlockStart(node); + .) + "{" + { UsingDirective } + { NamespaceMemberDecl } + "}" + [ ";" ] (. node.EndLocation = t.EndLocation; + compilationUnit.BlockEnd(); + .) + /*--- type declaration: */ + | { AttributeSection (. attributes.Add(section); .) } + { TypeModifier } + TypeDecl +. + +TypeDecl attributes> +(. + TypeReference type; + List names; + List p = new List(); + string name; + List templates; +.) += /*--- class declaration: */ (. m.Check(Modifiers.Classes); .) + "class" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + + newType.Type = Types.Class; + .) + Identifier (. newType.Name = t.val; .) + + /* .NET 2.0 */ + [ TypeParameterList ] + + [ ClassBase (. newType.BaseTypes = names; .) ] + + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + + (. newType.BodyStartLocation = t.EndLocation; .) + "{" + ClassBody + "}" + [ ";" ] (. newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + .) +| /*--- struct declaration: */ (. m.Check(Modifiers.StructsInterfacesEnumsDelegates); .) + ( "struct" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + newType.StartLocation = m.GetDeclarationLocation(t.Location); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.Type = Types.Struct; + .) + Identifier (. newType.Name = t.val; .) + + /* .NET 2.0 */ + [ TypeParameterList ] + + [ StructInterfaces (. newType.BaseTypes = names; .) ] + + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + + + (. newType.BodyStartLocation = t.EndLocation; .) + StructBody + [ ";" ] (. newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + .) +| /*--- interface declaration: */ + "interface" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + templates = newType.Templates; + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = Types.Interface; + .) + Identifier (. newType.Name = t.val; .) + + /* .NET 2.0 */ + [ TypeParameterList ] + + [ InterfaceBase (. newType.BaseTypes = names; .) ] + + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + + (. newType.BodyStartLocation = t.EndLocation; .) + InterfaceBody + [ ";" ] (. newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + .) +| /*--- enumeration declaration: */ + "enum" (. TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = Types.Enum; + .) + Identifier (. newType.Name = t.val; .) + [ ":" IntegralType (. newType.BaseTypes.Add(new TypeReference(name)); .) + ] + (. newType.BodyStartLocation = t.EndLocation; .) + EnumBody + [ ";" ] (. newType.EndLocation = t.Location; + compilationUnit.BlockEnd(); + .) +| /*--- delegate declaration: */ + "delegate" (. DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); + templates = delegateDeclr.Templates; + delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); + .) + ( IF (NotVoidPointer()) "void" (. delegateDeclr.ReturnType = new TypeReference("void", 0, null); .) + | Type (. delegateDeclr.ReturnType = type; .) + ) + Identifier (. delegateDeclr.Name = t.val; .) + + /* .NET 2.0 */ + [ TypeParameterList ] + + "(" [ FormalParameterList

(. delegateDeclr.Parameters = p; .) + ] ")" + + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + + ";" (. delegateDeclr.EndLocation = t.Location; + compilationUnit.AddChild(delegateDeclr); + .) + ) +. + +Qualident += + Identifier (. qualidentBuilder.Length = 0; qualidentBuilder.Append(t.val); .) + { IF (DotAndIdent()) "." Identifier (. qualidentBuilder.Append('.'); + qualidentBuilder.Append(t.val); + .) + } (. qualident = qualidentBuilder.ToString(); .) +. + +ClassBase names> +(. + TypeReference typeRef; + names = new List(); +.) += + ":" ClassType (. if (typeRef != null) { names.Add(typeRef); } .) + { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } +. + +ClassBody +(. AttributeSection section; .) += + { (.List attributes = new List(); + ModifierList m = new ModifierList(); + .) + SYNC + { AttributeSection (. attributes.Add(section); .) } + MemberModifiers + ClassMemberDecl + } +. + +StructInterfaces names> +(. + TypeReference typeRef; + names = new List(); +.) += + ":" TypeName (. if (typeRef != null) { names.Add(typeRef); } .) + { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } +. + +StructBody +(. AttributeSection section; .) += + "{" + { (.List attributes = new List(); + ModifierList m = new ModifierList(); + .) + { AttributeSection (. attributes.Add(section); .) } + MemberModifiers + StructMemberDecl + } + "}" +. + +InterfaceBase names> +(. + TypeReference typeRef; + names = new List(); +.) += + ":" TypeName (. if (typeRef != null) { names.Add(typeRef); } .) + { "," TypeName (. if (typeRef != null) { names.Add(typeRef); } .) } +. + +InterfaceBody += "{" + { SYNC InterfaceMemberDecl } + "}" +. + +EnumBody (. FieldDeclaration f; .) += + "{" + [ EnumMemberDecl (. compilationUnit.AddChild(f); .) + { IF (NotFinalComma()) "," + EnumMemberDecl (. compilationUnit.AddChild(f); .) + } + [","] ] + "}" +. + +Type += + TypeWithRestriction +. + +TypeWithRestriction +(. + string name; + int pointer = 0; + type = null; +.) += + ( ClassType + | SimpleType (. type = new TypeReference(name); .) + | "void" "*" (. pointer = 1; type = new TypeReference("void"); .) + ) (. List r = new List(); .) + + [ IF (allowNullable && la.kind == Tokens.Question) NullableQuestionMark ] + + { IF (IsPointerOrDims()) (. int i = 0; .) + ( "*" (. ++pointer; .) + | "[" { "," (. ++i; .) } "]" (. r.Add(i); .) + ) + } + (. if (type != null) { + type.RankSpecifier = r.ToArray(); + type.PointerNestingLevel = pointer; + } + .) +. + + +NonArrayType +(. + string name; + int pointer = 0; + type = null; +.) += + ( ClassType + | SimpleType (. type = new TypeReference(name); .) + | "void" "*" (. pointer = 1; type = new TypeReference("void"); .) + ) + + [ NullableQuestionMark ] + + { IF (IsPointer()) + "*" (. ++pointer; .) + } + (. if (type != null) { type.PointerNestingLevel = pointer; } .) +. + +SimpleType +(. name = String.Empty; .) += + IntegralType + | "float" (. name = "float"; .) + | "double" (. name = "double"; .) + | "decimal" (. name = "decimal"; .) + | "bool" (. name = "bool"; .) +. + + +FormalParameterList parameter> +(. + + ParameterDeclarationExpression p; + AttributeSection section; + List attributes = new List(); +.) += + { AttributeSection (.attributes.Add(section); .) } + ( + FixedParameter (. bool paramsFound = false; + p.Attributes = attributes; + parameter.Add(p); + .) + { + "," (. attributes = new List(); if (paramsFound) Error("params array must be at end of parameter list"); .) + { AttributeSection (.attributes.Add(section); .) } + ( + FixedParameter (. p.Attributes = attributes; parameter.Add(p); .) + | ParameterArray (. paramsFound = true; p.Attributes = attributes; parameter.Add(p); .) + ) + } + | ParameterArray (. p.Attributes = attributes; parameter.Add(p); .) + ) +. + +FixedParameter +(. + TypeReference type; + ParameterModifiers mod = ParameterModifiers.In; + Location start = t.Location; +.) += + [ + "ref" (. mod = ParameterModifiers.Ref; .) + | "out" (. mod = ParameterModifiers.Out; .) + ] + Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, mod); p.StartLocation = start; p.EndLocation = t.Location; .) +. + +ParameterArray +(. TypeReference type; .) += + "params" Type Identifier (. p = new ParameterDeclarationExpression(type, t.val, ParameterModifiers.Params); .) +. + +AccessorModifiers +(. m = new ModifierList(); .) += + "private" (. m.Add(Modifiers.Private, t.Location); .) + | "protected" (. m.Add(Modifiers.Protected, t.Location); .) + ["internal" (. m.Add(Modifiers.Internal, t.Location); .)] + | "internal" (. m.Add(Modifiers.Internal, t.Location); .) + ["protected" (. m.Add(Modifiers.Protected, t.Location); .)] +. + +TypeModifier += + "new" (. m.Add(Modifiers.New, t.Location); .) + | "public" (. m.Add(Modifiers.Public, t.Location); .) + | "protected" (. m.Add(Modifiers.Protected, t.Location); .) + | "internal" (. m.Add(Modifiers.Internal, t.Location); .) + | "private" (. m.Add(Modifiers.Private, t.Location); .) + | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .) + | "abstract" (. m.Add(Modifiers.Abstract, t.Location); .) + | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .) + | "static" (. m.Add(Modifiers.Static, t.Location); .) + | "partial" (. m.Add(Modifiers.Partial, t.Location); .) +. + +ClassType +(. TypeReference r; typeRef = null; .) += + TypeName (. typeRef = r; .) + | "object" (. typeRef = new TypeReference("object"); .) + | "string" (. typeRef = new TypeReference("string"); .) +. + +IntegralType (. name = ""; .) += + "sbyte" (. name = "sbyte"; .) + | "byte" (. name = "byte"; .) + | "short" (. name = "short"; .) + | "ushort" (. name = "ushort"; .) + | "int" (. name = "int"; .) + | "uint" (. name = "uint"; .) + | "long" (. name = "long"; .) + | "ulong" (. name = "ulong"; .) + | "char" (. name = "char"; .) +. + +MemberModifiers += + { + "abstract" (. m.Add(Modifiers.Abstract, t.Location); .) + | "extern" (. m.Add(Modifiers.Extern, t.Location); .) + | "internal" (. m.Add(Modifiers.Internal, t.Location); .) + | "new" (. m.Add(Modifiers.New, t.Location); .) + | "override" (. m.Add(Modifiers.Override, t.Location); .) + | "private" (. m.Add(Modifiers.Private, t.Location); .) + | "protected" (. m.Add(Modifiers.Protected, t.Location); .) + | "public" (. m.Add(Modifiers.Public, t.Location); .) + | "readonly" (. m.Add(Modifiers.ReadOnly, t.Location); .) + | "sealed" (. m.Add(Modifiers.Sealed, t.Location); .) + | "static" (. m.Add(Modifiers.Static, t.Location); .) + | "fixed" (. m.Add(Modifiers.Fixed, t.Location); .) + | "unsafe" (. m.Add(Modifiers.Unsafe, t.Location); .) + | "virtual" (. m.Add(Modifiers.Virtual, t.Location); .) + | "volatile" (. m.Add(Modifiers.Volatile, t.Location); .) + | "partial" (. m.Add(Modifiers.Partial, t.Location); .) + } +. + +StructMemberDecl attributes> +(. + string qualident = null; + TypeReference type; + Expression expr; + List p = new List(); + Statement stmt = null; + List variableDeclarators = new List(); + List templates = new List(); + TypeReference explicitInterface = null; + bool isExtensionMethod = false; +.) += + /*--- constant declaration: */ (. m.Check(Modifiers.Constants); .) + "const" (.Location startPos = t.Location; .) + Type Identifier (. FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier | Modifiers.Const); + fd.StartLocation = m.GetDeclarationLocation(startPos); + VariableDeclaration f = new VariableDeclaration(t.val); + fd.Fields.Add(f); + .) + "=" Expr (. f.Initializer = expr; .) + { "," Identifier (. f = new VariableDeclaration(t.val); + fd.Fields.Add(f); + .) + "=" Expr (. f.Initializer = expr; .) + } ";" (. fd.EndLocation = t.EndLocation; compilationUnit.AddChild(fd); .) + + +| /*--- void method (procedure) declaration: */ + IF (NotVoidPointer()) (. m.Check(Modifiers.PropertysEventsMethods); .) + "void" (. Location startPos = t.Location; .) + ( IF (IsExplicitInterfaceImplementation()) + TypeName + (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { + qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); + } .) + | Identifier (. qualident = t.val; .) + ) + /* .NET 2.0 */ + [ TypeParameterList ] + + "(" + [ "this" (. isExtensionMethod = true; /* C# 3.0 */ .) ] + [ FormalParameterList

] ")" + (. MethodDeclaration methodDeclaration = new MethodDeclaration { + Name = qualident, + Modifier = m.Modifier, + TypeReference = new TypeReference("void"), + Parameters = p, + Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation, + Templates = templates, + IsExtensionMethod = isExtensionMethod + }; + if (explicitInterface != null) + methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + compilationUnit.AddChild(methodDeclaration); + compilationUnit.BlockStart(methodDeclaration); + .) + + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + + ( Block | ";" ) (. compilationUnit.BlockEnd(); + methodDeclaration.Body = (BlockStatement)stmt; + .) + +| /*--- event declaration: */ (. m.Check(Modifiers.PropertysEventsMethods); .) + "event" + (. EventDeclaration eventDecl = new EventDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + StartLocation = t.Location + }; + compilationUnit.AddChild(eventDecl); + compilationUnit.BlockStart(eventDecl); + EventAddRegion addBlock = null; + EventRemoveRegion removeBlock = null; + .) + Type (. eventDecl.TypeReference = type; .) + ( IF (IsExplicitInterfaceImplementation()) + TypeName + (. qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); .) + (. eventDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); .) + + | Identifier (. qualident = t.val; .) + ) + (. eventDecl.Name = qualident; eventDecl.EndLocation = t.EndLocation; .) + [ "=" Expr (. eventDecl.Initializer = expr; .) ] + [ "{" (. eventDecl.BodyStart = t.Location; .) + EventAccessorDecls + "}" (. eventDecl.BodyEnd = t.EndLocation; .) + ] + [ ";" ] + (. compilationUnit.BlockEnd(); + eventDecl.AddRegion = addBlock; + eventDecl.RemoveRegion = removeBlock; + .) + +| /*--- constructor or static contructor declaration: */ + IF (IdentAndLPar()) (. m.Check(Modifiers.Constructors | Modifiers.StaticConstructors); .) + Identifier (. string name = t.val; Location startPos = t.Location; .) "(" [ (. m.Check(Modifiers.Constructors); .) + FormalParameterList

+ ] + ")" (.ConstructorInitializer init = null; .) + [ (. m.Check(Modifiers.Constructors); .) + ConstructorInitializer + ] (. + ConstructorDeclaration cd = new ConstructorDeclaration(name, m.Modifier, p, init, attributes); + cd.StartLocation = startPos; + cd.EndLocation = t.EndLocation; + .) + + ( Block | ";" ) (. cd.Body = (BlockStatement)stmt; compilationUnit.AddChild(cd); .) + + +| /*--- conversion operator declaration: */ (. m.Check(Modifiers.Operators); + if (m.isNone) Error("at least one modifier must be set"); + bool isImplicit = true; + Location startPos = Location.Empty; + .) + ( "implicit" (. startPos = t.Location; .) | "explicit" (. isImplicit = false; startPos = t.Location; .) ) + "operator" Type (. TypeReference operatorType = type; .) + "(" Type Identifier (. string varName = t.val; .) ")" + (. Location endPos = t.Location; .) + ( Block | ";" (. stmt = null; .) ) + (. + + List parameters = new List(); + parameters.Add(new ParameterDeclarationExpression(type, varName)); + OperatorDeclaration operatorDeclaration = new OperatorDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + Parameters = parameters, + TypeReference = operatorType, + ConversionType = isImplicit ? ConversionType.Implicit : ConversionType.Explicit, + Body = (BlockStatement)stmt, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = endPos + }; + compilationUnit.AddChild(operatorDeclaration); + .) + + +| /*--- inner type declaration: */ + TypeDecl + +| Type (. Location startPos = t.Location; .) + ( + /*--- operator declaration: */ (. OverloadableOperatorType op; + m.Check(Modifiers.Operators); + if (m.isNone) Error("at least one modifier must be set"); + .) + "operator" OverloadableOperator (. TypeReference firstType, secondType = null; string secondName = null; .) + "(" Type Identifier (. string firstName = t.val; .) + ( "," Type Identifier (. secondName = t.val; .) /* (. if (Tokens.OverloadableUnaryOp[op.kind] && !Tokens.OverloadableBinaryOp[op.kind]) + Error("too many operands for unary operator"); + .)*/ + | /* empty */ /*(. if (Tokens.OverloadableBinaryOp[op.kind]){ + Error("too few operands for binary operator"); + } + .)*/ + ) + (. Location endPos = t.Location; .) + ")" ( Block | ";" ) + (. + List parameters = new List(); + parameters.Add(new ParameterDeclarationExpression(firstType, firstName)); + if (secondType != null) { + parameters.Add(new ParameterDeclarationExpression(secondType, secondName)); + } + OperatorDeclaration operatorDeclaration = new OperatorDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + Parameters = parameters, + TypeReference = type, + OverloadableOperator = op, + Body = (BlockStatement)stmt, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = endPos + }; + compilationUnit.AddChild(operatorDeclaration); + .) + + /*--- field declaration: */ + | IF (IsVarDecl()) + (. m.Check(Modifiers.Fields); + FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); + fd.StartLocation = m.GetDeclarationLocation(startPos); + .) + ( IF (m.Contains(Modifiers.Fixed)) + VariableDeclarator + "[" + Expr (. if (variableDeclarators.Count > 0) + variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .) + "]" + { "," + VariableDeclarator + "[" + Expr (. if (variableDeclarators.Count > 0) + variableDeclarators[variableDeclarators.Count-1].FixedArrayInitialization = expr; .) + "]" + } + | /* non-fixed field */ + VariableDeclarator + { "," VariableDeclarator } + ) + ";" (. fd.EndLocation = t.EndLocation; fd.Fields = variableDeclarators; compilationUnit.AddChild(fd); .) + + /*--- unqualified indexer declaration (without interface name): */ + | (. m.Check(Modifiers.Indexers); .) + "this" "[" FormalParameterList

"]" (. Location endLocation = t.EndLocation; .) "{" (. + IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); + indexer.StartLocation = startPos; + indexer.EndLocation = endLocation; + indexer.BodyStart = t.Location; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + .) + AccessorDecls "}" (. + indexer.BodyEnd = t.EndLocation; + indexer.GetRegion = getRegion; + indexer.SetRegion = setRegion; + compilationUnit.AddChild(indexer); + .) + | IF (IsIdentifierToken(la)) + ( IF (IsExplicitInterfaceImplementation()) + TypeName + (.if (la.kind != Tokens.Dot || Peek(1).kind != Tokens.This) { + qualident = TypeReference.StripLastIdentifierFromType(ref explicitInterface); + } .) + | Identifier (. qualident = t.val; .) + ) + (. Location qualIdentEndLocation = t.EndLocation; .) + + ( + /*--- "not void" method (function) declaration: */ + ( (. m.Check(Modifiers.PropertysEventsMethods); .) + /* .NET 2.0 */ + [ TypeParameterList ] + "(" + [ "this" (. isExtensionMethod = true; .) ] + [ FormalParameterList

] ")" + (. + MethodDeclaration methodDeclaration = new MethodDeclaration { + Name = qualident, + Modifier = m.Modifier, + TypeReference = type, + Parameters = p, + Attributes = attributes + }; + if (explicitInterface != null) + methodDeclaration.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + methodDeclaration.StartLocation = m.GetDeclarationLocation(startPos); + methodDeclaration.EndLocation = t.EndLocation; + methodDeclaration.IsExtensionMethod = isExtensionMethod; + methodDeclaration.Templates = templates; + compilationUnit.AddChild(methodDeclaration); + .) + { TypeParameterConstraintsClause } + ( Block | ";" ) (. methodDeclaration.Body = (BlockStatement)stmt; .) + + /*--- property declaration: */ + | "{" (. PropertyDeclaration pDecl = new PropertyDeclaration(qualident, type, m.Modifier, attributes); + if (explicitInterface != null) + pDecl.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, qualident)); + pDecl.StartLocation = m.GetDeclarationLocation(startPos); + pDecl.EndLocation = qualIdentEndLocation; + pDecl.BodyStart = t.Location; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + .) + AccessorDecls + "}" (. + pDecl.GetRegion = getRegion; + pDecl.SetRegion = setRegion; + pDecl.BodyEnd = t.EndLocation; + compilationUnit.AddChild(pDecl); + .) + ) + + /*--- qualified indexer declaration (with interface name): */ + | (. m.Check(Modifiers.Indexers); .) + "." "this" "[" FormalParameterList

"]" (. + IndexerDeclaration indexer = new IndexerDeclaration(type, p, m.Modifier, attributes); + indexer.StartLocation = m.GetDeclarationLocation(startPos); + indexer.EndLocation = t.EndLocation; + if (explicitInterface != null) + indexer.InterfaceImplementations.Add(new InterfaceImplementation(explicitInterface, "this")); + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + .) + "{" (. Location bodyStart = t.Location; .) + AccessorDecls + "}" (. indexer.BodyStart = bodyStart; + indexer.BodyEnd = t.EndLocation; + indexer.GetRegion = getRegion; + indexer.SetRegion = setRegion; + compilationUnit.AddChild(indexer); + .) + ) + ) +. + +ClassMemberDecl attributes> +(. Statement stmt = null; .) += + StructMemberDecl + | /*--- destructor declaration: */ (. m.Check(Modifiers.Destructors); Location startPos = t.Location; .) + "~" Identifier (. DestructorDeclaration d = new DestructorDeclaration(t.val, m.Modifier, attributes); + d.Modifier = m.Modifier; + d.StartLocation = m.GetDeclarationLocation(startPos); + .) + "(" ")" (. d.EndLocation = t.EndLocation; .) ( Block | ";" ) (. + d.Body = (BlockStatement)stmt; + compilationUnit.AddChild(d); + .) +. + +InterfaceMemberDecl +(. + TypeReference type; + + AttributeSection section; + Modifiers mod = Modifiers.None; + List attributes = new List(); + List parameters = new List(); + string name; + PropertyGetRegion getBlock; + PropertySetRegion setBlock; + Location startLocation = new Location(-1, -1); + List templates = new List(); +.) += + { AttributeSection (. attributes.Add(section); .)} + [ "new" (. mod = Modifiers.New; startLocation = t.Location; .) ] + ( + /*--- interface void method (procedure) declaration: */ + IF (NotVoidPointer()) "void" (. if (startLocation.X == -1) startLocation = t.Location; .) + Identifier (. name = t.val; .) + [ TypeParameterList ] + "(" [ FormalParameterList ] ")" + { TypeParameterConstraintsClause } + ";" + (. MethodDeclaration md = new MethodDeclaration { + Name = name, Modifier = mod, TypeReference = new TypeReference("void"), + Parameters = parameters, Attributes = attributes, Templates = templates, + StartLocation = startLocation, EndLocation = t.EndLocation + }; + compilationUnit.AddChild(md); + .) + | ( + Type (. if (startLocation.X == -1) startLocation = t.Location; .) + ( + Identifier (. name = t.val; Location qualIdentEndLocation = t.EndLocation; .) + ( + /*--- interface "not void" method (function) declaration: */ + /* .NET 2.0 */ + [ TypeParameterList ] + "(" [ FormalParameterList ] ")" + /* .NET 2.0 */ + { TypeParameterConstraintsClause } + ";" (. MethodDeclaration md = new MethodDeclaration { + Name = name, Modifier = mod, TypeReference = type, + Parameters = parameters, Attributes = attributes, Templates = templates, + StartLocation = startLocation, EndLocation = t.EndLocation + }; + compilationUnit.AddChild(md); + .) + /*--- interface property declaration: */ + | (. PropertyDeclaration pd = new PropertyDeclaration(name, type, mod, attributes); compilationUnit.AddChild(pd); .) + "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. pd.GetRegion = getBlock; pd.SetRegion = setBlock; pd.StartLocation = startLocation; pd.EndLocation = qualIdentEndLocation; pd.BodyStart = bodyStart; pd.BodyEnd = t.EndLocation; .) + ) + /*--- interface indexer declaration: */ + | "this" "[" FormalParameterList "]" (.Location bracketEndLocation = t.EndLocation; .) (. IndexerDeclaration id = new IndexerDeclaration(type, parameters, mod, attributes); compilationUnit.AddChild(id); .) + "{" (. Location bodyStart = t.Location;.) InterfaceAccessors "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.) + ) + /*--- interface event declaration: */ + | "event" (. if (startLocation.X == -1) startLocation = t.Location; .) + Type Identifier + (. EventDeclaration ed = new EventDeclaration { + TypeReference = type, Name = t.val, Modifier = mod, Attributes = attributes + }; + compilationUnit.AddChild(ed); + .) + ";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .) + ) + ) +. + +EnumMemberDecl +(. + Expression expr = null; + List attributes = new List(); + AttributeSection section = null; + VariableDeclaration varDecl = null; +.) += + { AttributeSection (. attributes.Add(section); .) } + Identifier (. f = new FieldDeclaration(attributes); + varDecl = new VariableDeclaration(t.val); + f.Fields.Add(varDecl); + f.StartLocation = t.Location; + .) + [ "=" Expr (. varDecl.Initializer = expr; .) ] +. + + +AccessorDecls +(. + List attributes = new List(); + AttributeSection section; + getBlock = null; + setBlock = null; + ModifierList modifiers = null; +.) += + { AttributeSection (. attributes.Add(section); .) } + [ AccessorModifiers ] + ( + GetAccessorDecl + (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) + [ (. attributes = new List(); modifiers = null; .) + { AttributeSection (. attributes.Add(section); .) } + [ AccessorModifiers ] + SetAccessorDecl + (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) + ] + | + SetAccessorDecl + (. if (modifiers != null) {setBlock.Modifier = modifiers.Modifier; } .) + [ (. attributes = new List(); modifiers = null; .) + { AttributeSection (. attributes.Add(section); .) } + [ AccessorModifiers ] + GetAccessorDecl + (. if (modifiers != null) {getBlock.Modifier = modifiers.Modifier; } .) + ] + | Identifier (. Error("get or set accessor declaration expected"); .) + ) +. + +GetAccessorDecl attributes> +(. Statement stmt = null; .) += + "get" + (. Location startLocation = t.Location; .) + ( Block | ";" ) + (. getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); .) + (. getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; .) +. + +SetAccessorDecl attributes> +(. Statement stmt = null; .) += + "set" + (. Location startLocation = t.Location; .) + ( Block | ";" ) + (. setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); .) + (. setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; .) +. + +EventAccessorDecls +(. AttributeSection section; + List attributes = new List(); + Statement stmt; + addBlock = null; + removeBlock = null; +.) += + { AttributeSection (. attributes.Add(section); .) } + ( + (. addBlock = new EventAddRegion(attributes); .) + AddAccessorDecl (. attributes = new List(); addBlock.Block = (BlockStatement)stmt; .) + { AttributeSection (. attributes.Add(section); .)} + RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; .) + | + RemoveAccessorDecl (. removeBlock = new EventRemoveRegion(attributes); removeBlock.Block = (BlockStatement)stmt; attributes = new List(); .) + { AttributeSection (. attributes.Add(section); .) } + AddAccessorDecl (. addBlock = new EventAddRegion(attributes); addBlock.Block = (BlockStatement)stmt; .) + ) +. + +InterfaceAccessors +(. + AttributeSection section; + List attributes = new List(); + getBlock = null; setBlock = null; + PropertyGetSetRegion lastBlock = null; +.) += + { AttributeSection (. attributes.Add(section); .) } + (. Location startLocation = la.Location; .) + ( + "get" (. getBlock = new PropertyGetRegion(null, attributes); .) + | "set" (. setBlock = new PropertySetRegion(null, attributes); .) + ) + ";" + (. if (getBlock != null) { getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; } + if (setBlock != null) { setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; } + attributes = new List(); .) + [ + { AttributeSection (. attributes.Add(section); .) } + (. startLocation = la.Location; .) + ( + "get" (. if (getBlock != null) Error("get already declared"); + else { getBlock = new PropertyGetRegion(null, attributes); lastBlock = getBlock; } + .) + | "set" (. if (setBlock != null) Error("set already declared"); + else { setBlock = new PropertySetRegion(null, attributes); lastBlock = setBlock; } + .) + ) + ";" + (. if (lastBlock != null) { lastBlock.StartLocation = startLocation; lastBlock.EndLocation = t.EndLocation; } .) + ] +. + +VariableDeclarator fieldDeclaration> +(. Expression expr = null; .) += + Identifier (. VariableDeclaration f = new VariableDeclaration(t.val); .) + [ "=" VariableInitializer (. f.Initializer = expr; .) ] (. fieldDeclaration.Add(f); .) +. + +Block /* not BlockStatement because of EmbeddedStatement */ += + "{" (. BlockStatement blockStmt = new BlockStatement(); + blockStmt.StartLocation = t.Location; + compilationUnit.BlockStart(blockStmt); + if (!ParseMethodBodies) lexer.SkipCurrentBlock(0); + .) + { Statement } + "}" (. + stmt = blockStmt; + blockStmt.EndLocation = t.EndLocation; + compilationUnit.BlockEnd(); + .) +. + +AddAccessorDecl +(.stmt = null;.) += + "add" + Block +. + +RemoveAccessorDecl +(.stmt = null;.) += + "remove" + Block +. + +ConstructorInitializer +(. Expression expr; ci = new ConstructorInitializer(); .) += + ":" + ( + "base" (. ci.ConstructorInitializerType = ConstructorInitializerType.Base; .) + | "this" (. ci.ConstructorInitializerType = ConstructorInitializerType.This; .) + ) + "(" + [ Argument (. if (expr != null) { ci.Arguments.Add(expr); } .) { "," Argument (. if (expr != null) { ci.Arguments.Add(expr); } .) } ] + ")" +. + +VariableInitializer +(. TypeReference type = null; Expression expr = null; initializerExpression = null; .) += + Expr + | CollectionInitializer + | "stackalloc" Type "[" Expr "]" (. initializerExpression = new StackAllocExpression(type, expr); .) +. + +OverloadableOperator +(. op = OverloadableOperatorType.None; .) += + "+" (. op = OverloadableOperatorType.Add; .) + | "-" (. op = OverloadableOperatorType.Subtract; .) + + | "!" (. op = OverloadableOperatorType.Not; .) + | "~" (. op = OverloadableOperatorType.BitNot; .) + + | "++" (. op = OverloadableOperatorType.Increment; .) + | "--" (. op = OverloadableOperatorType.Decrement; .) + + | "true" (. op = OverloadableOperatorType.IsTrue; .) + | "false" (. op = OverloadableOperatorType.IsFalse; .) + + | "*" (. op = OverloadableOperatorType.Multiply; .) + | "/" (. op = OverloadableOperatorType.Divide; .) + | "%" (. op = OverloadableOperatorType.Modulus; .) + + | "&" (. op = OverloadableOperatorType.BitwiseAnd; .) + | "|" (. op = OverloadableOperatorType.BitwiseOr; .) + | "^" (. op = OverloadableOperatorType.ExclusiveOr; .) + + | "<<" (. op = OverloadableOperatorType.ShiftLeft; .) + | "==" (. op = OverloadableOperatorType.Equality; .) + | "!=" (. op = OverloadableOperatorType.InEquality; .) + | "<" (. op = OverloadableOperatorType.LessThan; .) + | ">=" (. op = OverloadableOperatorType.GreaterThanOrEqual; .) + | "<=" (. op = OverloadableOperatorType.LessThanOrEqual; .) + | ">" (. op = OverloadableOperatorType.GreaterThan; .) [ ">" (. op = OverloadableOperatorType.ShiftRight; .) ] +. + +Argument +(. + Expression expr; + FieldDirection fd = FieldDirection.None; +.) += + [ + "ref" (. fd = FieldDirection.Ref; .) + | "out" (. fd = FieldDirection.Out; .) + ] + Expr + (. argumentexpr = fd != FieldDirection.None ? argumentexpr = new DirectionExpression(fd, expr) : expr; .) +. + +AssignmentOperator +(. op = AssignmentOperatorType.None; .) += + "=" (. op = AssignmentOperatorType.Assign; .) + | "+=" (. op = AssignmentOperatorType.Add; .) + | "-=" (. op = AssignmentOperatorType.Subtract; .) + | "*=" (. op = AssignmentOperatorType.Multiply; .) + | "/=" (. op = AssignmentOperatorType.Divide; .) + | "%=" (. op = AssignmentOperatorType.Modulus; .) + | "&=" (. op = AssignmentOperatorType.BitwiseAnd; .) + | "|=" (. op = AssignmentOperatorType.BitwiseOr; .) + | "^=" (. op = AssignmentOperatorType.ExclusiveOr; .) + | "<<=" (. op = AssignmentOperatorType.ShiftLeft; .) + | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) + ">" ">=" (. op = AssignmentOperatorType.ShiftRight; .) +. + +CollectionInitializer +(. + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); +.) += + "{" (. initializer.StartLocation = t.Location; .) + [ VariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + { IF (NotFinalComma()) + "," VariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + } + [ "," ] + ] + "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .) +. + +CollectionOrObjectInitializer +(. + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); +.) += + "{" (. initializer.StartLocation = t.Location; .) + [ ObjectPropertyInitializerOrVariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + { IF (NotFinalComma()) + "," ObjectPropertyInitializerOrVariableInitializer + (. if (expr != null) { initializer.CreateExpressions.Add(expr); } .) + } + [ "," ] + ] + "}" (. initializer.EndLocation = t.Location; outExpr = initializer; .) +. + +ObjectPropertyInitializerOrVariableInitializer +(. expr = null; .) += +( IF (IdentAndAsgn()) + Identifier + (. NamedArgumentExpression nae = new NamedArgumentExpression(t.val, null); + nae.StartLocation = t.Location; + Expression r = null; .) + "=" + ( CollectionOrObjectInitializer + | VariableInitializer ) + (. nae.Expression = r; nae.EndLocation = t.EndLocation; expr = nae; .) + +| VariableInitializer +) +. + +LocalVariableDecl +(. + TypeReference type; + VariableDeclaration var = null; + LocalVariableDeclaration localVariableDeclaration; +.) += + Type (. localVariableDeclaration = new LocalVariableDeclaration(type); localVariableDeclaration.StartLocation = t.Location; .) + LocalVariableDeclarator (. localVariableDeclaration.Variables.Add(var); .) + { "," LocalVariableDeclarator (. localVariableDeclaration.Variables.Add(var); .) } + (. stmt = localVariableDeclaration; .) +. + +LocalVariableDeclarator +(. Expression expr = null; .) += + Identifier (. var = new VariableDeclaration(t.val); .) + [ "=" VariableInitializer (. var.Initializer = expr; .) ] +. + +Statement +(. + TypeReference type; + Expression expr; + Statement stmt = null; + Location startPos = la.Location; +.) += + SYNC + ( + /*--- labeled statement: */ + IF (IsLabel()) Identifier (. compilationUnit.AddChild(new LabelStatement(t.val)); .) + ":" Statement + /*--- local constant declaration: */ + | "const" Type (. LocalVariableDeclaration var = new LocalVariableDeclaration(type, Modifiers.Const); string ident = null; var.StartLocation = t.Location; .) + Identifier (. ident = t.val; .) + "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) + { "," Identifier (. ident = t.val; .) "=" Expr (. var.Variables.Add(new VariableDeclaration(ident, expr)); .) } + ";" (. compilationUnit.AddChild(var); .) + + /*--- local variable declaration: */ + | IF (IsLocalVarDecl()) LocalVariableDecl ";" (. compilationUnit.AddChild(stmt); .) + + | EmbeddedStatement (. compilationUnit.AddChild(stmt); .) + /* LL(1) confict: LocalVariableDecl * + * <-> StatementExpr * + * ident {"." ident} { "[" Expr ... */ + ) + (. + if (stmt != null) { + stmt.StartLocation = startPos; + stmt.EndLocation = t.EndLocation; + } + .) +. + +EmbeddedStatement +(. + TypeReference type = null; + Expression expr = null; + Statement embeddedStatement = null; + statement = null; +.) += + (. Location startLocation = la.Location; .) + ( + Block + + /*--- empty statement: */ + | ";" (. statement = new EmptyStatement(); .) + + /*--- checked / unchecked statement: */ + | IF (UnCheckedAndLBrace()) (. Statement block; bool isChecked = true; .) + ("checked" | "unchecked" (. isChecked = false;.) ) + Block (. statement = isChecked ? (Statement)new CheckedStatement(block) : (Statement)new UncheckedStatement(block); .) + + /*--- selection statements (if, switch): */ + | IfStatement + + | "switch" (. List switchSections = new List(); .) + "(" Expr ")" + "{" SwitchSections + "}" (. statement = new SwitchStatement(expr, switchSections); .) + + /*--- iteration statements (while, do, for, foreach): */ + | "while" "(" Expr ")" + EmbeddedStatement + (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start);.) + + | "do" EmbeddedStatement "while" + "(" Expr ")" ";" + (. statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.End); .) + + | "for" (. List initializer = null; List iterator = null; .) + "(" [ ForInitializer ] ";" + [ Expr ] ";" + [ ForIterator ] ")" + EmbeddedStatement (. statement = new ForStatement(initializer, expr, iterator, embeddedStatement); .) + + | "foreach" "(" Type Identifier (. string varName = t.val; .) + "in" Expr ")" + EmbeddedStatement + (. statement = new ForeachStatement(type, varName , expr, embeddedStatement); .) + + /*--- jump statements (break, contine, goto, return, throw): */ + | "break" ";" (. statement = new BreakStatement(); .) + | "continue" ";" (. statement = new ContinueStatement(); .) + | GotoStatement + + | IF (IsYieldStatement()) "yield" + ( "return" Expr (. statement = new YieldStatement(new ReturnStatement(expr)); .) + | "break" (. statement = new YieldStatement(new BreakStatement()); .) ) + ";" + + | "return" [ Expr ] ";" (. statement = new ReturnStatement(expr); .) + | "throw" [ Expr ] ";" (. statement = new ThrowStatement(expr); .) + + /*--- expression statement: */ + | StatementExpr SYNC ";" + + /*--- try statement: */ + | TryStatement + + /*--- lock satement: */ + | "lock" "(" Expr ")" + EmbeddedStatement (. statement = new LockStatement(expr, embeddedStatement); .) + + /*--- using statement: */ + | (.Statement resourceAcquisitionStmt = null; .) + "using" "(" + ResourceAcquisition ")" + EmbeddedStatement (. statement = new UsingStatement(resourceAcquisitionStmt, embeddedStatement); .) + + /*--- unsafe statement: */ + | "unsafe" Block (. statement = new UnsafeStatement(embeddedStatement); .) + /*--- fixed statement: */ + | "fixed" + "(" Type (. if (type == null || type.PointerNestingLevel == 0) Error("can only fix pointer types"); + List pointerDeclarators = new List(1); + .) + Identifier (. string identifier = t.val; .) + "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) + { + "," Identifier (. identifier = t.val; .) + "=" Expr (. pointerDeclarators.Add(new VariableDeclaration(identifier, expr)); .) + } + ")" EmbeddedStatement (. statement = new FixedStatement(type, pointerDeclarators, embeddedStatement); .) + ) + (. if (statement != null) { + statement.StartLocation = startLocation; + statement.EndLocation = t.EndLocation; + } + .) +. + +IfStatement +(. + Expression expr = null; + Statement embeddedStatement = null; + statement = null; +.) += + "if" + "(" Expr ")" + EmbeddedStatement + (. Statement elseStatement = null; .) + [ "else" EmbeddedStatement ] + (. statement = elseStatement != null ? new IfElseStatement(expr, embeddedStatement, elseStatement) : new IfElseStatement(expr, embeddedStatement); .) + (. if (elseStatement is IfElseStatement && (elseStatement as IfElseStatement).TrueStatement.Count == 1) { + /* else if-section (otherwise we would have a BlockStatment) */ + (statement as IfElseStatement).ElseIfSections.Add( + new ElseIfSection((elseStatement as IfElseStatement).Condition, + (elseStatement as IfElseStatement).TrueStatement[0])); + (statement as IfElseStatement).ElseIfSections.AddRange((elseStatement as IfElseStatement).ElseIfSections); + (statement as IfElseStatement).FalseStatement = (elseStatement as IfElseStatement).FalseStatement; + } + .) +. + +ForInitializer initializer> +(. + Statement stmt; + initializer = new List(); +.) += + IF (IsLocalVarDecl()) LocalVariableDecl (. initializer.Add(stmt);.) + | StatementExpr (.initializer.Add(stmt);.) { "," StatementExpr (. initializer.Add(stmt);.) } +. + +ForIterator iterator> +(. + Statement stmt; + iterator = new List(); +.) += + StatementExpr (. iterator.Add(stmt);.) { "," StatementExpr (. iterator.Add(stmt); .) } +. + +SwitchSections switchSections> +(. + SwitchSection switchSection = new SwitchSection(); + CaseLabel label; +.) += + SwitchLabel (. if (label != null) { switchSection.SwitchLabels.Add(label); } .) + (. compilationUnit.BlockStart(switchSection); .) + { + ( SwitchLabel + (. if (label != null) { + if (switchSection.Children.Count > 0) { + // open new section + compilationUnit.BlockEnd(); switchSections.Add(switchSection); + switchSection = new SwitchSection(); + compilationUnit.BlockStart(switchSection); + } + switchSection.SwitchLabels.Add(label); + } + .) + | Statement) + } + (. compilationUnit.BlockEnd(); switchSections.Add(switchSection); .) +. + +SwitchLabel + (. Expression expr = null; label = null; .) += + "case" Expr ":" (. label = new CaseLabel(expr); .) + | "default" ":" (. label = new CaseLabel(); .) +. + +TryStatement +(. + Statement blockStmt = null, finallyStmt = null; + List catchClauses = null; +.) += + "try" Block + ( + CatchClauses [ "finally" Block ] + | "finally" Block + ) + (. + tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); + + .) +. + +CatchClauses catchClauses> +(. + catchClauses = new List(); +.) += + "catch" (. string identifier; + Statement stmt; + TypeReference typeRef; + .) + /*--- general catch clause (as only catch clause) */ + ( + Block (. catchClauses.Add(new CatchClause(stmt)); .) + /*--- specific catch clause */ + | "(" ClassType (. identifier = null; .) + [ Identifier (. identifier = t.val; .) ] + ")" Block + (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) + { IF (IsTypedCatch()) "catch" "(" ClassType (. identifier = null; .) + [ Identifier (. identifier = t.val; .) ] + ")" Block + (. catchClauses.Add(new CatchClause(typeRef, identifier, stmt)); .) } + /*--- general catch clause (after specific catch clauses, optional) */ + [ "catch" Block (. catchClauses.Add(new CatchClause(stmt)); .) ] + ) +. + +GotoStatement +(. Expression expr; stmt = null; .) += + "goto" + ( + Identifier (. stmt = new GotoStatement(t.val); .) ";" + | "case" Expr ";" (. stmt = new GotoCaseStatement(expr); .) + | "default" ";" (. stmt = new GotoCaseStatement(null); .) + ) +. + +ResourceAcquisition +(. + stmt = null; + Expression expr; +.) += + ( + IF (IsLocalVarDecl()) LocalVariableDecl + | Expr /* LL(1) conflict resoltion: * + * check if next is Qualident followed by ident * + * ==> LocalVariableDecl * + * new problem: first set of ResourceAcquisition changes */ + (. stmt = new ExpressionStatement(expr); .) + ) +. + +StatementExpr +(. Expression expr; .) += + Expr + /* The grammar allows only assignments or method invocations here, */ + /* but we don't enforce that here */ + (. stmt = new ExpressionStatement(expr); .) +. + +Expr +(. expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; .) += + (. Location startLocation = la.Location; .) + UnaryExpr + /*--- conditional expression: */ + ( + ( AssignmentOperator Expr (. expr = new AssignmentExpression(expr, op, expr1); .) ) + | IF (la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) + ( AssignmentOperator Expr (. expr = new AssignmentExpression(expr, op, expr1); .) ) + | ( + ConditionalOrExpr + [ "??" Expr (. expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); .) ] + [ "?" Expr ":" Expr (. expr = new ConditionalExpression(expr, expr1, expr2); .) ] + ) + ) + (. if (expr != null) { + expr.StartLocation = startLocation; + expr.EndLocation = t.EndLocation; + } + .) +. + + +UnaryExpr +(. + TypeReference type = null; + Expression expr = null; + ArrayList expressions = new ArrayList(); + uExpr = null; +.) += + { + /* IF (Tokens.UnaryOp[la.kind] || IsTypeCast()) */ + ( + "+" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Plus)); .) + | "-" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Minus)); .) + | "!" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Not)); .) + | "~" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitNot)); .) + | "*" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Star)); .) + | "++" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Increment)); .) + | "--" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.Decrement)); .) + | "&" (. expressions.Add(new UnaryOperatorExpression(UnaryOperatorType.BitWiseAnd)); .) + + /*--- cast expression: */ + /* Problem: "(" Type ")" from here and * + * "(" Expr ")" from PrimaryExpr * + * Solution: (in IsTypeCast()) */ + | IF (IsTypeCast()) "(" Type ")" (. expressions.Add(new CastExpression(type)); .) + ) + } + + /* special rule (2.4.4.2) to allow writing int.MinValue and long.MinValue */ + ( IF (LastExpressionIsUnaryMinus(expressions) && IsMostNegativeIntegerWithoutTypeSuffix()) + Literal + (. + expressions.RemoveAt(expressions.Count - 1); + if (t.literalValue is uint) { + expr = new PrimitiveExpression(int.MinValue, int.MinValue.ToString()); + } else if (t.literalValue is ulong) { + expr = new PrimitiveExpression(long.MinValue, long.MinValue.ToString()); + } else { + throw new Exception("t.literalValue must be uint or ulong"); + } + .) + | PrimaryExpr + ) + (. for (int i = 0; i < expressions.Count; ++i) { + Expression nextExpression = i + 1 < expressions.Count ? (Expression)expressions[i + 1] : expr; + if (expressions[i] is CastExpression) { + ((CastExpression)expressions[i]).Expression = nextExpression; + } else { + ((UnaryOperatorExpression)expressions[i]).Expression = nextExpression; + } + } + if (expressions.Count > 0) { + uExpr = (Expression)expressions[0]; + } else { + uExpr = expr; + } + .) +. + + +PrimaryExpr +(. + TypeReference type = null; + Expression expr; + pexpr = null; +.) += + (. Location startLocation = la.Location; .) + ( + "true" (.pexpr = new PrimitiveExpression(true, "true"); .) + | "false" (.pexpr = new PrimitiveExpression(false, "false"); .) + | "null" (.pexpr = new PrimitiveExpression(null, "null"); .) /* from literal token */ + | Literal (.pexpr = new PrimitiveExpression(t.literalValue, t.val); .) + | IF (StartOfQueryExpression()) + QueryExpression + | IF (IdentAndDoubleColon()) + Identifier (. type = new TypeReference(t.val); .) + "::" (. pexpr = new TypeReferenceExpression(type); .) + Identifier (. if (type.Type == "global") { type.IsGlobal = true; type.Type = (t.val ?? "?"); } else type.Type += "." + (t.val ?? "?"); .) + + /*--- simple name (IdentifierExpression): */ + | Identifier + (. pexpr = new IdentifierExpression(t.val); .) + + [ ShortedLambdaExpression<(IdentifierExpression)pexpr, out pexpr> + | IF (IsGenericInSimpleNameOrMemberAccess()) + (. List typeList; .) + TypeArgumentList + (. ((IdentifierExpression)pexpr).TypeArguments = typeList; .) + ] + | IF (IsLambdaExpression()) /* Lambda expression */ + LambdaExpression + + /*--- parenthesized expression: */ + | "(" Expr ")" (. pexpr = new ParenthesizedExpression(expr); .) + + | /*--- predefined type member access: */ + (. string val = null; .) + ( "bool" (. val = "bool"; .) + | "byte" (. val = "byte"; .) + | "char" (. val = "char"; .) + | "decimal" (. val = "decimal"; .) + | "double" (. val = "double"; .) + | "float" (. val = "float"; .) + | "int" (. val = "int"; .) + | "long" (. val = "long"; .) + | "object" (. val = "object"; .) + | "sbyte" (. val = "sbyte"; .) + | "short" (. val = "short"; .) + | "string" (. val = "string"; .) + | "uint" (. val = "uint"; .) + | "ulong" (. val = "ulong"; .) + | "ushort" (. val = "ushort"; .) + ) + MemberAccess + + /*--- this access: */ + | "this" (. pexpr = new ThisReferenceExpression(); .) + /*--- base access: */ + | "base" (. pexpr = new BaseReferenceExpression(); .) + + /* new ... - ObjectCreationExpression or ArrayCreateExpression */ + | NewExpression + + | "typeof" "(" + ( + IF (NotVoidPointer()) "void" (. type = new TypeReference("void"); .) + | TypeWithRestriction + ) + ")" (. pexpr = new TypeOfExpression(type); .) + + | "default" "(" Type ")" (. pexpr = new DefaultValueExpression(type); .) + | "sizeof" "(" Type ")" (. pexpr = new SizeOfExpression(type); .) + | "checked" "(" Expr ")" (. pexpr = new CheckedExpression(expr); .) + | "unchecked" "(" Expr ")" (. pexpr = new UncheckedExpression(expr); .) + | "delegate" AnonymousMethodExpr (. pexpr = expr; .) + ) + (. if (pexpr != null) { + pexpr.StartLocation = startLocation; + pexpr.EndLocation = t.EndLocation; + } + .) + { + (. startLocation = la.Location; .) + ( + "++" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostIncrement); .) + | "--" (. pexpr = new UnaryOperatorExpression(pexpr, UnaryOperatorType.PostDecrement); .) + ) + /*--- member access */ + | PointerMemberAccess + | MemberAccess + + /*--- invocation expression: */ + | "(" (. List parameters = new List(); .) + [ Argument (. if (expr != null) {parameters.Add(expr);} .) + { "," Argument (. if (expr != null) {parameters.Add(expr);} .) + } + ] + ")" (. pexpr = new InvocationExpression(pexpr, parameters); .) + /*--- element access */ + | (. /*if (isArrayCreation) Error("element access not allow on array creation");*/ + List indices = new List(); + .) + "[" Expr (. if (expr != null) { indices.Add(expr); } .) + { "," Expr (. if (expr != null) { indices.Add(expr); } .) + } "]" (. pexpr = new IndexerExpression(pexpr, indices); .) + + (. if (pexpr != null) { + pexpr.StartLocation = startLocation; + pexpr.EndLocation = t.EndLocation; + } + .) + } +. + +MemberAccess +(. List typeList; .) += + (. if (ShouldConvertTargetExpressionToTypeReference(target)) { + TypeReference type = GetTypeReferenceFromExpression(target); + if (type != null) { + target = new TypeReferenceExpression(type) { StartLocation = t.Location, EndLocation = t.EndLocation }; + } + } + t.val = ""; // required for TypeReferenceExpressionTests.StandaloneIntReferenceExpression hack + .) + "." + Identifier + (. expr = new MemberReferenceExpression(target, t.val); .) + [ IF (IsGenericInSimpleNameOrMemberAccess()) + TypeArgumentList + (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .) + ] +. + +PointerMemberAccess +(. List typeList; .) += + "->" + Identifier + (. expr = new PointerReferenceExpression(target, t.val); .) + [ IF (IsGenericInSimpleNameOrMemberAccess()) + TypeArgumentList + (. ((MemberReferenceExpression)expr).TypeArguments = typeList; .) + ] +. + +NewExpression +(. pexpr = null; + List parameters = new List(); + TypeReference type = null; + Expression expr; +.) += + "new" + [ NonArrayType ] /* optional since .NET 3.0 */ + + /*--- delegate / object creation expression: */ + /* Note: a delegate creation expression allow only a single Expr */ + /* not an argument list, but this is not distinguished here */ + ( + ( (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) + "(" (. if (type == null) Error("Cannot use an anonymous type with arguments for the constructor"); .) + [ Argument (. if (expr != null) { parameters.Add(expr); } .) + { "," Argument (. if (expr != null) { parameters.Add(expr); } .) } + ] + ")" (. pexpr = oce; .) + [ CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) ] + | (. ObjectCreateExpression oce = new ObjectCreateExpression(type, parameters); .) + CollectionOrObjectInitializer (. oce.ObjectInitializer = (CollectionInitializerExpression)expr; .) + (. pexpr = oce; .) + ) + + /*--- array creation expression: */ + | "[" + (. ArrayCreateExpression ace = new ArrayCreateExpression(type); + /* we must not change RankSpecifier on the null type reference*/ + if (ace.CreateType.IsNull) { ace.CreateType = new TypeReference(""); } + pexpr = ace; + int dims = 0; List ranks = new List(); + .) + ( + { "," (. dims += 1; .) } + "]" (. ranks.Add(dims); dims = 0; .) + { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } + (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) + CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) + | Expr (. if (expr != null) parameters.Add(expr); .) + { "," (. dims += 1; .) + Expr (. if (expr != null) parameters.Add(expr); .) + } + "]" (. ranks.Add(dims); ace.Arguments = parameters; dims = 0; .) + { "[" { "," (. ++dims; .) } "]" (. ranks.Add(dims); dims = 0; .) } + (. ace.CreateType.RankSpecifier = ranks.ToArray(); .) + [ CollectionInitializer (. ace.ArrayInitializer = (CollectionInitializerExpression)expr; .) ] + ) + ) +. + +/* Lambda expression with parameter list */ +LambdaExpression +(. + LambdaExpression lambda = new LambdaExpression(); + lambda.StartLocation = la.Location; + ParameterDeclarationExpression p; + outExpr = lambda; +.) += + "(" + [ + LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) + { "," + LambdaExpressionParameter (. if (p != null) lambda.Parameters.Add(p); .) + } + ] + ")" + "=>" + LambdaExpressionBody +. + +ShortedLambdaExpression +(. LambdaExpression lambda = new LambdaExpression(); pexpr = lambda; .) += + "=>" + /* not an IdentifierExpression, but a short lambda expression*/ + (. + lambda.StartLocation = ident.StartLocation; + lambda.Parameters.Add(new ParameterDeclarationExpression(null, ident.Identifier)); + lambda.Parameters[0].StartLocation = ident.StartLocation; + lambda.Parameters[0].EndLocation = ident.EndLocation; + .) + LambdaExpressionBody +. + +LambdaExpressionParameter +(. Location start = la.Location; p = null; + TypeReference type; +.) += + ( IF (Peek(1).kind == Tokens.Comma || Peek(1).kind == Tokens.CloseParenthesis) + Identifier + (. p = new ParameterDeclarationExpression(null, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + .) + | Type + Identifier + (. p = new ParameterDeclarationExpression(type, t.val); + p.StartLocation = start; p.EndLocation = t.EndLocation; + .) + ) +. + +LambdaExpressionBody +(. Expression expr; BlockStatement stmt; .) += + ( + BlockInsideExpression (. lambda.StatementBody = stmt; .) + | Expr (. lambda.ExpressionBody = expr; .) + ) + (. lambda.EndLocation = t.EndLocation; .) +. + +AnonymousMethodExpr +(. + AnonymousMethodExpression expr = new AnonymousMethodExpression(); + expr.StartLocation = t.Location; + BlockStatement stmt; + List p = new List(); + outExpr = expr; +.) += + [ + "(" + [ FormalParameterList

(. expr.Parameters = p; .) ] + ")" + (. expr.HasParameterList = true; .) + ] + BlockInsideExpression (. expr.Body = stmt; .) + (. expr.EndLocation = t.Location; .) +. + +BlockInsideExpression +(. Statement stmt = null; outStmt = null; .) += + /*--- ParseExpression doesn't set a compilation unit, */ + /*--- so we can't use block then -> skip body of anonymous method */ + (. if (compilationUnit != null) { .) + Block (. outStmt = (BlockStatement)stmt; .) + (. } else { .) + "{" + (. lexer.SkipCurrentBlock(0); .) + "}" + (. } .) +. + +ConditionalOrExpr +(. Expression expr; .) += + ConditionalAndExpr { "||" UnaryExpr ConditionalAndExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalOr, expr); .) } +. + +ConditionalAndExpr +(. Expression expr; .) += + InclusiveOrExpr { "&&" UnaryExpr InclusiveOrExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.LogicalAnd, expr); .) } +. + +InclusiveOrExpr +(. Expression expr; .) += + ExclusiveOrExpr { "|" UnaryExpr ExclusiveOrExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseOr, expr); .) } +. + +ExclusiveOrExpr +(. Expression expr; .) += + AndExpr { "^" UnaryExpr AndExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.ExclusiveOr, expr); .) } +. + +AndExpr +(. Expression expr; .) += + EqualityExpr { "&" UnaryExpr EqualityExpr (. outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.BitwiseAnd, expr); .) } +. + +EqualityExpr +(. + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; +.) += + RelationalExpr + { + ( + "!=" (. op = BinaryOperatorType.InEquality; .) + | "==" (. op = BinaryOperatorType.Equality; .) + ) + UnaryExpr RelationalExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) + } +. + +RelationalExpr +(. + TypeReference type; + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; +.) += + ShiftExpr + { + ( "<" (. op = BinaryOperatorType.LessThan; .) + | ">" (. op = BinaryOperatorType.GreaterThan; .) + | "<=" (. op = BinaryOperatorType.LessThanOrEqual; .) + | ">=" (. op = BinaryOperatorType.GreaterThanOrEqual; .) + ) + UnaryExpr + ShiftExpr + (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) + | + ( "is" + TypeWithRestriction + [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) + NullableQuestionMark ] + (. outExpr = new TypeOfIsExpression(outExpr, type); .) + | "as" + TypeWithRestriction + [ IF (la.kind == Tokens.Question && !IsPossibleExpressionStart(Peek(1).kind)) + NullableQuestionMark ] + (. outExpr = new CastExpression(type, outExpr, CastType.TryCast); .) + ) + } +. + +ShiftExpr +(. + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; +.) += + AdditiveExpr + { + ( "<<" (. op = BinaryOperatorType.ShiftLeft; .) + | IF (IsShiftRight()) ( + ">" ">" (. op = BinaryOperatorType.ShiftRight; .) + ) + ) + UnaryExpr AdditiveExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) + } +. + +AdditiveExpr +(. + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; +.) += + MultiplicativeExpr + { + ( + "+" (. op = BinaryOperatorType.Add; .) + | "-" (. op = BinaryOperatorType.Subtract; .) + ) + UnaryExpr MultiplicativeExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) + } +. + +MultiplicativeExpr +(. + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; +.) += + { + ( + "*" (. op = BinaryOperatorType.Multiply; .) + | "/" (. op = BinaryOperatorType.Divide; .) + | "%" (. op = BinaryOperatorType.Modulus; .) + ) + UnaryExpr (. outExpr = new BinaryOperatorExpression(outExpr, op, expr); .) + } +. + +/* .NET 2.0 rules */ + +TypeName +(. List typeArguments = null; + string alias = null; + string qualident; +.) += + [ IF (IdentAndDoubleColon()) + Identifier (. alias = t.val; .) + "::" + ] + Qualident + [TypeArgumentList] + (. + if (alias == null) { + typeRef = new TypeReference(qualident, typeArguments); + } else if (alias == "global") { + typeRef = new TypeReference(qualident, typeArguments); + typeRef.IsGlobal = true; + } else { + typeRef = new TypeReference(alias + "." + qualident, typeArguments); + } + .) + { IF (DotAndIdent()) + "." (. typeArguments = null; .) + Qualident + [TypeArgumentList] + (. typeRef = new InnerClassTypeReference(typeRef, qualident, typeArguments); .) + } +. + + +NullableQuestionMark +(. List typeArguments = new List(1); .) += + "?" + (. + if (typeRef != null) typeArguments.Add(typeRef); + typeRef = new TypeReference("System.Nullable", typeArguments); + .) +. + +TypeArgumentList types, bool canBeUnbound> +(. + types = new List(); + TypeReference type = null; +.) += + "<" + ( IF (canBeUnbound && (la.kind == Tokens.GreaterThan || la.kind == Tokens.Comma)) + (. types.Add(TypeReference.Null); .) + { "," (. types.Add(TypeReference.Null); .) } + | Type (. if (type != null) { types.Add(type); } .) + { "," Type (. if (type != null) { types.Add(type); } .) } + ) + ">" +. + +TypeParameterList templates> +(. + AttributeSection section; + List attributes = new List(); +.) += + "<" { AttributeSection (. attributes.Add(section); .) } + Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .) + { "," { AttributeSection (. attributes.Add(section); .) } + Identifier (. templates.Add(new TemplateDefinition(t.val, attributes)); .)} + ">" +. + +TypeParameterConstraintsClause templates> +(. string name = ""; TypeReference type; .) += + "where" + Identifier (. name = t.val; .) + ":" + TypeParameterConstraintsClauseBase (. + TemplateDefinition td = null; + foreach (TemplateDefinition d in templates) { + if (d.Name == name) { + td = d; + break; + } + } + if ( td != null && type != null) { td.Bases.Add(type); } + .) + { "," TypeParameterConstraintsClauseBase (. + td = null; + foreach (TemplateDefinition d in templates) { + if (d.Name == name) { + td = d; + break; + } + } + if ( td != null && type != null) { td.Bases.Add(type); } + .) } +. + +TypeParameterConstraintsClauseBase +(. TypeReference t; type = null; .) += + "struct" (. type = TypeReference.StructConstraint; .) + | "class" (. type = TypeReference.ClassConstraint; .) + | "new" "(" ")" (. type = TypeReference.NewConstraint; .) + | Type (. type = t; .) +. + +QueryExpression +(. QueryExpression q = new QueryExpression(); outExpr = q; q.StartLocation = la.Location; + QueryExpressionFromClause fromClause; +.) += + QueryExpressionFromClause (. q.FromClause = fromClause; .) + QueryExpressionBody + (. q.EndLocation = t.EndLocation; .) +. + +QueryExpressionFromClause +(. fc = new QueryExpressionFromClause(); fc.StartLocation = la.Location; +.) += + "from" + QueryExpressionFromOrJoinClause + (. fc.EndLocation = t.EndLocation; .) +. + +QueryExpressionJoinClause +(. jc = new QueryExpressionJoinClause(); jc.StartLocation = la.Location; + Expression expr; +.) += + "join" + QueryExpressionFromOrJoinClause + "on" + Expr (. jc.OnExpression = expr; .) + "equals" + Expr (. jc.EqualsExpression = expr; .) + [ "into" + Identifier (. jc.IntoIdentifier = t.val; .) + ] + (. jc.EndLocation = t.EndLocation; .) +. + +QueryExpressionFromOrJoinClause +(. TypeReference type; Expression expr; .) += + (. fjc.Type = null; .) + [ IF (IsLocalVarDecl()) Type (. fjc.Type = type; .) ] + Identifier (. fjc.Identifier = t.val; .) + "in" + Expr (. fjc.InExpression = expr; .) +. + +QueryExpressionBody +(. QueryExpressionFromClause fromClause; QueryExpressionWhereClause whereClause; + QueryExpressionLetClause letClause; QueryExpressionJoinClause joinClause; + QueryExpressionSelectClause selectClause; QueryExpressionGroupClause groupClause; + QueryExpressionIntoClause intoClause; +.) += + { ( QueryExpressionFromClause (. SafeAdd(q, q.FromLetWhereClauses, fromClause); .) + | QueryExpressionWhereClause (. SafeAdd(q, q.FromLetWhereClauses, whereClause); .) + | QueryExpressionLetClause (. SafeAdd(q, q.FromLetWhereClauses, letClause); .) + | QueryExpressionJoinClause (. SafeAdd(q, q.FromLetWhereClauses, joinClause); .) + ) } + [ QueryExpressionOrderByClause ] + ( QueryExpressionSelectClause (. q.SelectOrGroupClause = selectClause; .) + | QueryExpressionGroupClause (. q.SelectOrGroupClause = groupClause; .) + ) + [ QueryExpressionIntoClause (. q.IntoClause = intoClause; .) ] +. + +QueryExpressionWhereClause +(. Expression expr; wc = new QueryExpressionWhereClause(); wc.StartLocation = la.Location; .) += + "where" + Expr (. wc.Condition = expr; .) + (. wc.EndLocation = t.EndLocation; .) +. + +QueryExpressionLetClause +(. Expression expr; wc = new QueryExpressionLetClause(); wc.StartLocation = la.Location; .) += + "let" + Identifier (. wc.Identifier = t.val; .) + "=" + Expr (. wc.Expression = expr; .) + (. wc.EndLocation = t.EndLocation; .) +. + +QueryExpressionOrderByClause +(. QueryExpressionOrdering ordering; .) += + "orderby" + QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) + { "," + QueryExpressionOrderingClause (. SafeAdd(q, q.Orderings, ordering); .) + } +. + +QueryExpressionOrderingClause +(. Expression expr; ordering = new QueryExpressionOrdering(); ordering.StartLocation = la.Location; .) += + Expr (. ordering.Criteria = expr; .) + [ "ascending" (. ordering.Direction = QueryExpressionOrderingDirection.Ascending; .) + | "descending" (. ordering.Direction = QueryExpressionOrderingDirection.Descending; .) + ] + (. ordering.EndLocation = t.EndLocation; .) +. + +QueryExpressionSelectClause +(. Expression expr; sc = new QueryExpressionSelectClause(); sc.StartLocation = la.Location; .) += + "select" + Expr (. sc.Projection = expr; .) + (. sc.EndLocation = t.EndLocation; .) +. + +QueryExpressionGroupClause +(. Expression expr; gc = new QueryExpressionGroupClause(); gc.StartLocation = la.Location; .) += + "group" + Expr (. gc.Projection = expr; .) + "by" + Expr (. gc.GroupBy = expr; .) + (. gc.EndLocation = t.EndLocation; .) +. + +QueryExpressionIntoClause +(. ic = new QueryExpressionIntoClause(); ic.StartLocation = la.Location; .) += + "into" + Identifier (. ic.IntoIdentifier = t.val; .) + (. ic.ContinuedQuery = new QueryExpression(); .) + (. ic.ContinuedQuery.StartLocation = la.Location; .) + QueryExpressionBody + (. ic.ContinuedQuery.EndLocation = t.EndLocation; .) + (. ic.EndLocation = t.EndLocation; .) +. + +/* allow usage of context sensitive keywords as identifiers */ +Identifier += +/* when updating this list, ensure you also change KeywordList.IdentifierTokens*/ + ident +| "partial" +| "where" +| "get" +| "set" +| "add" +| "remove" +| "yield" +| "select" +| "group" +| "by" +| "into" +| "from" +| "ascending" +| "descending" +| "orderby" +| "let" +| "join" +| "on" +| "equals" +. + + +END CS. diff --git a/lib/NRefactory/Project/Src/Parser/CSharp/trace.txt b/lib/NRefactory/Project/Src/Parser/CSharp/trace.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/NRefactory/Project/Src/Parser/Errors.cs b/lib/NRefactory/Project/Src/Parser/Errors.cs new file mode 100644 index 000000000..a670fcc37 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/Errors.cs @@ -0,0 +1,60 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Text; + +namespace ICSharpCode.NRefactory.Parser +{ + public delegate void ErrorCodeProc(int line, int col, int n); + public delegate void ErrorMsgProc(int line, int col, string msg); + + public class Errors + { + int count = 0; // number of errors detected + public ErrorCodeProc SynErr; + public ErrorCodeProc SemErr; + public ErrorMsgProc Error; + StringBuilder errorText = new StringBuilder(); + + public string ErrorOutput { + get { + return errorText.ToString(); + } + } + + public Errors() + { + SynErr = new ErrorCodeProc(DefaultCodeError); // syntactic errors + SemErr = new ErrorCodeProc(DefaultCodeError); // semantic errors + Error = new ErrorMsgProc(DefaultMsgError); // user defined string based errors + } + + public int Count { + get { + return count; + } + } + + // public void Exception (string s) + // { + // Console.WriteLine(s); + // System.Environment.Exit(0); + // } + + void DefaultCodeError(int line, int col, int n) + { + errorText.AppendLine(String.Format("-- line {0} col {1}: error {2}", line, col, n)); + count++; + } + + void DefaultMsgError(int line, int col, string s) { + errorText.AppendLine(String.Format("-- line {0} col {1}: {2}", line, col, s)); + count++; + } + } // Errors +} diff --git a/lib/NRefactory/Project/Src/Parser/Frames/Parser.frame b/lib/NRefactory/Project/Src/Parser/Frames/Parser.frame new file mode 100644 index 000000000..2cb1f273c --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/Frames/Parser.frame @@ -0,0 +1,50 @@ +/* + Parser.frame file for NRefactory. + */ +using System; +using System.Reflection; + +-->namespace + +-->tokens + +partial class Parser : AbstractParser +{ +-->constants + const bool T = true; + const bool x = false; + +-->declarations + +/* +-->pragmas +*/ + +-->productions + + public override void Parse() + { +-->parseRoot + } + + protected override void SynErr(int line, int col, int errorNumber) + { + string s; + switch (errorNumber) { +-->errors + default: s = "error " + errorNumber; break; + } + this.Errors.Error(line, col, s); + } + + private bool StartOf(int s) + { + return set[s, lexer.LookAhead.kind]; + } + + static bool[,] set = { +-->initialization + }; +} // end Parser + +$$$ diff --git a/lib/NRefactory/Project/Src/Parser/Frames/Scanner.frame b/lib/NRefactory/Project/Src/Parser/Frames/Scanner.frame new file mode 100644 index 000000000..b15924823 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/Frames/Scanner.frame @@ -0,0 +1,202 @@ +/*---------------------------------------------------------------------- +Compiler Generator Coco/R, +Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz +extended by M. Loeberbauer & A. Woess, Univ. of Linz +with improvements by Pat Terry, Rhodes University + +This program is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +As an exception, it is allowed to write an extension of Coco/R that is +used as a plugin in non-free software. + +If not otherwise stated, any source code generated by Coco/R (other than +Coco/R itself) does not fall under the GNU General Public License. +-----------------------------------------------------------------------*/ +-->begin +using System; +using System.IO; +using System.Collections; +using System.Text; + +-->namespace + +public class Token { + public int kind; // token kind + public int pos; // token position in the source text (starting at 0) + public int col; // token column (starting at 0) + public int line; // token line (starting at 1) + public string val; // token value + public Token next; // AW 2003-03-07 Tokens are kept in linked list +} + +public class Buffer { + public const char EOF = (char)256; + static byte[] buf; + static int bufLen; + static int pos; + // CHANGES by M.KRUEGER + public static int CountLines(int offset) + { + int line = 0; + for (int i = 0; i <= offset; ++i) { + if (buf[i] == '\n') { + ++line; + } + } + return line; + } + //EOC + public static void Fill (Stream s) { + bufLen = (int) s.Length; + buf = new byte[bufLen]; + s.Read(buf, 0, bufLen); + pos = 0; + } + + public static int Read () { + if (pos < bufLen) return buf[pos++]; + else return EOF; /* pdt */ + } + + public static int Peek () { + if (pos < bufLen) return buf[pos]; + else return EOF; /* pdt */ + } + + /* AW 2003-03-10 moved this from ParserGen.cs */ + public static string GetString (int beg, int end) { + StringBuilder s = new StringBuilder(64); + int oldPos = Buffer.Pos; + Buffer.Pos = beg; + while (beg < end) { s.Append((char)Buffer.Read()); beg++; } + Buffer.Pos = oldPos; + return s.ToString(); + } + + public static int Pos { + get { return pos; } + set { + if (value < 0) pos = 0; + else if (value >= bufLen) pos = bufLen; + else pos = value; + } + } +} + +public class Scanner { + const char EOL = '\n'; + const int eofSym = 0; /* pdt */ +-->declarations + + static Token t; // current token + static char ch; // current input character + static int pos; // column number of current character + static int line; // line number of current character + static int lineStart; // start position of current line + static int oldEols; // EOLs that appeared in a comment; + static BitArray ignore; // set of characters to be ignored by the scanner + + static Token tokens; // the complete input token stream + static Token pt; // current peek token + + public static void Init (string fileName) { + FileStream s = null; + try { + s = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); + Init(s); + } catch (IOException) { + Console.WriteLine("--- Cannot open file {0}", fileName); + System.Environment.Exit(1); + } finally { + if (s != null) s.Close(); + } + } + + public static void Init (Stream s) { + Buffer.Fill(s); + pos = -1; line = 1; lineStart = 0; + oldEols = 0; + NextCh(); +-->initialization + //--- AW: fill token list + tokens = new Token(); // first token is a dummy + Token node = tokens; + do { + node.next = NextToken(); + node = node.next; + } while (node.kind != eofSym); + node.next = node; + node.val = "EOF"; + t = pt = tokens; + } + + static void NextCh() { + if (oldEols > 0) { ch = EOL; oldEols--; } + else { + ch = (char)Buffer.Read(); pos++; + // replace isolated '\r' by '\n' in order to make + // eol handling uniform across Windows, Unix and Mac + if (ch == '\r' && Buffer.Peek() != '\n') ch = EOL; + if (ch == EOL) { line++; lineStart = pos + 1; } + } +-->casing + } + +-->comments + + static void CheckLiteral() { +-->literals + } + + /* AW Scan() renamed to NextToken() */ + static Token NextToken() { + while (ignore[ch]) NextCh(); +-->scan1 + t = new Token(); + t.pos = pos; t.col = pos - lineStart + 1; t.line = line; + int state = start[ch]; + StringBuilder buf = new StringBuilder(16); +-->scan2 + + switch (state) { + case -1: { t.kind = eofSym; goto done; } // NextCh already done /* pdt */ + case 0: { t.kind = noSym; goto done; } // NextCh already done +-->scan3 + } + done: + t.val = buf.ToString(); + return t; + } + + /* AW 2003-03-07 get the next token, move on and synch peek token with current */ + public static Token Scan () { + t = pt = t.next; + return t; + } + + /* AW 2003-03-07 get the next token, ignore pragmas */ + public static Token Peek () { + do { // skip pragmas while peeking + pt = pt.next; + } while (pt.kind > maxT); + return pt; + } + + /* AW 2003-03-11 to make sure peek start at current scan position */ + public static void ResetPeek () { pt = t; } + +} // end Scanner + +$$$ \ No newline at end of file diff --git a/lib/NRefactory/Project/Src/Parser/Frames/SharpCoco.exe b/lib/NRefactory/Project/Src/Parser/Frames/SharpCoco.exe new file mode 100644 index 000000000..da33326fe Binary files /dev/null and b/lib/NRefactory/Project/Src/Parser/Frames/SharpCoco.exe differ diff --git a/lib/NRefactory/Project/Src/Parser/IParser.cs b/lib/NRefactory/Project/Src/Parser/IParser.cs new file mode 100644 index 000000000..beb2d988c --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/IParser.cs @@ -0,0 +1,41 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory +{ + ///

+ /// Parser interface. + /// + public interface IParser : IDisposable + { + Parser.Errors Errors { + get; + } + + Parser.ILexer Lexer { + get; + } + + CompilationUnit CompilationUnit { + get; + } + + bool ParseMethodBodies { + get; set; + } + + void Parse(); + + Expression ParseExpression(); + BlockStatement ParseBlock(); + List ParseTypeMembers(); + } +} diff --git a/lib/NRefactory/Project/Src/Parser/ModifierList.cs b/lib/NRefactory/Project/Src/Parser/ModifierList.cs new file mode 100644 index 000000000..857392ce1 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/ModifierList.cs @@ -0,0 +1,73 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Parser +{ + internal class ModifierList + { + Modifiers cur; + Location location = new Location(-1, -1); + + public Modifiers Modifier { + get { + return cur; + } + } + + public Location GetDeclarationLocation(Location keywordLocation) + { + if(location.X == -1 && location.Y == -1) { + return keywordLocation; + } + return location; + } + +// public Location Location { +// get { +// return location; +// } +// set { +// location = value; +// } +// } + + public bool isNone { get { return cur == Modifiers.None; } } + + public bool Contains(Modifiers m) + { + return ((cur & m) != 0); + } + + public void Add(Modifiers m, Location tokenLocation) + { + if(location.X == -1 && location.Y == -1) { + location = tokenLocation; + } + + if ((cur & m) == 0) { + cur |= m; + } else { +// parser.Error("modifier " + m + " already defined"); + } + } + +// public void Add(Modifiers m) +// { +// Add(m.cur, m.Location); +// } + + public void Check(Modifiers allowed) + { + Modifiers wrong = cur & ~allowed; + if (wrong != Modifiers.None) { +// parser.Error("modifier(s) " + wrong + " not allowed here"); + } + } + } +} diff --git a/lib/NRefactory/Project/Src/Parser/VBNet/ParamModifierList.cs b/lib/NRefactory/Project/Src/Parser/VBNet/ParamModifierList.cs new file mode 100644 index 000000000..80a22b917 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/VBNet/ParamModifierList.cs @@ -0,0 +1,53 @@ +// +// +// +// +// $Revision$ +// + +using ICSharpCode.NRefactory.Ast; + +namespace ICSharpCode.NRefactory.Parser.VB +{ + internal class ParamModifierList + { + ParameterModifiers cur; + Parser parser; + + public ParameterModifiers Modifier { + get { + return cur; + } + } + + public ParamModifierList(Parser parser) + { + this.parser = parser; + cur = ParameterModifiers.None; + } + + public bool isNone { get { return cur == ParameterModifiers.None; } } + + public void Add(ParameterModifiers m) + { + if ((cur & m) == 0) { + cur |= m; + } else { + parser.Error("param modifier " + m + " already defined"); + } + } + + public void Add(ParamModifierList m) + { + Add(m.cur); + } + + public void Check() + { + if((cur & ParameterModifiers.In) != 0 && + (cur & ParameterModifiers.Ref) != 0) { + parser.Error("ByRef and ByVal are not allowed at the same time."); + } + } + } +} diff --git a/lib/NRefactory/Project/Src/Parser/VBNet/Parser.cs b/lib/NRefactory/Project/Src/Parser/VBNet/Parser.cs new file mode 100644 index 000000000..9f00d938a --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/VBNet/Parser.cs @@ -0,0 +1,6578 @@ + +#line 1 "VBNET.ATG" +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Text; +using ICSharpCode.NRefactory.Ast; +using ICSharpCode.NRefactory.Parser.VB; +using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute; +/* + Parser.frame file for NRefactory. + */ +using System; +using System.Reflection; + +namespace ICSharpCode.NRefactory.Parser.VB { + + + +partial class Parser : AbstractParser +{ + const int maxT = 206; + + const bool T = true; + const bool x = false; + + +#line 12 "VBNET.ATG" + + +/* + +*/ + + void VBNET() { + +#line 231 "VBNET.ATG" + lexer.NextToken(); // get the first token + compilationUnit = new CompilationUnit(); + + while (la.kind == 1) { + lexer.NextToken(); + } + while (la.kind == 136) { + OptionStmt(); + } + while (la.kind == 108) { + ImportsStmt(); + } + while ( +#line 237 "VBNET.ATG" +IsGlobalAttrTarget()) { + GlobalAttributeSection(); + } + while (StartOf(1)) { + NamespaceMemberDecl(); + } + Expect(0); + } + + void OptionStmt() { + +#line 242 "VBNET.ATG" + INode node = null; bool val = true; + Expect(136); + +#line 243 "VBNET.ATG" + Location startPos = t.Location; + if (la.kind == 95) { + lexer.NextToken(); + if (la.kind == 134 || la.kind == 135) { + OptionValue( +#line 245 "VBNET.ATG" +ref val); + } + +#line 246 "VBNET.ATG" + node = new OptionDeclaration(OptionType.Explicit, val); + } else if (la.kind == 164) { + lexer.NextToken(); + if (la.kind == 134 || la.kind == 135) { + OptionValue( +#line 248 "VBNET.ATG" +ref val); + } + +#line 249 "VBNET.ATG" + node = new OptionDeclaration(OptionType.Strict, val); + } else if (la.kind == 70) { + lexer.NextToken(); + if (la.kind == 51) { + lexer.NextToken(); + +#line 251 "VBNET.ATG" + node = new OptionDeclaration(OptionType.CompareBinary, val); + } else if (la.kind == 169) { + lexer.NextToken(); + +#line 252 "VBNET.ATG" + node = new OptionDeclaration(OptionType.CompareText, val); + } else SynErr(207); + } else SynErr(208); + EndOfStmt(); + +#line 257 "VBNET.ATG" + if (node != null) { + node.StartLocation = startPos; + node.EndLocation = t.Location; + compilationUnit.AddChild(node); + } + + } + + void ImportsStmt() { + +#line 280 "VBNET.ATG" + List usings = new List(); + + Expect(108); + +#line 284 "VBNET.ATG" + Location startPos = t.Location; + Using u; + + ImportClause( +#line 287 "VBNET.ATG" +out u); + +#line 287 "VBNET.ATG" + if (u != null) { usings.Add(u); } + while (la.kind == 12) { + lexer.NextToken(); + ImportClause( +#line 289 "VBNET.ATG" +out u); + +#line 289 "VBNET.ATG" + if (u != null) { usings.Add(u); } + } + EndOfStmt(); + +#line 293 "VBNET.ATG" + UsingDeclaration usingDeclaration = new UsingDeclaration(usings); + usingDeclaration.StartLocation = startPos; + usingDeclaration.EndLocation = t.Location; + compilationUnit.AddChild(usingDeclaration); + + } + + void GlobalAttributeSection() { + Expect(27); + +#line 2055 "VBNET.ATG" + Location startPos = t.Location; + if (la.kind == 49) { + lexer.NextToken(); + } else if (la.kind == 121) { + lexer.NextToken(); + } else SynErr(209); + +#line 2057 "VBNET.ATG" + string attributeTarget = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture); + List attributes = new List(); + ASTAttribute attribute; + + Expect(13); + Attribute( +#line 2061 "VBNET.ATG" +out attribute); + +#line 2061 "VBNET.ATG" + attributes.Add(attribute); + while ( +#line 2062 "VBNET.ATG" +NotFinalComma()) { + if (la.kind == 12) { + lexer.NextToken(); + if (la.kind == 49) { + lexer.NextToken(); + } else if (la.kind == 121) { + lexer.NextToken(); + } else SynErr(210); + Expect(13); + } + Attribute( +#line 2062 "VBNET.ATG" +out attribute); + +#line 2062 "VBNET.ATG" + attributes.Add(attribute); + } + if (la.kind == 12) { + lexer.NextToken(); + } + Expect(26); + EndOfStmt(); + +#line 2067 "VBNET.ATG" + AttributeSection section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + compilationUnit.AddChild(section); + + } + + void NamespaceMemberDecl() { + +#line 322 "VBNET.ATG" + ModifierList m = new ModifierList(); + AttributeSection section; + List attributes = new List(); + string qualident; + + if (la.kind == 126) { + lexer.NextToken(); + +#line 329 "VBNET.ATG" + Location startPos = t.Location; + + Qualident( +#line 331 "VBNET.ATG" +out qualident); + +#line 333 "VBNET.ATG" + INode node = new NamespaceDeclaration(qualident); + node.StartLocation = startPos; + compilationUnit.AddChild(node); + compilationUnit.BlockStart(node); + + Expect(1); + NamespaceBody(); + +#line 341 "VBNET.ATG" + node.EndLocation = t.Location; + compilationUnit.BlockEnd(); + + } else if (StartOf(2)) { + while (la.kind == 27) { + AttributeSection( +#line 345 "VBNET.ATG" +out section); + +#line 345 "VBNET.ATG" + attributes.Add(section); + } + while (StartOf(3)) { + TypeModifier( +#line 346 "VBNET.ATG" +m); + } + NonModuleDeclaration( +#line 346 "VBNET.ATG" +m, attributes); + } else SynErr(211); + } + + void OptionValue( +#line 265 "VBNET.ATG" +ref bool val) { + if (la.kind == 135) { + lexer.NextToken(); + +#line 267 "VBNET.ATG" + val = true; + } else if (la.kind == 134) { + lexer.NextToken(); + +#line 269 "VBNET.ATG" + val = false; + } else SynErr(212); + } + + void EndOfStmt() { + if (la.kind == 1) { + lexer.NextToken(); + } else if (la.kind == 13) { + lexer.NextToken(); + if (la.kind == 1) { + lexer.NextToken(); + } + } else SynErr(213); + } + + void ImportClause( +#line 300 "VBNET.ATG" +out Using u) { + +#line 302 "VBNET.ATG" + string qualident = null; + TypeReference aliasedType = null; + u = null; + + Qualident( +#line 306 "VBNET.ATG" +out qualident); + if (la.kind == 11) { + lexer.NextToken(); + TypeName( +#line 307 "VBNET.ATG" +out aliasedType); + } + +#line 309 "VBNET.ATG" + if (qualident != null && qualident.Length > 0) { + if (aliasedType != null) { + u = new Using(qualident, aliasedType); + } else { + u = new Using(qualident); + } + } + + } + + void Qualident( +#line 2794 "VBNET.ATG" +out string qualident) { + +#line 2796 "VBNET.ATG" + string name; + qualidentBuilder.Length = 0; + + Identifier(); + +#line 2800 "VBNET.ATG" + qualidentBuilder.Append(t.val); + while ( +#line 2801 "VBNET.ATG" +DotAndIdentOrKw()) { + Expect(10); + IdentifierOrKeyword( +#line 2801 "VBNET.ATG" +out name); + +#line 2801 "VBNET.ATG" + qualidentBuilder.Append('.'); qualidentBuilder.Append(name); + } + +#line 2803 "VBNET.ATG" + qualident = qualidentBuilder.ToString(); + } + + void TypeName( +#line 1948 "VBNET.ATG" +out TypeReference typeref) { + +#line 1949 "VBNET.ATG" + ArrayList rank = null; + NonArrayTypeName( +#line 1951 "VBNET.ATG" +out typeref, false); + ArrayTypeModifiers( +#line 1952 "VBNET.ATG" +out rank); + +#line 1953 "VBNET.ATG" + if (rank != null && typeref != null) { + typeref.RankSpecifier = (int[])rank.ToArray(typeof(int)); + } + + } + + void NamespaceBody() { + while (StartOf(1)) { + NamespaceMemberDecl(); + } + Expect(88); + Expect(126); + Expect(1); + } + + void AttributeSection( +#line 2128 "VBNET.ATG" +out AttributeSection section) { + +#line 2130 "VBNET.ATG" + string attributeTarget = "";List attributes = new List(); + ASTAttribute attribute; + + + Expect(27); + +#line 2134 "VBNET.ATG" + Location startPos = t.Location; + if ( +#line 2135 "VBNET.ATG" +IsLocalAttrTarget()) { + if (la.kind == 93) { + lexer.NextToken(); + +#line 2136 "VBNET.ATG" + attributeTarget = "event"; + } else if (la.kind == 154) { + lexer.NextToken(); + +#line 2137 "VBNET.ATG" + attributeTarget = "return"; + } else { + Identifier(); + +#line 2140 "VBNET.ATG" + string val = t.val.ToLower(System.Globalization.CultureInfo.InvariantCulture); + if (val != "field" || val != "method" || + val != "module" || val != "param" || + val != "property" || val != "type") + Error("attribute target specifier (event, return, field," + + "method, module, param, property, or type) expected"); + attributeTarget = t.val; + + } + Expect(13); + } + Attribute( +#line 2150 "VBNET.ATG" +out attribute); + +#line 2150 "VBNET.ATG" + attributes.Add(attribute); + while ( +#line 2151 "VBNET.ATG" +NotFinalComma()) { + Expect(12); + Attribute( +#line 2151 "VBNET.ATG" +out attribute); + +#line 2151 "VBNET.ATG" + attributes.Add(attribute); + } + if (la.kind == 12) { + lexer.NextToken(); + } + Expect(26); + +#line 2155 "VBNET.ATG" + section = new AttributeSection { + AttributeTarget = attributeTarget, + Attributes = attributes, + StartLocation = startPos, + EndLocation = t.EndLocation + }; + + } + + void TypeModifier( +#line 2874 "VBNET.ATG" +ModifierList m) { + switch (la.kind) { + case 148: { + lexer.NextToken(); + +#line 2875 "VBNET.ATG" + m.Add(Modifiers.Public, t.Location); + break; + } + case 147: { + lexer.NextToken(); + +#line 2876 "VBNET.ATG" + m.Add(Modifiers.Protected, t.Location); + break; + } + case 99: { + lexer.NextToken(); + +#line 2877 "VBNET.ATG" + m.Add(Modifiers.Internal, t.Location); + break; + } + case 145: { + lexer.NextToken(); + +#line 2878 "VBNET.ATG" + m.Add(Modifiers.Private, t.Location); + break; + } + case 158: { + lexer.NextToken(); + +#line 2879 "VBNET.ATG" + m.Add(Modifiers.Static, t.Location); + break; + } + case 157: { + lexer.NextToken(); + +#line 2880 "VBNET.ATG" + m.Add(Modifiers.New, t.Location); + break; + } + case 122: { + lexer.NextToken(); + +#line 2881 "VBNET.ATG" + m.Add(Modifiers.Abstract, t.Location); + break; + } + case 131: { + lexer.NextToken(); + +#line 2882 "VBNET.ATG" + m.Add(Modifiers.Sealed, t.Location); + break; + } + case 204: { + lexer.NextToken(); + +#line 2883 "VBNET.ATG" + m.Add(Modifiers.Partial, t.Location); + break; + } + default: SynErr(214); break; + } + } + + void NonModuleDeclaration( +#line 405 "VBNET.ATG" +ModifierList m, List attributes) { + +#line 407 "VBNET.ATG" + TypeReference typeRef = null; + List baseInterfaces = null; + + switch (la.kind) { + case 67: { + +#line 410 "VBNET.ATG" + m.Check(Modifiers.Classes); + lexer.NextToken(); + +#line 413 "VBNET.ATG" + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + newType.StartLocation = t.Location; + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + + newType.Type = ClassType.Class; + + Identifier(); + +#line 420 "VBNET.ATG" + newType.Name = t.val; + TypeParameterList( +#line 421 "VBNET.ATG" +newType.Templates); + EndOfStmt(); + +#line 423 "VBNET.ATG" + newType.BodyStartLocation = t.Location; + if (la.kind == 110) { + ClassBaseType( +#line 424 "VBNET.ATG" +out typeRef); + +#line 424 "VBNET.ATG" + newType.BaseTypes.Add(typeRef); + } + while (la.kind == 107) { + TypeImplementsClause( +#line 425 "VBNET.ATG" +out baseInterfaces); + +#line 425 "VBNET.ATG" + newType.BaseTypes.AddRange(baseInterfaces); + } + ClassBody( +#line 426 "VBNET.ATG" +newType); + Expect(88); + Expect(67); + +#line 427 "VBNET.ATG" + newType.EndLocation = t.EndLocation; + Expect(1); + +#line 430 "VBNET.ATG" + compilationUnit.BlockEnd(); + + break; + } + case 121: { + lexer.NextToken(); + +#line 434 "VBNET.ATG" + m.Check(Modifiers.VBModules); + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = ClassType.Module; + + Identifier(); + +#line 441 "VBNET.ATG" + newType.Name = t.val; + Expect(1); + +#line 443 "VBNET.ATG" + newType.BodyStartLocation = t.Location; + ModuleBody( +#line 444 "VBNET.ATG" +newType); + +#line 446 "VBNET.ATG" + compilationUnit.BlockEnd(); + + break; + } + case 166: { + lexer.NextToken(); + +#line 450 "VBNET.ATG" + m.Check(Modifiers.VBStructures); + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + newType.Type = ClassType.Struct; + + Identifier(); + +#line 457 "VBNET.ATG" + newType.Name = t.val; + TypeParameterList( +#line 458 "VBNET.ATG" +newType.Templates); + Expect(1); + +#line 460 "VBNET.ATG" + newType.BodyStartLocation = t.Location; + while (la.kind == 107) { + TypeImplementsClause( +#line 461 "VBNET.ATG" +out baseInterfaces); + +#line 461 "VBNET.ATG" + newType.BaseTypes.AddRange(baseInterfaces); + } + StructureBody( +#line 462 "VBNET.ATG" +newType); + +#line 464 "VBNET.ATG" + compilationUnit.BlockEnd(); + + break; + } + case 90: { + lexer.NextToken(); + +#line 469 "VBNET.ATG" + m.Check(Modifiers.VBEnums); + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + + newType.Type = ClassType.Enum; + + Identifier(); + +#line 477 "VBNET.ATG" + newType.Name = t.val; + if (la.kind == 48) { + lexer.NextToken(); + NonArrayTypeName( +#line 478 "VBNET.ATG" +out typeRef, false); + +#line 478 "VBNET.ATG" + newType.BaseTypes.Add(typeRef); + } + Expect(1); + +#line 480 "VBNET.ATG" + newType.BodyStartLocation = t.Location; + EnumBody( +#line 481 "VBNET.ATG" +newType); + +#line 483 "VBNET.ATG" + compilationUnit.BlockEnd(); + + break; + } + case 112: { + lexer.NextToken(); + +#line 488 "VBNET.ATG" + m.Check(Modifiers.VBInterfacs); + TypeDeclaration newType = new TypeDeclaration(m.Modifier, attributes); + newType.StartLocation = m.GetDeclarationLocation(t.Location); + compilationUnit.AddChild(newType); + compilationUnit.BlockStart(newType); + newType.Type = ClassType.Interface; + + Identifier(); + +#line 495 "VBNET.ATG" + newType.Name = t.val; + TypeParameterList( +#line 496 "VBNET.ATG" +newType.Templates); + EndOfStmt(); + +#line 498 "VBNET.ATG" + newType.BodyStartLocation = t.Location; + while (la.kind == 110) { + InterfaceBase( +#line 499 "VBNET.ATG" +out baseInterfaces); + +#line 499 "VBNET.ATG" + newType.BaseTypes.AddRange(baseInterfaces); + } + InterfaceBody( +#line 500 "VBNET.ATG" +newType); + +#line 502 "VBNET.ATG" + compilationUnit.BlockEnd(); + + break; + } + case 80: { + lexer.NextToken(); + +#line 507 "VBNET.ATG" + m.Check(Modifiers.VBDelegates); + DelegateDeclaration delegateDeclr = new DelegateDeclaration(m.Modifier, attributes); + delegateDeclr.ReturnType = new TypeReference("", "System.Void"); + delegateDeclr.StartLocation = m.GetDeclarationLocation(t.Location); + List p = new List(); + + if (la.kind == 167) { + lexer.NextToken(); + Identifier(); + +#line 514 "VBNET.ATG" + delegateDeclr.Name = t.val; + TypeParameterList( +#line 515 "VBNET.ATG" +delegateDeclr.Templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 516 "VBNET.ATG" +p); + } + Expect(25); + +#line 516 "VBNET.ATG" + delegateDeclr.Parameters = p; + } + } else if (la.kind == 100) { + lexer.NextToken(); + Identifier(); + +#line 518 "VBNET.ATG" + delegateDeclr.Name = t.val; + TypeParameterList( +#line 519 "VBNET.ATG" +delegateDeclr.Templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 520 "VBNET.ATG" +p); + } + Expect(25); + +#line 520 "VBNET.ATG" + delegateDeclr.Parameters = p; + } + if (la.kind == 48) { + lexer.NextToken(); + +#line 521 "VBNET.ATG" + TypeReference type; + TypeName( +#line 521 "VBNET.ATG" +out type); + +#line 521 "VBNET.ATG" + delegateDeclr.ReturnType = type; + } + } else SynErr(215); + +#line 523 "VBNET.ATG" + delegateDeclr.EndLocation = t.EndLocation; + Expect(1); + +#line 526 "VBNET.ATG" + compilationUnit.AddChild(delegateDeclr); + + break; + } + default: SynErr(216); break; + } + } + + void TypeParameterList( +#line 350 "VBNET.ATG" +List templates) { + +#line 352 "VBNET.ATG" + TemplateDefinition template; + + if ( +#line 355 "VBNET.ATG" +la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { + lexer.NextToken(); + Expect(201); + TypeParameter( +#line 356 "VBNET.ATG" +out template); + +#line 358 "VBNET.ATG" + if (template != null) templates.Add(template); + + while (la.kind == 12) { + lexer.NextToken(); + TypeParameter( +#line 361 "VBNET.ATG" +out template); + +#line 363 "VBNET.ATG" + if (template != null) templates.Add(template); + + } + Expect(25); + } + } + + void TypeParameter( +#line 371 "VBNET.ATG" +out TemplateDefinition template) { + Identifier(); + +#line 373 "VBNET.ATG" + template = new TemplateDefinition(t.val, null); + if (la.kind == 48) { + TypeParameterConstraints( +#line 374 "VBNET.ATG" +template); + } + } + + void Identifier() { + switch (la.kind) { + case 2: { + lexer.NextToken(); + break; + } + case 169: { + lexer.NextToken(); + break; + } + case 51: { + lexer.NextToken(); + break; + } + case 70: { + lexer.NextToken(); + break; + } + case 205: { + lexer.NextToken(); + break; + } + case 49: { + lexer.NextToken(); + break; + } + case 47: { + lexer.NextToken(); + break; + } + case 50: { + lexer.NextToken(); + break; + } + case 144: { + lexer.NextToken(); + break; + } + case 176: { + lexer.NextToken(); + break; + } + case 177: { + lexer.NextToken(); + break; + } + case 134: { + lexer.NextToken(); + break; + } + case 95: { + lexer.NextToken(); + break; + } + default: SynErr(217); break; + } + } + + void TypeParameterConstraints( +#line 378 "VBNET.ATG" +TemplateDefinition template) { + +#line 380 "VBNET.ATG" + TypeReference constraint; + + Expect(48); + if (la.kind == 22) { + lexer.NextToken(); + TypeParameterConstraint( +#line 386 "VBNET.ATG" +out constraint); + +#line 386 "VBNET.ATG" + if (constraint != null) { template.Bases.Add(constraint); } + while (la.kind == 12) { + lexer.NextToken(); + TypeParameterConstraint( +#line 389 "VBNET.ATG" +out constraint); + +#line 389 "VBNET.ATG" + if (constraint != null) { template.Bases.Add(constraint); } + } + Expect(23); + } else if (StartOf(5)) { + TypeParameterConstraint( +#line 392 "VBNET.ATG" +out constraint); + +#line 392 "VBNET.ATG" + if (constraint != null) { template.Bases.Add(constraint); } + } else SynErr(218); + } + + void TypeParameterConstraint( +#line 396 "VBNET.ATG" +out TypeReference constraint) { + +#line 397 "VBNET.ATG" + constraint = null; + if (la.kind == 67) { + lexer.NextToken(); + +#line 398 "VBNET.ATG" + constraint = TypeReference.ClassConstraint; + } else if (la.kind == 166) { + lexer.NextToken(); + +#line 399 "VBNET.ATG" + constraint = TypeReference.StructConstraint; + } else if (la.kind == 127) { + lexer.NextToken(); + +#line 400 "VBNET.ATG" + constraint = TypeReference.NewConstraint; + } else if (StartOf(6)) { + TypeName( +#line 401 "VBNET.ATG" +out constraint); + } else SynErr(219); + } + + void ClassBaseType( +#line 727 "VBNET.ATG" +out TypeReference typeRef) { + +#line 729 "VBNET.ATG" + typeRef = null; + + Expect(110); + TypeName( +#line 732 "VBNET.ATG" +out typeRef); + EndOfStmt(); + } + + void TypeImplementsClause( +#line 1520 "VBNET.ATG" +out List baseInterfaces) { + +#line 1522 "VBNET.ATG" + baseInterfaces = new List(); + TypeReference type = null; + + Expect(107); + TypeName( +#line 1525 "VBNET.ATG" +out type); + +#line 1527 "VBNET.ATG" + baseInterfaces.Add(type); + + while (la.kind == 12) { + lexer.NextToken(); + TypeName( +#line 1530 "VBNET.ATG" +out type); + +#line 1531 "VBNET.ATG" + baseInterfaces.Add(type); + } + EndOfStmt(); + } + + void ClassBody( +#line 536 "VBNET.ATG" +TypeDeclaration newType) { + +#line 537 "VBNET.ATG" + AttributeSection section; + while (StartOf(7)) { + +#line 539 "VBNET.ATG" + List attributes = new List(); + ModifierList m = new ModifierList(); + + while (la.kind == 27) { + AttributeSection( +#line 542 "VBNET.ATG" +out section); + +#line 542 "VBNET.ATG" + attributes.Add(section); + } + while (StartOf(8)) { + MemberModifier( +#line 543 "VBNET.ATG" +m); + } + ClassMemberDecl( +#line 544 "VBNET.ATG" +m, attributes); + } + } + + void ModuleBody( +#line 563 "VBNET.ATG" +TypeDeclaration newType) { + +#line 564 "VBNET.ATG" + AttributeSection section; + while (StartOf(7)) { + +#line 566 "VBNET.ATG" + List attributes = new List(); + ModifierList m = new ModifierList(); + + while (la.kind == 27) { + AttributeSection( +#line 569 "VBNET.ATG" +out section); + +#line 569 "VBNET.ATG" + attributes.Add(section); + } + while (StartOf(8)) { + MemberModifier( +#line 570 "VBNET.ATG" +m); + } + ClassMemberDecl( +#line 571 "VBNET.ATG" +m, attributes); + } + Expect(88); + Expect(121); + +#line 573 "VBNET.ATG" + newType.EndLocation = t.EndLocation; + Expect(1); + } + + void StructureBody( +#line 548 "VBNET.ATG" +TypeDeclaration newType) { + +#line 549 "VBNET.ATG" + AttributeSection section; + while (StartOf(7)) { + +#line 551 "VBNET.ATG" + List attributes = new List(); + ModifierList m = new ModifierList(); + + while (la.kind == 27) { + AttributeSection( +#line 554 "VBNET.ATG" +out section); + +#line 554 "VBNET.ATG" + attributes.Add(section); + } + while (StartOf(8)) { + MemberModifier( +#line 555 "VBNET.ATG" +m); + } + StructureMemberDecl( +#line 556 "VBNET.ATG" +m, attributes); + } + Expect(88); + Expect(166); + +#line 558 "VBNET.ATG" + newType.EndLocation = t.EndLocation; + Expect(1); + } + + void NonArrayTypeName( +#line 1971 "VBNET.ATG" +out TypeReference typeref, bool canBeUnbound) { + +#line 1973 "VBNET.ATG" + string name; + typeref = null; + bool isGlobal = false; + + if (StartOf(9)) { + if (la.kind == 199) { + lexer.NextToken(); + Expect(10); + +#line 1978 "VBNET.ATG" + isGlobal = true; + } + QualIdentAndTypeArguments( +#line 1979 "VBNET.ATG" +out typeref, canBeUnbound); + +#line 1980 "VBNET.ATG" + typeref.IsGlobal = isGlobal; + while (la.kind == 10) { + lexer.NextToken(); + +#line 1981 "VBNET.ATG" + TypeReference nestedTypeRef; + QualIdentAndTypeArguments( +#line 1982 "VBNET.ATG" +out nestedTypeRef, canBeUnbound); + +#line 1983 "VBNET.ATG" + typeref = new InnerClassTypeReference(typeref, nestedTypeRef.Type, nestedTypeRef.GenericTypes); + } + } else if (la.kind == 133) { + lexer.NextToken(); + +#line 1986 "VBNET.ATG" + typeref = new TypeReference("System.Object"); + } else if (StartOf(10)) { + PrimitiveTypeName( +#line 1987 "VBNET.ATG" +out name); + +#line 1987 "VBNET.ATG" + typeref = new TypeReference(name); + } else SynErr(220); + } + + void EnumBody( +#line 577 "VBNET.ATG" +TypeDeclaration newType) { + +#line 578 "VBNET.ATG" + FieldDeclaration f; + while (StartOf(11)) { + EnumMemberDecl( +#line 580 "VBNET.ATG" +out f); + +#line 580 "VBNET.ATG" + compilationUnit.AddChild(f); + } + Expect(88); + Expect(90); + +#line 582 "VBNET.ATG" + newType.EndLocation = t.EndLocation; + Expect(1); + } + + void InterfaceBase( +#line 1505 "VBNET.ATG" +out List bases) { + +#line 1507 "VBNET.ATG" + TypeReference type; + bases = new List(); + + Expect(110); + TypeName( +#line 1511 "VBNET.ATG" +out type); + +#line 1511 "VBNET.ATG" + bases.Add(type); + while (la.kind == 12) { + lexer.NextToken(); + TypeName( +#line 1514 "VBNET.ATG" +out type); + +#line 1514 "VBNET.ATG" + bases.Add(type); + } + Expect(1); + } + + void InterfaceBody( +#line 586 "VBNET.ATG" +TypeDeclaration newType) { + while (StartOf(12)) { + InterfaceMemberDecl(); + } + Expect(88); + Expect(112); + +#line 588 "VBNET.ATG" + newType.EndLocation = t.EndLocation; + Expect(1); + } + + void FormalParameterList( +#line 2165 "VBNET.ATG" +List parameter) { + +#line 2167 "VBNET.ATG" + ParameterDeclarationExpression p; + AttributeSection section; + List attributes = new List(); + + while (la.kind == 27) { + AttributeSection( +#line 2171 "VBNET.ATG" +out section); + +#line 2171 "VBNET.ATG" + attributes.Add(section); + } + FormalParameter( +#line 2173 "VBNET.ATG" +out p); + +#line 2175 "VBNET.ATG" + bool paramsFound = false; + p.Attributes = attributes; + parameter.Add(p); + + while (la.kind == 12) { + lexer.NextToken(); + +#line 2180 "VBNET.ATG" + if (paramsFound) Error("params array must be at end of parameter list"); + while (la.kind == 27) { + AttributeSection( +#line 2181 "VBNET.ATG" +out section); + +#line 2181 "VBNET.ATG" + attributes.Add(section); + } + FormalParameter( +#line 2183 "VBNET.ATG" +out p); + +#line 2183 "VBNET.ATG" + p.Attributes = attributes; parameter.Add(p); + } + } + + void MemberModifier( +#line 2886 "VBNET.ATG" +ModifierList m) { + switch (la.kind) { + case 122: { + lexer.NextToken(); + +#line 2887 "VBNET.ATG" + m.Add(Modifiers.Abstract, t.Location); + break; + } + case 79: { + lexer.NextToken(); + +#line 2888 "VBNET.ATG" + m.Add(Modifiers.Default, t.Location); + break; + } + case 99: { + lexer.NextToken(); + +#line 2889 "VBNET.ATG" + m.Add(Modifiers.Internal, t.Location); + break; + } + case 157: { + lexer.NextToken(); + +#line 2890 "VBNET.ATG" + m.Add(Modifiers.New, t.Location); + break; + } + case 142: { + lexer.NextToken(); + +#line 2891 "VBNET.ATG" + m.Add(Modifiers.Override, t.Location); + break; + } + case 123: { + lexer.NextToken(); + +#line 2892 "VBNET.ATG" + m.Add(Modifiers.Abstract, t.Location); + break; + } + case 145: { + lexer.NextToken(); + +#line 2893 "VBNET.ATG" + m.Add(Modifiers.Private, t.Location); + break; + } + case 147: { + lexer.NextToken(); + +#line 2894 "VBNET.ATG" + m.Add(Modifiers.Protected, t.Location); + break; + } + case 148: { + lexer.NextToken(); + +#line 2895 "VBNET.ATG" + m.Add(Modifiers.Public, t.Location); + break; + } + case 131: { + lexer.NextToken(); + +#line 2896 "VBNET.ATG" + m.Add(Modifiers.Sealed, t.Location); + break; + } + case 132: { + lexer.NextToken(); + +#line 2897 "VBNET.ATG" + m.Add(Modifiers.Sealed, t.Location); + break; + } + case 158: { + lexer.NextToken(); + +#line 2898 "VBNET.ATG" + m.Add(Modifiers.Static, t.Location); + break; + } + case 141: { + lexer.NextToken(); + +#line 2899 "VBNET.ATG" + m.Add(Modifiers.Virtual, t.Location); + break; + } + case 140: { + lexer.NextToken(); + +#line 2900 "VBNET.ATG" + m.Add(Modifiers.Overloads, t.Location); + break; + } + case 150: { + lexer.NextToken(); + +#line 2901 "VBNET.ATG" + m.Add(Modifiers.ReadOnly, t.Location); + break; + } + case 184: { + lexer.NextToken(); + +#line 2902 "VBNET.ATG" + m.Add(Modifiers.WriteOnly, t.Location); + break; + } + case 183: { + lexer.NextToken(); + +#line 2903 "VBNET.ATG" + m.Add(Modifiers.WithEvents, t.Location); + break; + } + case 81: { + lexer.NextToken(); + +#line 2904 "VBNET.ATG" + m.Add(Modifiers.Dim, t.Location); + break; + } + default: SynErr(221); break; + } + } + + void ClassMemberDecl( +#line 723 "VBNET.ATG" +ModifierList m, List attributes) { + StructureMemberDecl( +#line 724 "VBNET.ATG" +m, attributes); + } + + void StructureMemberDecl( +#line 737 "VBNET.ATG" +ModifierList m, List attributes) { + +#line 739 "VBNET.ATG" + TypeReference type = null; + List p = new List(); + Statement stmt = null; + List variableDeclarators = new List(); + List templates = new List(); + + switch (la.kind) { + case 67: case 80: case 90: case 112: case 121: case 166: { + NonModuleDeclaration( +#line 746 "VBNET.ATG" +m, attributes); + break; + } + case 167: { + lexer.NextToken(); + +#line 750 "VBNET.ATG" + Location startPos = t.Location; + + if (StartOf(13)) { + +#line 754 "VBNET.ATG" + string name = String.Empty; + MethodDeclaration methodDeclaration; List handlesClause = null; + List implementsClause = null; + + Identifier(); + +#line 760 "VBNET.ATG" + name = t.val; + m.Check(Modifiers.VBMethods); + + TypeParameterList( +#line 763 "VBNET.ATG" +templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 764 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 105 || la.kind == 107) { + if (la.kind == 107) { + ImplementsClause( +#line 767 "VBNET.ATG" +out implementsClause); + } else { + HandlesClause( +#line 769 "VBNET.ATG" +out handlesClause); + } + } + +#line 772 "VBNET.ATG" + Location endLocation = t.EndLocation; + Expect(1); + if ( +#line 776 "VBNET.ATG" +IsMustOverride(m)) { + +#line 778 "VBNET.ATG" + methodDeclaration = new MethodDeclaration { + Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation, + TypeReference = new TypeReference("", "System.Void"), + Templates = templates, + HandlesClause = handlesClause, + InterfaceImplementations = implementsClause + }; + compilationUnit.AddChild(methodDeclaration); + + } else if (StartOf(14)) { + +#line 790 "VBNET.ATG" + methodDeclaration = new MethodDeclaration { + Name = name, Modifier = m.Modifier, Parameters = p, Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), EndLocation = endLocation, + TypeReference = new TypeReference("", "System.Void"), + Templates = templates, + HandlesClause = handlesClause, + InterfaceImplementations = implementsClause + }; + compilationUnit.AddChild(methodDeclaration); + + +#line 801 "VBNET.ATG" + if (ParseMethodBodies) { + Block( +#line 802 "VBNET.ATG" +out stmt); + Expect(88); + Expect(167); + +#line 804 "VBNET.ATG" + } else { + // don't parse method body + lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement(); + } + + +#line 810 "VBNET.ATG" + methodDeclaration.Body = (BlockStatement)stmt; + +#line 811 "VBNET.ATG" + methodDeclaration.Body.EndLocation = t.EndLocation; + Expect(1); + } else SynErr(222); + } else if (la.kind == 127) { + lexer.NextToken(); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 814 "VBNET.ATG" +p); + } + Expect(25); + } + +#line 815 "VBNET.ATG" + m.Check(Modifiers.Constructors); + +#line 816 "VBNET.ATG" + Location constructorEndLocation = t.EndLocation; + Expect(1); + +#line 819 "VBNET.ATG" + if (ParseMethodBodies) { + Block( +#line 820 "VBNET.ATG" +out stmt); + Expect(88); + Expect(167); + +#line 822 "VBNET.ATG" + } else { + // don't parse method body + lexer.SkipCurrentBlock(Tokens.Sub); stmt = new BlockStatement(); + } + + +#line 828 "VBNET.ATG" + Location endLocation = t.EndLocation; + Expect(1); + +#line 830 "VBNET.ATG" + ConstructorDeclaration cd = new ConstructorDeclaration("New", m.Modifier, p, attributes); + cd.StartLocation = m.GetDeclarationLocation(startPos); + cd.EndLocation = constructorEndLocation; + cd.Body = (BlockStatement)stmt; + cd.Body.EndLocation = endLocation; + compilationUnit.AddChild(cd); + + } else SynErr(223); + break; + } + case 100: { + lexer.NextToken(); + +#line 842 "VBNET.ATG" + m.Check(Modifiers.VBMethods); + string name = String.Empty; + Location startPos = t.Location; + MethodDeclaration methodDeclaration;List handlesClause = null; + List implementsClause = null; + AttributeSection returnTypeAttributeSection = null; + + Identifier(); + +#line 849 "VBNET.ATG" + name = t.val; + TypeParameterList( +#line 850 "VBNET.ATG" +templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 851 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + while (la.kind == 27) { + AttributeSection( +#line 852 "VBNET.ATG" +out returnTypeAttributeSection); + } + TypeName( +#line 852 "VBNET.ATG" +out type); + } + +#line 854 "VBNET.ATG" + if(type == null) { + type = new TypeReference("System.Object"); + } + + if (la.kind == 105 || la.kind == 107) { + if (la.kind == 107) { + ImplementsClause( +#line 860 "VBNET.ATG" +out implementsClause); + } else { + HandlesClause( +#line 862 "VBNET.ATG" +out handlesClause); + } + } + Expect(1); + if ( +#line 868 "VBNET.ATG" +IsMustOverride(m)) { + +#line 870 "VBNET.ATG" + methodDeclaration = new MethodDeclaration { + Name = name, Modifier = m.Modifier, TypeReference = type, + Parameters = p, Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation, + HandlesClause = handlesClause, + Templates = templates, + InterfaceImplementations = implementsClause + }; + if (returnTypeAttributeSection != null) { + returnTypeAttributeSection.AttributeTarget = "return"; + methodDeclaration.Attributes.Add(returnTypeAttributeSection); + } + compilationUnit.AddChild(methodDeclaration); + + } else if (StartOf(14)) { + +#line 887 "VBNET.ATG" + methodDeclaration = new MethodDeclaration { + Name = name, Modifier = m.Modifier, TypeReference = type, + Parameters = p, Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation, + Templates = templates, + HandlesClause = handlesClause, + InterfaceImplementations = implementsClause + }; + if (returnTypeAttributeSection != null) { + returnTypeAttributeSection.AttributeTarget = "return"; + methodDeclaration.Attributes.Add(returnTypeAttributeSection); + } + + compilationUnit.AddChild(methodDeclaration); + + if (ParseMethodBodies) { + Block( +#line 904 "VBNET.ATG" +out stmt); + Expect(88); + Expect(100); + +#line 906 "VBNET.ATG" + } else { + // don't parse method body + lexer.SkipCurrentBlock(Tokens.Function); stmt = new BlockStatement(); + } + methodDeclaration.Body = (BlockStatement)stmt; + methodDeclaration.Body.StartLocation = methodDeclaration.EndLocation; + methodDeclaration.Body.EndLocation = t.EndLocation; + + Expect(1); + } else SynErr(224); + break; + } + case 78: { + lexer.NextToken(); + +#line 920 "VBNET.ATG" + m.Check(Modifiers.VBExternalMethods); + Location startPos = t.Location; + CharsetModifier charsetModifer = CharsetModifier.None; + string library = String.Empty; + string alias = null; + string name = String.Empty; + + if (StartOf(15)) { + Charset( +#line 927 "VBNET.ATG" +out charsetModifer); + } + if (la.kind == 167) { + lexer.NextToken(); + Identifier(); + +#line 930 "VBNET.ATG" + name = t.val; + Expect(115); + Expect(3); + +#line 931 "VBNET.ATG" + library = t.literalValue as string; + if (la.kind == 44) { + lexer.NextToken(); + Expect(3); + +#line 932 "VBNET.ATG" + alias = t.literalValue as string; + } + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 933 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + +#line 936 "VBNET.ATG" + DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, null, p, attributes, library, alias, charsetModifer); + declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos); + declareDeclaration.EndLocation = t.EndLocation; + compilationUnit.AddChild(declareDeclaration); + + } else if (la.kind == 100) { + lexer.NextToken(); + Identifier(); + +#line 943 "VBNET.ATG" + name = t.val; + Expect(115); + Expect(3); + +#line 944 "VBNET.ATG" + library = t.literalValue as string; + if (la.kind == 44) { + lexer.NextToken(); + Expect(3); + +#line 945 "VBNET.ATG" + alias = t.literalValue as string; + } + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 946 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 947 "VBNET.ATG" +out type); + } + Expect(1); + +#line 950 "VBNET.ATG" + DeclareDeclaration declareDeclaration = new DeclareDeclaration(name, m.Modifier, type, p, attributes, library, alias, charsetModifer); + declareDeclaration.StartLocation = m.GetDeclarationLocation(startPos); + declareDeclaration.EndLocation = t.EndLocation; + compilationUnit.AddChild(declareDeclaration); + + } else SynErr(225); + break; + } + case 93: { + lexer.NextToken(); + +#line 960 "VBNET.ATG" + m.Check(Modifiers.VBEvents); + Location startPos = t.Location; + EventDeclaration eventDeclaration; + string name = String.Empty; + List implementsClause = null; + + Identifier(); + +#line 966 "VBNET.ATG" + name= t.val; + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 968 "VBNET.ATG" +out type); + } else if (la.kind == 1 || la.kind == 24 || la.kind == 107) { + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 970 "VBNET.ATG" +p); + } + Expect(25); + } + } else SynErr(226); + if (la.kind == 107) { + ImplementsClause( +#line 972 "VBNET.ATG" +out implementsClause); + } + +#line 974 "VBNET.ATG" + eventDeclaration = new EventDeclaration { + Name = name, TypeReference = type, Modifier = m.Modifier, + Parameters = p, Attributes = attributes, InterfaceImplementations = implementsClause, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation + }; + compilationUnit.AddChild(eventDeclaration); + + Expect(1); + break; + } + case 2: case 47: case 49: case 50: case 51: case 70: case 95: case 134: case 144: case 169: case 176: case 177: { + +#line 984 "VBNET.ATG" + Location startPos = t.Location; + +#line 986 "VBNET.ATG" + m.Check(Modifiers.Fields); + FieldDeclaration fd = new FieldDeclaration(attributes, null, m.Modifier); + fd.StartLocation = m.GetDeclarationLocation(startPos); + + IdentifierForFieldDeclaration(); + +#line 990 "VBNET.ATG" + string name = t.val; + VariableDeclaratorPartAfterIdentifier( +#line 991 "VBNET.ATG" +variableDeclarators, name); + while (la.kind == 12) { + lexer.NextToken(); + VariableDeclarator( +#line 992 "VBNET.ATG" +variableDeclarators); + } + Expect(1); + +#line 995 "VBNET.ATG" + fd.EndLocation = t.EndLocation; + fd.Fields = variableDeclarators; + compilationUnit.AddChild(fd); + + break; + } + case 71: { + +#line 1000 "VBNET.ATG" + m.Check(Modifiers.Fields); + lexer.NextToken(); + +#line 1001 "VBNET.ATG" + m.Add(Modifiers.Const, t.Location); + +#line 1003 "VBNET.ATG" + FieldDeclaration fd = new FieldDeclaration(attributes, type, m.Modifier); + fd.StartLocation = m.GetDeclarationLocation(t.Location); + List constantDeclarators = new List(); + + ConstantDeclarator( +#line 1007 "VBNET.ATG" +constantDeclarators); + while (la.kind == 12) { + lexer.NextToken(); + ConstantDeclarator( +#line 1008 "VBNET.ATG" +constantDeclarators); + } + +#line 1010 "VBNET.ATG" + fd.Fields = constantDeclarators; + fd.EndLocation = t.Location; + + Expect(1); + +#line 1015 "VBNET.ATG" + fd.EndLocation = t.EndLocation; + compilationUnit.AddChild(fd); + + break; + } + case 146: { + lexer.NextToken(); + +#line 1021 "VBNET.ATG" + m.Check(Modifiers.VBProperties); + Location startPos = t.Location; + List implementsClause = null; + + Identifier(); + +#line 1025 "VBNET.ATG" + string propertyName = t.val; + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 1026 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 1027 "VBNET.ATG" +out type); + } + +#line 1029 "VBNET.ATG" + if(type == null) { + type = new TypeReference("System.Object"); + } + + if (la.kind == 107) { + ImplementsClause( +#line 1033 "VBNET.ATG" +out implementsClause); + } + Expect(1); + if ( +#line 1037 "VBNET.ATG" +IsMustOverride(m)) { + +#line 1039 "VBNET.ATG" + PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes); + pDecl.StartLocation = m.GetDeclarationLocation(startPos); + pDecl.EndLocation = t.Location; + pDecl.TypeReference = type; + pDecl.InterfaceImplementations = implementsClause; + pDecl.Parameters = p; + compilationUnit.AddChild(pDecl); + + } else if (StartOf(16)) { + +#line 1049 "VBNET.ATG" + PropertyDeclaration pDecl = new PropertyDeclaration(propertyName, type, m.Modifier, attributes); + pDecl.StartLocation = m.GetDeclarationLocation(startPos); + pDecl.EndLocation = t.Location; + pDecl.BodyStart = t.Location; + pDecl.TypeReference = type; + pDecl.InterfaceImplementations = implementsClause; + pDecl.Parameters = p; + PropertyGetRegion getRegion; + PropertySetRegion setRegion; + + AccessorDecls( +#line 1059 "VBNET.ATG" +out getRegion, out setRegion); + Expect(88); + Expect(146); + Expect(1); + +#line 1063 "VBNET.ATG" + pDecl.GetRegion = getRegion; + pDecl.SetRegion = setRegion; + pDecl.BodyEnd = t.EndLocation; + compilationUnit.AddChild(pDecl); + + } else SynErr(227); + break; + } + case 205: { + lexer.NextToken(); + +#line 1070 "VBNET.ATG" + Location startPos = t.Location; + Expect(93); + +#line 1072 "VBNET.ATG" + m.Check(Modifiers.VBCustomEvents); + EventAddRemoveRegion eventAccessorDeclaration; + EventAddRegion addHandlerAccessorDeclaration = null; + EventRemoveRegion removeHandlerAccessorDeclaration = null; + EventRaiseRegion raiseEventAccessorDeclaration = null; + List implementsClause = null; + + Identifier(); + +#line 1079 "VBNET.ATG" + string customEventName = t.val; + Expect(48); + TypeName( +#line 1080 "VBNET.ATG" +out type); + if (la.kind == 107) { + ImplementsClause( +#line 1081 "VBNET.ATG" +out implementsClause); + } + Expect(1); + while (StartOf(17)) { + EventAccessorDeclaration( +#line 1084 "VBNET.ATG" +out eventAccessorDeclaration); + +#line 1086 "VBNET.ATG" + if(eventAccessorDeclaration is EventAddRegion) + { + addHandlerAccessorDeclaration = (EventAddRegion)eventAccessorDeclaration; + } + else if(eventAccessorDeclaration is EventRemoveRegion) + { + removeHandlerAccessorDeclaration = (EventRemoveRegion)eventAccessorDeclaration; + } + else if(eventAccessorDeclaration is EventRaiseRegion) + { + raiseEventAccessorDeclaration = (EventRaiseRegion)eventAccessorDeclaration; + } + + } + Expect(88); + Expect(93); + Expect(1); + +#line 1102 "VBNET.ATG" + if(addHandlerAccessorDeclaration == null) + { + Error("Need to provide AddHandler accessor."); + } + + if(removeHandlerAccessorDeclaration == null) + { + Error("Need to provide RemoveHandler accessor."); + } + + if(raiseEventAccessorDeclaration == null) + { + Error("Need to provide RaiseEvent accessor."); + } + + EventDeclaration decl = new EventDeclaration { + TypeReference = type, Name = customEventName, Modifier = m.Modifier, + Attributes = attributes, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = t.EndLocation, + AddRegion = addHandlerAccessorDeclaration, + RemoveRegion = removeHandlerAccessorDeclaration, + RaiseRegion = raiseEventAccessorDeclaration + }; + compilationUnit.AddChild(decl); + + break; + } + case 188: case 202: case 203: { + +#line 1128 "VBNET.ATG" + ConversionType opConversionType = ConversionType.None; + if (la.kind == 202 || la.kind == 203) { + if (la.kind == 203) { + lexer.NextToken(); + +#line 1129 "VBNET.ATG" + opConversionType = ConversionType.Implicit; + } else { + lexer.NextToken(); + +#line 1130 "VBNET.ATG" + opConversionType = ConversionType.Explicit; + } + } + Expect(188); + +#line 1133 "VBNET.ATG" + m.Check(Modifiers.VBOperators); + Location startPos = t.Location; + TypeReference returnType = NullTypeReference.Instance; + TypeReference operandType = NullTypeReference.Instance; + string operandName; + OverloadableOperatorType operatorType; + AttributeSection section; + List parameters = new List(); + List returnTypeAttributes = new List(); + + OverloadableOperator( +#line 1143 "VBNET.ATG" +out operatorType); + Expect(24); + if (la.kind == 55) { + lexer.NextToken(); + } + Identifier(); + +#line 1144 "VBNET.ATG" + operandName = t.val; + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 1145 "VBNET.ATG" +out operandType); + } + +#line 1146 "VBNET.ATG" + parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); + while (la.kind == 12) { + lexer.NextToken(); + if (la.kind == 55) { + lexer.NextToken(); + } + Identifier(); + +#line 1150 "VBNET.ATG" + operandName = t.val; + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 1151 "VBNET.ATG" +out operandType); + } + +#line 1152 "VBNET.ATG" + parameters.Add(new ParameterDeclarationExpression(operandType, operandName, ParameterModifiers.In)); + } + Expect(25); + +#line 1155 "VBNET.ATG" + Location endPos = t.EndLocation; + if (la.kind == 48) { + lexer.NextToken(); + while (la.kind == 27) { + AttributeSection( +#line 1156 "VBNET.ATG" +out section); + +#line 1156 "VBNET.ATG" + returnTypeAttributes.Add(section); + } + TypeName( +#line 1156 "VBNET.ATG" +out returnType); + +#line 1156 "VBNET.ATG" + endPos = t.EndLocation; + Expect(1); + } + Block( +#line 1157 "VBNET.ATG" +out stmt); + Expect(88); + Expect(188); + Expect(1); + +#line 1159 "VBNET.ATG" + OperatorDeclaration operatorDeclaration = new OperatorDeclaration { + Modifier = m.Modifier, + Attributes = attributes, + Parameters = parameters, + TypeReference = returnType, + OverloadableOperator = operatorType, + ConversionType = opConversionType, + ReturnTypeAttributes = returnTypeAttributes, + Body = (BlockStatement)stmt, + StartLocation = m.GetDeclarationLocation(startPos), + EndLocation = endPos + }; + operatorDeclaration.Body.StartLocation = startPos; + operatorDeclaration.Body.EndLocation = t.Location; + compilationUnit.AddChild(operatorDeclaration); + + break; + } + default: SynErr(228); break; + } + } + + void EnumMemberDecl( +#line 705 "VBNET.ATG" +out FieldDeclaration f) { + +#line 707 "VBNET.ATG" + Expression expr = null;List attributes = new List(); + AttributeSection section = null; + VariableDeclaration varDecl = null; + + while (la.kind == 27) { + AttributeSection( +#line 711 "VBNET.ATG" +out section); + +#line 711 "VBNET.ATG" + attributes.Add(section); + } + Identifier(); + +#line 714 "VBNET.ATG" + f = new FieldDeclaration(attributes); + varDecl = new VariableDeclaration(t.val); + f.Fields.Add(varDecl); + f.StartLocation = varDecl.StartLocation = t.Location; + + if (la.kind == 11) { + lexer.NextToken(); + Expr( +#line 719 "VBNET.ATG" +out expr); + +#line 719 "VBNET.ATG" + varDecl.Initializer = expr; + } + Expect(1); + } + + void InterfaceMemberDecl() { + +#line 596 "VBNET.ATG" + TypeReference type =null; + List p = new List(); + List templates = new List(); + AttributeSection section, returnTypeAttributeSection = null; + ModifierList mod = new ModifierList(); + List attributes = new List(); + string name; + + if (StartOf(18)) { + while (la.kind == 27) { + AttributeSection( +#line 604 "VBNET.ATG" +out section); + +#line 604 "VBNET.ATG" + attributes.Add(section); + } + while (StartOf(8)) { + MemberModifier( +#line 607 "VBNET.ATG" +mod); + } + if (la.kind == 93) { + lexer.NextToken(); + +#line 611 "VBNET.ATG" + mod.Check(Modifiers.VBInterfaceEvents); + Location startLocation = t.Location; + + Identifier(); + +#line 614 "VBNET.ATG" + name = t.val; + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 615 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 616 "VBNET.ATG" +out type); + } + Expect(1); + +#line 619 "VBNET.ATG" + EventDeclaration ed = new EventDeclaration { + Name = name, TypeReference = type, Modifier = mod.Modifier, + Parameters = p, Attributes = attributes, + StartLocation = startLocation, EndLocation = t.EndLocation + }; + compilationUnit.AddChild(ed); + + } else if (la.kind == 167) { + lexer.NextToken(); + +#line 629 "VBNET.ATG" + Location startLocation = t.Location; + mod.Check(Modifiers.VBInterfaceMethods); + + Identifier(); + +#line 632 "VBNET.ATG" + name = t.val; + TypeParameterList( +#line 633 "VBNET.ATG" +templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 634 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + +#line 637 "VBNET.ATG" + MethodDeclaration md = new MethodDeclaration { + Name = name, + Modifier = mod.Modifier, + Parameters = p, + Attributes = attributes, + TypeReference = new TypeReference("", "System.Void"), + StartLocation = startLocation, + EndLocation = t.EndLocation, + Templates = templates + }; + compilationUnit.AddChild(md); + + } else if (la.kind == 100) { + lexer.NextToken(); + +#line 652 "VBNET.ATG" + mod.Check(Modifiers.VBInterfaceMethods); + Location startLocation = t.Location; + + Identifier(); + +#line 655 "VBNET.ATG" + name = t.val; + TypeParameterList( +#line 656 "VBNET.ATG" +templates); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 657 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + while (la.kind == 27) { + AttributeSection( +#line 658 "VBNET.ATG" +out returnTypeAttributeSection); + } + TypeName( +#line 658 "VBNET.ATG" +out type); + } + +#line 660 "VBNET.ATG" + if(type == null) { + type = new TypeReference("System.Object"); + } + MethodDeclaration md = new MethodDeclaration { + Name = name, Modifier = mod.Modifier, + TypeReference = type, Parameters = p, Attributes = attributes + }; + if (returnTypeAttributeSection != null) { + returnTypeAttributeSection.AttributeTarget = "return"; + md.Attributes.Add(returnTypeAttributeSection); + } + md.StartLocation = startLocation; + md.EndLocation = t.EndLocation; + md.Templates = templates; + compilationUnit.AddChild(md); + + Expect(1); + } else if (la.kind == 146) { + lexer.NextToken(); + +#line 680 "VBNET.ATG" + Location startLocation = t.Location; + mod.Check(Modifiers.VBInterfaceProperties); + + Identifier(); + +#line 683 "VBNET.ATG" + name = t.val; + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 684 "VBNET.ATG" +p); + } + Expect(25); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 685 "VBNET.ATG" +out type); + } + +#line 687 "VBNET.ATG" + if(type == null) { + type = new TypeReference("System.Object"); + } + + Expect(1); + +#line 693 "VBNET.ATG" + PropertyDeclaration pd = new PropertyDeclaration(name, type, mod.Modifier, attributes); + pd.Parameters = p; + pd.EndLocation = t.EndLocation; + pd.StartLocation = startLocation; + compilationUnit.AddChild(pd); + + } else SynErr(229); + } else if (StartOf(19)) { + NonModuleDeclaration( +#line 701 "VBNET.ATG" +mod, attributes); + } else SynErr(230); + } + + void Expr( +#line 1564 "VBNET.ATG" +out Expression expr) { + DisjunctionExpr( +#line 1566 "VBNET.ATG" +out expr); + } + + void ImplementsClause( +#line 1537 "VBNET.ATG" +out List baseInterfaces) { + +#line 1539 "VBNET.ATG" + baseInterfaces = new List(); + TypeReference type = null; + string memberName = null; + + Expect(107); + NonArrayTypeName( +#line 1544 "VBNET.ATG" +out type, false); + +#line 1545 "VBNET.ATG" + if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); + +#line 1546 "VBNET.ATG" + baseInterfaces.Add(new InterfaceImplementation(type, memberName)); + while (la.kind == 12) { + lexer.NextToken(); + NonArrayTypeName( +#line 1548 "VBNET.ATG" +out type, false); + +#line 1549 "VBNET.ATG" + if (type != null) memberName = TypeReference.StripLastIdentifierFromType(ref type); + +#line 1550 "VBNET.ATG" + baseInterfaces.Add(new InterfaceImplementation(type, memberName)); + } + } + + void HandlesClause( +#line 1495 "VBNET.ATG" +out List handlesClause) { + +#line 1497 "VBNET.ATG" + handlesClause = new List(); + string name; + + Expect(105); + EventMemberSpecifier( +#line 1500 "VBNET.ATG" +out name); + +#line 1500 "VBNET.ATG" + handlesClause.Add(name); + while (la.kind == 12) { + lexer.NextToken(); + EventMemberSpecifier( +#line 1501 "VBNET.ATG" +out name); + +#line 1501 "VBNET.ATG" + handlesClause.Add(name); + } + } + + void Block( +#line 2221 "VBNET.ATG" +out Statement stmt) { + +#line 2224 "VBNET.ATG" + BlockStatement blockStmt = new BlockStatement(); + /* in snippet parsing mode, t might be null */ + if (t != null) blockStmt.StartLocation = t.Location; + compilationUnit.BlockStart(blockStmt); + + while (StartOf(20) || +#line 2230 "VBNET.ATG" +IsEndStmtAhead()) { + if ( +#line 2230 "VBNET.ATG" +IsEndStmtAhead()) { + Expect(88); + EndOfStmt(); + +#line 2230 "VBNET.ATG" + compilationUnit.AddChild(new EndStatement()); + } else { + Statement(); + EndOfStmt(); + } + } + +#line 2235 "VBNET.ATG" + stmt = blockStmt; + if (t != null) blockStmt.EndLocation = t.EndLocation; + compilationUnit.BlockEnd(); + + } + + void Charset( +#line 1487 "VBNET.ATG" +out CharsetModifier charsetModifier) { + +#line 1488 "VBNET.ATG" + charsetModifier = CharsetModifier.None; + if (la.kind == 100 || la.kind == 167) { + } else if (la.kind == 47) { + lexer.NextToken(); + +#line 1489 "VBNET.ATG" + charsetModifier = CharsetModifier.Ansi; + } else if (la.kind == 50) { + lexer.NextToken(); + +#line 1490 "VBNET.ATG" + charsetModifier = CharsetModifier.Auto; + } else if (la.kind == 176) { + lexer.NextToken(); + +#line 1491 "VBNET.ATG" + charsetModifier = CharsetModifier.Unicode; + } else SynErr(231); + } + + void IdentifierForFieldDeclaration() { + switch (la.kind) { + case 2: { + lexer.NextToken(); + break; + } + case 169: { + lexer.NextToken(); + break; + } + case 51: { + lexer.NextToken(); + break; + } + case 70: { + lexer.NextToken(); + break; + } + case 49: { + lexer.NextToken(); + break; + } + case 47: { + lexer.NextToken(); + break; + } + case 50: { + lexer.NextToken(); + break; + } + case 144: { + lexer.NextToken(); + break; + } + case 176: { + lexer.NextToken(); + break; + } + case 177: { + lexer.NextToken(); + break; + } + case 134: { + lexer.NextToken(); + break; + } + case 95: { + lexer.NextToken(); + break; + } + default: SynErr(232); break; + } + } + + void VariableDeclaratorPartAfterIdentifier( +#line 1363 "VBNET.ATG" +List fieldDeclaration, string name) { + +#line 1365 "VBNET.ATG" + Expression expr = null; + TypeReference type = null; + ArrayList rank = null; + List dimension = null; + Location startLocation = t.Location; + + if ( +#line 1371 "VBNET.ATG" +IsSize() && !IsDims()) { + ArrayInitializationModifier( +#line 1371 "VBNET.ATG" +out dimension); + } + if ( +#line 1372 "VBNET.ATG" +IsDims()) { + ArrayNameModifier( +#line 1372 "VBNET.ATG" +out rank); + } + if ( +#line 1374 "VBNET.ATG" +IsObjectCreation()) { + Expect(48); + ObjectCreateExpression( +#line 1374 "VBNET.ATG" +out expr); + +#line 1376 "VBNET.ATG" + if (expr is ObjectCreateExpression) { + type = ((ObjectCreateExpression)expr).CreateType; + } else { + type = ((ArrayCreateExpression)expr).CreateType; + } + + } else if (StartOf(21)) { + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 1383 "VBNET.ATG" +out type); + +#line 1385 "VBNET.ATG" + if (type != null) { + for (int i = fieldDeclaration.Count - 1; i >= 0; i--) { + VariableDeclaration vd = fieldDeclaration[i]; + if (vd.TypeReference.Type.Length > 0) break; + TypeReference newType = type.Clone(); + newType.RankSpecifier = vd.TypeReference.RankSpecifier; + vd.TypeReference = newType; + } + } + + } + +#line 1397 "VBNET.ATG" + if (type == null && (dimension != null || rank != null)) { + type = new TypeReference(""); + } + if (dimension != null) { + if(type.RankSpecifier != null) { + Error("array rank only allowed one time"); + } else { + if (rank == null) { + type.RankSpecifier = new int[] { dimension.Count - 1 }; + } else { + rank.Insert(0, dimension.Count - 1); + type.RankSpecifier = (int[])rank.ToArray(typeof(int)); + } + expr = new ArrayCreateExpression(type, dimension); + } + } else if (rank != null) { + if(type.RankSpecifier != null) { + Error("array rank only allowed one time"); + } else { + type.RankSpecifier = (int[])rank.ToArray(typeof(int)); + } + } + + if (la.kind == 11) { + lexer.NextToken(); + VariableInitializer( +#line 1420 "VBNET.ATG" +out expr); + } + } else SynErr(233); + +#line 1423 "VBNET.ATG" + VariableDeclaration varDecl = new VariableDeclaration(name, expr, type); + varDecl.StartLocation = startLocation; + varDecl.EndLocation = t.Location; + fieldDeclaration.Add(varDecl); + + } + + void VariableDeclarator( +#line 1357 "VBNET.ATG" +List fieldDeclaration) { + Identifier(); + +#line 1359 "VBNET.ATG" + string name = t.val; + VariableDeclaratorPartAfterIdentifier( +#line 1360 "VBNET.ATG" +fieldDeclaration, name); + } + + void ConstantDeclarator( +#line 1338 "VBNET.ATG" +List constantDeclaration) { + +#line 1340 "VBNET.ATG" + Expression expr = null; + TypeReference type = null; + string name = String.Empty; + Location location; + + Identifier(); + +#line 1345 "VBNET.ATG" + name = t.val; location = t.Location; + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 1346 "VBNET.ATG" +out type); + } + Expect(11); + Expr( +#line 1347 "VBNET.ATG" +out expr); + +#line 1349 "VBNET.ATG" + VariableDeclaration f = new VariableDeclaration(name, expr); + f.TypeReference = type; + f.StartLocation = location; + constantDeclaration.Add(f); + + } + + void AccessorDecls( +#line 1272 "VBNET.ATG" +out PropertyGetRegion getBlock, out PropertySetRegion setBlock) { + +#line 1274 "VBNET.ATG" + List attributes = new List(); + AttributeSection section; + getBlock = null; + setBlock = null; + + while (la.kind == 27) { + AttributeSection( +#line 1279 "VBNET.ATG" +out section); + +#line 1279 "VBNET.ATG" + attributes.Add(section); + } + if (StartOf(22)) { + GetAccessorDecl( +#line 1281 "VBNET.ATG" +out getBlock, attributes); + if (StartOf(23)) { + +#line 1283 "VBNET.ATG" + attributes = new List(); + while (la.kind == 27) { + AttributeSection( +#line 1284 "VBNET.ATG" +out section); + +#line 1284 "VBNET.ATG" + attributes.Add(section); + } + SetAccessorDecl( +#line 1285 "VBNET.ATG" +out setBlock, attributes); + } + } else if (StartOf(24)) { + SetAccessorDecl( +#line 1288 "VBNET.ATG" +out setBlock, attributes); + if (StartOf(25)) { + +#line 1290 "VBNET.ATG" + attributes = new List(); + while (la.kind == 27) { + AttributeSection( +#line 1291 "VBNET.ATG" +out section); + +#line 1291 "VBNET.ATG" + attributes.Add(section); + } + GetAccessorDecl( +#line 1292 "VBNET.ATG" +out getBlock, attributes); + } + } else SynErr(234); + } + + void EventAccessorDeclaration( +#line 1235 "VBNET.ATG" +out EventAddRemoveRegion eventAccessorDeclaration) { + +#line 1237 "VBNET.ATG" + Statement stmt = null; + List p = new List(); + AttributeSection section; + List attributes = new List(); + eventAccessorDeclaration = null; + + while (la.kind == 27) { + AttributeSection( +#line 1243 "VBNET.ATG" +out section); + +#line 1243 "VBNET.ATG" + attributes.Add(section); + } + if (la.kind == 42) { + lexer.NextToken(); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 1245 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + Block( +#line 1246 "VBNET.ATG" +out stmt); + Expect(88); + Expect(42); + Expect(1); + +#line 1248 "VBNET.ATG" + eventAccessorDeclaration = new EventAddRegion(attributes); + eventAccessorDeclaration.Block = (BlockStatement)stmt; + eventAccessorDeclaration.Parameters = p; + + } else if (la.kind == 152) { + lexer.NextToken(); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 1253 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + Block( +#line 1254 "VBNET.ATG" +out stmt); + Expect(88); + Expect(152); + Expect(1); + +#line 1256 "VBNET.ATG" + eventAccessorDeclaration = new EventRemoveRegion(attributes); + eventAccessorDeclaration.Block = (BlockStatement)stmt; + eventAccessorDeclaration.Parameters = p; + + } else if (la.kind == 149) { + lexer.NextToken(); + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 1261 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + Block( +#line 1262 "VBNET.ATG" +out stmt); + Expect(88); + Expect(149); + Expect(1); + +#line 1264 "VBNET.ATG" + eventAccessorDeclaration = new EventRaiseRegion(attributes); + eventAccessorDeclaration.Block = (BlockStatement)stmt; + eventAccessorDeclaration.Parameters = p; + + } else SynErr(235); + } + + void OverloadableOperator( +#line 1177 "VBNET.ATG" +out OverloadableOperatorType operatorType) { + +#line 1178 "VBNET.ATG" + operatorType = OverloadableOperatorType.None; + switch (la.kind) { + case 14: { + lexer.NextToken(); + +#line 1180 "VBNET.ATG" + operatorType = OverloadableOperatorType.Add; + break; + } + case 15: { + lexer.NextToken(); + +#line 1182 "VBNET.ATG" + operatorType = OverloadableOperatorType.Subtract; + break; + } + case 16: { + lexer.NextToken(); + +#line 1184 "VBNET.ATG" + operatorType = OverloadableOperatorType.Multiply; + break; + } + case 17: { + lexer.NextToken(); + +#line 1186 "VBNET.ATG" + operatorType = OverloadableOperatorType.Divide; + break; + } + case 18: { + lexer.NextToken(); + +#line 1188 "VBNET.ATG" + operatorType = OverloadableOperatorType.DivideInteger; + break; + } + case 19: { + lexer.NextToken(); + +#line 1190 "VBNET.ATG" + operatorType = OverloadableOperatorType.Concat; + break; + } + case 116: { + lexer.NextToken(); + +#line 1192 "VBNET.ATG" + operatorType = OverloadableOperatorType.Like; + break; + } + case 120: { + lexer.NextToken(); + +#line 1194 "VBNET.ATG" + operatorType = OverloadableOperatorType.Modulus; + break; + } + case 45: { + lexer.NextToken(); + +#line 1196 "VBNET.ATG" + operatorType = OverloadableOperatorType.BitwiseAnd; + break; + } + case 138: { + lexer.NextToken(); + +#line 1198 "VBNET.ATG" + operatorType = OverloadableOperatorType.BitwiseOr; + break; + } + case 185: { + lexer.NextToken(); + +#line 1200 "VBNET.ATG" + operatorType = OverloadableOperatorType.ExclusiveOr; + break; + } + case 20: { + lexer.NextToken(); + +#line 1202 "VBNET.ATG" + operatorType = OverloadableOperatorType.Power; + break; + } + case 31: { + lexer.NextToken(); + +#line 1204 "VBNET.ATG" + operatorType = OverloadableOperatorType.ShiftLeft; + break; + } + case 32: { + lexer.NextToken(); + +#line 1206 "VBNET.ATG" + operatorType = OverloadableOperatorType.ShiftRight; + break; + } + case 11: { + lexer.NextToken(); + +#line 1208 "VBNET.ATG" + operatorType = OverloadableOperatorType.Equality; + break; + } + case 28: { + lexer.NextToken(); + +#line 1210 "VBNET.ATG" + operatorType = OverloadableOperatorType.InEquality; + break; + } + case 27: { + lexer.NextToken(); + +#line 1212 "VBNET.ATG" + operatorType = OverloadableOperatorType.LessThan; + break; + } + case 30: { + lexer.NextToken(); + +#line 1214 "VBNET.ATG" + operatorType = OverloadableOperatorType.LessThanOrEqual; + break; + } + case 26: { + lexer.NextToken(); + +#line 1216 "VBNET.ATG" + operatorType = OverloadableOperatorType.GreaterThan; + break; + } + case 29: { + lexer.NextToken(); + +#line 1218 "VBNET.ATG" + operatorType = OverloadableOperatorType.GreaterThanOrEqual; + break; + } + case 75: { + lexer.NextToken(); + +#line 1220 "VBNET.ATG" + operatorType = OverloadableOperatorType.CType; + break; + } + case 2: case 47: case 49: case 50: case 51: case 70: case 95: case 134: case 144: case 169: case 176: case 177: case 205: { + Identifier(); + +#line 1224 "VBNET.ATG" + string opName = t.val; + if (string.Equals(opName, "istrue", StringComparison.InvariantCultureIgnoreCase)) { + operatorType = OverloadableOperatorType.IsTrue; + } else if (string.Equals(opName, "isfalse", StringComparison.InvariantCultureIgnoreCase)) { + operatorType = OverloadableOperatorType.IsFalse; + } else { + Error("Invalid operator. Possible operators are '+', '-', 'Not', 'IsTrue', 'IsFalse'."); + } + + break; + } + default: SynErr(236); break; + } + } + + void GetAccessorDecl( +#line 1298 "VBNET.ATG" +out PropertyGetRegion getBlock, List attributes) { + +#line 1299 "VBNET.ATG" + Statement stmt = null; Modifiers m; + PropertyAccessorAccessModifier( +#line 1301 "VBNET.ATG" +out m); + Expect(101); + +#line 1303 "VBNET.ATG" + Location startLocation = t.Location; + Expect(1); + Block( +#line 1305 "VBNET.ATG" +out stmt); + +#line 1306 "VBNET.ATG" + getBlock = new PropertyGetRegion((BlockStatement)stmt, attributes); + Expect(88); + Expect(101); + +#line 1308 "VBNET.ATG" + getBlock.Modifier = m; + +#line 1309 "VBNET.ATG" + getBlock.StartLocation = startLocation; getBlock.EndLocation = t.EndLocation; + Expect(1); + } + + void SetAccessorDecl( +#line 1314 "VBNET.ATG" +out PropertySetRegion setBlock, List attributes) { + +#line 1316 "VBNET.ATG" + Statement stmt = null; + List p = new List(); + Modifiers m; + + PropertyAccessorAccessModifier( +#line 1321 "VBNET.ATG" +out m); + Expect(156); + +#line 1323 "VBNET.ATG" + Location startLocation = t.Location; + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(4)) { + FormalParameterList( +#line 1324 "VBNET.ATG" +p); + } + Expect(25); + } + Expect(1); + Block( +#line 1326 "VBNET.ATG" +out stmt); + +#line 1328 "VBNET.ATG" + setBlock = new PropertySetRegion((BlockStatement)stmt, attributes); + setBlock.Modifier = m; + setBlock.Parameters = p; + + Expect(88); + Expect(156); + +#line 1333 "VBNET.ATG" + setBlock.StartLocation = startLocation; setBlock.EndLocation = t.EndLocation; + Expect(1); + } + + void PropertyAccessorAccessModifier( +#line 2907 "VBNET.ATG" +out Modifiers m) { + +#line 2908 "VBNET.ATG" + m = Modifiers.None; + while (StartOf(26)) { + if (la.kind == 148) { + lexer.NextToken(); + +#line 2910 "VBNET.ATG" + m |= Modifiers.Public; + } else if (la.kind == 147) { + lexer.NextToken(); + +#line 2911 "VBNET.ATG" + m |= Modifiers.Protected; + } else if (la.kind == 99) { + lexer.NextToken(); + +#line 2912 "VBNET.ATG" + m |= Modifiers.Internal; + } else { + lexer.NextToken(); + +#line 2913 "VBNET.ATG" + m |= Modifiers.Private; + } + } + } + + void ArrayInitializationModifier( +#line 1431 "VBNET.ATG" +out List arrayModifiers) { + +#line 1433 "VBNET.ATG" + arrayModifiers = null; + + Expect(24); + InitializationRankList( +#line 1435 "VBNET.ATG" +out arrayModifiers); + Expect(25); + } + + void ArrayNameModifier( +#line 2007 "VBNET.ATG" +out ArrayList arrayModifiers) { + +#line 2009 "VBNET.ATG" + arrayModifiers = null; + + ArrayTypeModifiers( +#line 2011 "VBNET.ATG" +out arrayModifiers); + } + + void ObjectCreateExpression( +#line 1860 "VBNET.ATG" +out Expression oce) { + +#line 1862 "VBNET.ATG" + TypeReference type = null; + Expression initializer = null; + List arguments = null; + ArrayList dimensions = null; + oce = null; + bool canBeNormal; bool canBeReDim; + + Expect(127); + NonArrayTypeName( +#line 1869 "VBNET.ATG" +out type, false); + if (la.kind == 24) { + lexer.NextToken(); + NormalOrReDimArgumentList( +#line 1870 "VBNET.ATG" +out arguments, out canBeNormal, out canBeReDim); + Expect(25); + if (la.kind == 22 || +#line 1871 "VBNET.ATG" +la.kind == Tokens.OpenParenthesis) { + if ( +#line 1871 "VBNET.ATG" +la.kind == Tokens.OpenParenthesis) { + ArrayTypeModifiers( +#line 1872 "VBNET.ATG" +out dimensions); + CollectionInitializer( +#line 1873 "VBNET.ATG" +out initializer); + } else { + CollectionInitializer( +#line 1874 "VBNET.ATG" +out initializer); + } + } + +#line 1876 "VBNET.ATG" + if (canBeReDim && !canBeNormal && initializer == null) initializer = new CollectionInitializerExpression(); + } + +#line 1879 "VBNET.ATG" + if (type == null) type = new TypeReference("Object"); // fallback type on parser errors + if (initializer == null) { + oce = new ObjectCreateExpression(type, arguments); + } else { + if (dimensions == null) dimensions = new ArrayList(); + dimensions.Insert(0, (arguments == null) ? 0 : Math.Max(arguments.Count - 1, 0)); + type.RankSpecifier = (int[])dimensions.ToArray(typeof(int)); + ArrayCreateExpression ace = new ArrayCreateExpression(type, initializer as CollectionInitializerExpression); + ace.Arguments = arguments; + oce = ace; + } + + } + + void VariableInitializer( +#line 1459 "VBNET.ATG" +out Expression initializerExpression) { + +#line 1461 "VBNET.ATG" + initializerExpression = null; + + if (StartOf(27)) { + Expr( +#line 1463 "VBNET.ATG" +out initializerExpression); + } else if (la.kind == 22) { + CollectionInitializer( +#line 1464 "VBNET.ATG" +out initializerExpression); + } else SynErr(237); + } + + void InitializationRankList( +#line 1439 "VBNET.ATG" +out List rank) { + +#line 1441 "VBNET.ATG" + rank = new List(); + Expression expr = null; + + Expr( +#line 1444 "VBNET.ATG" +out expr); + if (la.kind == 172) { + lexer.NextToken(); + +#line 1445 "VBNET.ATG" + EnsureIsZero(expr); + Expr( +#line 1446 "VBNET.ATG" +out expr); + } + +#line 1448 "VBNET.ATG" + if (expr != null) { rank.Add(expr); } + while (la.kind == 12) { + lexer.NextToken(); + Expr( +#line 1450 "VBNET.ATG" +out expr); + if (la.kind == 172) { + lexer.NextToken(); + +#line 1451 "VBNET.ATG" + EnsureIsZero(expr); + Expr( +#line 1452 "VBNET.ATG" +out expr); + } + +#line 1454 "VBNET.ATG" + if (expr != null) { rank.Add(expr); } + } + } + + void CollectionInitializer( +#line 1468 "VBNET.ATG" +out Expression outExpr) { + +#line 1470 "VBNET.ATG" + Expression expr = null; + CollectionInitializerExpression initializer = new CollectionInitializerExpression(); + + Expect(22); + if (StartOf(28)) { + VariableInitializer( +#line 1475 "VBNET.ATG" +out expr); + +#line 1477 "VBNET.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + + while ( +#line 1480 "VBNET.ATG" +NotFinalComma()) { + Expect(12); + VariableInitializer( +#line 1480 "VBNET.ATG" +out expr); + +#line 1481 "VBNET.ATG" + if (expr != null) { initializer.CreateExpressions.Add(expr); } + } + } + Expect(23); + +#line 1484 "VBNET.ATG" + outExpr = initializer; + } + + void EventMemberSpecifier( +#line 1554 "VBNET.ATG" +out string name) { + +#line 1555 "VBNET.ATG" + string eventName; + if (StartOf(13)) { + Identifier(); + } else if (la.kind == 124) { + lexer.NextToken(); + } else if (la.kind == 119) { + lexer.NextToken(); + } else SynErr(238); + +#line 1558 "VBNET.ATG" + name = t.val; + Expect(10); + IdentifierOrKeyword( +#line 1560 "VBNET.ATG" +out eventName); + +#line 1561 "VBNET.ATG" + name = name + "." + eventName; + } + + void IdentifierOrKeyword( +#line 2841 "VBNET.ATG" +out string name) { + +#line 2843 "VBNET.ATG" + lexer.NextToken(); name = t.val; + } + + void DisjunctionExpr( +#line 1704 "VBNET.ATG" +out Expression outExpr) { + +#line 1706 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + ConjunctionExpr( +#line 1709 "VBNET.ATG" +out outExpr); + while (la.kind == 138 || la.kind == 139 || la.kind == 185) { + if (la.kind == 138) { + lexer.NextToken(); + +#line 1712 "VBNET.ATG" + op = BinaryOperatorType.BitwiseOr; + } else if (la.kind == 139) { + lexer.NextToken(); + +#line 1713 "VBNET.ATG" + op = BinaryOperatorType.LogicalOr; + } else { + lexer.NextToken(); + +#line 1714 "VBNET.ATG" + op = BinaryOperatorType.ExclusiveOr; + } + ConjunctionExpr( +#line 1716 "VBNET.ATG" +out expr); + +#line 1716 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void AssignmentOperator( +#line 1569 "VBNET.ATG" +out AssignmentOperatorType op) { + +#line 1570 "VBNET.ATG" + op = AssignmentOperatorType.None; + switch (la.kind) { + case 11: { + lexer.NextToken(); + +#line 1571 "VBNET.ATG" + op = AssignmentOperatorType.Assign; + break; + } + case 41: { + lexer.NextToken(); + +#line 1572 "VBNET.ATG" + op = AssignmentOperatorType.ConcatString; + break; + } + case 33: { + lexer.NextToken(); + +#line 1573 "VBNET.ATG" + op = AssignmentOperatorType.Add; + break; + } + case 35: { + lexer.NextToken(); + +#line 1574 "VBNET.ATG" + op = AssignmentOperatorType.Subtract; + break; + } + case 36: { + lexer.NextToken(); + +#line 1575 "VBNET.ATG" + op = AssignmentOperatorType.Multiply; + break; + } + case 37: { + lexer.NextToken(); + +#line 1576 "VBNET.ATG" + op = AssignmentOperatorType.Divide; + break; + } + case 38: { + lexer.NextToken(); + +#line 1577 "VBNET.ATG" + op = AssignmentOperatorType.DivideInteger; + break; + } + case 34: { + lexer.NextToken(); + +#line 1578 "VBNET.ATG" + op = AssignmentOperatorType.Power; + break; + } + case 39: { + lexer.NextToken(); + +#line 1579 "VBNET.ATG" + op = AssignmentOperatorType.ShiftLeft; + break; + } + case 40: { + lexer.NextToken(); + +#line 1580 "VBNET.ATG" + op = AssignmentOperatorType.ShiftRight; + break; + } + default: SynErr(239); break; + } + } + + void SimpleExpr( +#line 1584 "VBNET.ATG" +out Expression pexpr) { + SimpleNonInvocationExpression( +#line 1586 "VBNET.ATG" +out pexpr); + while (la.kind == 10 || la.kind == 24) { + if (la.kind == 10) { + +#line 1587 "VBNET.ATG" + string name; + lexer.NextToken(); + IdentifierOrKeyword( +#line 1588 "VBNET.ATG" +out name); + +#line 1588 "VBNET.ATG" + pexpr = new MemberReferenceExpression(pexpr, name); + } else { + InvocationExpression( +#line 1589 "VBNET.ATG" +ref pexpr); + } + } + } + + void SimpleNonInvocationExpression( +#line 1593 "VBNET.ATG" +out Expression pexpr) { + +#line 1595 "VBNET.ATG" + Expression expr; + TypeReference type = null; + string name = String.Empty; + pexpr = null; + + if (StartOf(29)) { + switch (la.kind) { + case 3: { + lexer.NextToken(); + +#line 1603 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 4: { + lexer.NextToken(); + +#line 1604 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 7: { + lexer.NextToken(); + +#line 1605 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 6: { + lexer.NextToken(); + +#line 1606 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 5: { + lexer.NextToken(); + +#line 1607 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 9: { + lexer.NextToken(); + +#line 1608 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 8: { + lexer.NextToken(); + +#line 1609 "VBNET.ATG" + pexpr = new PrimitiveExpression(t.literalValue, t.val); + break; + } + case 173: { + lexer.NextToken(); + +#line 1611 "VBNET.ATG" + pexpr = new PrimitiveExpression(true, "true"); + break; + } + case 96: { + lexer.NextToken(); + +#line 1612 "VBNET.ATG" + pexpr = new PrimitiveExpression(false, "false"); + break; + } + case 130: { + lexer.NextToken(); + +#line 1613 "VBNET.ATG" + pexpr = new PrimitiveExpression(null, "null"); + break; + } + case 24: { + lexer.NextToken(); + Expr( +#line 1614 "VBNET.ATG" +out expr); + Expect(25); + +#line 1614 "VBNET.ATG" + pexpr = new ParenthesizedExpression(expr); + break; + } + case 2: case 47: case 49: case 50: case 51: case 70: case 95: case 134: case 144: case 169: case 176: case 177: case 205: { + Identifier(); + +#line 1616 "VBNET.ATG" + pexpr = new IdentifierExpression(t.val); + +#line 1617 "VBNET.ATG" + pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation; + break; + } + case 52: case 54: case 65: case 76: case 77: case 84: case 111: case 117: case 133: case 159: case 160: case 165: case 191: case 192: case 193: case 194: { + +#line 1618 "VBNET.ATG" + string val = String.Empty; + if (StartOf(10)) { + PrimitiveTypeName( +#line 1619 "VBNET.ATG" +out val); + } else if (la.kind == 133) { + lexer.NextToken(); + +#line 1619 "VBNET.ATG" + val = "Object"; + } else SynErr(240); + Expect(10); + +#line 1620 "VBNET.ATG" + t.val = ""; + Identifier(); + +#line 1620 "VBNET.ATG" + pexpr = new MemberReferenceExpression(new TypeReferenceExpression(val), t.val); + break; + } + case 119: { + lexer.NextToken(); + +#line 1621 "VBNET.ATG" + pexpr = new ThisReferenceExpression(); + break; + } + case 124: case 125: { + +#line 1622 "VBNET.ATG" + Expression retExpr = null; + if (la.kind == 124) { + lexer.NextToken(); + +#line 1623 "VBNET.ATG" + retExpr = new BaseReferenceExpression(); + } else if (la.kind == 125) { + lexer.NextToken(); + +#line 1624 "VBNET.ATG" + retExpr = new ClassReferenceExpression(); + } else SynErr(241); + Expect(10); + IdentifierOrKeyword( +#line 1626 "VBNET.ATG" +out name); + +#line 1626 "VBNET.ATG" + pexpr = new MemberReferenceExpression(retExpr, name); + break; + } + case 199: { + lexer.NextToken(); + Expect(10); + Identifier(); + +#line 1628 "VBNET.ATG" + type = new TypeReference(t.val ?? ""); + +#line 1630 "VBNET.ATG" + type.IsGlobal = true; + +#line 1631 "VBNET.ATG" + pexpr = new TypeReferenceExpression(type); + break; + } + case 127: { + ObjectCreateExpression( +#line 1632 "VBNET.ATG" +out expr); + +#line 1632 "VBNET.ATG" + pexpr = expr; + break; + } + case 75: case 82: case 200: { + +#line 1634 "VBNET.ATG" + CastType castType = CastType.Cast; + if (la.kind == 82) { + lexer.NextToken(); + } else if (la.kind == 75) { + lexer.NextToken(); + +#line 1636 "VBNET.ATG" + castType = CastType.Conversion; + } else if (la.kind == 200) { + lexer.NextToken(); + +#line 1637 "VBNET.ATG" + castType = CastType.TryCast; + } else SynErr(242); + Expect(24); + Expr( +#line 1639 "VBNET.ATG" +out expr); + Expect(12); + TypeName( +#line 1639 "VBNET.ATG" +out type); + Expect(25); + +#line 1640 "VBNET.ATG" + pexpr = new CastExpression(type, expr, castType); + break; + } + case 59: case 60: case 61: case 62: case 63: case 64: case 66: case 68: case 69: case 72: case 73: case 74: case 195: case 196: case 197: case 198: { + CastTarget( +#line 1641 "VBNET.ATG" +out type); + Expect(24); + Expr( +#line 1641 "VBNET.ATG" +out expr); + Expect(25); + +#line 1641 "VBNET.ATG" + pexpr = new CastExpression(type, expr, CastType.PrimitiveConversion); + break; + } + case 43: { + lexer.NextToken(); + Expr( +#line 1642 "VBNET.ATG" +out expr); + +#line 1642 "VBNET.ATG" + pexpr = new AddressOfExpression(expr); + break; + } + case 102: { + lexer.NextToken(); + Expect(24); + GetTypeTypeName( +#line 1643 "VBNET.ATG" +out type); + Expect(25); + +#line 1643 "VBNET.ATG" + pexpr = new TypeOfExpression(type); + break; + } + case 175: { + lexer.NextToken(); + SimpleExpr( +#line 1644 "VBNET.ATG" +out expr); + Expect(113); + TypeName( +#line 1644 "VBNET.ATG" +out type); + +#line 1644 "VBNET.ATG" + pexpr = new TypeOfIsExpression(expr, type); + break; + } + } + } else if (la.kind == 10) { + lexer.NextToken(); + IdentifierOrKeyword( +#line 1648 "VBNET.ATG" +out name); + +#line 1648 "VBNET.ATG" + pexpr = new MemberReferenceExpression(null, name); + } else SynErr(243); + } + + void InvocationExpression( +#line 1652 "VBNET.ATG" +ref Expression pexpr) { + +#line 1653 "VBNET.ATG" + List typeParameters = new List(); + List parameters = null; + TypeReference type; + Expect(24); + +#line 1657 "VBNET.ATG" + Location start = t.Location; + if (la.kind == 201) { + lexer.NextToken(); + TypeName( +#line 1659 "VBNET.ATG" +out type); + +#line 1659 "VBNET.ATG" + if (type != null) typeParameters.Add(type); + while (la.kind == 12) { + lexer.NextToken(); + TypeName( +#line 1662 "VBNET.ATG" +out type); + +#line 1662 "VBNET.ATG" + if (type != null) typeParameters.Add(type); + } + Expect(25); + if (la.kind == 10) { + lexer.NextToken(); + Identifier(); + +#line 1667 "VBNET.ATG" + pexpr = new MemberReferenceExpression(GetTypeReferenceExpression(pexpr, typeParameters), t.val); + } else if (la.kind == 24) { + lexer.NextToken(); + ArgumentList( +#line 1669 "VBNET.ATG" +out parameters); + Expect(25); + +#line 1671 "VBNET.ATG" + pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); + } else SynErr(244); + } else if (StartOf(30)) { + ArgumentList( +#line 1673 "VBNET.ATG" +out parameters); + Expect(25); + +#line 1675 "VBNET.ATG" + pexpr = CreateInvocationExpression(pexpr, parameters, typeParameters); + } else SynErr(245); + +#line 1677 "VBNET.ATG" + pexpr.StartLocation = start; pexpr.EndLocation = t.Location; + } + + void PrimitiveTypeName( +#line 2848 "VBNET.ATG" +out string type) { + +#line 2849 "VBNET.ATG" + type = String.Empty; + switch (la.kind) { + case 52: { + lexer.NextToken(); + +#line 2850 "VBNET.ATG" + type = "Boolean"; + break; + } + case 76: { + lexer.NextToken(); + +#line 2851 "VBNET.ATG" + type = "Date"; + break; + } + case 65: { + lexer.NextToken(); + +#line 2852 "VBNET.ATG" + type = "Char"; + break; + } + case 165: { + lexer.NextToken(); + +#line 2853 "VBNET.ATG" + type = "String"; + break; + } + case 77: { + lexer.NextToken(); + +#line 2854 "VBNET.ATG" + type = "Decimal"; + break; + } + case 54: { + lexer.NextToken(); + +#line 2855 "VBNET.ATG" + type = "Byte"; + break; + } + case 159: { + lexer.NextToken(); + +#line 2856 "VBNET.ATG" + type = "Short"; + break; + } + case 111: { + lexer.NextToken(); + +#line 2857 "VBNET.ATG" + type = "Integer"; + break; + } + case 117: { + lexer.NextToken(); + +#line 2858 "VBNET.ATG" + type = "Long"; + break; + } + case 160: { + lexer.NextToken(); + +#line 2859 "VBNET.ATG" + type = "Single"; + break; + } + case 84: { + lexer.NextToken(); + +#line 2860 "VBNET.ATG" + type = "Double"; + break; + } + case 192: { + lexer.NextToken(); + +#line 2861 "VBNET.ATG" + type = "UInteger"; + break; + } + case 193: { + lexer.NextToken(); + +#line 2862 "VBNET.ATG" + type = "ULong"; + break; + } + case 194: { + lexer.NextToken(); + +#line 2863 "VBNET.ATG" + type = "UShort"; + break; + } + case 191: { + lexer.NextToken(); + +#line 2864 "VBNET.ATG" + type = "SByte"; + break; + } + default: SynErr(246); break; + } + } + + void CastTarget( +#line 1682 "VBNET.ATG" +out TypeReference type) { + +#line 1684 "VBNET.ATG" + type = null; + + switch (la.kind) { + case 59: { + lexer.NextToken(); + +#line 1686 "VBNET.ATG" + type = new TypeReference("System.Boolean"); + break; + } + case 60: { + lexer.NextToken(); + +#line 1687 "VBNET.ATG" + type = new TypeReference("System.Byte"); + break; + } + case 195: { + lexer.NextToken(); + +#line 1688 "VBNET.ATG" + type = new TypeReference("System.SByte"); + break; + } + case 61: { + lexer.NextToken(); + +#line 1689 "VBNET.ATG" + type = new TypeReference("System.Char"); + break; + } + case 62: { + lexer.NextToken(); + +#line 1690 "VBNET.ATG" + type = new TypeReference("System.DateTime"); + break; + } + case 64: { + lexer.NextToken(); + +#line 1691 "VBNET.ATG" + type = new TypeReference("System.Decimal"); + break; + } + case 63: { + lexer.NextToken(); + +#line 1692 "VBNET.ATG" + type = new TypeReference("System.Double"); + break; + } + case 72: { + lexer.NextToken(); + +#line 1693 "VBNET.ATG" + type = new TypeReference("System.Int16"); + break; + } + case 66: { + lexer.NextToken(); + +#line 1694 "VBNET.ATG" + type = new TypeReference("System.Int32"); + break; + } + case 68: { + lexer.NextToken(); + +#line 1695 "VBNET.ATG" + type = new TypeReference("System.Int64"); + break; + } + case 196: { + lexer.NextToken(); + +#line 1696 "VBNET.ATG" + type = new TypeReference("System.UInt16"); + break; + } + case 197: { + lexer.NextToken(); + +#line 1697 "VBNET.ATG" + type = new TypeReference("System.UInt32"); + break; + } + case 198: { + lexer.NextToken(); + +#line 1698 "VBNET.ATG" + type = new TypeReference("System.UInt64"); + break; + } + case 69: { + lexer.NextToken(); + +#line 1699 "VBNET.ATG" + type = new TypeReference("System.Object"); + break; + } + case 73: { + lexer.NextToken(); + +#line 1700 "VBNET.ATG" + type = new TypeReference("System.Single"); + break; + } + case 74: { + lexer.NextToken(); + +#line 1701 "VBNET.ATG" + type = new TypeReference("System.String"); + break; + } + default: SynErr(247); break; + } + } + + void GetTypeTypeName( +#line 1959 "VBNET.ATG" +out TypeReference typeref) { + +#line 1960 "VBNET.ATG" + ArrayList rank = null; + NonArrayTypeName( +#line 1962 "VBNET.ATG" +out typeref, true); + ArrayTypeModifiers( +#line 1963 "VBNET.ATG" +out rank); + +#line 1964 "VBNET.ATG" + if (rank != null && typeref != null) { + typeref.RankSpecifier = (int[])rank.ToArray(typeof(int)); + } + + } + + void ArgumentList( +#line 1894 "VBNET.ATG" +out List arguments) { + +#line 1896 "VBNET.ATG" + arguments = new List(); + Expression expr = null; + + if (StartOf(27)) { + Argument( +#line 1899 "VBNET.ATG" +out expr); + } + while (la.kind == 12) { + lexer.NextToken(); + +#line 1900 "VBNET.ATG" + arguments.Add(expr ?? Expression.Null); expr = null; + if (StartOf(27)) { + Argument( +#line 1901 "VBNET.ATG" +out expr); + } + +#line 1902 "VBNET.ATG" + if (expr == null) expr = Expression.Null; + } + +#line 1904 "VBNET.ATG" + if (expr != null) arguments.Add(expr); + } + + void ConjunctionExpr( +#line 1720 "VBNET.ATG" +out Expression outExpr) { + +#line 1722 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + NotExpr( +#line 1725 "VBNET.ATG" +out outExpr); + while (la.kind == 45 || la.kind == 46) { + if (la.kind == 45) { + lexer.NextToken(); + +#line 1728 "VBNET.ATG" + op = BinaryOperatorType.BitwiseAnd; + } else { + lexer.NextToken(); + +#line 1729 "VBNET.ATG" + op = BinaryOperatorType.LogicalAnd; + } + NotExpr( +#line 1731 "VBNET.ATG" +out expr); + +#line 1731 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void NotExpr( +#line 1735 "VBNET.ATG" +out Expression outExpr) { + +#line 1736 "VBNET.ATG" + UnaryOperatorType uop = UnaryOperatorType.None; + while (la.kind == 129) { + lexer.NextToken(); + +#line 1737 "VBNET.ATG" + uop = UnaryOperatorType.Not; + } + ComparisonExpr( +#line 1738 "VBNET.ATG" +out outExpr); + +#line 1739 "VBNET.ATG" + if (uop != UnaryOperatorType.None) + outExpr = new UnaryOperatorExpression(outExpr, uop); + + } + + void ComparisonExpr( +#line 1744 "VBNET.ATG" +out Expression outExpr) { + +#line 1746 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + ShiftExpr( +#line 1749 "VBNET.ATG" +out outExpr); + while (StartOf(31)) { + switch (la.kind) { + case 27: { + lexer.NextToken(); + +#line 1752 "VBNET.ATG" + op = BinaryOperatorType.LessThan; + break; + } + case 26: { + lexer.NextToken(); + +#line 1753 "VBNET.ATG" + op = BinaryOperatorType.GreaterThan; + break; + } + case 30: { + lexer.NextToken(); + +#line 1754 "VBNET.ATG" + op = BinaryOperatorType.LessThanOrEqual; + break; + } + case 29: { + lexer.NextToken(); + +#line 1755 "VBNET.ATG" + op = BinaryOperatorType.GreaterThanOrEqual; + break; + } + case 28: { + lexer.NextToken(); + +#line 1756 "VBNET.ATG" + op = BinaryOperatorType.InEquality; + break; + } + case 11: { + lexer.NextToken(); + +#line 1757 "VBNET.ATG" + op = BinaryOperatorType.Equality; + break; + } + case 116: { + lexer.NextToken(); + +#line 1758 "VBNET.ATG" + op = BinaryOperatorType.Like; + break; + } + case 113: { + lexer.NextToken(); + +#line 1759 "VBNET.ATG" + op = BinaryOperatorType.ReferenceEquality; + break; + } + case 190: { + lexer.NextToken(); + +#line 1760 "VBNET.ATG" + op = BinaryOperatorType.ReferenceInequality; + break; + } + } + if (StartOf(32)) { + ShiftExpr( +#line 1763 "VBNET.ATG" +out expr); + +#line 1763 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } else if (la.kind == 129) { + lexer.NextToken(); + ShiftExpr( +#line 1766 "VBNET.ATG" +out expr); + +#line 1766 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, new UnaryOperatorExpression(expr, UnaryOperatorType.Not)); + } else SynErr(248); + } + } + + void ShiftExpr( +#line 1771 "VBNET.ATG" +out Expression outExpr) { + +#line 1773 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + ConcatenationExpr( +#line 1776 "VBNET.ATG" +out outExpr); + while (la.kind == 31 || la.kind == 32) { + if (la.kind == 31) { + lexer.NextToken(); + +#line 1779 "VBNET.ATG" + op = BinaryOperatorType.ShiftLeft; + } else { + lexer.NextToken(); + +#line 1780 "VBNET.ATG" + op = BinaryOperatorType.ShiftRight; + } + ConcatenationExpr( +#line 1782 "VBNET.ATG" +out expr); + +#line 1782 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void ConcatenationExpr( +#line 1786 "VBNET.ATG" +out Expression outExpr) { + +#line 1787 "VBNET.ATG" + Expression expr; + AdditiveExpr( +#line 1789 "VBNET.ATG" +out outExpr); + while (la.kind == 19) { + lexer.NextToken(); + AdditiveExpr( +#line 1789 "VBNET.ATG" +out expr); + +#line 1789 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Concat, expr); + } + } + + void AdditiveExpr( +#line 1792 "VBNET.ATG" +out Expression outExpr) { + +#line 1794 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + ModuloExpr( +#line 1797 "VBNET.ATG" +out outExpr); + while (la.kind == 14 || la.kind == 15) { + if (la.kind == 14) { + lexer.NextToken(); + +#line 1800 "VBNET.ATG" + op = BinaryOperatorType.Add; + } else { + lexer.NextToken(); + +#line 1801 "VBNET.ATG" + op = BinaryOperatorType.Subtract; + } + ModuloExpr( +#line 1803 "VBNET.ATG" +out expr); + +#line 1803 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void ModuloExpr( +#line 1807 "VBNET.ATG" +out Expression outExpr) { + +#line 1808 "VBNET.ATG" + Expression expr; + IntegerDivisionExpr( +#line 1810 "VBNET.ATG" +out outExpr); + while (la.kind == 120) { + lexer.NextToken(); + IntegerDivisionExpr( +#line 1810 "VBNET.ATG" +out expr); + +#line 1810 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Modulus, expr); + } + } + + void IntegerDivisionExpr( +#line 1813 "VBNET.ATG" +out Expression outExpr) { + +#line 1814 "VBNET.ATG" + Expression expr; + MultiplicativeExpr( +#line 1816 "VBNET.ATG" +out outExpr); + while (la.kind == 18) { + lexer.NextToken(); + MultiplicativeExpr( +#line 1816 "VBNET.ATG" +out expr); + +#line 1816 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.DivideInteger, expr); + } + } + + void MultiplicativeExpr( +#line 1819 "VBNET.ATG" +out Expression outExpr) { + +#line 1821 "VBNET.ATG" + Expression expr; + BinaryOperatorType op = BinaryOperatorType.None; + + UnaryExpr( +#line 1824 "VBNET.ATG" +out outExpr); + while (la.kind == 16 || la.kind == 17) { + if (la.kind == 16) { + lexer.NextToken(); + +#line 1827 "VBNET.ATG" + op = BinaryOperatorType.Multiply; + } else { + lexer.NextToken(); + +#line 1828 "VBNET.ATG" + op = BinaryOperatorType.Divide; + } + UnaryExpr( +#line 1830 "VBNET.ATG" +out expr); + +#line 1830 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, op, expr); + } + } + + void UnaryExpr( +#line 1834 "VBNET.ATG" +out Expression uExpr) { + +#line 1836 "VBNET.ATG" + Expression expr; + UnaryOperatorType uop = UnaryOperatorType.None; + bool isUOp = false; + + while (la.kind == 14 || la.kind == 15 || la.kind == 16) { + if (la.kind == 14) { + lexer.NextToken(); + +#line 1840 "VBNET.ATG" + uop = UnaryOperatorType.Plus; isUOp = true; + } else if (la.kind == 15) { + lexer.NextToken(); + +#line 1841 "VBNET.ATG" + uop = UnaryOperatorType.Minus; isUOp = true; + } else { + lexer.NextToken(); + +#line 1842 "VBNET.ATG" + uop = UnaryOperatorType.Star; isUOp = true; + } + } + ExponentiationExpr( +#line 1844 "VBNET.ATG" +out expr); + +#line 1846 "VBNET.ATG" + if (isUOp) { + uExpr = new UnaryOperatorExpression(expr, uop); + } else { + uExpr = expr; + } + + } + + void ExponentiationExpr( +#line 1854 "VBNET.ATG" +out Expression outExpr) { + +#line 1855 "VBNET.ATG" + Expression expr; + SimpleExpr( +#line 1857 "VBNET.ATG" +out outExpr); + while (la.kind == 20) { + lexer.NextToken(); + SimpleExpr( +#line 1857 "VBNET.ATG" +out expr); + +#line 1857 "VBNET.ATG" + outExpr = new BinaryOperatorExpression(outExpr, BinaryOperatorType.Power, expr); + } + } + + void NormalOrReDimArgumentList( +#line 1908 "VBNET.ATG" +out List arguments, out bool canBeNormal, out bool canBeRedim) { + +#line 1910 "VBNET.ATG" + arguments = new List(); + canBeNormal = true; canBeRedim = !IsNamedAssign(); + Expression expr = null; + + if (StartOf(27)) { + Argument( +#line 1915 "VBNET.ATG" +out expr); + if (la.kind == 172) { + lexer.NextToken(); + +#line 1916 "VBNET.ATG" + EnsureIsZero(expr); canBeNormal = false; + Expr( +#line 1917 "VBNET.ATG" +out expr); + } + } + while (la.kind == 12) { + lexer.NextToken(); + +#line 1920 "VBNET.ATG" + if (expr == null) canBeRedim = false; + +#line 1921 "VBNET.ATG" + arguments.Add(expr ?? Expression.Null); expr = null; + +#line 1922 "VBNET.ATG" + canBeRedim &= !IsNamedAssign(); + if (StartOf(27)) { + Argument( +#line 1923 "VBNET.ATG" +out expr); + if (la.kind == 172) { + lexer.NextToken(); + +#line 1924 "VBNET.ATG" + EnsureIsZero(expr); canBeNormal = false; + Expr( +#line 1925 "VBNET.ATG" +out expr); + } + } + +#line 1927 "VBNET.ATG" + if (expr == null) { canBeRedim = false; expr = Expression.Null; } + } + +#line 1929 "VBNET.ATG" + if (expr != null) arguments.Add(expr); else canBeRedim = false; + } + + void ArrayTypeModifiers( +#line 2016 "VBNET.ATG" +out ArrayList arrayModifiers) { + +#line 2018 "VBNET.ATG" + arrayModifiers = new ArrayList(); + int i = 0; + + while ( +#line 2021 "VBNET.ATG" +IsDims()) { + Expect(24); + if (la.kind == 12 || la.kind == 25) { + RankList( +#line 2023 "VBNET.ATG" +out i); + } + +#line 2025 "VBNET.ATG" + arrayModifiers.Add(i); + + Expect(25); + } + +#line 2030 "VBNET.ATG" + if(arrayModifiers.Count == 0) { + arrayModifiers = null; + } + + } + + void Argument( +#line 1933 "VBNET.ATG" +out Expression argumentexpr) { + +#line 1935 "VBNET.ATG" + Expression expr; + argumentexpr = null; + string name; + + if ( +#line 1939 "VBNET.ATG" +IsNamedAssign()) { + Identifier(); + +#line 1939 "VBNET.ATG" + name = t.val; + Expect(13); + Expect(11); + Expr( +#line 1939 "VBNET.ATG" +out expr); + +#line 1941 "VBNET.ATG" + argumentexpr = new NamedArgumentExpression(name, expr); + + } else if (StartOf(27)) { + Expr( +#line 1944 "VBNET.ATG" +out argumentexpr); + } else SynErr(249); + } + + void QualIdentAndTypeArguments( +#line 1990 "VBNET.ATG" +out TypeReference typeref, bool canBeUnbound) { + +#line 1991 "VBNET.ATG" + string name; typeref = null; + Qualident( +#line 1993 "VBNET.ATG" +out name); + +#line 1994 "VBNET.ATG" + typeref = new TypeReference(name); + if ( +#line 1995 "VBNET.ATG" +la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { + lexer.NextToken(); + Expect(201); + if ( +#line 1997 "VBNET.ATG" +canBeUnbound && (la.kind == Tokens.CloseParenthesis || la.kind == Tokens.Comma)) { + +#line 1998 "VBNET.ATG" + typeref.GenericTypes.Add(NullTypeReference.Instance); + while (la.kind == 12) { + lexer.NextToken(); + +#line 1999 "VBNET.ATG" + typeref.GenericTypes.Add(NullTypeReference.Instance); + } + } else if (StartOf(6)) { + TypeArgumentList( +#line 2000 "VBNET.ATG" +typeref.GenericTypes); + } else SynErr(250); + Expect(25); + } + } + + void TypeArgumentList( +#line 2043 "VBNET.ATG" +List typeArguments) { + +#line 2045 "VBNET.ATG" + TypeReference typeref; + + TypeName( +#line 2047 "VBNET.ATG" +out typeref); + +#line 2047 "VBNET.ATG" + if (typeref != null) typeArguments.Add(typeref); + while (la.kind == 12) { + lexer.NextToken(); + TypeName( +#line 2050 "VBNET.ATG" +out typeref); + +#line 2050 "VBNET.ATG" + if (typeref != null) typeArguments.Add(typeref); + } + } + + void RankList( +#line 2037 "VBNET.ATG" +out int i) { + +#line 2038 "VBNET.ATG" + i = 0; + while (la.kind == 12) { + lexer.NextToken(); + +#line 2039 "VBNET.ATG" + ++i; + } + } + + void Attribute( +#line 2078 "VBNET.ATG" +out ASTAttribute attribute) { + +#line 2079 "VBNET.ATG" + string name; + List positional = new List(); + List named = new List(); + + if (la.kind == 199) { + lexer.NextToken(); + Expect(10); + } + Qualident( +#line 2084 "VBNET.ATG" +out name); + if (la.kind == 24) { + AttributeArguments( +#line 2085 "VBNET.ATG" +positional, named); + } + +#line 2086 "VBNET.ATG" + attribute = new ASTAttribute(name, positional, named); + } + + void AttributeArguments( +#line 2090 "VBNET.ATG" +List positional, List named) { + +#line 2092 "VBNET.ATG" + bool nameFound = false; + string name = ""; + Expression expr; + + Expect(24); + if ( +#line 2098 "VBNET.ATG" +IsNotClosingParenthesis()) { + if ( +#line 2100 "VBNET.ATG" +IsNamedAssign()) { + +#line 2100 "VBNET.ATG" + nameFound = true; + IdentifierOrKeyword( +#line 2101 "VBNET.ATG" +out name); + if (la.kind == 13) { + lexer.NextToken(); + } + Expect(11); + } + Expr( +#line 2103 "VBNET.ATG" +out expr); + +#line 2105 "VBNET.ATG" + if (expr != null) { + if (string.IsNullOrEmpty(name)) { positional.Add(expr); } + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + + while (la.kind == 12) { + lexer.NextToken(); + if ( +#line 2113 "VBNET.ATG" +IsNamedAssign()) { + +#line 2113 "VBNET.ATG" + nameFound = true; + IdentifierOrKeyword( +#line 2114 "VBNET.ATG" +out name); + if (la.kind == 13) { + lexer.NextToken(); + } + Expect(11); + } else if (StartOf(27)) { + +#line 2116 "VBNET.ATG" + if (nameFound) Error("no positional argument after named argument"); + } else SynErr(251); + Expr( +#line 2117 "VBNET.ATG" +out expr); + +#line 2117 "VBNET.ATG" + if (expr != null) { if(name == "") positional.Add(expr); + else { named.Add(new NamedArgumentExpression(name, expr)); name = ""; } + } + + } + } + Expect(25); + } + + void FormalParameter( +#line 2189 "VBNET.ATG" +out ParameterDeclarationExpression p) { + +#line 2191 "VBNET.ATG" + TypeReference type = null; + ParamModifierList mod = new ParamModifierList(this); + Expression expr = null; + p = null;ArrayList arrayModifiers = null; + + while (StartOf(33)) { + ParameterModifier( +#line 2196 "VBNET.ATG" +mod); + } + Identifier(); + +#line 2197 "VBNET.ATG" + string parameterName = t.val; + if ( +#line 2198 "VBNET.ATG" +IsDims()) { + ArrayTypeModifiers( +#line 2198 "VBNET.ATG" +out arrayModifiers); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 2199 "VBNET.ATG" +out type); + } + +#line 2201 "VBNET.ATG" + if(type != null) { + if (arrayModifiers != null) { + if (type.RankSpecifier != null) { + Error("array rank only allowed one time"); + } else { + type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int)); + } + } + } else { + type = new TypeReference("System.Object", arrayModifiers == null ? null : (int[])arrayModifiers.ToArray(typeof(int))); + } + + if (la.kind == 11) { + lexer.NextToken(); + Expr( +#line 2213 "VBNET.ATG" +out expr); + } + +#line 2215 "VBNET.ATG" + mod.Check(); + p = new ParameterDeclarationExpression(type, parameterName, mod.Modifier, expr); + + } + + void ParameterModifier( +#line 2867 "VBNET.ATG" +ParamModifierList m) { + if (la.kind == 55) { + lexer.NextToken(); + +#line 2868 "VBNET.ATG" + m.Add(ParameterModifiers.In); + } else if (la.kind == 53) { + lexer.NextToken(); + +#line 2869 "VBNET.ATG" + m.Add(ParameterModifiers.Ref); + } else if (la.kind == 137) { + lexer.NextToken(); + +#line 2870 "VBNET.ATG" + m.Add(ParameterModifiers.Optional); + } else if (la.kind == 143) { + lexer.NextToken(); + +#line 2871 "VBNET.ATG" + m.Add(ParameterModifiers.Params); + } else SynErr(252); + } + + void Statement() { + +#line 2243 "VBNET.ATG" + Statement stmt = null; + Location startPos = la.Location; + string label = String.Empty; + + + if (la.kind == 1 || la.kind == 13) { + } else if ( +#line 2249 "VBNET.ATG" +IsLabel()) { + LabelName( +#line 2249 "VBNET.ATG" +out label); + +#line 2251 "VBNET.ATG" + compilationUnit.AddChild(new LabelStatement(t.val)); + + Expect(13); + Statement(); + } else if (StartOf(34)) { + EmbeddedStatement( +#line 2254 "VBNET.ATG" +out stmt); + +#line 2254 "VBNET.ATG" + compilationUnit.AddChild(stmt); + } else if (StartOf(35)) { + LocalDeclarationStatement( +#line 2255 "VBNET.ATG" +out stmt); + +#line 2255 "VBNET.ATG" + compilationUnit.AddChild(stmt); + } else SynErr(253); + +#line 2258 "VBNET.ATG" + if (stmt != null) { + stmt.StartLocation = startPos; + stmt.EndLocation = t.Location; + } + + } + + void LabelName( +#line 2646 "VBNET.ATG" +out string name) { + +#line 2648 "VBNET.ATG" + name = String.Empty; + + if (StartOf(13)) { + Identifier(); + +#line 2650 "VBNET.ATG" + name = t.val; + } else if (la.kind == 5) { + lexer.NextToken(); + +#line 2651 "VBNET.ATG" + name = t.val; + } else SynErr(254); + } + + void EmbeddedStatement( +#line 2297 "VBNET.ATG" +out Statement statement) { + +#line 2299 "VBNET.ATG" + Statement embeddedStatement = null; + statement = null; + Expression expr = null; + string name = String.Empty; + List p = null; + + switch (la.kind) { + case 94: { + lexer.NextToken(); + +#line 2305 "VBNET.ATG" + ExitType exitType = ExitType.None; + switch (la.kind) { + case 167: { + lexer.NextToken(); + +#line 2307 "VBNET.ATG" + exitType = ExitType.Sub; + break; + } + case 100: { + lexer.NextToken(); + +#line 2309 "VBNET.ATG" + exitType = ExitType.Function; + break; + } + case 146: { + lexer.NextToken(); + +#line 2311 "VBNET.ATG" + exitType = ExitType.Property; + break; + } + case 83: { + lexer.NextToken(); + +#line 2313 "VBNET.ATG" + exitType = ExitType.Do; + break; + } + case 98: { + lexer.NextToken(); + +#line 2315 "VBNET.ATG" + exitType = ExitType.For; + break; + } + case 174: { + lexer.NextToken(); + +#line 2317 "VBNET.ATG" + exitType = ExitType.Try; + break; + } + case 181: { + lexer.NextToken(); + +#line 2319 "VBNET.ATG" + exitType = ExitType.While; + break; + } + case 155: { + lexer.NextToken(); + +#line 2321 "VBNET.ATG" + exitType = ExitType.Select; + break; + } + default: SynErr(255); break; + } + +#line 2323 "VBNET.ATG" + statement = new ExitStatement(exitType); + break; + } + case 174: { + TryStatement( +#line 2324 "VBNET.ATG" +out statement); + break; + } + case 187: { + lexer.NextToken(); + +#line 2325 "VBNET.ATG" + ContinueType continueType = ContinueType.None; + if (la.kind == 83 || la.kind == 98 || la.kind == 181) { + if (la.kind == 83) { + lexer.NextToken(); + +#line 2325 "VBNET.ATG" + continueType = ContinueType.Do; + } else if (la.kind == 98) { + lexer.NextToken(); + +#line 2325 "VBNET.ATG" + continueType = ContinueType.For; + } else { + lexer.NextToken(); + +#line 2325 "VBNET.ATG" + continueType = ContinueType.While; + } + } + +#line 2325 "VBNET.ATG" + statement = new ContinueStatement(continueType); + break; + } + case 171: { + lexer.NextToken(); + if (StartOf(27)) { + Expr( +#line 2327 "VBNET.ATG" +out expr); + } + +#line 2327 "VBNET.ATG" + statement = new ThrowStatement(expr); + break; + } + case 154: { + lexer.NextToken(); + if (StartOf(27)) { + Expr( +#line 2329 "VBNET.ATG" +out expr); + } + +#line 2329 "VBNET.ATG" + statement = new ReturnStatement(expr); + break; + } + case 168: { + lexer.NextToken(); + Expr( +#line 2331 "VBNET.ATG" +out expr); + EndOfStmt(); + Block( +#line 2331 "VBNET.ATG" +out embeddedStatement); + Expect(88); + Expect(168); + +#line 2332 "VBNET.ATG" + statement = new LockStatement(expr, embeddedStatement); + break; + } + case 149: { + lexer.NextToken(); + Identifier(); + +#line 2334 "VBNET.ATG" + name = t.val; + if (la.kind == 24) { + lexer.NextToken(); + if (StartOf(30)) { + ArgumentList( +#line 2335 "VBNET.ATG" +out p); + } + Expect(25); + } + +#line 2336 "VBNET.ATG" + statement = new RaiseEventStatement(name, p); + break; + } + case 182: { + WithStatement( +#line 2338 "VBNET.ATG" +out statement); + break; + } + case 42: { + lexer.NextToken(); + +#line 2340 "VBNET.ATG" + Expression handlerExpr = null; + Expr( +#line 2341 "VBNET.ATG" +out expr); + Expect(12); + Expr( +#line 2341 "VBNET.ATG" +out handlerExpr); + +#line 2343 "VBNET.ATG" + statement = new AddHandlerStatement(expr, handlerExpr); + + break; + } + case 152: { + lexer.NextToken(); + +#line 2346 "VBNET.ATG" + Expression handlerExpr = null; + Expr( +#line 2347 "VBNET.ATG" +out expr); + Expect(12); + Expr( +#line 2347 "VBNET.ATG" +out handlerExpr); + +#line 2349 "VBNET.ATG" + statement = new RemoveHandlerStatement(expr, handlerExpr); + + break; + } + case 181: { + lexer.NextToken(); + Expr( +#line 2352 "VBNET.ATG" +out expr); + EndOfStmt(); + Block( +#line 2353 "VBNET.ATG" +out embeddedStatement); + Expect(88); + Expect(181); + +#line 2355 "VBNET.ATG" + statement = new DoLoopStatement(expr, embeddedStatement, ConditionType.While, ConditionPosition.Start); + + break; + } + case 83: { + lexer.NextToken(); + +#line 2360 "VBNET.ATG" + ConditionType conditionType = ConditionType.None; + + if (la.kind == 177 || la.kind == 181) { + WhileOrUntil( +#line 2363 "VBNET.ATG" +out conditionType); + Expr( +#line 2363 "VBNET.ATG" +out expr); + EndOfStmt(); + Block( +#line 2364 "VBNET.ATG" +out embeddedStatement); + Expect(118); + +#line 2367 "VBNET.ATG" + statement = new DoLoopStatement(expr, + embeddedStatement, + conditionType == ConditionType.While ? ConditionType.DoWhile : conditionType, + ConditionPosition.Start); + + } else if (la.kind == 1 || la.kind == 13) { + EndOfStmt(); + Block( +#line 2374 "VBNET.ATG" +out embeddedStatement); + Expect(118); + if (la.kind == 177 || la.kind == 181) { + WhileOrUntil( +#line 2375 "VBNET.ATG" +out conditionType); + Expr( +#line 2375 "VBNET.ATG" +out expr); + } + +#line 2377 "VBNET.ATG" + statement = new DoLoopStatement(expr, embeddedStatement, conditionType, ConditionPosition.End); + + } else SynErr(256); + break; + } + case 98: { + lexer.NextToken(); + +#line 2382 "VBNET.ATG" + Expression group = null; + TypeReference typeReference; + string typeName; + Location startLocation = t.Location; + + if (la.kind == 85) { + lexer.NextToken(); + LoopControlVariable( +#line 2389 "VBNET.ATG" +out typeReference, out typeName); + Expect(109); + Expr( +#line 2390 "VBNET.ATG" +out group); + EndOfStmt(); + Block( +#line 2391 "VBNET.ATG" +out embeddedStatement); + Expect(128); + if (StartOf(27)) { + Expr( +#line 2392 "VBNET.ATG" +out expr); + } + +#line 2394 "VBNET.ATG" + statement = new ForeachStatement(typeReference, + typeName, + group, + embeddedStatement, + expr); + statement.StartLocation = startLocation; + statement.EndLocation = t.EndLocation; + + + } else if (StartOf(13)) { + +#line 2405 "VBNET.ATG" + Expression start = null; + Expression end = null; + Expression step = null; + Expression nextExpr = null;List nextExpressions = null; + + LoopControlVariable( +#line 2410 "VBNET.ATG" +out typeReference, out typeName); + Expect(11); + Expr( +#line 2411 "VBNET.ATG" +out start); + Expect(172); + Expr( +#line 2411 "VBNET.ATG" +out end); + if (la.kind == 162) { + lexer.NextToken(); + Expr( +#line 2411 "VBNET.ATG" +out step); + } + EndOfStmt(); + Block( +#line 2412 "VBNET.ATG" +out embeddedStatement); + Expect(128); + if (StartOf(27)) { + Expr( +#line 2415 "VBNET.ATG" +out nextExpr); + +#line 2415 "VBNET.ATG" + nextExpressions = new List(); nextExpressions.Add(nextExpr); + while (la.kind == 12) { + lexer.NextToken(); + Expr( +#line 2416 "VBNET.ATG" +out nextExpr); + +#line 2416 "VBNET.ATG" + nextExpressions.Add(nextExpr); + } + } + +#line 2419 "VBNET.ATG" + statement = new ForNextStatement(typeReference, typeName, start, end, step, embeddedStatement, nextExpressions); + + } else SynErr(257); + break; + } + case 92: { + lexer.NextToken(); + Expr( +#line 2423 "VBNET.ATG" +out expr); + +#line 2423 "VBNET.ATG" + statement = new ErrorStatement(expr); + break; + } + case 151: { + lexer.NextToken(); + +#line 2425 "VBNET.ATG" + bool isPreserve = false; + if (la.kind == 144) { + lexer.NextToken(); + +#line 2425 "VBNET.ATG" + isPreserve = true; + } + ReDimClause( +#line 2426 "VBNET.ATG" +out expr); + +#line 2428 "VBNET.ATG" + ReDimStatement reDimStatement = new ReDimStatement(isPreserve); + statement = reDimStatement; + SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); + + while (la.kind == 12) { + lexer.NextToken(); + ReDimClause( +#line 2432 "VBNET.ATG" +out expr); + +#line 2433 "VBNET.ATG" + SafeAdd(reDimStatement, reDimStatement.ReDimClauses, expr as InvocationExpression); + } + break; + } + case 91: { + lexer.NextToken(); + Expr( +#line 2437 "VBNET.ATG" +out expr); + +#line 2438 "VBNET.ATG" + List arrays = new List(); + if (expr != null) { arrays.Add(expr);} + EraseStatement eraseStatement = new EraseStatement(arrays); + + + while (la.kind == 12) { + lexer.NextToken(); + Expr( +#line 2443 "VBNET.ATG" +out expr); + +#line 2443 "VBNET.ATG" + if (expr != null) { arrays.Add(expr); } + } + +#line 2444 "VBNET.ATG" + statement = eraseStatement; + break; + } + case 163: { + lexer.NextToken(); + +#line 2446 "VBNET.ATG" + statement = new StopStatement(); + break; + } + case 106: { + lexer.NextToken(); + +#line 2448 "VBNET.ATG" + Location ifStartLocation = t.Location; + Expr( +#line 2448 "VBNET.ATG" +out expr); + if (la.kind == 170) { + lexer.NextToken(); + } + if (la.kind == 1 || la.kind == 13) { + EndOfStmt(); + Block( +#line 2451 "VBNET.ATG" +out embeddedStatement); + +#line 2453 "VBNET.ATG" + IfElseStatement ifStatement = new IfElseStatement(expr, embeddedStatement); + ifStatement.StartLocation = ifStartLocation; + Location elseIfStart; + + while (la.kind == 87 || +#line 2459 "VBNET.ATG" +IsElseIf()) { + if ( +#line 2459 "VBNET.ATG" +IsElseIf()) { + Expect(86); + +#line 2459 "VBNET.ATG" + elseIfStart = t.Location; + Expect(106); + } else { + lexer.NextToken(); + +#line 2460 "VBNET.ATG" + elseIfStart = t.Location; + } + +#line 2462 "VBNET.ATG" + Expression condition = null; Statement block = null; + Expr( +#line 2463 "VBNET.ATG" +out condition); + if (la.kind == 170) { + lexer.NextToken(); + } + EndOfStmt(); + Block( +#line 2464 "VBNET.ATG" +out block); + +#line 2466 "VBNET.ATG" + ElseIfSection elseIfSection = new ElseIfSection(condition, block); + elseIfSection.StartLocation = elseIfStart; + elseIfSection.EndLocation = t.Location; + elseIfSection.Parent = ifStatement; + ifStatement.ElseIfSections.Add(elseIfSection); + + } + if (la.kind == 86) { + lexer.NextToken(); + EndOfStmt(); + Block( +#line 2475 "VBNET.ATG" +out embeddedStatement); + +#line 2477 "VBNET.ATG" + ifStatement.FalseStatement.Add(embeddedStatement); + + } + Expect(88); + Expect(106); + +#line 2481 "VBNET.ATG" + ifStatement.EndLocation = t.Location; + statement = ifStatement; + + } else if (StartOf(36)) { + +#line 2486 "VBNET.ATG" + IfElseStatement ifStatement = new IfElseStatement(expr); + ifStatement.StartLocation = ifStartLocation; + + SingleLineStatementList( +#line 2489 "VBNET.ATG" +ifStatement.TrueStatement); + if (la.kind == 86) { + lexer.NextToken(); + if (StartOf(36)) { + SingleLineStatementList( +#line 2492 "VBNET.ATG" +ifStatement.FalseStatement); + } + } + +#line 2494 "VBNET.ATG" + ifStatement.EndLocation = t.Location; statement = ifStatement; + } else SynErr(258); + break; + } + case 155: { + lexer.NextToken(); + if (la.kind == 57) { + lexer.NextToken(); + } + Expr( +#line 2497 "VBNET.ATG" +out expr); + EndOfStmt(); + +#line 2498 "VBNET.ATG" + List selectSections = new List(); + Statement block = null; + + while (la.kind == 57) { + +#line 2502 "VBNET.ATG" + List caseClauses = null; Location caseLocation = la.Location; + lexer.NextToken(); + CaseClauses( +#line 2503 "VBNET.ATG" +out caseClauses); + if ( +#line 2503 "VBNET.ATG" +IsNotStatementSeparator()) { + lexer.NextToken(); + } + EndOfStmt(); + +#line 2505 "VBNET.ATG" + SwitchSection selectSection = new SwitchSection(caseClauses); + selectSection.StartLocation = caseLocation; + + Block( +#line 2508 "VBNET.ATG" +out block); + +#line 2510 "VBNET.ATG" + selectSection.Children = block.Children; + selectSection.EndLocation = t.EndLocation; + selectSections.Add(selectSection); + + } + +#line 2515 "VBNET.ATG" + statement = new SwitchStatement(expr, selectSections); + Expect(88); + Expect(155); + break; + } + case 135: { + +#line 2517 "VBNET.ATG" + OnErrorStatement onErrorStatement = null; + OnErrorStatement( +#line 2518 "VBNET.ATG" +out onErrorStatement); + +#line 2518 "VBNET.ATG" + statement = onErrorStatement; + break; + } + case 104: { + +#line 2519 "VBNET.ATG" + GotoStatement goToStatement = null; + GotoStatement( +#line 2520 "VBNET.ATG" +out goToStatement); + +#line 2520 "VBNET.ATG" + statement = goToStatement; + break; + } + case 153: { + +#line 2521 "VBNET.ATG" + ResumeStatement resumeStatement = null; + ResumeStatement( +#line 2522 "VBNET.ATG" +out resumeStatement); + +#line 2522 "VBNET.ATG" + statement = resumeStatement; + break; + } + case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 24: case 43: case 47: case 49: case 50: case 51: case 52: case 54: case 59: case 60: case 61: case 62: case 63: case 64: case 65: case 66: case 68: case 69: case 70: case 72: case 73: case 74: case 75: case 76: case 77: case 82: case 84: case 95: case 96: case 102: case 111: case 117: case 119: case 124: case 125: case 127: case 130: case 133: case 134: case 144: case 159: case 160: case 165: case 169: case 173: case 175: case 176: case 177: case 191: case 192: case 193: case 194: case 195: case 196: case 197: case 198: case 199: case 200: case 205: { + +#line 2525 "VBNET.ATG" + Expression val = null; + AssignmentOperatorType op; + + bool mustBeAssignment = la.kind == Tokens.Plus || la.kind == Tokens.Minus || + la.kind == Tokens.Not || la.kind == Tokens.Times; + + SimpleExpr( +#line 2531 "VBNET.ATG" +out expr); + if (StartOf(37)) { + AssignmentOperator( +#line 2533 "VBNET.ATG" +out op); + Expr( +#line 2533 "VBNET.ATG" +out val); + +#line 2533 "VBNET.ATG" + expr = new AssignmentExpression(expr, op, val); + } else if (la.kind == 1 || la.kind == 13 || la.kind == 86) { + +#line 2534 "VBNET.ATG" + if (mustBeAssignment) Error("error in assignment."); + } else SynErr(259); + +#line 2537 "VBNET.ATG" + // a field reference expression that stands alone is a + // invocation expression without parantheses and arguments + if(expr is MemberReferenceExpression || expr is IdentifierExpression) { + expr = new InvocationExpression(expr); + } + statement = new ExpressionStatement(expr); + + break; + } + case 56: { + lexer.NextToken(); + SimpleExpr( +#line 2544 "VBNET.ATG" +out expr); + +#line 2544 "VBNET.ATG" + statement = new ExpressionStatement(expr); + break; + } + case 189: { + lexer.NextToken(); + +#line 2546 "VBNET.ATG" + Statement block; + if ( +#line 2547 "VBNET.ATG" +Peek(1).kind == Tokens.As) { + +#line 2548 "VBNET.ATG" + LocalVariableDeclaration resourceAquisition = new LocalVariableDeclaration(Modifiers.None); + VariableDeclarator( +#line 2549 "VBNET.ATG" +resourceAquisition.Variables); + while (la.kind == 12) { + lexer.NextToken(); + VariableDeclarator( +#line 2551 "VBNET.ATG" +resourceAquisition.Variables); + } + Block( +#line 2553 "VBNET.ATG" +out block); + +#line 2554 "VBNET.ATG" + statement = new UsingStatement(resourceAquisition, block); + } else if (StartOf(27)) { + Expr( +#line 2555 "VBNET.ATG" +out expr); + Block( +#line 2556 "VBNET.ATG" +out block); + +#line 2557 "VBNET.ATG" + statement = new UsingStatement(new ExpressionStatement(expr), block); + } else SynErr(260); + Expect(88); + Expect(189); + break; + } + default: SynErr(261); break; + } + } + + void LocalDeclarationStatement( +#line 2266 "VBNET.ATG" +out Statement statement) { + +#line 2268 "VBNET.ATG" + ModifierList m = new ModifierList(); + LocalVariableDeclaration localVariableDeclaration; + bool dimfound = false; + + while (la.kind == 71 || la.kind == 81 || la.kind == 161) { + if (la.kind == 71) { + lexer.NextToken(); + +#line 2274 "VBNET.ATG" + m.Add(Modifiers.Const, t.Location); + } else if (la.kind == 161) { + lexer.NextToken(); + +#line 2275 "VBNET.ATG" + m.Add(Modifiers.Static, t.Location); + } else { + lexer.NextToken(); + +#line 2276 "VBNET.ATG" + dimfound = true; + } + } + +#line 2279 "VBNET.ATG" + if(dimfound && (m.Modifier & Modifiers.Const) != 0) { + Error("Dim is not allowed on constants."); + } + + if(m.isNone && dimfound == false) { + Error("Const, Dim or Static expected"); + } + + localVariableDeclaration = new LocalVariableDeclaration(m.Modifier); + localVariableDeclaration.StartLocation = t.Location; + + VariableDeclarator( +#line 2290 "VBNET.ATG" +localVariableDeclaration.Variables); + while (la.kind == 12) { + lexer.NextToken(); + VariableDeclarator( +#line 2291 "VBNET.ATG" +localVariableDeclaration.Variables); + } + +#line 2293 "VBNET.ATG" + statement = localVariableDeclaration; + + } + + void TryStatement( +#line 2760 "VBNET.ATG" +out Statement tryStatement) { + +#line 2762 "VBNET.ATG" + Statement blockStmt = null, finallyStmt = null;List catchClauses = null; + + Expect(174); + EndOfStmt(); + Block( +#line 2765 "VBNET.ATG" +out blockStmt); + if (la.kind == 58 || la.kind == 88 || la.kind == 97) { + CatchClauses( +#line 2766 "VBNET.ATG" +out catchClauses); + } + if (la.kind == 97) { + lexer.NextToken(); + EndOfStmt(); + Block( +#line 2767 "VBNET.ATG" +out finallyStmt); + } + Expect(88); + Expect(174); + +#line 2770 "VBNET.ATG" + tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt); + + } + + void WithStatement( +#line 2740 "VBNET.ATG" +out Statement withStatement) { + +#line 2742 "VBNET.ATG" + Statement blockStmt = null; + Expression expr = null; + + Expect(182); + +#line 2745 "VBNET.ATG" + Location start = t.Location; + Expr( +#line 2746 "VBNET.ATG" +out expr); + EndOfStmt(); + +#line 2748 "VBNET.ATG" + withStatement = new WithStatement(expr); + withStatement.StartLocation = start; + + Block( +#line 2751 "VBNET.ATG" +out blockStmt); + +#line 2753 "VBNET.ATG" + ((WithStatement)withStatement).Body = (BlockStatement)blockStmt; + + Expect(88); + Expect(182); + +#line 2756 "VBNET.ATG" + withStatement.EndLocation = t.Location; + } + + void WhileOrUntil( +#line 2733 "VBNET.ATG" +out ConditionType conditionType) { + +#line 2734 "VBNET.ATG" + conditionType = ConditionType.None; + if (la.kind == 181) { + lexer.NextToken(); + +#line 2735 "VBNET.ATG" + conditionType = ConditionType.While; + } else if (la.kind == 177) { + lexer.NextToken(); + +#line 2736 "VBNET.ATG" + conditionType = ConditionType.Until; + } else SynErr(262); + } + + void LoopControlVariable( +#line 2576 "VBNET.ATG" +out TypeReference type, out string name) { + +#line 2577 "VBNET.ATG" + ArrayList arrayModifiers = null; + type = null; + + Qualident( +#line 2581 "VBNET.ATG" +out name); + if ( +#line 2582 "VBNET.ATG" +IsDims()) { + ArrayTypeModifiers( +#line 2582 "VBNET.ATG" +out arrayModifiers); + } + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 2583 "VBNET.ATG" +out type); + +#line 2583 "VBNET.ATG" + if (name.IndexOf('.') > 0) { Error("No type def for 'for each' member indexer allowed."); } + } + +#line 2585 "VBNET.ATG" + if (type != null) { + if(type.RankSpecifier != null && arrayModifiers != null) { + Error("array rank only allowed one time"); + } else if (arrayModifiers != null) { + type.RankSpecifier = (int[])arrayModifiers.ToArray(typeof(int)); + } + } + + } + + void ReDimClause( +#line 2655 "VBNET.ATG" +out Expression expr) { + SimpleNonInvocationExpression( +#line 2657 "VBNET.ATG" +out expr); + ReDimClauseInternal( +#line 2658 "VBNET.ATG" +ref expr); + } + + void SingleLineStatementList( +#line 2562 "VBNET.ATG" +List list) { + +#line 2563 "VBNET.ATG" + Statement embeddedStatement = null; + if (la.kind == 88) { + lexer.NextToken(); + +#line 2565 "VBNET.ATG" + embeddedStatement = new EndStatement(); + } else if (StartOf(34)) { + EmbeddedStatement( +#line 2566 "VBNET.ATG" +out embeddedStatement); + } else SynErr(263); + +#line 2567 "VBNET.ATG" + if (embeddedStatement != null) list.Add(embeddedStatement); + while (la.kind == 13) { + lexer.NextToken(); + while (la.kind == 13) { + lexer.NextToken(); + } + if (la.kind == 88) { + lexer.NextToken(); + +#line 2569 "VBNET.ATG" + embeddedStatement = new EndStatement(); + } else if (StartOf(34)) { + EmbeddedStatement( +#line 2570 "VBNET.ATG" +out embeddedStatement); + } else SynErr(264); + +#line 2571 "VBNET.ATG" + if (embeddedStatement != null) list.Add(embeddedStatement); + } + } + + void CaseClauses( +#line 2693 "VBNET.ATG" +out List caseClauses) { + +#line 2695 "VBNET.ATG" + caseClauses = new List(); + CaseLabel caseClause = null; + + CaseClause( +#line 2698 "VBNET.ATG" +out caseClause); + +#line 2698 "VBNET.ATG" + if (caseClause != null) { caseClauses.Add(caseClause); } + while (la.kind == 12) { + lexer.NextToken(); + CaseClause( +#line 2699 "VBNET.ATG" +out caseClause); + +#line 2699 "VBNET.ATG" + if (caseClause != null) { caseClauses.Add(caseClause); } + } + } + + void OnErrorStatement( +#line 2596 "VBNET.ATG" +out OnErrorStatement stmt) { + +#line 2598 "VBNET.ATG" + stmt = null; + GotoStatement goToStatement = null; + + Expect(135); + Expect(92); + if ( +#line 2604 "VBNET.ATG" +IsNegativeLabelName()) { + Expect(104); + Expect(15); + Expect(5); + +#line 2606 "VBNET.ATG" + long intLabel = Int64.Parse(t.val); + if(intLabel != 1) { + Error("invalid label in on error statement."); + } + stmt = new OnErrorStatement(new GotoStatement((intLabel * -1).ToString())); + + } else if (la.kind == 104) { + GotoStatement( +#line 2612 "VBNET.ATG" +out goToStatement); + +#line 2614 "VBNET.ATG" + string val = goToStatement.Label; + + // if value is numeric, make sure that is 0 + try { + long intLabel = Int64.Parse(val); + if(intLabel != 0) { + Error("invalid label in on error statement."); + } + } catch { + } + stmt = new OnErrorStatement(goToStatement); + + } else if (la.kind == 153) { + lexer.NextToken(); + Expect(128); + +#line 2628 "VBNET.ATG" + stmt = new OnErrorStatement(new ResumeStatement(true)); + + } else SynErr(265); + } + + void GotoStatement( +#line 2634 "VBNET.ATG" +out GotoStatement goToStatement) { + +#line 2636 "VBNET.ATG" + string label = String.Empty; + + Expect(104); + LabelName( +#line 2639 "VBNET.ATG" +out label); + +#line 2641 "VBNET.ATG" + goToStatement = new GotoStatement(label); + + } + + void ResumeStatement( +#line 2682 "VBNET.ATG" +out ResumeStatement resumeStatement) { + +#line 2684 "VBNET.ATG" + resumeStatement = null; + string label = String.Empty; + + if ( +#line 2687 "VBNET.ATG" +IsResumeNext()) { + Expect(153); + Expect(128); + +#line 2688 "VBNET.ATG" + resumeStatement = new ResumeStatement(true); + } else if (la.kind == 153) { + lexer.NextToken(); + if (StartOf(38)) { + LabelName( +#line 2689 "VBNET.ATG" +out label); + } + +#line 2689 "VBNET.ATG" + resumeStatement = new ResumeStatement(label); + } else SynErr(266); + } + + void ReDimClauseInternal( +#line 2661 "VBNET.ATG" +ref Expression expr) { + +#line 2662 "VBNET.ATG" + List arguments; bool canBeNormal; bool canBeRedim; string name; + while (la.kind == 10 || +#line 2665 "VBNET.ATG" +la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) { + if (la.kind == 10) { + lexer.NextToken(); + IdentifierOrKeyword( +#line 2664 "VBNET.ATG" +out name); + +#line 2664 "VBNET.ATG" + expr = new MemberReferenceExpression(expr, name); + } else { + InvocationExpression( +#line 2666 "VBNET.ATG" +ref expr); + } + } + Expect(24); + NormalOrReDimArgumentList( +#line 2669 "VBNET.ATG" +out arguments, out canBeNormal, out canBeRedim); + Expect(25); + +#line 2671 "VBNET.ATG" + expr = new InvocationExpression(expr, arguments); + if (canBeRedim == false || canBeNormal && (la.kind == Tokens.Dot || la.kind == Tokens.OpenParenthesis)) { + if (this.Errors.Count == 0) { + // don't recurse on parse errors - could result in endless recursion + ReDimClauseInternal(ref expr); + } + } + + } + + void CaseClause( +#line 2703 "VBNET.ATG" +out CaseLabel caseClause) { + +#line 2705 "VBNET.ATG" + Expression expr = null; + Expression sexpr = null; + BinaryOperatorType op = BinaryOperatorType.None; + caseClause = null; + + if (la.kind == 86) { + lexer.NextToken(); + +#line 2711 "VBNET.ATG" + caseClause = new CaseLabel(); + } else if (StartOf(39)) { + if (la.kind == 113) { + lexer.NextToken(); + } + switch (la.kind) { + case 27: { + lexer.NextToken(); + +#line 2715 "VBNET.ATG" + op = BinaryOperatorType.LessThan; + break; + } + case 26: { + lexer.NextToken(); + +#line 2716 "VBNET.ATG" + op = BinaryOperatorType.GreaterThan; + break; + } + case 30: { + lexer.NextToken(); + +#line 2717 "VBNET.ATG" + op = BinaryOperatorType.LessThanOrEqual; + break; + } + case 29: { + lexer.NextToken(); + +#line 2718 "VBNET.ATG" + op = BinaryOperatorType.GreaterThanOrEqual; + break; + } + case 11: { + lexer.NextToken(); + +#line 2719 "VBNET.ATG" + op = BinaryOperatorType.Equality; + break; + } + case 28: { + lexer.NextToken(); + +#line 2720 "VBNET.ATG" + op = BinaryOperatorType.InEquality; + break; + } + default: SynErr(267); break; + } + Expr( +#line 2722 "VBNET.ATG" +out expr); + +#line 2724 "VBNET.ATG" + caseClause = new CaseLabel(op, expr); + + } else if (StartOf(27)) { + Expr( +#line 2726 "VBNET.ATG" +out expr); + if (la.kind == 172) { + lexer.NextToken(); + Expr( +#line 2726 "VBNET.ATG" +out sexpr); + } + +#line 2728 "VBNET.ATG" + caseClause = new CaseLabel(expr, sexpr); + + } else SynErr(268); + } + + void CatchClauses( +#line 2775 "VBNET.ATG" +out List catchClauses) { + +#line 2777 "VBNET.ATG" + catchClauses = new List(); + TypeReference type = null; + Statement blockStmt = null; + Expression expr = null; + string name = String.Empty; + + while (la.kind == 58) { + lexer.NextToken(); + if (StartOf(13)) { + Identifier(); + +#line 2785 "VBNET.ATG" + name = t.val; + if (la.kind == 48) { + lexer.NextToken(); + TypeName( +#line 2785 "VBNET.ATG" +out type); + } + } + if (la.kind == 180) { + lexer.NextToken(); + Expr( +#line 2786 "VBNET.ATG" +out expr); + } + EndOfStmt(); + Block( +#line 2788 "VBNET.ATG" +out blockStmt); + +#line 2789 "VBNET.ATG" + catchClauses.Add(new CatchClause(type, name, blockStmt, expr)); + } + } + + + + public override void Parse() + { + VBNET(); + + } + + protected override void SynErr(int line, int col, int errorNumber) + { + string s; + switch (errorNumber) { + case 0: s = "EOF expected"; break; + case 1: s = "EOL expected"; break; + case 2: s = "ident expected"; break; + case 3: s = "LiteralString expected"; break; + case 4: s = "LiteralCharacter expected"; break; + case 5: s = "LiteralInteger expected"; break; + case 6: s = "LiteralDouble expected"; break; + case 7: s = "LiteralSingle expected"; break; + case 8: s = "LiteralDecimal expected"; break; + case 9: s = "LiteralDate expected"; break; + case 10: s = "\".\" expected"; break; + case 11: s = "\"=\" expected"; break; + case 12: s = "\",\" expected"; break; + case 13: s = "\":\" expected"; break; + case 14: s = "\"+\" expected"; break; + case 15: s = "\"-\" expected"; break; + case 16: s = "\"*\" expected"; break; + case 17: s = "\"/\" expected"; break; + case 18: s = "\"\\\\\" expected"; break; + case 19: s = "\"&\" expected"; break; + case 20: s = "\"^\" expected"; break; + case 21: s = "\"?\" expected"; break; + case 22: s = "\"{\" expected"; break; + case 23: s = "\"}\" expected"; break; + case 24: s = "\"(\" expected"; break; + case 25: s = "\")\" expected"; break; + case 26: s = "\">\" expected"; break; + case 27: s = "\"<\" expected"; break; + case 28: s = "\"<>\" expected"; break; + case 29: s = "\">=\" expected"; break; + case 30: s = "\"<=\" expected"; break; + case 31: s = "\"<<\" expected"; break; + case 32: s = "\">>\" expected"; break; + case 33: s = "\"+=\" expected"; break; + case 34: s = "\"^=\" expected"; break; + case 35: s = "\"-=\" expected"; break; + case 36: s = "\"*=\" expected"; break; + case 37: s = "\"/=\" expected"; break; + case 38: s = "\"\\\\=\" expected"; break; + case 39: s = "\"<<=\" expected"; break; + case 40: s = "\">>=\" expected"; break; + case 41: s = "\"&=\" expected"; break; + case 42: s = "\"AddHandler\" expected"; break; + case 43: s = "\"AddressOf\" expected"; break; + case 44: s = "\"Alias\" expected"; break; + case 45: s = "\"And\" expected"; break; + case 46: s = "\"AndAlso\" expected"; break; + case 47: s = "\"Ansi\" expected"; break; + case 48: s = "\"As\" expected"; break; + case 49: s = "\"Assembly\" expected"; break; + case 50: s = "\"Auto\" expected"; break; + case 51: s = "\"Binary\" expected"; break; + case 52: s = "\"Boolean\" expected"; break; + case 53: s = "\"ByRef\" expected"; break; + case 54: s = "\"Byte\" expected"; break; + case 55: s = "\"ByVal\" expected"; break; + case 56: s = "\"Call\" expected"; break; + case 57: s = "\"Case\" expected"; break; + case 58: s = "\"Catch\" expected"; break; + case 59: s = "\"CBool\" expected"; break; + case 60: s = "\"CByte\" expected"; break; + case 61: s = "\"CChar\" expected"; break; + case 62: s = "\"CDate\" expected"; break; + case 63: s = "\"CDbl\" expected"; break; + case 64: s = "\"CDec\" expected"; break; + case 65: s = "\"Char\" expected"; break; + case 66: s = "\"CInt\" expected"; break; + case 67: s = "\"Class\" expected"; break; + case 68: s = "\"CLng\" expected"; break; + case 69: s = "\"CObj\" expected"; break; + case 70: s = "\"Compare\" expected"; break; + case 71: s = "\"Const\" expected"; break; + case 72: s = "\"CShort\" expected"; break; + case 73: s = "\"CSng\" expected"; break; + case 74: s = "\"CStr\" expected"; break; + case 75: s = "\"CType\" expected"; break; + case 76: s = "\"Date\" expected"; break; + case 77: s = "\"Decimal\" expected"; break; + case 78: s = "\"Declare\" expected"; break; + case 79: s = "\"Default\" expected"; break; + case 80: s = "\"Delegate\" expected"; break; + case 81: s = "\"Dim\" expected"; break; + case 82: s = "\"DirectCast\" expected"; break; + case 83: s = "\"Do\" expected"; break; + case 84: s = "\"Double\" expected"; break; + case 85: s = "\"Each\" expected"; break; + case 86: s = "\"Else\" expected"; break; + case 87: s = "\"ElseIf\" expected"; break; + case 88: s = "\"End\" expected"; break; + case 89: s = "\"EndIf\" expected"; break; + case 90: s = "\"Enum\" expected"; break; + case 91: s = "\"Erase\" expected"; break; + case 92: s = "\"Error\" expected"; break; + case 93: s = "\"Event\" expected"; break; + case 94: s = "\"Exit\" expected"; break; + case 95: s = "\"Explicit\" expected"; break; + case 96: s = "\"False\" expected"; break; + case 97: s = "\"Finally\" expected"; break; + case 98: s = "\"For\" expected"; break; + case 99: s = "\"Friend\" expected"; break; + case 100: s = "\"Function\" expected"; break; + case 101: s = "\"Get\" expected"; break; + case 102: s = "\"GetType\" expected"; break; + case 103: s = "\"GoSub\" expected"; break; + case 104: s = "\"GoTo\" expected"; break; + case 105: s = "\"Handles\" expected"; break; + case 106: s = "\"If\" expected"; break; + case 107: s = "\"Implements\" expected"; break; + case 108: s = "\"Imports\" expected"; break; + case 109: s = "\"In\" expected"; break; + case 110: s = "\"Inherits\" expected"; break; + case 111: s = "\"Integer\" expected"; break; + case 112: s = "\"Interface\" expected"; break; + case 113: s = "\"Is\" expected"; break; + case 114: s = "\"Let\" expected"; break; + case 115: s = "\"Lib\" expected"; break; + case 116: s = "\"Like\" expected"; break; + case 117: s = "\"Long\" expected"; break; + case 118: s = "\"Loop\" expected"; break; + case 119: s = "\"Me\" expected"; break; + case 120: s = "\"Mod\" expected"; break; + case 121: s = "\"Module\" expected"; break; + case 122: s = "\"MustInherit\" expected"; break; + case 123: s = "\"MustOverride\" expected"; break; + case 124: s = "\"MyBase\" expected"; break; + case 125: s = "\"MyClass\" expected"; break; + case 126: s = "\"Namespace\" expected"; break; + case 127: s = "\"New\" expected"; break; + case 128: s = "\"Next\" expected"; break; + case 129: s = "\"Not\" expected"; break; + case 130: s = "\"Nothing\" expected"; break; + case 131: s = "\"NotInheritable\" expected"; break; + case 132: s = "\"NotOverridable\" expected"; break; + case 133: s = "\"Object\" expected"; break; + case 134: s = "\"Off\" expected"; break; + case 135: s = "\"On\" expected"; break; + case 136: s = "\"Option\" expected"; break; + case 137: s = "\"Optional\" expected"; break; + case 138: s = "\"Or\" expected"; break; + case 139: s = "\"OrElse\" expected"; break; + case 140: s = "\"Overloads\" expected"; break; + case 141: s = "\"Overridable\" expected"; break; + case 142: s = "\"Overrides\" expected"; break; + case 143: s = "\"ParamArray\" expected"; break; + case 144: s = "\"Preserve\" expected"; break; + case 145: s = "\"Private\" expected"; break; + case 146: s = "\"Property\" expected"; break; + case 147: s = "\"Protected\" expected"; break; + case 148: s = "\"Public\" expected"; break; + case 149: s = "\"RaiseEvent\" expected"; break; + case 150: s = "\"ReadOnly\" expected"; break; + case 151: s = "\"ReDim\" expected"; break; + case 152: s = "\"RemoveHandler\" expected"; break; + case 153: s = "\"Resume\" expected"; break; + case 154: s = "\"Return\" expected"; break; + case 155: s = "\"Select\" expected"; break; + case 156: s = "\"Set\" expected"; break; + case 157: s = "\"Shadows\" expected"; break; + case 158: s = "\"Shared\" expected"; break; + case 159: s = "\"Short\" expected"; break; + case 160: s = "\"Single\" expected"; break; + case 161: s = "\"Static\" expected"; break; + case 162: s = "\"Step\" expected"; break; + case 163: s = "\"Stop\" expected"; break; + case 164: s = "\"Strict\" expected"; break; + case 165: s = "\"String\" expected"; break; + case 166: s = "\"Structure\" expected"; break; + case 167: s = "\"Sub\" expected"; break; + case 168: s = "\"SyncLock\" expected"; break; + case 169: s = "\"Text\" expected"; break; + case 170: s = "\"Then\" expected"; break; + case 171: s = "\"Throw\" expected"; break; + case 172: s = "\"To\" expected"; break; + case 173: s = "\"True\" expected"; break; + case 174: s = "\"Try\" expected"; break; + case 175: s = "\"TypeOf\" expected"; break; + case 176: s = "\"Unicode\" expected"; break; + case 177: s = "\"Until\" expected"; break; + case 178: s = "\"Variant\" expected"; break; + case 179: s = "\"Wend\" expected"; break; + case 180: s = "\"When\" expected"; break; + case 181: s = "\"While\" expected"; break; + case 182: s = "\"With\" expected"; break; + case 183: s = "\"WithEvents\" expected"; break; + case 184: s = "\"WriteOnly\" expected"; break; + case 185: s = "\"Xor\" expected"; break; + case 186: s = "\"Rem\" expected"; break; + case 187: s = "\"Continue\" expected"; break; + case 188: s = "\"Operator\" expected"; break; + case 189: s = "\"Using\" expected"; break; + case 190: s = "\"IsNot\" expected"; break; + case 191: s = "\"SByte\" expected"; break; + case 192: s = "\"UInteger\" expected"; break; + case 193: s = "\"ULong\" expected"; break; + case 194: s = "\"UShort\" expected"; break; + case 195: s = "\"CSByte\" expected"; break; + case 196: s = "\"CUShort\" expected"; break; + case 197: s = "\"CUInt\" expected"; break; + case 198: s = "\"CULng\" expected"; break; + case 199: s = "\"Global\" expected"; break; + case 200: s = "\"TryCast\" expected"; break; + case 201: s = "\"Of\" expected"; break; + case 202: s = "\"Narrowing\" expected"; break; + case 203: s = "\"Widening\" expected"; break; + case 204: s = "\"Partial\" expected"; break; + case 205: s = "\"Custom\" expected"; break; + case 206: s = "??? expected"; break; + case 207: s = "invalid OptionStmt"; break; + case 208: s = "invalid OptionStmt"; break; + case 209: s = "invalid GlobalAttributeSection"; break; + case 210: s = "invalid GlobalAttributeSection"; break; + case 211: s = "invalid NamespaceMemberDecl"; break; + case 212: s = "invalid OptionValue"; break; + case 213: s = "invalid EndOfStmt"; break; + case 214: s = "invalid TypeModifier"; break; + case 215: s = "invalid NonModuleDeclaration"; break; + case 216: s = "invalid NonModuleDeclaration"; break; + case 217: s = "invalid Identifier"; break; + case 218: s = "invalid TypeParameterConstraints"; break; + case 219: s = "invalid TypeParameterConstraint"; break; + case 220: s = "invalid NonArrayTypeName"; break; + case 221: s = "invalid MemberModifier"; break; + case 222: s = "invalid StructureMemberDecl"; break; + case 223: s = "invalid StructureMemberDecl"; break; + case 224: s = "invalid StructureMemberDecl"; break; + case 225: s = "invalid StructureMemberDecl"; break; + case 226: s = "invalid StructureMemberDecl"; break; + case 227: s = "invalid StructureMemberDecl"; break; + case 228: s = "invalid StructureMemberDecl"; break; + case 229: s = "invalid InterfaceMemberDecl"; break; + case 230: s = "invalid InterfaceMemberDecl"; break; + case 231: s = "invalid Charset"; break; + case 232: s = "invalid IdentifierForFieldDeclaration"; break; + case 233: s = "invalid VariableDeclaratorPartAfterIdentifier"; break; + case 234: s = "invalid AccessorDecls"; break; + case 235: s = "invalid EventAccessorDeclaration"; break; + case 236: s = "invalid OverloadableOperator"; break; + case 237: s = "invalid VariableInitializer"; break; + case 238: s = "invalid EventMemberSpecifier"; break; + case 239: s = "invalid AssignmentOperator"; break; + case 240: s = "invalid SimpleNonInvocationExpression"; break; + case 241: s = "invalid SimpleNonInvocationExpression"; break; + case 242: s = "invalid SimpleNonInvocationExpression"; break; + case 243: s = "invalid SimpleNonInvocationExpression"; break; + case 244: s = "invalid InvocationExpression"; break; + case 245: s = "invalid InvocationExpression"; break; + case 246: s = "invalid PrimitiveTypeName"; break; + case 247: s = "invalid CastTarget"; break; + case 248: s = "invalid ComparisonExpr"; break; + case 249: s = "invalid Argument"; break; + case 250: s = "invalid QualIdentAndTypeArguments"; break; + case 251: s = "invalid AttributeArguments"; break; + case 252: s = "invalid ParameterModifier"; break; + case 253: s = "invalid Statement"; break; + case 254: s = "invalid LabelName"; break; + case 255: s = "invalid EmbeddedStatement"; break; + case 256: s = "invalid EmbeddedStatement"; break; + case 257: s = "invalid EmbeddedStatement"; break; + case 258: s = "invalid EmbeddedStatement"; break; + case 259: s = "invalid EmbeddedStatement"; break; + case 260: s = "invalid EmbeddedStatement"; break; + case 261: s = "invalid EmbeddedStatement"; break; + case 262: s = "invalid WhileOrUntil"; break; + case 263: s = "invalid SingleLineStatementList"; break; + case 264: s = "invalid SingleLineStatementList"; break; + case 265: s = "invalid OnErrorStatement"; break; + case 266: s = "invalid ResumeStatement"; break; + case 267: s = "invalid CaseClause"; break; + case 268: s = "invalid CaseClause"; break; + + default: s = "error " + errorNumber; break; + } + this.Errors.Error(line, col, s); + } + + private bool StartOf(int s) + { + return set[s, lexer.LookAhead.kind]; + } + + static bool[,] set = { + {T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,x, x,x,T,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,T,x, x,x,x,x, T,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,T,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,T, x,x,x,x, x,T,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,T,x, x,x,x,x, T,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,T, x,x,x,x, x,T,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,T, x,x,x,x, x,x,T,T, T,T,x,x, x,x,x,x, x,x,T,x, x,T,x,T, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,T, T,x,T,x, x,x,x,x, T,T,T,x, T,T,T,T, T,x,T,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,T,T, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,T, T,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, T,T,T,x, x,T,x,T, T,x,T,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,T,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,T, T,T,x,x, x,x,x,x, x,x,T,x, x,T,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,T,T, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, T,T,T,x, x,T,T,T, T,x,T,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x}, + {x,T,T,T, T,T,T,T, T,T,T,x, x,T,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, x,T,T,T, T,x,T,x, T,x,x,T, T,T,T,T, T,T,T,x, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,x,x,x, T,x,x,T, T,x,T,T, T,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,T, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,T, x,x,x,T, T,T,x,T, x,T,x,x, T,T,x,T, x,T,T,T, T,T,x,x, x,T,T,x, x,x,x,T, x,T,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, T,T,T,x, x,T,T,T, T,x,T,x, x,x,x,x, x,T,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,T,T,T, T,T,T,T, T,T,T,x, x,T,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, x,T,T,T, T,x,T,x, T,x,x,T, T,T,T,T, T,T,T,x, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,x,x,x, x,x,x,T, T,x,T,T, T,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,T, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,T, x,x,x,T, T,T,x,T, x,T,x,x, T,T,x,T, x,T,T,T, T,T,x,x, x,T,T,x, x,x,x,T, x,T,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,T,T,T, T,T,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, T,T,T,T, T,x,T,x, T,x,x,T, T,T,T,T, T,T,T,x, T,T,T,T, T,T,T,T, T,T,x,x, x,T,T,T, T,x,x,x, T,x,x,T, T,x,T,T, T,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,T, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,T, x,x,x,T, T,T,x,T, x,T,x,x, T,T,x,T, x,T,T,T, T,T,x,x, x,T,T,x, x,x,x,T, x,T,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, x,x,T,T, T,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, x,x,T,T, T,x,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, T,x,T,T, T,x,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,T,T,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, x,x,T,T, T,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,T, x,T,T,T, T,x,T,x, x,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,x, T,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,x,T,x, x,x,x,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,x,x,x, x,T,x,x, x,T,x,x, x,T,x,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, x,T,T,T, T,x,T,x, T,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,T, T,x,x,x, x,x,x,T, T,x,T,T, T,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,T, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,T, x,x,x,T, T,x,x,T, x,T,x,x, T,T,x,T, x,T,T,T, T,T,x,x, x,T,T,x, x,x,x,T, x,T,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x}, + {x,x,T,T, T,T,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, x,x,x,T, x,T,T,T, T,x,T,x, T,x,x,T, T,T,T,T, T,T,T,x, T,T,T,x, T,T,T,T, T,T,x,x, x,x,T,T, T,x,x,x, T,x,x,T, T,x,T,T, T,x,T,x, x,x,T,x, T,x,T,x, x,x,x,T, x,x,x,x, x,T,x,T, x,x,x,x, T,T,x,T, x,x,T,x, x,T,T,T, x,x,x,x, x,x,x,x, T,x,x,x, x,T,x,T, T,T,T,T, x,x,x,T, T,x,x,T, x,T,x,x, T,T,x,T, x,T,T,T, T,T,x,x, x,T,T,x, x,x,x,T, x,T,x,T, T,T,T,T, T,T,T,T, T,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,T,T, T,T,T,T, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x}, + {x,x,T,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,T,T,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,x, x,x,x,x, x,x,x,x, T,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, T,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x}, + {x,x,x,x, x,x,x,x, x,x,x,T, x,x,x,x, x,x,x,x, x,x,x,x, x,x,T,T, T,T,T,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,T,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x, x,x,x,x} + + }; +} // end Parser + +} \ No newline at end of file diff --git a/lib/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG b/lib/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG new file mode 100644 index 000000000..db6423b44 --- /dev/null +++ b/lib/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG @@ -0,0 +1,2917 @@ +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Text; +using ICSharpCode.NRefactory.Ast; +using ICSharpCode.NRefactory.Parser.VB; +using ASTAttribute = ICSharpCode.NRefactory.Ast.Attribute; + +COMPILER VBNET + +/* START AUTOGENERATED TOKENS SECTION */ +TOKENS + /* ----- terminal classes ----- */ + /* EOF is 0 */ + EOL + ident + LiteralString + LiteralCharacter + LiteralInteger + LiteralDouble + LiteralSingle + LiteralDecimal + LiteralDate + + /* ----- special character ----- */ + "." + "=" + "," + ":" + "+" + "-" + "*" + "/" + "\\" + "&" + "^" + "?" + "{" + "}" + "(" + ")" + ">" + "<" + "<>" + ">=" + "<=" + "<<" + ">>" + "+=" + "^=" + "-=" + "*=" + "/=" + "\\=" + "<<=" + ">>=" + "&=" + + /* ----- keywords ----- */ + "AddHandler" + "AddressOf" + "Alias" + "And" + "AndAlso" + "Ansi" + "As" + "Assembly" + "Auto" + "Binary" + "Boolean" + "ByRef" + "Byte" + "ByVal" + "Call" + "Case" + "Catch" + "CBool" + "CByte" + "CChar" + "CDate" + "CDbl" + "CDec" + "Char" + "CInt" + "Class" + "CLng" + "CObj" + "Compare" + "Const" + "CShort" + "CSng" + "CStr" + "CType" + "Date" + "Decimal" + "Declare" + "Default" + "Delegate" + "Dim" + "DirectCast" + "Do" + "Double" + "Each" + "Else" + "ElseIf" + "End" + "EndIf" + "Enum" + "Erase" + "Error" + "Event" + "Exit" + "Explicit" + "False" + "Finally" + "For" + "Friend" + "Function" + "Get" + "GetType" + "GoSub" + "GoTo" + "Handles" + "If" + "Implements" + "Imports" + "In" + "Inherits" + "Integer" + "Interface" + "Is" + "Let" + "Lib" + "Like" + "Long" + "Loop" + "Me" + "Mod" + "Module" + "MustInherit" + "MustOverride" + "MyBase" + "MyClass" + "Namespace" + "New" + "Next" + "Not" + "Nothing" + "NotInheritable" + "NotOverridable" + "Object" + "Off" + "On" + "Option" + "Optional" + "Or" + "OrElse" + "Overloads" + "Overridable" + "Overrides" + "ParamArray" + "Preserve" + "Private" + "Property" + "Protected" + "Public" + "RaiseEvent" + "ReadOnly" + "ReDim" + "RemoveHandler" + "Resume" + "Return" + "Select" + "Set" + "Shadows" + "Shared" + "Short" + "Single" + "Static" + "Step" + "Stop" + "Strict" + "String" + "Structure" + "Sub" + "SyncLock" + "Text" + "Then" + "Throw" + "To" + "True" + "Try" + "TypeOf" + "Unicode" + "Until" + "Variant" + "Wend" + "When" + "While" + "With" + "WithEvents" + "WriteOnly" + "Xor" + "Rem" + "Continue" + "Operator" + "Using" + "IsNot" + "SByte" + "UInteger" + "ULong" + "UShort" + "CSByte" + "CUShort" + "CUInt" + "CULng" + "Global" + "TryCast" + "Of" + "Narrowing" + "Widening" + "Partial" + "Custom" +/* END AUTOGENERATED TOKENS SECTION */ + + +PRODUCTIONS + +VBNET + (. + lexer.NextToken(); // get the first token + compilationUnit = new CompilationUnit(); + .) = + { EOL } + { OptionStmt } + { ImportsStmt} + { IF (IsGlobalAttrTarget()) GlobalAttributeSection } + { NamespaceMemberDecl } + EOF + . + +OptionStmt (. INode node = null; bool val = true; .) = + "Option" (. Location startPos = t.Location; .) + ( + "Explicit" [ OptionValue ] + (. node = new OptionDeclaration(OptionType.Explicit, val); .) + | + "Strict" [ OptionValue ] + (. node = new OptionDeclaration(OptionType.Strict, val); .) + | + "Compare" ( "Binary" (. node = new OptionDeclaration(OptionType.CompareBinary, val); .) + | "Text" (. node = new OptionDeclaration(OptionType.CompareText, val); .) + ) + ) + EndOfStmt + (. + if (node != null) { + node.StartLocation = startPos; + node.EndLocation = t.Location; + compilationUnit.AddChild(node); + } + .) + . + +OptionValue = + ( + "On" (. val = true; .) + | + "Off" (. val = false; .) + ) + . + +EndOfStmt = + EOL + | + ":" [ EOL ] + . + +ImportsStmt + (.List usings = new List(); + .) = + "Imports" + (. + Location startPos = t.Location; + Using u; + .) + ImportClause (. if (u != null) { usings.Add(u); } .) + { + "," ImportClause (. if (u != null) { usings.Add(u); } .) + } + EndOfStmt + (. + UsingDeclaration usingDeclaration = new UsingDeclaration(usings); + usingDeclaration.StartLocation = startPos; + usingDeclaration.EndLocation = t.Location; + compilationUnit.AddChild(usingDeclaration); + .) + . + +ImportClause + (. + string qualident = null; + TypeReference aliasedType = null; + u = null; + .) = + Qualident + [ "=" TypeName ] + (. + if (qualident != null && qualident.Length > 0) { + if (aliasedType != null) { + u = new Using(qualident, aliasedType); + } else { + u = new Using(qualident); + } + } + .) + . + +/* 6.4.2 */ +NamespaceMemberDecl + (. + ModifierList m = new ModifierList(); + AttributeSection section; + List attributes = new List(); + string qualident; + .) = + "Namespace" + (. + Location startPos = t.Location; + .) + Qualident + (. + INode node = new NamespaceDeclaration(qualident); + node.StartLocation = startPos; + compilationUnit.AddChild(node); + compilationUnit.BlockStart(node); + .) + EOL + NamespaceBody + (. + node.EndLocation = t.Location; + compilationUnit.BlockEnd(); + .) + | + { AttributeSection (. attributes.Add(section); .) } + { TypeModifier } NonModuleDeclaration + . + +/* 4.9.1 */ +TypeParameterList templates> +(. + TemplateDefinition template; +.) = + [ + IF (la.kind == Tokens.OpenParenthesis && Peek(1).kind == Tokens.Of) + "(" "Of" TypeParameter + (. + if (template != null) templates.Add(template); + .) + { + "," TypeParameter + (. + if (template != null) templates.Add(template); + .) + } + ")" + ] +. + +/* 4.9.1 */ +TypeParameter += + Identifier (. template = new TemplateDefinition(t.val, null); .) + [TypeParameterConstraints