199 changed files with 61612 additions and 1 deletions
@ -0,0 +1,436 @@
@@ -0,0 +1,436 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.Ast |
||||
{ |
||||
[CustomImplementation] |
||||
abstract class Expression : AbstractNode, INullable {} |
||||
|
||||
[CustomImplementation] |
||||
class PrimitiveExpression : Expression {} |
||||
|
||||
enum ParameterModifiers { In } |
||||
enum QueryExpressionPartitionType { } |
||||
|
||||
class ParameterDeclarationExpression : Expression { |
||||
List<AttributeSection> 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() { } |
||||
public NamedArgumentExpression(string name, Expression expression) {} |
||||
} |
||||
|
||||
class MemberInitializerExpression : Expression { |
||||
string name; |
||||
bool isKey; |
||||
Expression expression; |
||||
|
||||
public MemberInitializerExpression() { } |
||||
public MemberInitializerExpression(string name, Expression expression) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsAnonymousType", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] |
||||
class ObjectCreateExpression : Expression { |
||||
TypeReference createType; |
||||
List<Expression> parameters; |
||||
CollectionInitializerExpression objectInitializer; |
||||
|
||||
public ObjectCreateExpression(TypeReference createType, List<Expression> parameters) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsImplicitlyTyped", "return createType.IsNull || string.IsNullOrEmpty(createType.Type);")] |
||||
class ArrayCreateExpression : Expression { |
||||
TypeReference createType; |
||||
List<Expression> arguments; |
||||
CollectionInitializerExpression arrayInitializer; |
||||
|
||||
public ArrayCreateExpression(TypeReference createType) {} |
||||
public ArrayCreateExpression(TypeReference createType, List<Expression> arguments) {} |
||||
public ArrayCreateExpression(TypeReference createType, CollectionInitializerExpression arrayInitializer) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Shadow)] |
||||
class CollectionInitializerExpression : Expression { |
||||
List<Expression> createExpressions; |
||||
|
||||
public CollectionInitializerExpression() {} |
||||
public CollectionInitializerExpression(List<Expression> 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() { } |
||||
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) {} |
||||
} |
||||
|
||||
class MemberReferenceExpression : Expression |
||||
{ |
||||
Expression targetObject; |
||||
string memberName; |
||||
List<TypeReference> typeArguments; |
||||
|
||||
public MemberReferenceExpression(Expression targetObject, string memberName) {} |
||||
} |
||||
|
||||
class PointerReferenceExpression : Expression { |
||||
Expression targetObject; |
||||
string memberName; |
||||
List<TypeReference> typeArguments; |
||||
|
||||
public PointerReferenceExpression(Expression targetObject, string memberName) {} |
||||
} |
||||
|
||||
class IdentifierExpression : Expression { |
||||
string identifier; |
||||
List<TypeReference> typeArguments; |
||||
|
||||
public IdentifierExpression(string identifier) {} |
||||
} |
||||
|
||||
class InvocationExpression : Expression { |
||||
Expression targetObject; |
||||
List<Expression> arguments; |
||||
|
||||
public InvocationExpression(Expression targetObject) {} |
||||
public InvocationExpression(Expression targetObject, List<Expression> arguments) {} |
||||
} |
||||
|
||||
class ParenthesizedExpression : Expression { |
||||
Expression expression; |
||||
|
||||
public ParenthesizedExpression(Expression expression) {} |
||||
} |
||||
|
||||
class ThisReferenceExpression : Expression {} |
||||
|
||||
class TypeOfExpression : Expression { |
||||
TypeReference typeReference; |
||||
|
||||
public TypeOfExpression(TypeReference typeReference) {} |
||||
} |
||||
|
||||
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<ParameterDeclarationExpression> parameters; |
||||
BlockStatement body; |
||||
bool hasParameterList; |
||||
} |
||||
|
||||
[IncludeMember("public Location ExtendedEndLocation { get; set; }")] |
||||
class LambdaExpression : Expression { |
||||
List<ParameterDeclarationExpression> parameters; |
||||
Statement statementBody; |
||||
Expression expressionBody; |
||||
TypeReference returnType; |
||||
} |
||||
|
||||
class CheckedExpression : Expression { |
||||
Expression expression; |
||||
|
||||
public CheckedExpression(Expression expression) {} |
||||
} |
||||
|
||||
class ConditionalExpression : Expression { |
||||
Expression condition; |
||||
Expression trueExpression; |
||||
Expression falseExpression; |
||||
|
||||
public ConditionalExpression() { } |
||||
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<Expression> indexes; |
||||
|
||||
public IndexerExpression(Expression targetObject, List<Expression> 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 { |
||||
|
||||
/// <remarks>
|
||||
/// Either from or aggregate clause.
|
||||
/// </remarks>
|
||||
QueryExpressionFromClause fromClause; |
||||
|
||||
bool isQueryContinuation; |
||||
|
||||
List<QueryExpressionClause> middleClauses; |
||||
|
||||
/// <remarks>
|
||||
/// C# only.
|
||||
/// </remarks>
|
||||
QueryExpressionClause selectOrGroupClause; |
||||
} |
||||
|
||||
class QueryExpressionVB : Expression { |
||||
List<QueryExpressionClause> clauses; |
||||
} |
||||
|
||||
[ImplementNullable] |
||||
abstract class QueryExpressionClause : AbstractNode, INullable { } |
||||
|
||||
class QueryExpressionWhereClause : QueryExpressionClause { |
||||
Expression condition; |
||||
} |
||||
|
||||
class QueryExpressionLetClause : QueryExpressionClause { |
||||
[QuestionMarkDefault] |
||||
string identifier; |
||||
Expression expression; |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Shadow)] |
||||
class QueryExpressionFromClause : QueryExpressionClause { |
||||
List<CollectionRangeVariable> sources; |
||||
} |
||||
|
||||
class QueryExpressionAggregateClause : QueryExpressionClause { |
||||
CollectionRangeVariable source; |
||||
List<QueryExpressionClause> middleClauses; |
||||
List<ExpressionRangeVariable> intoVariables; |
||||
} |
||||
|
||||
[ImplementNullable] |
||||
class ExpressionRangeVariable : AbstractNode, INullable { |
||||
string identifier; |
||||
Expression expression; |
||||
TypeReference type; |
||||
} |
||||
|
||||
[ImplementNullable] |
||||
class CollectionRangeVariable : AbstractNode, INullable { |
||||
string identifier; |
||||
Expression expression; |
||||
TypeReference type; |
||||
} |
||||
|
||||
class QueryExpressionJoinClause : QueryExpressionClause { |
||||
Expression onExpression; |
||||
Expression equalsExpression; |
||||
CollectionRangeVariable source; |
||||
|
||||
string intoIdentifier; |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Shadow)] |
||||
class QueryExpressionJoinVBClause : QueryExpressionClause { |
||||
CollectionRangeVariable joinVariable; |
||||
QueryExpressionJoinVBClause subJoin; |
||||
List<QueryExpressionJoinConditionVB> conditions; |
||||
} |
||||
|
||||
class QueryExpressionPartitionVBClause : QueryExpressionClause { |
||||
Expression expression; |
||||
QueryExpressionPartitionType partitionType; |
||||
} |
||||
|
||||
class QueryExpressionJoinConditionVB : AbstractNode { |
||||
Expression leftSide; |
||||
Expression rightSide; |
||||
} |
||||
|
||||
class QueryExpressionOrderClause : QueryExpressionClause { |
||||
List<QueryExpressionOrdering> orderings; |
||||
} |
||||
|
||||
class QueryExpressionOrdering : AbstractNode { |
||||
Expression criteria; |
||||
QueryExpressionOrderingDirection direction; |
||||
} |
||||
|
||||
enum QueryExpressionOrderingDirection { |
||||
None, Ascending, Descending |
||||
} |
||||
|
||||
class QueryExpressionSelectClause : QueryExpressionClause { |
||||
Expression projection; |
||||
} |
||||
|
||||
class QueryExpressionSelectVBClause : QueryExpressionClause { |
||||
List<ExpressionRangeVariable> variables; |
||||
} |
||||
|
||||
class QueryExpressionLetVBClause : QueryExpressionClause { |
||||
List<ExpressionRangeVariable> variables; |
||||
} |
||||
|
||||
class QueryExpressionDistinctClause : QueryExpressionClause { |
||||
|
||||
} |
||||
|
||||
class QueryExpressionGroupClause : QueryExpressionClause { |
||||
Expression projection; |
||||
Expression groupBy; |
||||
} |
||||
|
||||
class QueryExpressionGroupVBClause : QueryExpressionClause { |
||||
List<ExpressionRangeVariable> groupVariables; |
||||
List<ExpressionRangeVariable> byVariables; |
||||
List<ExpressionRangeVariable> intoVariables; |
||||
} |
||||
|
||||
class QueryExpressionGroupJoinVBClause : QueryExpressionClause { |
||||
QueryExpressionJoinVBClause joinClause; |
||||
List<ExpressionRangeVariable> intoVariables; |
||||
} |
||||
|
||||
enum XmlAxisType { } |
||||
|
||||
class XmlMemberAccessExpression : Expression { |
||||
Expression targetObject; |
||||
XmlAxisType axisType; |
||||
bool isXmlIdentifier; |
||||
string identifier; |
||||
|
||||
public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier) {} |
||||
} |
||||
|
||||
abstract class XmlExpression : Expression { } |
||||
|
||||
class XmlDocumentExpression : XmlExpression { |
||||
List<XmlExpression> expressions; |
||||
} |
||||
|
||||
enum XmlContentType { } |
||||
|
||||
class XmlContentExpression : XmlExpression { |
||||
string content; |
||||
XmlContentType type; |
||||
|
||||
public XmlContentExpression(string content, XmlContentType type) {} |
||||
} |
||||
|
||||
class XmlEmbeddedExpression : XmlExpression { |
||||
Expression inlineVBExpression; |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsExpression", "return !content.IsNull;")] |
||||
[IncludeBoolProperty("NameIsExpression", "return !nameExpression.IsNull;")] |
||||
[HasChildren] |
||||
class XmlElementExpression : XmlExpression { |
||||
Expression content; |
||||
Expression nameExpression; |
||||
string xmlName; |
||||
List<XmlExpression> attributes; |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsLiteralValue", "return expressionValue.IsNull;")] |
||||
class XmlAttributeExpression : XmlExpression { |
||||
string name; |
||||
string literalValue; |
||||
bool useDoubleQuotes; |
||||
Expression expressionValue; |
||||
} |
||||
} |
@ -0,0 +1,107 @@
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.Ast |
||||
{ |
||||
[CustomImplementation, HasChildren] |
||||
class CompilationUnit : AbstractNode {} |
||||
|
||||
[HasChildren] |
||||
class NamespaceDeclaration : AbstractNode |
||||
{ |
||||
string name; |
||||
|
||||
public NamespaceDeclaration(string name) {} |
||||
} |
||||
|
||||
enum VarianceModifier { Invariant, Covariant, Contravariant }; |
||||
|
||||
class TemplateDefinition : AttributedNode |
||||
{ |
||||
[QuestionMarkDefault] |
||||
string name; |
||||
VarianceModifier varianceModifier; |
||||
List<TypeReference> bases; |
||||
|
||||
public TemplateDefinition() {} |
||||
public TemplateDefinition(string name, List<AttributeSection> attributes) : base(attributes) {} |
||||
} |
||||
|
||||
class DelegateDeclaration : AttributedNode |
||||
{ |
||||
[QuestionMarkDefault] |
||||
string name; |
||||
TypeReference returnType; |
||||
List<ParameterDeclarationExpression> parameters; |
||||
List<TemplateDefinition> templates; |
||||
|
||||
public DelegateDeclaration(Modifiers modifier, List<AttributeSection> 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<TypeReference> baseTypes; |
||||
List<TemplateDefinition> templates; |
||||
Location bodyStartLocation; |
||||
|
||||
public TypeDeclaration(Modifiers modifier, List<AttributeSection> attributes) : base(modifier, attributes) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsAlias", "return !alias.IsNull;")] |
||||
[IncludeBoolProperty("IsXml", "return xmlPrefix != null;")] |
||||
class Using : AbstractNode |
||||
{ |
||||
[QuestionMarkDefault] |
||||
string name; |
||||
TypeReference alias; |
||||
string xmlPrefix; |
||||
|
||||
public Using(string name) {} |
||||
public Using(string name, TypeReference alias) {} |
||||
public Using(string name, string xmlPrefix) {} |
||||
} |
||||
|
||||
[IncludeMember("public UsingDeclaration(string @namespace) : this(@namespace, TypeReference.Null) {}")] |
||||
[IncludeMember("public UsingDeclaration(string @namespace, TypeReference alias) {" + |
||||
" usings = new List<Using>(1);" + |
||||
" usings.Add(new Using(@namespace, alias)); " + |
||||
"}")] |
||||
[IncludeMember("public UsingDeclaration(string xmlNamespace, string prefix) {" + |
||||
" usings = new List<Using>(1);" + |
||||
" usings.Add(new Using(xmlNamespace, prefix)); " + |
||||
"}")] |
||||
class UsingDeclaration : AbstractNode |
||||
{ |
||||
List<Using> usings; |
||||
|
||||
public UsingDeclaration(List<Using> usings) {} |
||||
} |
||||
|
||||
enum OptionType { None } |
||||
|
||||
class OptionDeclaration : AbstractNode |
||||
{ |
||||
OptionType optionType; |
||||
bool optionValue; |
||||
|
||||
public OptionDeclaration(OptionType optionType, bool optionValue) {} |
||||
} |
||||
|
||||
class ExternAliasDirective : AbstractNode |
||||
{ |
||||
string name; |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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<AttributeSection> attributes; |
||||
Modifiers modifier; |
||||
|
||||
public AttributedNode() {} |
||||
public AttributedNode(List<AttributeSection> attributes) {} |
||||
public AttributedNode(Modifiers modifier, List<AttributeSection> attributes) {} |
||||
} |
||||
|
||||
abstract class ParametrizedNode : AttributedNode |
||||
{ |
||||
string name; |
||||
List<ParameterDeclarationExpression> parameters; |
||||
|
||||
public ParametrizedNode() {} |
||||
|
||||
public ParametrizedNode(Modifiers modifier, List<AttributeSection> attributes, |
||||
string name, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes) |
||||
{} |
||||
} |
||||
|
||||
[CustomImplementation] |
||||
class TypeReference : AbstractNode, INullable |
||||
{ |
||||
List<TypeReference> genericTypes; |
||||
} |
||||
|
||||
[CustomImplementation] |
||||
class InnerClassTypeReference : TypeReference |
||||
{ |
||||
TypeReference baseType; |
||||
} |
||||
|
||||
class AttributeSection : AbstractNode, INullable |
||||
{ |
||||
string attributeTarget; |
||||
List<Attribute> attributes; |
||||
} |
||||
|
||||
class Attribute : AbstractNode |
||||
{ |
||||
string name; |
||||
List<Expression> positionalArguments; |
||||
List<NamedArgumentExpression> namedArguments; |
||||
|
||||
public Attribute() {} |
||||
public Attribute(string name, List<Expression> positionalArguments, List<NamedArgumentExpression> namedArguments) {} |
||||
} |
||||
} |
@ -0,0 +1,313 @@
@@ -0,0 +1,313 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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<Statement> initializers; |
||||
Expression condition; |
||||
List<Statement> iterator; |
||||
|
||||
public ForStatement(List<Statement> initializers, Expression condition, List<Statement> 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)); |
||||
if (trueStatement != null) trueStatement.Parent = this; |
||||
}")]
|
||||
[IncludeMember(@"
|
||||
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) |
||||
: this(condition) { |
||||
this.trueStatement.Add(Statement.CheckNull(trueStatement)); |
||||
this.falseStatement.Add(Statement.CheckNull(falseStatement)); |
||||
if (trueStatement != null) trueStatement.Parent = this; |
||||
if (falseStatement != null) falseStatement.Parent = this; |
||||
}")]
|
||||
[IncludeBoolProperty("HasElseStatements", "return falseStatement.Count > 0;")] |
||||
[IncludeBoolProperty("HasElseIfSections", "return elseIfSections.Count > 0;")] |
||||
class IfElseStatement : Statement { |
||||
Expression condition; |
||||
List<Statement> trueStatement; // List for stmt : stmt : stmt ... in VB.NET
|
||||
List<Statement> falseStatement; |
||||
List<ElseIfSection> 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<VariableDeclaration> 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<SwitchSection> switchSections; |
||||
|
||||
public SwitchStatement(Expression switchExpression, List<SwitchSection> switchSections) {} |
||||
} |
||||
|
||||
class SwitchSection : BlockStatement { |
||||
List<CaseLabel> switchLabels; |
||||
|
||||
public SwitchSection() { } |
||||
public SwitchSection(List<CaseLabel> 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<CatchClause> catchClauses; |
||||
Statement finallyBlock; |
||||
|
||||
public TryCatchStatement(Statement statementBlock, List<CatchClause> 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 { |
||||
Statement pointerDeclaration; |
||||
|
||||
public FixedStatement(Statement pointerDeclaration, 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<Expression> expressions; |
||||
|
||||
public EraseStatement() {} |
||||
public EraseStatement(List<Expression> 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<Expression> nextExpressions; |
||||
// either use typeReference+variableName
|
||||
TypeReference typeReference; |
||||
string variableName; |
||||
// or use loopVariableExpression:
|
||||
Expression loopVariableExpression; |
||||
} |
||||
|
||||
class OnErrorStatement : StatementWithEmbeddedStatement { |
||||
public OnErrorStatement(Statement embeddedStatement) {} |
||||
} |
||||
|
||||
class RaiseEventStatement : Statement { |
||||
string eventName; |
||||
List<Expression> arguments; |
||||
|
||||
public RaiseEventStatement(string eventName, List<Expression> arguments) {} |
||||
} |
||||
|
||||
class ReDimStatement : Statement { |
||||
List<InvocationExpression> 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) {} |
||||
} |
||||
} |
@ -0,0 +1,235 @@
@@ -0,0 +1,235 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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<ParameterDeclarationExpression> parameters, |
||||
List<AttributeSection> attributes) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
|
||||
public ConstructorDeclaration(string name, Modifiers modifier, |
||||
List<ParameterDeclarationExpression> parameters, |
||||
ConstructorInitializer constructorInitializer, |
||||
List<AttributeSection> attributes) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
|
||||
enum ConstructorInitializerType { None } |
||||
|
||||
[ImplementNullable] |
||||
class ConstructorInitializer : AbstractNode, INullable |
||||
{ |
||||
ConstructorInitializerType constructorInitializerType; |
||||
List<Expression> arguments; |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Abstract)] |
||||
abstract class EventAddRemoveRegion : AttributedNode, INullable |
||||
{ |
||||
BlockStatement block; |
||||
List<ParameterDeclarationExpression> parameters; |
||||
|
||||
public EventAddRemoveRegion(List<AttributeSection> attributes) : base(attributes) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.CompleteAbstract)] |
||||
class EventAddRegion : EventAddRemoveRegion |
||||
{ |
||||
public EventAddRegion(List<AttributeSection> attributes) : base(attributes) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.CompleteAbstract)] |
||||
class EventRemoveRegion : EventAddRemoveRegion |
||||
{ |
||||
public EventRemoveRegion(List<AttributeSection> attributes) : base(attributes) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.CompleteAbstract)] |
||||
class EventRaiseRegion : EventAddRemoveRegion |
||||
{ |
||||
public EventRaiseRegion(List<AttributeSection> 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<VariableDeclaration> fields; |
||||
|
||||
// for enum members
|
||||
public FieldDeclaration(List<AttributeSection> attributes) : base(attributes) {} |
||||
|
||||
// for all other cases
|
||||
public FieldDeclaration(List<AttributeSection> attributes, TypeReference typeReference, Modifiers modifier) |
||||
: base(modifier, attributes) |
||||
{} |
||||
} |
||||
|
||||
abstract class MemberNode : ParametrizedNode |
||||
{ |
||||
List<InterfaceImplementation> interfaceImplementations; |
||||
TypeReference typeReference; |
||||
|
||||
public MemberNode() {} |
||||
|
||||
public MemberNode(Modifiers modifier, List<AttributeSection> attributes, |
||||
string name, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
|
||||
class MethodDeclaration : MemberNode |
||||
{ |
||||
BlockStatement body; |
||||
List<string> handlesClause; |
||||
List<TemplateDefinition> templates; |
||||
bool isExtensionMethod; |
||||
} |
||||
|
||||
enum ConversionType { None } |
||||
enum OverloadableOperatorType { None } |
||||
|
||||
[IncludeBoolProperty("IsConversionOperator", "return conversionType != ConversionType.None;")] |
||||
class OperatorDeclaration : MethodDeclaration |
||||
{ |
||||
ConversionType conversionType; |
||||
OverloadableOperatorType overloadableOperator; |
||||
} |
||||
|
||||
[IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")] |
||||
[IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")] |
||||
[IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")] |
||||
[IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")] |
||||
[IncludeBoolProperty("IsIndexer", "return (Modifier & Modifiers.Default) != 0;")] |
||||
[IncludeMember(@"
|
||||
internal PropertyDeclaration(string name, TypeReference typeReference, Modifiers modifier, List<AttributeSection> 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; |
||||
Expression initializer; |
||||
|
||||
public PropertyDeclaration(Modifiers modifier, List<AttributeSection> attributes, |
||||
string name, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Abstract)] |
||||
abstract class PropertyGetSetRegion : AttributedNode, INullable |
||||
{ |
||||
// can be null if only the definition is there (interface declaration)
|
||||
BlockStatement block; |
||||
|
||||
public PropertyGetSetRegion(BlockStatement block, List<AttributeSection> attributes) : base(attributes) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.CompleteAbstract)] |
||||
class PropertyGetRegion : PropertyGetSetRegion |
||||
{ |
||||
public PropertyGetRegion(BlockStatement block, List<AttributeSection> attributes) : base(block, attributes) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.CompleteAbstract)] |
||||
class PropertySetRegion : PropertyGetSetRegion |
||||
{ |
||||
List<ParameterDeclarationExpression> parameters; |
||||
|
||||
public PropertySetRegion(BlockStatement block, List<AttributeSection> attributes) : base(block, attributes) {} |
||||
} |
||||
|
||||
class DestructorDeclaration : AttributedNode |
||||
{ |
||||
string name; |
||||
BlockStatement body; |
||||
|
||||
public DestructorDeclaration(string name, Modifiers modifier, List<AttributeSection> 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<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes, string library, string alias, CharsetModifier charset) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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")] |
@ -0,0 +1,176 @@
@@ -0,0 +1,176 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.Reflection; |
||||
using ICSharpCode.EasyCodeDom; |
||||
|
||||
namespace NRefactoryASTGenerator |
||||
{ |
||||
public enum NullableImplementation |
||||
{ |
||||
/// <summary>
|
||||
/// Implement INullable with a virtual bool IsNull, create Null class and static instance
|
||||
/// of it.
|
||||
/// </summary>
|
||||
Default, |
||||
/// <summary>
|
||||
/// Create Null class and a static instance using the "new" modifier.
|
||||
/// </summary>
|
||||
Shadow, |
||||
/// <summary>
|
||||
/// Implement INullable with a virtual bool IsNull.
|
||||
/// </summary>
|
||||
Abstract, |
||||
/// <summary>
|
||||
/// Complete an abstract nullable implementation by creating the Null class
|
||||
/// and the static instance.
|
||||
/// </summary>
|
||||
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) { |
||||
CodeTypeDeclaration newType = new CodeTypeDeclaration("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); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,382 @@
@@ -0,0 +1,382 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the CodeExpression for any primitive value that can be expressed as literal.
|
||||
/// Also works for enumeration values.
|
||||
/// </summary>
|
||||
public static CodeExpression Prim(object literalValue) |
||||
{ |
||||
if (literalValue is Enum) { |
||||
return Type(literalValue.GetType()).Field(literalValue.ToString()); |
||||
} else { |
||||
return new CodePrimitiveExpression(literalValue); |
||||
} |
||||
} |
||||
|
||||
public static CodeTypeReferenceExpression Type(Type type) |
||||
{ |
||||
return Type(TypeRef(type)); |
||||
} |
||||
public static CodeTypeReferenceExpression Type(CodeTypeReference type) |
||||
{ |
||||
return new CodeTypeReferenceExpression(type); |
||||
} |
||||
public static CodeTypeReferenceExpression Type(string type) |
||||
{ |
||||
return Type(new CodeTypeReference(type)); |
||||
} |
||||
|
||||
public static CodeTypeOfExpression TypeOf(Type type) |
||||
{ |
||||
return TypeOf(TypeRef(type)); |
||||
} |
||||
public static CodeTypeOfExpression TypeOf(CodeTypeReference type) |
||||
{ |
||||
return new CodeTypeOfExpression(type); |
||||
} |
||||
|
||||
public static CodeObjectCreateExpression New(Type type, params CodeExpression[] arguments) |
||||
{ |
||||
return New(TypeRef(type), arguments); |
||||
} |
||||
public static CodeObjectCreateExpression New(CodeTypeReference type, params CodeExpression[] arguments) |
||||
{ |
||||
return new CodeObjectCreateExpression(type, arguments); |
||||
} |
||||
|
||||
public static CodeVariableReferenceExpression Var(string name) |
||||
{ |
||||
return new CodeVariableReferenceExpression(name); |
||||
} |
||||
|
||||
public static CodeBinaryOperatorExpression Binary(CodeExpression left, |
||||
CodeBinaryOperatorType op, |
||||
CodeExpression right) |
||||
{ |
||||
return new CodeBinaryOperatorExpression(left, op, right); |
||||
} |
||||
|
||||
public static CodeThisReferenceExpression This { |
||||
get { |
||||
return new CodeThisReferenceExpression(); |
||||
} |
||||
} |
||||
|
||||
public static CodeBaseReferenceExpression Base { |
||||
get { |
||||
return new CodeBaseReferenceExpression(); |
||||
} |
||||
} |
||||
|
||||
public static CodePropertySetValueReferenceExpression Value { |
||||
get { |
||||
return new CodePropertySetValueReferenceExpression(); |
||||
} |
||||
} |
||||
|
||||
public static CodePrimitiveExpression Null { |
||||
get { |
||||
return new CodePrimitiveExpression(null); |
||||
} |
||||
} |
||||
|
||||
public static void AddSummary(CodeTypeMember member, string summary) |
||||
{ |
||||
member.Comments.Add(new CodeCommentStatement("<summary>", true)); |
||||
member.Comments.Add(new CodeCommentStatement(summary, true)); |
||||
member.Comments.Add(new CodeCommentStatement("</summary>", 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 static class ExtensionMethods |
||||
{ |
||||
public static CodeMethodInvokeExpression InvokeMethod(this CodeExpression expr, string name, params CodeExpression[] arguments) |
||||
{ |
||||
return new CodeMethodInvokeExpression(expr, name, arguments); |
||||
} |
||||
|
||||
public static CodeCastExpression CastTo(this CodeExpression expr, Type type) |
||||
{ |
||||
return expr.CastTo(Easy.TypeRef(type)); |
||||
} |
||||
public static CodeCastExpression CastTo(this CodeExpression expr, CodeTypeReference type) |
||||
{ |
||||
return new CodeCastExpression(type, expr); |
||||
} |
||||
|
||||
public static CodeIndexerExpression Index(this CodeExpression expr, params CodeExpression[] indices) |
||||
{ |
||||
return new CodeIndexerExpression(expr, indices); |
||||
} |
||||
|
||||
public static CodeFieldReferenceExpression Field(this CodeExpression expr, string name) |
||||
{ |
||||
return new CodeFieldReferenceExpression(expr, name); |
||||
} |
||||
|
||||
public static CodePropertyReferenceExpression Property(this CodeExpression expr, string name) |
||||
{ |
||||
return new CodePropertyReferenceExpression(expr, name); |
||||
} |
||||
|
||||
public static CodeNamespace AddNamespace(this CodeCompileUnit ccu, string name) |
||||
{ |
||||
CodeNamespace n = new CodeNamespace(name); |
||||
ccu.Namespaces.Add(n); |
||||
return n; |
||||
} |
||||
|
||||
public static CodeTypeDeclaration AddType(this CodeNamespace ns, string name) |
||||
{ |
||||
CodeTypeDeclaration n = new CodeTypeDeclaration(name); |
||||
ns.Types.Add(n); |
||||
return n; |
||||
} |
||||
|
||||
public static CodeNamespaceImport AddImport(this CodeNamespace ns, string nameSpace) |
||||
{ |
||||
CodeNamespaceImport cni = new CodeNamespaceImport(nameSpace); |
||||
ns.Imports.Add(cni); |
||||
return cni; |
||||
} |
||||
|
||||
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, Type type, string name) |
||||
{ |
||||
return typeDecl.AddField(Easy.TypeRef(type), name); |
||||
} |
||||
public static CodeMemberField AddField(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name) |
||||
{ |
||||
CodeMemberField f = new CodeMemberField(type, name); |
||||
typeDecl.Members.Add(f); |
||||
return f; |
||||
} |
||||
|
||||
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, Type type, string name) |
||||
{ |
||||
return AddProperty(typeDecl, Easy.TypeRef(type), name); |
||||
} |
||||
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name) |
||||
{ |
||||
EasyProperty p = new EasyProperty(type, name); |
||||
typeDecl.Members.Add(p); |
||||
if (typeDecl.IsInterface == false) { |
||||
p.Attributes = MemberAttributes.Public | MemberAttributes.Final; |
||||
} |
||||
return p; |
||||
} |
||||
|
||||
public static EasyProperty AddProperty(this CodeTypeDeclaration typeDecl, CodeMemberField field, string name) |
||||
{ |
||||
EasyProperty p = AddProperty(typeDecl, field.Type, name); |
||||
p.Getter.Return(new CodeVariableReferenceExpression(field.Name)); |
||||
p.Attributes |= field.Attributes & MemberAttributes.Static; // copy static flag
|
||||
return p; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a method with return type <c>void</c> and attributes=Public|Final to this type.
|
||||
/// </summary>
|
||||
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, string name) |
||||
{ |
||||
return AddMethod(typeDecl, Easy.TypeRef(typeof(void)), name); |
||||
} |
||||
/// <summary>
|
||||
/// Adds a method with return type <paramref name="type"/> and attributes=Public|Final to this type.
|
||||
/// </summary>
|
||||
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, Type type, string name) |
||||
{ |
||||
return AddMethod(typeDecl, Easy.TypeRef(type), name); |
||||
} |
||||
/// <summary>
|
||||
/// Adds a method with return type <paramref name="type"/> and attributes=Public|Final to this type.
|
||||
/// </summary>
|
||||
public static EasyMethod AddMethod(this CodeTypeDeclaration typeDecl, CodeTypeReference type, string name) |
||||
{ |
||||
EasyMethod p = new EasyMethod(type, name); |
||||
typeDecl.Members.Add(p); |
||||
if (typeDecl.IsInterface == false) { |
||||
p.Attributes = MemberAttributes.Public | MemberAttributes.Final; |
||||
} |
||||
return p; |
||||
} |
||||
|
||||
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, Type type, params CodeExpression[] arguments) |
||||
{ |
||||
return Easy.AddAttribute(typeMember.CustomAttributes, Easy.TypeRef(type), arguments); |
||||
} |
||||
public static CodeAttributeDeclaration AddAttribute(this CodeTypeMember typeMember, CodeTypeReference type, params CodeExpression[] arguments) |
||||
{ |
||||
return Easy.AddAttribute(typeMember.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 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 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 CodeThrowExceptionStatement Throw(CodeExpression expr) |
||||
{ |
||||
CodeThrowExceptionStatement st = new CodeThrowExceptionStatement(expr); |
||||
csc.Add(st); |
||||
return st; |
||||
} |
||||
|
||||
public CodeAssignStatement Assign(CodeExpression lhs, CodeExpression rhs) |
||||
{ |
||||
CodeAssignStatement st = new CodeAssignStatement(lhs, rhs); |
||||
csc.Add(st); |
||||
return st; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Execute one expression as statement.
|
||||
/// </summary>
|
||||
public CodeExpressionStatement Add(CodeExpression expr) |
||||
{ |
||||
CodeExpressionStatement st = new CodeExpressionStatement(expr); |
||||
csc.Add(st); |
||||
return st; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds the statement.
|
||||
/// </summary>
|
||||
public CodeStatement Add(CodeStatement st) |
||||
{ |
||||
csc.Add(st); |
||||
return st; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Invoke a method on target as statement.
|
||||
/// </summary>
|
||||
public CodeExpressionStatement InvokeMethod(CodeExpression target, string name, params CodeExpression[] arguments) |
||||
{ |
||||
return Add(new CodeMethodInvokeExpression(target, name, arguments)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Declares a local variable.
|
||||
/// </summary>
|
||||
public CodeVariableDeclarationStatement DeclareVariable(Type type, string name) |
||||
{ |
||||
return DeclareVariable(Easy.TypeRef(type), name); |
||||
} |
||||
/// <summary>
|
||||
/// Declares a local variable.
|
||||
/// </summary>
|
||||
public CodeVariableDeclarationStatement DeclareVariable(CodeTypeReference type, string name) |
||||
{ |
||||
CodeVariableDeclarationStatement st = new CodeVariableDeclarationStatement(type, name); |
||||
csc.Add(st); |
||||
return st; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,379 @@
@@ -0,0 +1,379 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Text.RegularExpressions; |
||||
|
||||
namespace NRefactoryASTGenerator |
||||
{ |
||||
static class KeywordGenerator |
||||
{ |
||||
static readonly string baseDir = "../../../Project/Lexer/"; |
||||
static readonly string testBaseDir = "../../../Test/Lexer/"; |
||||
static readonly string parserBaseDir = "../../../Project/Parser/"; |
||||
|
||||
public static void Generate() |
||||
{ |
||||
try { |
||||
Dictionary<string, string> properties = new Dictionary<string, string>(); |
||||
Dictionary<string, string[]> sets = new Dictionary<string, string[]>(); |
||||
List<string> keywords = new List<string>(); |
||||
List<string> terminals = new List<string>(); |
||||
Dictionary<string, string> specialChars = new Dictionary<string, string>(); |
||||
|
||||
ReadFile(properties, sets, keywords, terminals, specialChars); |
||||
|
||||
GenerateFiles(properties, sets, keywords, terminals, specialChars); |
||||
} catch (Exception e) { |
||||
Debug.Print(e.ToString()); |
||||
} |
||||
} |
||||
|
||||
static void GenerateFiles(Dictionary<string, string> properties, Dictionary<string, string[]> sets, |
||||
List<string> keywords, List<string> terminals, Dictionary<string, string> specialChars) |
||||
{ |
||||
GenerateKeywords(properties, keywords); |
||||
GenerateTokens(properties, sets, keywords, terminals, specialChars); |
||||
GenerateTests(keywords, specialChars); |
||||
GenerateKeywordSection(keywords, terminals, specialChars); |
||||
} |
||||
|
||||
static void GenerateKeywordSection(List<string> keywords, List<string> terminals, Dictionary<string, string> specialChars) |
||||
{ |
||||
string sourceDir = Path.Combine(parserBaseDir, "vbnet.atg"); |
||||
StringBuilder builder = new StringBuilder(); |
||||
|
||||
builder.AppendLine("/* START AUTOGENERATED TOKENS SECTION */"); |
||||
builder.AppendLine("TOKENS"); |
||||
builder.AppendLine("\t/* ----- terminal classes ----- */"); |
||||
builder.AppendLine("\t/* EOF is 0 */"); |
||||
|
||||
foreach (string terminal in terminals) { |
||||
if (terminal == "EOF") |
||||
continue; |
||||
if (terminal == "Identifier") { |
||||
builder.AppendLine("\tident"); |
||||
continue; |
||||
} |
||||
builder.AppendLine("\t" + terminal); |
||||
} |
||||
|
||||
builder.AppendLine(); |
||||
builder.AppendLine("\t/* ----- special character ----- */"); |
||||
foreach (string specialChar in specialChars.Values) { |
||||
builder.AppendLine("\t" + specialChar); |
||||
} |
||||
|
||||
builder.AppendLine(); |
||||
builder.AppendLine("\t/* ----- keywords ----- */"); |
||||
foreach (string keyword in keywords) { |
||||
builder.AppendLine("\t\"" + keyword + "\""); |
||||
} |
||||
|
||||
builder.AppendLine("/* END AUTOGENERATED TOKENS SECTION */"); |
||||
|
||||
string[] generatedLines = builder.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); |
||||
string[] lines = File.ReadAllLines(sourceDir); |
||||
|
||||
var newContent = lines |
||||
.TakeWhile(l => l != "/* START AUTOGENERATED TOKENS SECTION */") |
||||
.Concat(generatedLines) |
||||
.Concat(lines.SkipWhile(l => l != "/* END AUTOGENERATED TOKENS SECTION */").Skip(2)) |
||||
.ToArray(); |
||||
|
||||
File.WriteAllLines(sourceDir, newContent); |
||||
} |
||||
|
||||
static void GenerateTests(List<string> keywords, Dictionary<string, string> specialChars) |
||||
{ |
||||
string sourceDir = Path.Combine(testBaseDir, "LexerTests.cs"); |
||||
using (StreamWriter writer = new StreamWriter(new FileStream(sourceDir, FileMode.Create))) { |
||||
writer.WriteLine("// this file was autogenerated by a tool."); |
||||
writer.WriteLine("using System;"); |
||||
writer.WriteLine("using System.IO;"); |
||||
writer.WriteLine("using NUnit.Framework;"); |
||||
writer.WriteLine("using ICSharpCode.NRefactory.VB.Parser;"); |
||||
writer.WriteLine("using ICSharpCode.NRefactory.VB.PrettyPrinter;"); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("namespace ICSharpCode.NRefactory.Tests.VB.Lexer"); |
||||
writer.WriteLine("{"); |
||||
writer.WriteLine("\t[TestFixture]"); |
||||
writer.WriteLine("\tpublic sealed class LexerTests"); |
||||
writer.WriteLine("\t{"); |
||||
writer.WriteLine("\t\tILexer GenerateLexer(StringReader sr)"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\treturn ParserFactory.CreateLexer(sr);"); |
||||
writer.WriteLine("\t\t}"); |
||||
for (int i = 0; i < specialChars.Values.Count; i++) { |
||||
writer.WriteLine(); |
||||
writer.WriteLine("\t\t[Test]"); |
||||
writer.WriteLine("\t\tpublic void Test{0}()", specialChars.Keys.ElementAt(i)); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tILexer lexer = GenerateLexer(new StringReader({0}));", specialChars.Values.ElementAt(i)); |
||||
writer.WriteLine("\t\t\tAssert.AreEqual(Tokens.{0}, lexer.NextToken().Kind);", specialChars.Keys.ElementAt(i)); |
||||
writer.WriteLine("\t\t}"); |
||||
} |
||||
foreach (string keyword in keywords) { |
||||
if (keyword == "Rem") |
||||
continue; |
||||
writer.WriteLine(); |
||||
writer.WriteLine("\t\t[Test]"); |
||||
writer.WriteLine("\t\tpublic void Test{0}()", UpperCaseFirst(keyword)); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tILexer lexer = GenerateLexer(new StringReader(\"{0}\"));", keyword); |
||||
writer.WriteLine("\t\t\tAssert.AreEqual(Tokens.{0}, lexer.NextToken().Kind);", UpperCaseFirst(keyword)); |
||||
writer.WriteLine("\t\t}"); |
||||
} |
||||
writer.WriteLine("\t}"); |
||||
writer.WriteLine("}"); |
||||
} |
||||
} |
||||
|
||||
static void GenerateTokens(Dictionary<string, string> properties, Dictionary<string, string[]> sets, List<string> keywords, List<string> terminals, Dictionary<string, string> specialChars) |
||||
{ |
||||
string sourceDir = Path.Combine(baseDir, "Tokens.cs"); |
||||
using (StreamWriter writer = new StreamWriter(new FileStream(sourceDir, FileMode.Create))) { |
||||
writer.WriteLine("// this file was autogenerated by a tool."); |
||||
writer.WriteLine("using System;"); |
||||
writer.WriteLine("using System.Collections;"); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("namespace {0}", properties["Namespace"]); |
||||
writer.WriteLine("{"); |
||||
writer.WriteLine("\tpublic static class Tokens"); |
||||
writer.WriteLine("\t{"); |
||||
writer.WriteLine("\t\t// ----- terminal classes -----"); |
||||
int tokenValue = 0; |
||||
foreach (string terminal in terminals) |
||||
writer.WriteToken(terminal, ref tokenValue); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("\t\t// ----- special character -----"); |
||||
foreach (string specialChar in specialChars.Keys) |
||||
writer.WriteToken(specialChar, ref tokenValue); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("\t\t// ----- keywords -----"); |
||||
foreach (string keyword in keywords) |
||||
writer.WriteToken(keyword, ref tokenValue); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("\t\tpublic const int MaxToken = {0};", tokenValue); |
||||
if (sets.Any()) { |
||||
writer.WriteLine("\t\tstatic BitArray NewSet(params int[] values)"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tBitArray bitArray = new BitArray(MaxToken);"); |
||||
writer.WriteLine("\t\t\tforeach (int val in values) {"); |
||||
writer.WriteLine("\t\t\tbitArray[val] = true;"); |
||||
writer.WriteLine("\t\t\t}"); |
||||
writer.WriteLine("\t\t\treturn bitArray;"); |
||||
writer.WriteLine("\t\t}"); |
||||
foreach (var pair in sets) { |
||||
StringBuilder builder = new StringBuilder(); |
||||
PrintList(pair.Value, builder, sets, specialChars); |
||||
writer.WriteLine("\t\tpublic static BitArray {0} = NewSet({1});", pair.Key, builder.ToString()); |
||||
} |
||||
writer.WriteLine(); |
||||
} |
||||
|
||||
// write token number --> string function.
|
||||
writer.WriteLine("\t\tstatic string[] tokenList = new string[] {"); |
||||
|
||||
writer.WriteLine("\t\t\t// ----- terminal classes -----"); |
||||
foreach (string terminal in terminals) |
||||
writer.WriteLine("\t\t\t\"<{0}>\",", terminal); |
||||
|
||||
writer.WriteLine("\t\t\t// ----- special character -----"); |
||||
foreach (string specialChar in specialChars.Values) |
||||
writer.WriteLine("\t\t\t{0},", specialChar); |
||||
|
||||
writer.WriteLine("\t\t\t// ----- keywords -----"); |
||||
foreach (string keyword in keywords) |
||||
writer.WriteLine("\t\t\t\"{0}\",", keyword); |
||||
|
||||
writer.WriteLine("\t\t};"); |
||||
|
||||
writer.WriteLine("\t\tpublic static string GetTokenString(int token)"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tif (token >= 0 && token < tokenList.Length) {"); |
||||
writer.WriteLine("\t\t\t\treturn tokenList[token];"); |
||||
writer.WriteLine("\t\t\t}"); |
||||
writer.WriteLine("\t\t\tthrow new System.NotSupportedException(\"Unknown token:\" + token);"); |
||||
writer.WriteLine("\t\t}"); |
||||
|
||||
writer.WriteLine("\t}"); |
||||
writer.WriteLine("}"); |
||||
} |
||||
} |
||||
|
||||
static void PrintList(string[] value, StringBuilder builder, Dictionary<string, string[]> sets, Dictionary<string, string> specialChars) |
||||
{ |
||||
for (int i = 0; i < value.Length; i++) { |
||||
string item = value[i]; |
||||
if (Regex.IsMatch(item, "\\\"(\\w+)\\\"")) // keywords
|
||||
builder.Append(UpperCaseFirst(item.Trim('"', ' ', '\t'))); |
||||
else if (Regex.IsMatch(item, "\\\"(\\W+)\\\"")) // special chars
|
||||
builder.Append(specialChars.Keys.ElementAt(specialChars.Values.FindIndex(it => item == it))); |
||||
else if (Regex.IsMatch(item, "@(\\w+)")) // other list
|
||||
PrintList(sets[item.Substring(1)], builder, sets, specialChars); |
||||
else |
||||
builder.Append(item); |
||||
if (i + 1 < value.Length) |
||||
builder.Append(", "); |
||||
} |
||||
} |
||||
|
||||
static void GenerateKeywords(Dictionary<string, string> properties, List<string> keywords) |
||||
{ |
||||
string sourceDir = Path.Combine(baseDir, "Keywords.cs"); |
||||
using (StreamWriter writer = new StreamWriter(new FileStream(sourceDir, FileMode.Create))) { |
||||
writer.WriteLine("// this file was autogenerated by a tool."); |
||||
writer.WriteLine("using System;"); |
||||
writer.WriteLine(); |
||||
writer.WriteLine("namespace {0}", properties["Namespace"]); |
||||
writer.WriteLine("{"); |
||||
writer.WriteLine("\tpublic static class Keywords"); |
||||
writer.WriteLine("\t{"); |
||||
writer.WriteLine("\t\tstatic readonly string[] keywordList = {"); |
||||
for (int i = 0; i < keywords.Count; i++) { |
||||
writer.Write("\t\t\t\"{0}\"", properties["UpperCaseKeywords"] == "True" ? keywords[i].ToUpperInvariant() : keywords[i]); |
||||
if (i + 1 < keywords.Count) |
||||
writer.Write(","); |
||||
writer.WriteLine(); |
||||
} |
||||
writer.WriteLine("\t\t};"); |
||||
writer.WriteLine("\t\t"); |
||||
writer.WriteLine("\t\tstatic LookupTable keywords = new LookupTable({0});", properties["UpperCaseKeywords"] == "True" ? "false" : "true"); |
||||
writer.WriteLine("\t\t"); |
||||
writer.WriteLine("\t\tstatic Keywords()"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tfor (int i = 0; i < keywordList.Length; ++i) {"); |
||||
writer.WriteLine("\t\t\t\tkeywords[keywordList[i]] = i + Tokens.{0};", UpperCaseFirst(keywords[0])); |
||||
writer.WriteLine("\t\t\t}"); |
||||
writer.WriteLine("\t\t}"); |
||||
writer.WriteLine("\t\t"); |
||||
writer.WriteLine("\t\tpublic static int GetToken(string keyword)"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\treturn keywords[keyword];"); |
||||
writer.WriteLine("\t\t}"); |
||||
writer.WriteLine("\t\t"); |
||||
writer.WriteLine("\t\tpublic static bool IsNonIdentifierKeyword(string word)"); |
||||
writer.WriteLine("\t\t{"); |
||||
writer.WriteLine("\t\t\tint token = GetToken(word);"); |
||||
writer.WriteLine("\t\t\tif (token < 0)"); |
||||
writer.WriteLine("\t\t\t\treturn false;"); |
||||
writer.WriteLine("\t\t\treturn !Tokens.IdentifierTokens[token];"); |
||||
writer.WriteLine("\t\t}"); |
||||
|
||||
writer.WriteLine("\t}"); |
||||
writer.WriteLine("}"); |
||||
|
||||
writer.Close(); |
||||
} |
||||
} |
||||
|
||||
#region input
|
||||
static void ReadFile(Dictionary<string, string> properties, Dictionary<string, string[]> sets, |
||||
List<string> keywords, List<string> terminals, Dictionary<string, string> specialChars) |
||||
{ |
||||
string sourceDir = Path.Combine(baseDir, "KeywordList.txt"); |
||||
|
||||
using (StreamReader reader = new StreamReader(new FileStream(sourceDir, FileMode.Open))) { |
||||
string line = reader.ReadLine(); |
||||
while (line != null) { |
||||
ReadProperty(properties, line); |
||||
ReadKeyword(keywords, line); |
||||
ReadSet(sets, line); |
||||
ReadTerminalSymbol(terminals, line); |
||||
ReadSpecialChar(specialChars, line); |
||||
line = reader.ReadLine(); |
||||
} |
||||
reader.Close(); |
||||
} |
||||
} |
||||
|
||||
static void ReadProperty(Dictionary<string, string> properties, string line) |
||||
{ |
||||
// properties form: $PROPERTY = "VALUE"
|
||||
Match match = Regex.Match(line, @"^\s*\$(\w+)\s*=\s*(\S+)\s*$"); |
||||
|
||||
if (match.Success) { |
||||
properties.Add(match.Groups[1].Value, match.Groups[2].Value); |
||||
} |
||||
} |
||||
|
||||
static void ReadKeyword(List<string> keywords, string line) |
||||
{ |
||||
// special keywords form: "VALUE"
|
||||
Match match = Regex.Match(line, "^\\s*\\\"(\\S+)\\s*\\\"\\s*$"); |
||||
|
||||
if (match.Success) { |
||||
keywords.Add(match.Groups[1].Value); |
||||
} |
||||
} |
||||
|
||||
static void ReadSet(Dictionary<string, string[]> sets, string line) |
||||
{ |
||||
// sets form: NAME(comma separated list)
|
||||
Match match = Regex.Match(line, @"^\s*(\w+)\s*\((.*)\)\s*$"); |
||||
|
||||
if (match.Success) { |
||||
sets.Add( |
||||
match.Groups[1].Value, |
||||
match.Groups[2].Value.Split(new[] {", "}, StringSplitOptions.None) |
||||
); |
||||
} |
||||
} |
||||
|
||||
static void ReadTerminalSymbol(List<string> terminals, string line) |
||||
{ |
||||
// special terminal classes form: name
|
||||
Match match = Regex.Match(line, @"^\s*(\w+)\s*$"); |
||||
|
||||
if (match.Success) { |
||||
terminals.Add(match.Groups[1].Value); |
||||
} |
||||
} |
||||
|
||||
static void ReadSpecialChar(Dictionary<string, string> specialChars, string line) |
||||
{ |
||||
// special characters form: name = "VALUE"
|
||||
Match match = Regex.Match(line, @"^\s*(\w+)\s*=\s*(\S+)\s*$"); |
||||
|
||||
if (match.Success) { |
||||
specialChars.Add(match.Groups[1].Value, match.Groups[2].Value); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region helpers
|
||||
static string UpperCaseFirst(string keyword) |
||||
{ |
||||
return char.ToUpperInvariant(keyword[0]) + keyword.Substring(1); |
||||
} |
||||
|
||||
static void WriteToken(this StreamWriter writer, string tokenName, ref int tokenValue) |
||||
{ |
||||
string formattedName = UpperCaseFirst(tokenName).PadRight(20); |
||||
if (tokenName == "GetType" || tokenName.ToLowerInvariant() == "equals") |
||||
writer.WriteLine("\t\tnew public const int {0} = {1};", formattedName, tokenValue); |
||||
else |
||||
writer.WriteLine("\t\tpublic const int {0} = {1};", formattedName, tokenValue); |
||||
tokenValue++; |
||||
} |
||||
|
||||
static int FindIndex<T>(this IEnumerable<T> items, Func<T, bool> f) |
||||
{ |
||||
int index = -1; |
||||
foreach (T item in items) { |
||||
index++; |
||||
if (f(item)) |
||||
return index; |
||||
} |
||||
|
||||
return -1; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,591 @@
@@ -0,0 +1,591 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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"; |
||||
|
||||
static readonly string[] lineEndings = { "\r\n", "\r", "\n" }; |
||||
|
||||
public static void Main(string[] args) |
||||
{ |
||||
string directory = "../../../Project/Dom/"; |
||||
string visitorsDir = "../../../Project/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<Type> nodeTypes = new List<Type>(); |
||||
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); }); |
||||
|
||||
CodeCompileUnit ccu = new CodeCompileUnit(); |
||||
CodeNamespace cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB.Dom"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("System.Collections.Generic"); |
||||
foreach (Type type in nodeTypes) { |
||||
if (type.GetCustomAttributes(typeof(CustomImplementationAttribute), false).Length == 0) { |
||||
CodeTypeDeclaration 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", NormalizeNewLines(writer)); |
||||
} |
||||
|
||||
ccu = new CodeCompileUnit(); |
||||
cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("ICSharpCode.NRefactory.VB.Dom"); |
||||
cns.Types.Add(CreateAstVisitorInterface(nodeTypes)); |
||||
|
||||
using (StringWriter writer = new StringWriter()) { |
||||
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); |
||||
File.WriteAllText(visitorsDir + "../IAstVisitor.cs", NormalizeNewLines(writer)); |
||||
} |
||||
|
||||
ccu = new CodeCompileUnit(); |
||||
cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB.Visitors"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("System.Collections.Generic"); |
||||
cns.AddImport("System.Diagnostics"); |
||||
cns.AddImport("ICSharpCode.NRefactory.VB.Dom"); |
||||
cns.Types.Add(CreateAstVisitorClass(nodeTypes, false)); |
||||
|
||||
using (StringWriter writer = new StringWriter()) { |
||||
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); |
||||
File.WriteAllText(visitorsDir + "AbstractAstVisitor.cs", NormalizeNewLines(writer)); |
||||
} |
||||
|
||||
ccu = new CodeCompileUnit(); |
||||
cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB.Visitors"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("System.Collections.Generic"); |
||||
cns.AddImport("System.Diagnostics"); |
||||
cns.AddImport("ICSharpCode.NRefactory.VB.Dom"); |
||||
cns.Types.Add(CreateAstVisitorClass(nodeTypes, true)); |
||||
|
||||
using (StringWriter writer = new StringWriter()) { |
||||
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); |
||||
File.WriteAllText(visitorsDir + "AbstractAstTransformer.cs", NormalizeNewLines(writer)); |
||||
} |
||||
|
||||
ccu = new CodeCompileUnit(); |
||||
cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB.Visitors"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("ICSharpCode.NRefactory.VB.Dom"); |
||||
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", |
||||
NormalizeNewLines(writer).Replace("public override object", "public sealed override object")); |
||||
} |
||||
|
||||
//NotImplementedAstVisitor
|
||||
ccu = new CodeCompileUnit(); |
||||
cns = ccu.AddNamespace("ICSharpCode.NRefactory.VB.Visitors"); |
||||
cns.AddImport("System"); |
||||
cns.AddImport("ICSharpCode.NRefactory.VB.Dom"); |
||||
cns.Types.Add(CreateNotImplementedAstVisitorClass(nodeTypes)); |
||||
|
||||
using (StringWriter writer = new StringWriter()) { |
||||
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, settings); |
||||
File.WriteAllText(visitorsDir + "NotImplementedAstVisitor.cs", NormalizeNewLines(writer)); |
||||
} |
||||
Debug.WriteLine("AST Generator done!"); |
||||
|
||||
Debug.WriteLine("start keyword list generation..."); |
||||
|
||||
KeywordGenerator.Generate(); |
||||
|
||||
Debug.WriteLine("keyword list generation done!"); |
||||
} |
||||
|
||||
static string NormalizeNewLines(StringWriter writer) |
||||
{ |
||||
return string.Join(Environment.NewLine, writer.ToString().Split(lineEndings, StringSplitOptions.None)); |
||||
} |
||||
|
||||
static CodeTypeDeclaration CreateAstVisitorInterface(List<Type> nodeTypes) |
||||
{ |
||||
CodeTypeDeclaration td = new CodeTypeDeclaration("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<Type> nodeTypes, bool transformer) |
||||
{ |
||||
CodeTypeDeclaration td = new CodeTypeDeclaration(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); |
||||
|
||||
CodeMemberField 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<CodeStatement> assertions = new List<CodeStatement>(); |
||||
string varVariableName = GetFieldName(type.Name); |
||||
CodeExpression 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, CodeExpression var, List<CodeStatement> 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, CodeExpression var, List<CodeStatement> assertions, bool transformer) |
||||
{ |
||||
CodeExpression prop = var.Property(GetPropertyName(field.Name)); |
||||
CodeExpression 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, CodeTypeDeclaration 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)) { |
||||
if (typeof(INullable).IsAssignableFrom(field.FieldType)) { |
||||
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\tif (!" +field.Name+".IsNull) "+field.Name+".Parent = this;")); |
||||
} else { |
||||
p.SetStatements.Add(new CodeSnippetStatement("\t\t\t\t"+field.Name+".Parent = this;")); |
||||
} |
||||
} |
||||
} |
||||
foreach (ConstructorInfo ctor in type.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)) { |
||||
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.VB.Dom.Attribute"); |
||||
return new CodeTypeReference(type.Name); |
||||
} else { |
||||
return new CodeTypeReference(type); |
||||
} |
||||
} |
||||
|
||||
static CodeTypeDeclaration CreateNodeTrackingAstVisitorClass(List<Type> nodeTypes) |
||||
{ |
||||
CodeTypeDeclaration td = new CodeTypeDeclaration("NodeTrackingAstVisitor"); |
||||
td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Abstract; |
||||
td.BaseTypes.Add(new CodeTypeReference("AbstractAstVisitor")); |
||||
|
||||
string comment = "<summary>\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 " + |
||||
"</summary>"; |
||||
td.Comments.Add(new CodeCommentStatement(comment, true)); |
||||
comment = "<remarks>\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 " + |
||||
"</remarks>"; |
||||
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.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; |
||||
} |
||||
|
||||
static CodeTypeDeclaration CreateNotImplementedAstVisitorClass(List<Type> nodeTypes) |
||||
{ |
||||
CodeTypeDeclaration td = new CodeTypeDeclaration("NotImplementedAstVisitor"); |
||||
td.TypeAttributes = TypeAttributes.Public | TypeAttributes.Class; |
||||
td.BaseTypes.Add(new CodeTypeReference("IAstVisitor")); |
||||
|
||||
string comment = "<summary>\n " + |
||||
"IAstVisitor implementation that always throws NotImplementedExceptions.\n " + |
||||
"</summary>"; |
||||
td.Comments.Add(new CodeCommentStatement(comment, true)); |
||||
|
||||
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(new CodeTypeReference(typeof(object)), "data"); |
||||
|
||||
m.Body.Throw(Easy.New(typeof(NotImplementedException), Easy.Prim(type.Name))); |
||||
} |
||||
} |
||||
|
||||
return td; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> |
||||
<PropertyGroup> |
||||
<OutputType>Exe</OutputType> |
||||
<RootNamespace>NRefactoryASTGenerator</RootNamespace> |
||||
<AssemblyName>NRefactoryASTGenerator</AssemblyName> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProjectGuid>{B22522AA-B5BF-4A58-AC6D-D4B45805521F}</ProjectGuid> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<WarningLevel>4</WarningLevel> |
||||
<NoWarn>0169</NoWarn> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<Optimize>False</Optimize> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<Optimize>True</Optimize> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="EasyCodeDom.cs" /> |
||||
<Compile Include="KeywordGenerator.cs" /> |
||||
<Compile Include="Main.cs" /> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="AST\Expressions.cs" /> |
||||
<Compile Include="Attributes.cs" /> |
||||
<Compile Include="AST\Node.cs" /> |
||||
<Compile Include="AST\Statements.cs" /> |
||||
<Compile Include="AST\TypeLevel.cs" /> |
||||
<Compile Include="AST\GlobalLevel.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="AST" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public abstract class AbstractNode : INode |
||||
{ |
||||
List<INode> children = new List<INode>(); |
||||
|
||||
public INode Parent { get; set; } |
||||
public Location StartLocation { get; set; } |
||||
public Location EndLocation { get; set; } |
||||
public object UserData { get; set; } |
||||
|
||||
public List<INode> Children { |
||||
get { |
||||
return children; |
||||
} |
||||
set { |
||||
Debug.Assert(value != null); |
||||
children = value; |
||||
} |
||||
} |
||||
|
||||
public virtual void AddChild(INode childNode) |
||||
{ |
||||
Debug.Assert(childNode != null); |
||||
childNode.Parent = this; |
||||
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 ? "<null>" : en.Current.ToString()); |
||||
} |
||||
} else { |
||||
return "null"; |
||||
} |
||||
|
||||
output.Append('}'); |
||||
return output.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,412 @@
@@ -0,0 +1,412 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
[Flags] |
||||
public enum Modifiers |
||||
{ |
||||
None = 0x0000, |
||||
|
||||
// Access
|
||||
Private = 0x0001, |
||||
/// <summary>C# 'internal', VB 'Friend'</summary>
|
||||
Internal = 0x0002, |
||||
Protected = 0x0004, |
||||
Public = 0x0008, |
||||
|
||||
// Scope
|
||||
Abstract = 0x0010, // == MustOverride/MustInherit
|
||||
Virtual = 0x0020, |
||||
Sealed = 0x0040, |
||||
/// <summary>C# 'static', VB 'Shared'</summary>
|
||||
Static = 0x0080, |
||||
Override = 0x0100, |
||||
/// <summary>For fields: readonly (c# and vb), for properties: get-only (vb)</summary>
|
||||
ReadOnly = 0x0200, |
||||
Const = 0x0400, |
||||
/// <summary>C# 'new', VB 'Shadows'</summary>
|
||||
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)
|
||||
|
||||
Dim = 0x100000, // VB.NET SPECIFIC, for fields/local variables only
|
||||
|
||||
/// <summary>Generated code, not part of parsed code</summary>
|
||||
Synthetic = 0x200000, |
||||
/// <summary>Only for VB properties.</summary>
|
||||
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 VarianceModifier |
||||
{ |
||||
Invariant, |
||||
Covariant, |
||||
Contravariant |
||||
}; |
||||
|
||||
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, |
||||
|
||||
/// <summary>'&' in C#, 'And' in VB.</summary>
|
||||
BitwiseAnd, |
||||
/// <summary>'|' in C#, 'Or' in VB.</summary>
|
||||
BitwiseOr, |
||||
/// <summary>'&&' in C#, 'AndAlso' in VB.</summary>
|
||||
LogicalAnd, |
||||
/// <summary>'||' in C#, 'OrElse' in VB.</summary>
|
||||
LogicalOr, |
||||
/// <summary>'^' in C#, 'Xor' in VB.</summary>
|
||||
ExclusiveOr, |
||||
|
||||
/// <summary>></summary>
|
||||
GreaterThan, |
||||
/// <summary>>=</summary>
|
||||
GreaterThanOrEqual, |
||||
/// <summary>'==' in C#, '=' in VB.</summary>
|
||||
Equality, |
||||
/// <summary>'!=' in C#, '<>' in VB.</summary>
|
||||
InEquality, |
||||
/// <summary><</summary>
|
||||
LessThan, |
||||
/// <summary><=</summary>
|
||||
LessThanOrEqual, |
||||
|
||||
/// <summary>+</summary>
|
||||
Add, |
||||
/// <summary>-</summary>
|
||||
Subtract, |
||||
/// <summary>*</summary>
|
||||
Multiply, |
||||
/// <summary>/</summary>
|
||||
Divide, |
||||
/// <summary>'%' in C#, 'Mod' in VB.</summary>
|
||||
Modulus, |
||||
/// <summary>VB-only: \</summary>
|
||||
DivideInteger, |
||||
/// <summary>VB-only: ^</summary>
|
||||
Power, |
||||
/// <summary>VB-only: &</summary>
|
||||
Concat, |
||||
|
||||
/// <summary>C#: <<</summary>
|
||||
ShiftLeft, |
||||
/// <summary>C#: >></summary>
|
||||
ShiftRight, |
||||
/// <summary>VB-only: Is</summary>
|
||||
ReferenceEquality, |
||||
/// <summary>VB-only: IsNot</summary>
|
||||
ReferenceInequality, |
||||
|
||||
/// <summary>VB-only: Like</summary>
|
||||
Like, |
||||
/// <summary>
|
||||
/// C#: ??
|
||||
/// VB: IF(x, y)
|
||||
/// </summary>
|
||||
NullCoalescing, |
||||
|
||||
/// <summary>VB-only: !</summary>
|
||||
DictionaryAccess |
||||
} |
||||
|
||||
public enum CastType |
||||
{ |
||||
/// <summary>
|
||||
/// direct cast (C#, VB "DirectCast")
|
||||
/// </summary>
|
||||
Cast, |
||||
/// <summary>
|
||||
/// try cast (C# "as", VB "TryCast")
|
||||
/// </summary>
|
||||
TryCast, |
||||
/// <summary>
|
||||
/// converting cast (VB "CType")
|
||||
/// </summary>
|
||||
Conversion, |
||||
/// <summary>
|
||||
/// primitive converting cast (VB "CString" etc.)
|
||||
/// </summary>
|
||||
PrimitiveConversion |
||||
} |
||||
|
||||
public enum UnaryOperatorType |
||||
{ |
||||
None, |
||||
Not, |
||||
BitNot, |
||||
|
||||
Minus, |
||||
Plus, |
||||
|
||||
Increment, |
||||
Decrement, |
||||
|
||||
PostIncrement, |
||||
PostDecrement, |
||||
|
||||
/// <summary>Dereferencing pointer</summary>
|
||||
Dereference, |
||||
/// <summary>Get address of</summary>
|
||||
AddressOf |
||||
} |
||||
|
||||
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, |
||||
|
||||
UnaryPlus, |
||||
UnaryMinus, |
||||
|
||||
Not, |
||||
BitNot, |
||||
|
||||
BitwiseAnd, |
||||
BitwiseOr, |
||||
ExclusiveOr, |
||||
|
||||
ShiftLeft, |
||||
ShiftRight, |
||||
|
||||
GreaterThan, |
||||
GreaterThanOrEqual, |
||||
Equality, |
||||
InEquality, |
||||
LessThan, |
||||
LessThanOrEqual, |
||||
|
||||
Increment, |
||||
Decrement, |
||||
|
||||
IsTrue, |
||||
IsFalse, |
||||
|
||||
// VB specific
|
||||
Like, |
||||
Power, |
||||
CType, |
||||
DivideInteger |
||||
} |
||||
|
||||
///<summary>
|
||||
/// Charset types, used in external methods
|
||||
/// declarations (VB only).
|
||||
///</summary>
|
||||
public enum CharsetModifier |
||||
{ |
||||
None, |
||||
Auto, |
||||
Unicode, |
||||
Ansi |
||||
} |
||||
|
||||
///<summary>
|
||||
/// Compare type, used in the <c>Option Compare</c>
|
||||
/// pragma (VB only).
|
||||
///</summary>
|
||||
public enum OptionType |
||||
{ |
||||
None, |
||||
Explicit, |
||||
Strict, |
||||
CompareBinary, |
||||
CompareText, |
||||
Infer |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Specifies the ordering direction of a QueryExpressionOrdering node.
|
||||
/// </summary>
|
||||
public enum QueryExpressionOrderingDirection |
||||
{ |
||||
None, |
||||
Ascending, |
||||
Descending |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Specifies the partition type for a VB.NET
|
||||
/// query expression.
|
||||
/// </summary>
|
||||
public enum QueryExpressionPartitionType |
||||
{ |
||||
Take, |
||||
TakeWhile, |
||||
Skip, |
||||
SkipWhile |
||||
} |
||||
|
||||
public enum XmlAxisType |
||||
{ |
||||
Element, // .
|
||||
Attribute, // .@
|
||||
Descendents // ...
|
||||
} |
||||
|
||||
public enum XmlContentType |
||||
{ |
||||
Comment, |
||||
Text, |
||||
CData, |
||||
ProcessingInstruction |
||||
} |
||||
} |
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public class BlockStatement : 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]"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public class CompilationUnit : AbstractNode |
||||
{ |
||||
// Children in C#: UsingAliasDeclaration, UsingDeclaration, AttributeSection, NamespaceDeclaration
|
||||
// Children in VB: OptionStatements, ImportsStatement, AttributeSection, NamespaceDeclaration
|
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitCompilationUnit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[CompilationUnit]"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
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; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the existing expression plus the specified integer value.
|
||||
/// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression
|
||||
/// (and thus its parent property is modified).
|
||||
/// </summary>
|
||||
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]"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public class LocalVariableDeclaration : Statement |
||||
{ |
||||
TypeReference typeReference; |
||||
Modifiers modifier = Modifiers.None; |
||||
List<VariableDeclaration> variables = new List<VariableDeclaration>(); |
||||
|
||||
public TypeReference TypeReference { |
||||
get { |
||||
return typeReference; |
||||
} |
||||
set { |
||||
typeReference = TypeReference.CheckNull(value); |
||||
if (!typeReference.IsNull) typeReference.Parent = this; |
||||
} |
||||
} |
||||
|
||||
public Modifiers Modifier { |
||||
get { |
||||
return modifier; |
||||
} |
||||
set { |
||||
modifier = value; |
||||
} |
||||
} |
||||
|
||||
public List<VariableDeclaration> 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)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.PrettyPrinter; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public class PrimitiveExpression : Expression |
||||
{ |
||||
string stringValue; |
||||
|
||||
public Parser.LiteralFormat LiteralFormat { get; set; } |
||||
public object Value { get; set; } |
||||
|
||||
public string StringValue { |
||||
get { |
||||
if (stringValue == null) |
||||
return VBNetOutputVisitor.ToVBNetString(this); |
||||
else |
||||
return stringValue; |
||||
} |
||||
set { |
||||
stringValue = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public PrimitiveExpression(object val) |
||||
{ |
||||
this.Value = val; |
||||
} |
||||
|
||||
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}]", |
||||
this.StringValue, |
||||
this.Value, |
||||
this.Value == null ? "null" : this.Value.GetType().FullName |
||||
); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
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]"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,51 @@
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public interface INode |
||||
{ |
||||
INode Parent { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
List<INode> Children { |
||||
get; |
||||
} |
||||
|
||||
Location StartLocation { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
Location EndLocation { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
object UserData { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Visits all children
|
||||
/// </summary>
|
||||
/// <param name="visitor">The visitor to accept</param>
|
||||
/// <param name="data">Additional data for the visitor</param>
|
||||
/// <returns>The paremeter <paramref name="data"/></returns>
|
||||
object AcceptChildren(IAstVisitor visitor, object data); |
||||
|
||||
/// <summary>
|
||||
/// Accept the visitor
|
||||
/// </summary>
|
||||
/// <param name="visitor">The visitor to accept</param>
|
||||
/// <param name="data">Additional data for the visitor</param>
|
||||
/// <returns>The value the visitor returns after the visit</returns>
|
||||
object AcceptVisitor(IAstVisitor visitor, object data); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
public interface INullable |
||||
{ |
||||
bool IsNull { |
||||
get; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,427 @@
@@ -0,0 +1,427 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Globalization; |
||||
using System.Runtime.InteropServices; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Dom |
||||
{ |
||||
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 = ""; |
||||
int pointerNestingLevel; |
||||
int[] rankSpecifier; |
||||
List<TypeReference> genericTypes = new List<TypeReference>(); |
||||
|
||||
#region Static primitive type list
|
||||
static Dictionary<string, string> types = new Dictionary<string, string>(); |
||||
static Dictionary<string, string> vbtypes = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase); |
||||
static Dictionary<string, string> typesReverse = new Dictionary<string, string>(); |
||||
static Dictionary<string, string> vbtypesReverse = new Dictionary<string, string>(); |
||||
|
||||
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<string, string> pair in types) { |
||||
typesReverse.Add(pair.Value, pair.Key); |
||||
} |
||||
foreach (KeyValuePair<string, string> pair in vbtypes) { |
||||
vbtypesReverse.Add(pair.Value, pair.Key); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a shortname=>full name dictionary of C# types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesCSharp { |
||||
get { return types; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a shortname=>full name dictionary of VB types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesVB { |
||||
get { return vbtypes; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a full name=>shortname dictionary of C# types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> PrimitiveTypesCSharpReverse { |
||||
get { return typesReverse; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a full name=>shortname dictionary of VB types.
|
||||
/// </summary>
|
||||
public static IDictionary<string, string> 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); |
||||
CopyFields(this, c); |
||||
return c; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Copies the pointerNestingLevel, RankSpecifier, GenericTypes and IsGlobal flag
|
||||
/// from <paramref name="from"/> to <paramref name="to"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If <paramref name="to"/> already contains generics, the new generics are appended to the list.
|
||||
/// </remarks>
|
||||
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; |
||||
to.IsKeyword = from.IsKeyword; |
||||
} |
||||
|
||||
public string Type { |
||||
get { |
||||
return type; |
||||
} |
||||
set { |
||||
Debug.Assert(value != null); |
||||
type = value ?? "?"; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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 int PointerNestingLevel { |
||||
get { |
||||
return pointerNestingLevel; |
||||
} |
||||
set { |
||||
Debug.Assert(this.IsNull == false); |
||||
pointerNestingLevel = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 {}.
|
||||
/// </summary>
|
||||
public int[] RankSpecifier { |
||||
get { |
||||
return rankSpecifier; |
||||
} |
||||
set { |
||||
Debug.Assert(this.IsNull == false); |
||||
rankSpecifier = value; |
||||
} |
||||
} |
||||
|
||||
public List<TypeReference> 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; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the type reference had a "global::" prefix.
|
||||
/// </summary>
|
||||
public bool IsGlobal { |
||||
get; set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the type reference was using a language keyword.
|
||||
/// </summary>
|
||||
public bool IsKeyword { |
||||
get; set; |
||||
} |
||||
|
||||
public TypeReference(string type) |
||||
{ |
||||
this.Type = type; |
||||
} |
||||
|
||||
public TypeReference(string type, bool isKeyword) |
||||
{ |
||||
this.Type = type; |
||||
this.IsKeyword = isKeyword; |
||||
} |
||||
|
||||
public TypeReference(string type, List<TypeReference> 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<TypeReference> genericTypes) |
||||
{ |
||||
Debug.Assert(type != null); |
||||
this.type = 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.type != b.type) return false; |
||||
if (a.IsKeyword != b.IsKeyword) return false; |
||||
if (a.IsGlobal != b.IsGlobal) 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 TypeReference Clone() |
||||
{ |
||||
return this; |
||||
} |
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullTypeReference]"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
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, new List<TypeReference>()); |
||||
CopyFields(this, c); |
||||
return c; |
||||
} |
||||
|
||||
public InnerClassTypeReference(TypeReference outerClass, string innerType, List<TypeReference> innerGenericTypes) |
||||
: base(innerType, innerGenericTypes) |
||||
{ |
||||
this.baseType = outerClass; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.VisitInnerClassTypeReference(this, data); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
/// </summary>
|
||||
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 baseType.ToString() + "+" + base.ToString(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.DomBuilder |
||||
{ |
||||
/// <summary>
|
||||
/// Extension methods for NRefactory.Ast.Expression.
|
||||
/// </summary>
|
||||
public static class ExpressionBuilder |
||||
{ |
||||
public static IdentifierExpression Identifier(string identifier) |
||||
{ |
||||
return new IdentifierExpression(identifier); |
||||
} |
||||
|
||||
public static MemberReferenceExpression Member(this Expression targetObject, string memberName) |
||||
{ |
||||
if (targetObject == null) |
||||
throw new ArgumentNullException("targetObject"); |
||||
return new MemberReferenceExpression(targetObject, memberName); |
||||
} |
||||
|
||||
public static InvocationExpression Call(this Expression callTarget, string methodName, params Expression[] arguments) |
||||
{ |
||||
if (callTarget == null) |
||||
throw new ArgumentNullException("callTarget"); |
||||
return Call(Member(callTarget, methodName), arguments); |
||||
} |
||||
|
||||
public static InvocationExpression Call(this Expression callTarget, params Expression[] arguments) |
||||
{ |
||||
if (callTarget == null) |
||||
throw new ArgumentNullException("callTarget"); |
||||
if (arguments == null) |
||||
throw new ArgumentNullException("arguments"); |
||||
return new InvocationExpression(callTarget, new List<Expression>(arguments)); |
||||
} |
||||
|
||||
public static ObjectCreateExpression New(this TypeReference createType, params Expression[] arguments) |
||||
{ |
||||
if (createType == null) |
||||
throw new ArgumentNullException("createType"); |
||||
if (arguments == null) |
||||
throw new ArgumentNullException("arguments"); |
||||
return new ObjectCreateExpression(createType, new List<Expression>(arguments)); |
||||
} |
||||
|
||||
public static Expression CreateDefaultValueForType(TypeReference type) |
||||
{ |
||||
if (type != null && !type.IsArrayType) { |
||||
switch (type.Type) { |
||||
case "System.SByte": |
||||
case "System.Byte": |
||||
case "System.Int16": |
||||
case "System.UInt16": |
||||
case "System.Int32": |
||||
case "System.UInt32": |
||||
case "System.Int64": |
||||
case "System.UInt64": |
||||
case "System.Single": |
||||
case "System.Double": |
||||
return new PrimitiveExpression(0, "0"); |
||||
case "System.Char": |
||||
return new PrimitiveExpression('\0', "'\\0'"); |
||||
case "System.Object": |
||||
case "System.String": |
||||
return new PrimitiveExpression(null, "null"); |
||||
case "System.Boolean": |
||||
return new PrimitiveExpression(false, "false"); |
||||
default: |
||||
return new DefaultValueExpression(type); |
||||
} |
||||
} else { |
||||
return new PrimitiveExpression(null, "null"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Just calls the BinaryOperatorExpression constructor,
|
||||
/// but being an extension method; this allows for a nicer
|
||||
/// infix syntax in some cases.
|
||||
/// </summary>
|
||||
public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right) |
||||
{ |
||||
return new BinaryOperatorExpression(left, op, right); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.DomBuilder |
||||
{ |
||||
/// <summary>
|
||||
/// Extension methods for NRefactory.Ast.Expression.
|
||||
/// </summary>
|
||||
public static class StatementBuilder |
||||
{ |
||||
public static void AddStatement(this BlockStatement block, Statement statement) |
||||
{ |
||||
if (block == null) |
||||
throw new ArgumentNullException("block"); |
||||
if (statement == null) |
||||
throw new ArgumentNullException("statement"); |
||||
block.AddChild(statement); |
||||
statement.Parent = block; |
||||
} |
||||
|
||||
public static void AddStatement(this BlockStatement block, Expression expressionStatement) |
||||
{ |
||||
if (expressionStatement == null) |
||||
throw new ArgumentNullException("expressionStatement"); |
||||
AddStatement(block, new ExpressionStatement(expressionStatement)); |
||||
} |
||||
|
||||
public static void Throw(this BlockStatement block, Expression expression) |
||||
{ |
||||
if (expression == null) |
||||
throw new ArgumentNullException("expression"); |
||||
AddStatement(block, new ThrowStatement(expression)); |
||||
} |
||||
|
||||
public static void Return(this BlockStatement block, Expression expression) |
||||
{ |
||||
if (expression == null) |
||||
throw new ArgumentNullException("expression"); |
||||
AddStatement(block, new ReturnStatement(expression)); |
||||
} |
||||
|
||||
public static void Assign(this BlockStatement block, Expression left, Expression right) |
||||
{ |
||||
if (left == null) |
||||
throw new ArgumentNullException("left"); |
||||
if (right == null) |
||||
throw new ArgumentNullException("right"); |
||||
AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public interface IEnvironmentInformationProvider |
||||
{ |
||||
bool HasField(string reflectionTypeName, int typeParameterCount, string fieldName); |
||||
} |
||||
|
||||
sealed class DummyEnvironmentInformationProvider : IEnvironmentInformationProvider |
||||
{ |
||||
internal static readonly IEnvironmentInformationProvider Instance = new DummyEnvironmentInformationProvider(); |
||||
|
||||
public bool HasField(string reflectionTypeName, int typeParameterCount, string fieldName) |
||||
{ |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,278 @@
@@ -0,0 +1,278 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.1
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ICSharpCode.NRefactory.VB { |
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
|
||||
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.VB.Dom.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 VisitCollectionRangeVariable(CollectionRangeVariable collectionRangeVariable, 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 VisitExpressionRangeVariable(ExpressionRangeVariable expressionRangeVariable, object data); |
||||
|
||||
object VisitExpressionStatement(ExpressionStatement expressionStatement, object data); |
||||
|
||||
object VisitExternAliasDirective(ExternAliasDirective externAliasDirective, 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 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 VisitMemberInitializerExpression(MemberInitializerExpression memberInitializerExpression, 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 VisitQueryExpressionAggregateClause(QueryExpressionAggregateClause queryExpressionAggregateClause, object data); |
||||
|
||||
object VisitQueryExpressionDistinctClause(QueryExpressionDistinctClause queryExpressionDistinctClause, object data); |
||||
|
||||
object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data); |
||||
|
||||
object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data); |
||||
|
||||
object VisitQueryExpressionGroupJoinVBClause(QueryExpressionGroupJoinVBClause queryExpressionGroupJoinVBClause, object data); |
||||
|
||||
object VisitQueryExpressionGroupVBClause(QueryExpressionGroupVBClause queryExpressionGroupVBClause, object data); |
||||
|
||||
object VisitQueryExpressionJoinClause(QueryExpressionJoinClause queryExpressionJoinClause, object data); |
||||
|
||||
object VisitQueryExpressionJoinConditionVB(QueryExpressionJoinConditionVB queryExpressionJoinConditionVB, object data); |
||||
|
||||
object VisitQueryExpressionJoinVBClause(QueryExpressionJoinVBClause queryExpressionJoinVBClause, object data); |
||||
|
||||
object VisitQueryExpressionLetClause(QueryExpressionLetClause queryExpressionLetClause, object data); |
||||
|
||||
object VisitQueryExpressionLetVBClause(QueryExpressionLetVBClause queryExpressionLetVBClause, object data); |
||||
|
||||
object VisitQueryExpressionOrderClause(QueryExpressionOrderClause queryExpressionOrderClause, object data); |
||||
|
||||
object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data); |
||||
|
||||
object VisitQueryExpressionPartitionVBClause(QueryExpressionPartitionVBClause queryExpressionPartitionVBClause, object data); |
||||
|
||||
object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data); |
||||
|
||||
object VisitQueryExpressionSelectVBClause(QueryExpressionSelectVBClause queryExpressionSelectVBClause, object data); |
||||
|
||||
object VisitQueryExpressionVB(QueryExpressionVB queryExpressionVB, 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 VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data); |
||||
|
||||
object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data); |
||||
|
||||
object VisitXmlDocumentExpression(XmlDocumentExpression xmlDocumentExpression, object data); |
||||
|
||||
object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data); |
||||
|
||||
object VisitXmlEmbeddedExpression(XmlEmbeddedExpression xmlEmbeddedExpression, object data); |
||||
|
||||
object VisitXmlMemberAccessExpression(XmlMemberAccessExpression xmlMemberAccessExpression, object data); |
||||
|
||||
object VisitYieldStatement(YieldStatement yieldStatement, object data); |
||||
} |
||||
} |
@ -0,0 +1,151 @@
@@ -0,0 +1,151 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{7B82B671-419F-45F4-B778-D9286F996EFA}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.NRefactory.VB</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.VB</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<DebugSymbols>True</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<Optimize>False</Optimize> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="DomBuilder\ExpressionBuilder.cs" /> |
||||
<Compile Include="DomBuilder\StatementBuilder.cs" /> |
||||
<Compile Include="Dom\AbstractNode.cs" /> |
||||
<Compile Include="Dom\Enums.cs" /> |
||||
<Compile Include="Dom\General\BlockStatement.cs" /> |
||||
<Compile Include="Dom\General\CompilationUnit.cs" /> |
||||
<Compile Include="Dom\General\Expression.cs" /> |
||||
<Compile Include="Dom\General\LocalVariableDeclaration.cs" /> |
||||
<Compile Include="Dom\General\PrimitiveExpression.cs" /> |
||||
<Compile Include="Dom\General\Statement.cs" /> |
||||
<Compile Include="Dom\Generated.cs" /> |
||||
<Compile Include="Dom\INode.cs" /> |
||||
<Compile Include="Dom\INullable.cs" /> |
||||
<Compile Include="Dom\TypeReference.cs" /> |
||||
<Compile Include="EnvironmentInformationProvider.cs" /> |
||||
<Compile Include="IAstVisitor.cs" /> |
||||
<Compile Include="Lexer\AbstractLexer.cs" /> |
||||
<Compile Include="Lexer\Block.cs" /> |
||||
<Compile Include="Lexer\ExpressionFinder.cs" /> |
||||
<Compile Include="Lexer\ExpressionFinderState.cs" /> |
||||
<Compile Include="Lexer\Extensions.cs" /> |
||||
<Compile Include="Lexer\ILexer.cs" /> |
||||
<Compile Include="Lexer\Keywords.cs" /> |
||||
<Compile Include="Lexer\LATextReader.cs" /> |
||||
<Compile Include="Lexer\Lexer.cs" /> |
||||
<Compile Include="Lexer\LexerMemento.cs" /> |
||||
<Compile Include="Lexer\LookupTable.cs" /> |
||||
<Compile Include="Lexer\Parser.cs"> |
||||
<DependentUpon>ExpressionFinder.atg</DependentUpon> |
||||
</Compile> |
||||
<Compile Include="Lexer\SavepointEventArgs.cs" /> |
||||
<Compile Include="Lexer\Special\BlankLine.cs" /> |
||||
<Compile Include="Lexer\Special\Comment.cs" /> |
||||
<Compile Include="Lexer\Special\CommentType.cs" /> |
||||
<Compile Include="Lexer\Special\ISpecial.cs" /> |
||||
<Compile Include="Lexer\Special\PreProcessingDirective.cs" /> |
||||
<Compile Include="Lexer\Special\SpecialTracker.cs" /> |
||||
<Compile Include="Lexer\Special\TagComment.cs" /> |
||||
<Compile Include="Lexer\Token.cs" /> |
||||
<Compile Include="Lexer\Tokens.cs" /> |
||||
<Compile Include="Lexer\VBLexerMemento.cs" /> |
||||
<Compile Include="Lexer\XmlModeInfo.cs" /> |
||||
<Compile Include="Location.cs" /> |
||||
<Compile Include="OperatorPrecedence.cs" /> |
||||
<Compile Include="ParserFactory.cs" /> |
||||
<Compile Include="Parser\AbstractParser.cs" /> |
||||
<Compile Include="Parser\Errors.cs" /> |
||||
<Compile Include="Parser\IParser.cs" /> |
||||
<Compile Include="Parser\ModifierList.cs" /> |
||||
<Compile Include="Parser\ParamModifierList.cs" /> |
||||
<Compile Include="Parser\Parser.cs" /> |
||||
<Compile Include="Parser\VBNetParser.cs" /> |
||||
<Compile Include="PrettyPrinter\AbstractOutputFormatter.cs" /> |
||||
<Compile Include="PrettyPrinter\AbstractPrettyPrintOptions.cs" /> |
||||
<Compile Include="PrettyPrinter\IOutputAstVisitor.cs" /> |
||||
<Compile Include="PrettyPrinter\SpecialNodesInserter.cs" /> |
||||
<Compile Include="PrettyPrinter\VBNet\VBNetOutputFormatter.cs" /> |
||||
<Compile Include="PrettyPrinter\VBNet\VBNetOutputVisitor.cs" /> |
||||
<Compile Include="PrettyPrinter\VBNet\VBNetPrettyPrintOptions.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="SnippetParser.cs" /> |
||||
<Compile Include="Visitors\AbstractAstTransformer.cs" /> |
||||
<Compile Include="Visitors\AbstractASTVisitor.cs" /> |
||||
<Compile Include="Visitors\CodeDOMOutputVisitor.cs" /> |
||||
<Compile Include="Visitors\CodeDOMVerboseOutputGenerator.cs" /> |
||||
<Compile Include="Visitors\LookupTableVisitor.cs" /> |
||||
<Compile Include="Visitors\NodeTrackingAstVisitor.cs" /> |
||||
<Compile Include="Visitors\NotImplementedAstVisitor.cs" /> |
||||
<Compile Include="Visitors\PrefixFieldsVisitor.cs" /> |
||||
<Compile Include="Visitors\RenameIdentifierVisitor.cs" /> |
||||
<Compile Include="Visitors\SetParentVisitor.cs" /> |
||||
<Compile Include="Visitors\SetRegionInclusionVisitor.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="Dom" /> |
||||
<Folder Include="DomBuilder" /> |
||||
<Folder Include="Dom\General" /> |
||||
<Folder Include="Lexer" /> |
||||
<Folder Include="Lexer\Special" /> |
||||
<Folder Include="Parser" /> |
||||
<Folder Include="Parser\Frames" /> |
||||
<Folder Include="PrettyPrinter" /> |
||||
<Folder Include="PrettyPrinter\VBNet" /> |
||||
<Folder Include="Visitors" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj"> |
||||
<Project>{3B2A5653-EC97-4001-BB9B-D90F1AF2C371}</Project> |
||||
<Name>ICSharpCode.NRefactory</Name> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<None Include="Lexer\ExpressionFinder.atg"> |
||||
<Generator>CocoParserGenerator</Generator> |
||||
<CustomToolNamespace>ICSharpCode.NRefactory.VB.Parser</CustomToolNamespace> |
||||
</None> |
||||
<None Include="Lexer\KeywordList.txt" /> |
||||
<None Include="Lexer\PushParser.frame"> |
||||
<DependentUpon>ExpressionFinder.atg</DependentUpon> |
||||
</None> |
||||
<None Include="Parser\Frames\Parser.frame" /> |
||||
<None Include="Parser\Frames\Scanner.frame" /> |
||||
<None Include="Parser\Frames\SharpCoco.exe" /> |
||||
<None Include="Parser\Frames\trace.txt" /> |
||||
<None Include="Parser\gen.bat" /> |
||||
<None Include="Parser\vbnet.atg" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,386 @@
@@ -0,0 +1,386 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// This is the base class for the C# and VB.NET lexer
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1708:IdentifiersShouldDifferByMoreThanCase")] |
||||
internal abstract class AbstractLexer : ILexer |
||||
{ |
||||
LATextReader reader; |
||||
int col = 1; |
||||
int line = 1; |
||||
|
||||
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<TagComment> tagComments = new List<TagComment>(); |
||||
protected StringBuilder sb = new StringBuilder(); |
||||
protected SpecialTracker specialTracker = new SpecialTracker(); |
||||
|
||||
// used for the original value of strings (with escape sequences).
|
||||
protected StringBuilder originalValue = new StringBuilder(); |
||||
|
||||
public bool SkipAllComments { get; set; } |
||||
public bool EvaluateConditionalCompilation { get; set; } |
||||
public virtual IDictionary<string, object> ConditionalCompilationSymbols { |
||||
get { throw new NotSupportedException(); } |
||||
} |
||||
|
||||
protected static IEnumerable<string> GetSymbols (string symbols) |
||||
{ |
||||
if (!string.IsNullOrEmpty(symbols)) { |
||||
foreach (string symbol in symbols.Split (';', ' ', '\t')) { |
||||
string s = symbol.Trim (); |
||||
if (s.Length == 0) |
||||
continue; |
||||
yield return s; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public virtual void SetConditionalCompilationSymbols (string symbols) |
||||
{ |
||||
throw new NotSupportedException (); |
||||
} |
||||
|
||||
protected int Line { |
||||
get { |
||||
return line; |
||||
} |
||||
} |
||||
protected int Col { |
||||
get { |
||||
return col; |
||||
} |
||||
} |
||||
|
||||
protected bool recordRead = false; |
||||
protected StringBuilder recordedText = new StringBuilder (); |
||||
|
||||
protected int ReaderRead() |
||||
{ |
||||
int val = reader.Read(); |
||||
if (recordRead && val >= 0) |
||||
recordedText.Append ((char)val); |
||||
if ((val == '\r' && reader.Peek() != '\n') || val == '\n') { |
||||
++line; |
||||
col = 1; |
||||
LineBreak(); |
||||
} else if (val >= 0) { |
||||
col++; |
||||
} |
||||
return val; |
||||
} |
||||
|
||||
protected int ReaderPeek() |
||||
{ |
||||
return reader.Peek(); |
||||
} |
||||
|
||||
protected int ReaderPeek(int step) |
||||
{ |
||||
return reader.Peek(step); |
||||
} |
||||
|
||||
protected void ReaderSkip(int steps) |
||||
{ |
||||
for (int i = 0; i < steps; i++) { |
||||
ReaderRead(); |
||||
} |
||||
} |
||||
|
||||
protected string ReaderPeekString(int length) |
||||
{ |
||||
StringBuilder builder = new StringBuilder(); |
||||
|
||||
for (int i = 0; i < length; i++) { |
||||
int peek = ReaderPeek(i); |
||||
if (peek != -1) |
||||
builder.Append((char)peek); |
||||
} |
||||
|
||||
return builder.ToString(); |
||||
} |
||||
|
||||
public void SetInitialLocation(Location location) |
||||
{ |
||||
if (lastToken != null || curToken != null || peekToken != null) |
||||
throw new InvalidOperationException(); |
||||
this.line = location.Line; |
||||
this.col = location.Column; |
||||
} |
||||
|
||||
public Errors Errors { |
||||
get { |
||||
return errors; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the comments that had been read and containing tag key words.
|
||||
/// </summary>
|
||||
public List<TagComment> TagComments { |
||||
get { |
||||
return tagComments; |
||||
} |
||||
} |
||||
|
||||
public SpecialTracker SpecialTracker { |
||||
get { |
||||
return specialTracker; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Special comment tags are tags like TODO, HACK or UNDONE which are read by the lexer and stored in <see cref="TagComments"/>.
|
||||
/// </summary>
|
||||
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); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The current Token. <seealso cref="ICSharpCode.NRefactory.VB.Parser.Token"/>
|
||||
/// </summary>
|
||||
public Token Token { |
||||
get { |
||||
// Console.WriteLine("Call to Token");
|
||||
return lastToken; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The next Token (The <see cref="Token"/> after <see cref="NextToken"/> call) . <seealso cref="ICSharpCode.NRefactory.VB.Parser.Token"/>
|
||||
/// </summary>
|
||||
public Token LookAhead { |
||||
get { |
||||
// Console.WriteLine("Call to LookAhead");
|
||||
return curToken; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor for the abstract lexer class.
|
||||
/// </summary>
|
||||
protected AbstractLexer(TextReader reader) |
||||
{ |
||||
this.reader = new LATextReader(reader); |
||||
} |
||||
|
||||
protected AbstractLexer(TextReader reader, LexerMemento state) |
||||
: this(reader) |
||||
{ |
||||
SetInitialLocation(new Location(state.Column, state.Line)); |
||||
lastToken = new Token(state.PrevTokenKind, 0, 0); |
||||
} |
||||
|
||||
#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
|
||||
|
||||
/// <summary>
|
||||
/// Must be called before a peek operation.
|
||||
/// </summary>
|
||||
public void StartPeek() |
||||
{ |
||||
peekToken = curToken; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gives back the next token. A second call to Peek() gives the next token after the last call for Peek() and so on.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Token"/> object.</returns>
|
||||
public Token Peek() |
||||
{ |
||||
// Console.WriteLine("Call to Peek");
|
||||
if (peekToken.next == null) { |
||||
peekToken.next = Next(); |
||||
} |
||||
peekToken = peekToken.next; |
||||
return peekToken; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the next token and gives it back.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Token"/> object.</returns>
|
||||
public virtual Token NextToken() |
||||
{ |
||||
if (curToken == null) { |
||||
curToken = Next(); |
||||
//Console.WriteLine(ICSharpCode.NRefactory.VB.Parser.CSharp.Tokens.GetTokenString(curToken.kind) + " -- " + curToken.val + "(" + curToken.kind + ")");
|
||||
return curToken; |
||||
} |
||||
|
||||
lastToken = curToken; |
||||
|
||||
if (curToken.next == null) { |
||||
curToken.next = Next(); |
||||
} |
||||
|
||||
curToken = curToken.next; |
||||
//Console.WriteLine(ICSharpCode.NRefactory.VB.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 Location lastLineEnd = new Location (1, 1); |
||||
protected Location curLineEnd = new Location (1, 1); |
||||
protected void LineBreak () |
||||
{ |
||||
lastLineEnd = curLineEnd; |
||||
curLineEnd = new Location (col - 1, line); |
||||
} |
||||
protected bool HandleLineEnd(char ch) |
||||
{ |
||||
// Handle MS-DOS or MacOS line ends.
|
||||
if (ch == '\r') { |
||||
if (reader.Peek() == '\n') { // MS-DOS line end '\r\n'
|
||||
ReaderRead(); // LineBreak (); called by ReaderRead ();
|
||||
return true; |
||||
} else { // assume MacOS line end which is '\r'
|
||||
LineBreak (); |
||||
return true; |
||||
} |
||||
} |
||||
if (ch == '\n') { |
||||
LineBreak (); |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
protected void SkipToEndOfLine() |
||||
{ |
||||
int nextChar; |
||||
while ((nextChar = reader.Read()) != -1) { |
||||
if (nextChar == '\r') { |
||||
if (reader.Peek() == '\n') |
||||
reader.Read(); |
||||
nextChar = '\n'; |
||||
} |
||||
if (nextChar == '\n') { |
||||
++line; |
||||
col = 1; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
protected string ReadToEndOfLine() |
||||
{ |
||||
sb.Length = 0; |
||||
int nextChar; |
||||
while ((nextChar = reader.Read()) != -1) { |
||||
char ch = (char)nextChar; |
||||
|
||||
if (nextChar == '\r') { |
||||
if (reader.Peek() == '\n') |
||||
reader.Read(); |
||||
nextChar = '\n'; |
||||
} |
||||
// Return read string, if EOL is reached
|
||||
if (nextChar == '\n') { |
||||
++line; |
||||
col = 1; |
||||
return sb.ToString(); |
||||
} |
||||
|
||||
sb.Append(ch); |
||||
} |
||||
|
||||
// Got EOF before EOL
|
||||
string retStr = sb.ToString(); |
||||
col += retStr.Length; |
||||
return retStr; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public abstract void SkipCurrentBlock(int targetToken); |
||||
|
||||
public event EventHandler<SavepointEventArgs> SavepointReached; |
||||
|
||||
protected virtual void OnSavepointReached(SavepointEventArgs e) |
||||
{ |
||||
if (SavepointReached != null) { |
||||
SavepointReached(this, e); |
||||
} |
||||
} |
||||
|
||||
public virtual LexerMemento Export() |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
public virtual void SetInitialContext(SnippetType context) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public enum Context |
||||
{ |
||||
Global, |
||||
TypeDeclaration, |
||||
ObjectCreation, |
||||
ObjectInitializer, |
||||
CollectionInitializer, |
||||
Type, |
||||
Member, |
||||
Parameter, |
||||
Identifier, |
||||
Body, |
||||
Xml, |
||||
Attribute, |
||||
Importable, |
||||
Query, |
||||
Expression, |
||||
Debug, |
||||
Default |
||||
} |
||||
|
||||
public class Block : ICloneable |
||||
{ |
||||
public static readonly Block Default = new Block() { |
||||
context = Context.Global, |
||||
lastExpressionStart = Location.Empty |
||||
}; |
||||
|
||||
public Context context; |
||||
public Location lastExpressionStart; |
||||
public bool isClosed; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[Block Context={0}, LastExpressionStart={1}, IsClosed={2}]", context, lastExpressionStart, isClosed); |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
return new Block() { |
||||
context = this.context, |
||||
lastExpressionStart = this.lastExpressionStart, |
||||
isClosed = this.isClosed |
||||
}; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,154 @@
@@ -0,0 +1,154 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public partial class ExpressionFinder |
||||
{ |
||||
Stack<Block> stack = new Stack<Block>(); |
||||
StringBuilder output = new StringBuilder(); |
||||
|
||||
void PopContext() |
||||
{ |
||||
if (stack.Any()) { |
||||
string indent = new string('\t', stack.Count - 1); |
||||
var item = stack.Pop(); |
||||
item.isClosed = true; |
||||
Print(indent + "exit " + item.context); |
||||
} else { |
||||
Print("empty stack"); |
||||
} |
||||
} |
||||
|
||||
void PushContext(Context context, Token la, Token t) |
||||
{ |
||||
string indent = new string('\t', stack.Count); |
||||
Location l = la == null ? (t == null ? Location.Empty : t.EndLocation) : la.Location; |
||||
|
||||
stack.Push(new Block() { context = context, lastExpressionStart = l }); |
||||
Print(indent + "enter " + context); |
||||
} |
||||
|
||||
public ExpressionFinder(ExpressionFinderState state) |
||||
{ |
||||
wasQualifierTokenAtStart = state.WasQualifierTokenAtStart; |
||||
nextTokenIsPotentialStartOfExpression = state.NextTokenIsPotentialStartOfExpression; |
||||
nextTokenIsStartOfImportsOrAccessExpression = state.NextTokenIsStartOfImportsOrAccessExpression; |
||||
readXmlIdentifier = state.ReadXmlIdentifier; |
||||
identifierExpected = state.IdentifierExpected; |
||||
stateStack = new Stack<int>(state.StateStack.Reverse()); |
||||
stack = new Stack<Block>(state.BlockStack.Select(x => (Block)x.Clone()).Reverse()); |
||||
currentState = state.CurrentState; |
||||
output = new StringBuilder(); |
||||
} |
||||
|
||||
void Print(string text) |
||||
{ |
||||
//Console.WriteLine(text);
|
||||
output.AppendLine(text); |
||||
} |
||||
|
||||
public void SetContext(SnippetType type) |
||||
{ |
||||
switch (type) { |
||||
case SnippetType.Expression: |
||||
currentState = startOfExpression; |
||||
break; |
||||
} |
||||
|
||||
Advance(); |
||||
} |
||||
|
||||
public string Output { |
||||
get { return output.ToString(); } |
||||
} |
||||
|
||||
public string Stacktrace { |
||||
get { |
||||
string text = ""; |
||||
|
||||
foreach (Block b in stack) { |
||||
text += b.ToString() + "\n"; |
||||
} |
||||
|
||||
return text; |
||||
} |
||||
} |
||||
|
||||
public Block CurrentBlock { |
||||
get { return stack.Any() ? stack.Peek() : Block.Default; } |
||||
} |
||||
|
||||
public bool IsIdentifierExpected { |
||||
get { return identifierExpected; } |
||||
} |
||||
|
||||
void SetIdentifierExpected(Token la) |
||||
{ |
||||
identifierExpected = true; |
||||
if (la != null) |
||||
CurrentBlock.lastExpressionStart = la.Location; |
||||
else if (t != null) |
||||
CurrentBlock.lastExpressionStart = t.EndLocation; |
||||
} |
||||
|
||||
public bool InContext(Context expected) |
||||
{ |
||||
return stack |
||||
.SkipWhile(f => f.context == Context.Expression) |
||||
.IsElement(fx => fx.context == expected); |
||||
} |
||||
|
||||
public bool NextTokenIsPotentialStartOfExpression { |
||||
get { return nextTokenIsPotentialStartOfExpression; } |
||||
} |
||||
|
||||
public bool ReadXmlIdentifier { |
||||
get { return readXmlIdentifier; } |
||||
set { readXmlIdentifier = value; } |
||||
} |
||||
|
||||
public bool NextTokenIsStartOfImportsOrAccessExpression { |
||||
get { return nextTokenIsStartOfImportsOrAccessExpression; } |
||||
} |
||||
|
||||
public bool WasQualifierTokenAtStart { |
||||
get { return wasQualifierTokenAtStart; } |
||||
} |
||||
|
||||
public bool IsMissingModifier { |
||||
get { return isMissingModifier; } |
||||
} |
||||
|
||||
public bool WasNormalAttribute { |
||||
get { return wasNormalAttribute; } |
||||
} |
||||
|
||||
public int ActiveArgument { |
||||
get { return activeArgument; } |
||||
} |
||||
|
||||
public List<Token> Errors { |
||||
get { return errors; } |
||||
} |
||||
|
||||
public ExpressionFinderState Export() |
||||
{ |
||||
return new ExpressionFinderState() { |
||||
WasQualifierTokenAtStart = wasQualifierTokenAtStart, |
||||
NextTokenIsPotentialStartOfExpression = nextTokenIsPotentialStartOfExpression, |
||||
NextTokenIsStartOfImportsOrAccessExpression = nextTokenIsStartOfImportsOrAccessExpression, |
||||
ReadXmlIdentifier = readXmlIdentifier, |
||||
IdentifierExpected = identifierExpected, |
||||
StateStack = new Stack<int>(stateStack.Reverse()), |
||||
BlockStack = new Stack<Block>(stack.Select(x => (Block)x.Clone()).Reverse()), |
||||
CurrentState = currentState |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public class ExpressionFinderState |
||||
{ |
||||
public bool WasQualifierTokenAtStart { get; set; } |
||||
public bool NextTokenIsPotentialStartOfExpression { get; set; } |
||||
public bool ReadXmlIdentifier { get; set; } |
||||
public bool IdentifierExpected { get; set; } |
||||
public bool NextTokenIsStartOfImportsOrAccessExpression { get; set; } |
||||
public Stack<int> StateStack { get; set; } |
||||
public Stack<Block> BlockStack { get; set; } |
||||
public int CurrentState { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public static class Extensions |
||||
{ |
||||
public static bool IsElement<T>(this IEnumerable<T> items, Func<T, bool> check) |
||||
{ |
||||
T item = items.FirstOrDefault(); |
||||
|
||||
if (item != null) |
||||
return check(item); |
||||
return false; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,123 @@
@@ -0,0 +1,123 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Lexer interface
|
||||
/// </summary>
|
||||
public interface ILexer : IDisposable |
||||
{ |
||||
/// <summary>
|
||||
/// Sets the start line/column number. This method can be called only before the first token is read.
|
||||
/// </summary>
|
||||
void SetInitialLocation(Location location); |
||||
|
||||
/// <summary>
|
||||
/// Sets the context of the lexer.
|
||||
/// </summary>
|
||||
void SetInitialContext(SnippetType context); |
||||
|
||||
Errors Errors { |
||||
get; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The current Token. <seealso cref="ICSharpCode.NRefactory.VB.Parser.Token"/>
|
||||
/// </summary>
|
||||
Token Token { |
||||
get; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The next Token (The <see cref="Token"/> after <see cref="NextToken"/> call) . <seealso cref="ICSharpCode.NRefactory.VB.Parser.Token"/>
|
||||
/// </summary>
|
||||
Token LookAhead { |
||||
get; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Special comment tags are tags like TODO, HACK or UNDONE which are read by the lexer and stored in <see cref="TagComments"/>.
|
||||
/// </summary>
|
||||
string[] SpecialCommentTags { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the lexer should skip adding comments to the special tracker. Set this
|
||||
/// property to true to improve lexing performance.
|
||||
/// </summary>
|
||||
bool SkipAllComments { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets if the lexer should evaluate conditional compilation symbols.
|
||||
/// </summary>
|
||||
bool EvaluateConditionalCompilation { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// The dictionary with the conditional compilation symbols.
|
||||
/// C# ignores the value (you can use null), it just cares whether a symbol is defined.
|
||||
/// </summary>
|
||||
IDictionary<string, object> ConditionalCompilationSymbols { get; } |
||||
|
||||
/// <summary>
|
||||
/// Sets the conditional compilation symbols.
|
||||
/// </summary>
|
||||
/// <param name="symbols">
|
||||
/// A <see cref="System.String"/> containing the symbols. The symbols are separated by ';'.
|
||||
/// </param>
|
||||
void SetConditionalCompilationSymbols (string symbols); |
||||
|
||||
/// <summary>
|
||||
/// Returns the comments that had been read and containing tag key words.
|
||||
/// </summary>
|
||||
List<TagComment> TagComments { |
||||
get; |
||||
} |
||||
|
||||
SpecialTracker SpecialTracker { |
||||
get; |
||||
} |
||||
|
||||
void StartPeek(); |
||||
|
||||
/// <summary>
|
||||
/// Gives back the next token. A second call to Peek() gives the next token after the last call for Peek() and so on.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Token"/> object.</returns>
|
||||
Token Peek(); |
||||
|
||||
/// <summary>
|
||||
/// Reads the next token and gives it back.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="Token"/> object.</returns>
|
||||
Token NextToken(); |
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
void SkipCurrentBlock(int targetToken); |
||||
|
||||
/// <summary>
|
||||
/// Used to export the current state of the lexer. The exported state should be
|
||||
/// complete, so that it is possible to reset the lexer to a previous state completely.
|
||||
/// </summary>
|
||||
LexerMemento Export(); |
||||
|
||||
/// <summary>
|
||||
/// Is fired by the lexer as soon as a savepoint is reached.
|
||||
/// The Export-method can be used to retrieve the current state.
|
||||
/// </summary>
|
||||
event EventHandler<SavepointEventArgs> SavepointReached; |
||||
} |
||||
} |
@ -0,0 +1,284 @@
@@ -0,0 +1,284 @@
|
||||
# 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.VB.Parser |
||||
$UpperCaseKeywords=True |
||||
|
||||
# TERMINAL_CLASSES |
||||
EOF |
||||
EOL |
||||
Identifier |
||||
LiteralString |
||||
LiteralCharacter |
||||
LiteralInteger |
||||
LiteralDouble |
||||
LiteralSingle |
||||
LiteralDecimal |
||||
LiteralDate |
||||
|
||||
# XML_TERMINALS |
||||
XmlOpenTag |
||||
XmlCloseTag |
||||
XmlStartInlineVB |
||||
XmlEndInlineVB |
||||
XmlCloseTagEmptyElement |
||||
XmlOpenEndTag |
||||
XmlContent |
||||
XmlComment |
||||
XmlCData |
||||
XmlProcessingInstruction |
||||
|
||||
# SPECIAL_CHARACTERS |
||||
Assign = "=" |
||||
Colon =":" |
||||
Comma = "," |
||||
ConcatString = "&" |
||||
Div ="/" |
||||
DivInteger = "\\" |
||||
Dot = "." |
||||
TripleDot = "..." |
||||
DotAt = ".@" |
||||
# Exclamation mark = Dictionary access operator (not always a token, sometimes it's a type character) |
||||
ExclamationMark = "!" |
||||
Minus = "-" |
||||
Plus = "+" |
||||
Power = "^" |
||||
QuestionMark = "?" |
||||
Times = "*" |
||||
|
||||
OpenCurlyBrace = "{" |
||||
CloseCurlyBrace = "}" |
||||
|
||||
OpenParenthesis = "(" |
||||
CloseParenthesis = ")" |
||||
|
||||
GreaterThan = ">" |
||||
LessThan = "<" |
||||
|
||||
NotEqual = "<>" |
||||
GreaterEqual = ">=" |
||||
LessEqual = "<=" |
||||
|
||||
ShiftLeft = "<<" |
||||
ShiftRight = ">>" |
||||
|
||||
PlusAssign = "+=" |
||||
PowerAssign = "^=" |
||||
MinusAssign = "-=" |
||||
TimesAssign = "*=" |
||||
DivAssign = "/=" |
||||
DivIntegerAssign = "\\=" |
||||
ShiftLeftAssign = "<<=" |
||||
ShiftRightAssign = ">>=" |
||||
ConcatStringAssign = "&=" |
||||
ColonAssign = ":=" |
||||
|
||||
# keywords according to the spec: |
||||
# Keywordlist |
||||
"AddHandler" |
||||
"AddressOf" |
||||
"Aggregate" |
||||
"Alias" |
||||
"And" |
||||
"AndAlso" |
||||
"Ansi" |
||||
"As" |
||||
"Ascending" |
||||
"Assembly" |
||||
"Auto" |
||||
"Binary" |
||||
"Boolean" |
||||
"ByRef" |
||||
"By" |
||||
"Byte" |
||||
"ByVal" |
||||
"Call" |
||||
"Case" |
||||
"Catch" |
||||
"CBool" |
||||
"CByte" |
||||
"CChar" |
||||
"CDate" |
||||
"CDbl" |
||||
"CDec" |
||||
"Char" |
||||
"CInt" |
||||
"Class" |
||||
"CLng" |
||||
"CObj" |
||||
"Compare" |
||||
"Const" |
||||
"Continue" |
||||
"CSByte" |
||||
"CShort" |
||||
"CSng" |
||||
"CStr" |
||||
"CType" |
||||
"CUInt" |
||||
"CULng" |
||||
"CUShort" |
||||
"Custom" |
||||
"Date" |
||||
"Decimal" |
||||
"Declare" |
||||
"Default" |
||||
"Delegate" |
||||
"Descending" |
||||
"Dim" |
||||
"DirectCast" |
||||
"Distinct" |
||||
"Do" |
||||
"Double" |
||||
"Each" |
||||
"Else" |
||||
"ElseIf" |
||||
"End" |
||||
"EndIf" |
||||
"Enum" |
||||
"Equals" |
||||
"Erase" |
||||
"Error" |
||||
"Event" |
||||
"Exit" |
||||
"Explicit" |
||||
"False" |
||||
"Finally" |
||||
"For" |
||||
"Friend" |
||||
"From" |
||||
"Function" |
||||
"Get" |
||||
"GetType" |
||||
"Global" |
||||
"GoSub" |
||||
"GoTo" |
||||
"Group" |
||||
"Handles" |
||||
"If" |
||||
"Implements" |
||||
"Imports" |
||||
"In" |
||||
"Infer" |
||||
"Inherits" |
||||
"Integer" |
||||
"Interface" |
||||
"Into" |
||||
"Is" |
||||
"IsNot" |
||||
# Note: IsTrue and IsFalse are 'NOT' keywords they're only valid in Operator declarations (like get/set/value are no C# 'keywords') |
||||
"Join" |
||||
"Key" |
||||
"Let" |
||||
"Lib" |
||||
"Like" |
||||
"Long" |
||||
"Loop" |
||||
"Me" |
||||
"Mod" |
||||
"Module" |
||||
"MustInherit" |
||||
"MustOverride" |
||||
"MyBase" |
||||
"MyClass" |
||||
"Namespace" |
||||
"Narrowing" |
||||
"New" |
||||
"Next" |
||||
"Not" |
||||
"Nothing" |
||||
"NotInheritable" |
||||
"NotOverridable" |
||||
"Object" |
||||
"Of" |
||||
"Off" |
||||
"On" |
||||
"Operator" |
||||
"Option" |
||||
"Optional" |
||||
"Or" |
||||
"Order" |
||||
"OrElse" |
||||
"Out" |
||||
"Overloads" |
||||
"Overridable" |
||||
"Overrides" |
||||
"ParamArray" |
||||
"Partial" |
||||
"Preserve" |
||||
"Private" |
||||
"Property" |
||||
"Protected" |
||||
"Public" |
||||
"RaiseEvent" |
||||
"ReadOnly" |
||||
"ReDim" |
||||
# has to be in the keyword list for the output formatter |
||||
"Rem" |
||||
"RemoveHandler" |
||||
"Resume" |
||||
"Return" |
||||
"SByte" |
||||
"Select" |
||||
"Set" |
||||
"Shadows" |
||||
"Shared" |
||||
"Short" |
||||
"Single" |
||||
"Skip" |
||||
"Static" |
||||
"Step" |
||||
"Stop" |
||||
"Strict" |
||||
"String" |
||||
"Structure" |
||||
"Sub" |
||||
"SyncLock" |
||||
"Take" |
||||
"Text" |
||||
"Then" |
||||
"Throw" |
||||
"To" |
||||
"True" |
||||
"Try" |
||||
"TryCast" |
||||
"TypeOf" |
||||
"UInteger" |
||||
"ULong" |
||||
"Unicode" |
||||
"Until" |
||||
"UShort" |
||||
"Using" |
||||
"Variant" |
||||
"Wend" |
||||
"When" |
||||
"Where" |
||||
"While" |
||||
"Widening" |
||||
"With" |
||||
"WithEvents" |
||||
"WriteOnly" |
||||
"Xor" |
||||
|
||||
#XML specific keywords |
||||
"GetXmlNamespace" |
||||
|
||||
#Sets |
||||
Null("Nothing") |
||||
BlockSucc("Case", "Catch", "Else", "ElseIf", "End", "Finally", "Loop", "Next") |
||||
GlobalLevel("Namespace", "Module", "Class", "Structure", "Imports", "Option") |
||||
TypeLevel("Sub", "Function", "Property") |
||||
|
||||
# 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", "Off", "Out", "Key", "Explicit", "Infer", "From", "Join", "Equals", "Distinct", "Where", "Take", "Skip", "Order", "By", "Ascending", "Descending", "Group", "Into", "Aggregate") |
||||
ExpressionStart("Me", "MyBase", "MyClass", @BooleanExpressions, @OperatorsAtStart, "New", @Null, "AddressOf", "GetType", "TypeOf", "GetXmlNamespace", "Global", @TypeKW, @LambdaStart, @CastExpressions) |
||||
StatementStart(@Null, @ExpressionStart, "Dim", "Const", "Static", "For", "While", "Do", "Select") |
||||
SimpleTypeName(@TypeKW, @IdentifierTokens) |
||||
CastExpressions("DirectCast", "TryCast", "CType", "CBool", "CByte", "CChar", "CDate", "CDec", "CDbl", "CInt", "CLng", "CObj", "CSByte", "CShort", "CSng", "CStr", "CUInt", "CULng", "CUShort") |
||||
BooleanExpressions("True", "False") |
||||
LambdaStart("Sub", "Function") |
||||
OperatorsAtStart("Not", "From", "Aggregate") |
||||
TypeKW("Boolean", "Date", "Char", "String", "Decimal", "Byte", "Short", "Integer", "Long", "Single", "Double", "UInteger", "ULong", "UShort", "SByte") |
@ -0,0 +1,215 @@
@@ -0,0 +1,215 @@
|
||||
// this file was autogenerated by a tool.
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public static class Keywords |
||||
{ |
||||
static readonly string[] keywordList = { |
||||
"ADDHANDLER", |
||||
"ADDRESSOF", |
||||
"AGGREGATE", |
||||
"ALIAS", |
||||
"AND", |
||||
"ANDALSO", |
||||
"ANSI", |
||||
"AS", |
||||
"ASCENDING", |
||||
"ASSEMBLY", |
||||
"AUTO", |
||||
"BINARY", |
||||
"BOOLEAN", |
||||
"BYREF", |
||||
"BY", |
||||
"BYTE", |
||||
"BYVAL", |
||||
"CALL", |
||||
"CASE", |
||||
"CATCH", |
||||
"CBOOL", |
||||
"CBYTE", |
||||
"CCHAR", |
||||
"CDATE", |
||||
"CDBL", |
||||
"CDEC", |
||||
"CHAR", |
||||
"CINT", |
||||
"CLASS", |
||||
"CLNG", |
||||
"COBJ", |
||||
"COMPARE", |
||||
"CONST", |
||||
"CONTINUE", |
||||
"CSBYTE", |
||||
"CSHORT", |
||||
"CSNG", |
||||
"CSTR", |
||||
"CTYPE", |
||||
"CUINT", |
||||
"CULNG", |
||||
"CUSHORT", |
||||
"CUSTOM", |
||||
"DATE", |
||||
"DECIMAL", |
||||
"DECLARE", |
||||
"DEFAULT", |
||||
"DELEGATE", |
||||
"DESCENDING", |
||||
"DIM", |
||||
"DIRECTCAST", |
||||
"DISTINCT", |
||||
"DO", |
||||
"DOUBLE", |
||||
"EACH", |
||||
"ELSE", |
||||
"ELSEIF", |
||||
"END", |
||||
"ENDIF", |
||||
"ENUM", |
||||
"EQUALS", |
||||
"ERASE", |
||||
"ERROR", |
||||
"EVENT", |
||||
"EXIT", |
||||
"EXPLICIT", |
||||
"FALSE", |
||||
"FINALLY", |
||||
"FOR", |
||||
"FRIEND", |
||||
"FROM", |
||||
"FUNCTION", |
||||
"GET", |
||||
"GETTYPE", |
||||
"GLOBAL", |
||||
"GOSUB", |
||||
"GOTO", |
||||
"GROUP", |
||||
"HANDLES", |
||||
"IF", |
||||
"IMPLEMENTS", |
||||
"IMPORTS", |
||||
"IN", |
||||
"INFER", |
||||
"INHERITS", |
||||
"INTEGER", |
||||
"INTERFACE", |
||||
"INTO", |
||||
"IS", |
||||
"ISNOT", |
||||
"JOIN", |
||||
"KEY", |
||||
"LET", |
||||
"LIB", |
||||
"LIKE", |
||||
"LONG", |
||||
"LOOP", |
||||
"ME", |
||||
"MOD", |
||||
"MODULE", |
||||
"MUSTINHERIT", |
||||
"MUSTOVERRIDE", |
||||
"MYBASE", |
||||
"MYCLASS", |
||||
"NAMESPACE", |
||||
"NARROWING", |
||||
"NEW", |
||||
"NEXT", |
||||
"NOT", |
||||
"NOTHING", |
||||
"NOTINHERITABLE", |
||||
"NOTOVERRIDABLE", |
||||
"OBJECT", |
||||
"OF", |
||||
"OFF", |
||||
"ON", |
||||
"OPERATOR", |
||||
"OPTION", |
||||
"OPTIONAL", |
||||
"OR", |
||||
"ORDER", |
||||
"ORELSE", |
||||
"OUT", |
||||
"OVERLOADS", |
||||
"OVERRIDABLE", |
||||
"OVERRIDES", |
||||
"PARAMARRAY", |
||||
"PARTIAL", |
||||
"PRESERVE", |
||||
"PRIVATE", |
||||
"PROPERTY", |
||||
"PROTECTED", |
||||
"PUBLIC", |
||||
"RAISEEVENT", |
||||
"READONLY", |
||||
"REDIM", |
||||
"REM", |
||||
"REMOVEHANDLER", |
||||
"RESUME", |
||||
"RETURN", |
||||
"SBYTE", |
||||
"SELECT", |
||||
"SET", |
||||
"SHADOWS", |
||||
"SHARED", |
||||
"SHORT", |
||||
"SINGLE", |
||||
"SKIP", |
||||
"STATIC", |
||||
"STEP", |
||||
"STOP", |
||||
"STRICT", |
||||
"STRING", |
||||
"STRUCTURE", |
||||
"SUB", |
||||
"SYNCLOCK", |
||||
"TAKE", |
||||
"TEXT", |
||||
"THEN", |
||||
"THROW", |
||||
"TO", |
||||
"TRUE", |
||||
"TRY", |
||||
"TRYCAST", |
||||
"TYPEOF", |
||||
"UINTEGER", |
||||
"ULONG", |
||||
"UNICODE", |
||||
"UNTIL", |
||||
"USHORT", |
||||
"USING", |
||||
"VARIANT", |
||||
"WEND", |
||||
"WHEN", |
||||
"WHERE", |
||||
"WHILE", |
||||
"WIDENING", |
||||
"WITH", |
||||
"WITHEVENTS", |
||||
"WRITEONLY", |
||||
"XOR", |
||||
"GETXMLNAMESPACE" |
||||
}; |
||||
|
||||
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]; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public class LATextReader : TextReader |
||||
{ |
||||
List<int> buffer; |
||||
TextReader reader; |
||||
|
||||
public LATextReader(TextReader reader) |
||||
{ |
||||
this.buffer = new List<int>(); |
||||
this.reader = reader; |
||||
} |
||||
|
||||
public override int Peek() |
||||
{ |
||||
return Peek(0); |
||||
} |
||||
|
||||
public override int Read() |
||||
{ |
||||
int c = Peek(); |
||||
buffer.RemoveAt(0); |
||||
return c; |
||||
} |
||||
|
||||
public int Peek(int step) |
||||
{ |
||||
while (step >= buffer.Count) { |
||||
buffer.Add(reader.Read()); |
||||
} |
||||
|
||||
if (step < 0) |
||||
return -1; |
||||
|
||||
return buffer[step]; |
||||
} |
||||
|
||||
protected override void Dispose(bool disposing) |
||||
{ |
||||
if (disposing) |
||||
reader.Dispose(); |
||||
base.Dispose(disposing); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public abstract class LexerMemento |
||||
{ |
||||
public int Line { get; set; } |
||||
public int Column { get; set; } |
||||
public int PrevTokenKind { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,116 @@
@@ -0,0 +1,116 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Globalization; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// This class implements a keyword map. It implements a digital search trees (tries) to find
|
||||
/// a word.
|
||||
/// </summary>
|
||||
internal class LookupTable |
||||
{ |
||||
Node root = new Node(-1, null); |
||||
bool casesensitive; |
||||
int length; |
||||
|
||||
/// <value>
|
||||
/// The number of elements in the table
|
||||
/// </value>
|
||||
public int Count { |
||||
get { |
||||
return length; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inserts an int in the tree, under keyword
|
||||
/// </summary>
|
||||
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; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="LookupTable"/>
|
||||
/// </summary>
|
||||
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]; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
/*---------------------------------------------------------------------- |
||||
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 |
||||
-->namespace |
||||
|
||||
partial class ExpressionFinder { |
||||
-->constants |
||||
const bool T = true; |
||||
const bool x = false; |
||||
|
||||
-->declarations |
||||
readonly Stack<int> stateStack = new Stack<int>(); |
||||
bool wasQualifierTokenAtStart = false; |
||||
bool nextTokenIsPotentialStartOfExpression = false; |
||||
bool readXmlIdentifier = false; |
||||
bool identifierExpected = false; |
||||
bool nextTokenIsStartOfImportsOrAccessExpression = false; |
||||
bool isMissingModifier = false; |
||||
bool isAlreadyInExpr = false; |
||||
bool wasNormalAttribute = false; |
||||
int activeArgument = 0; |
||||
List<Token> errors = new List<Token>(); |
||||
|
||||
public ExpressionFinder() |
||||
{ |
||||
stateStack.Push(-1); // required so that we don't crash when leaving the root production |
||||
} |
||||
|
||||
void Expect(int expectedKind, Token la) |
||||
{ |
||||
if (la.kind != expectedKind) { |
||||
Error(la); |
||||
output.AppendLine("expected: " + expectedKind); |
||||
//Console.WriteLine("expected: " + expectedKind); |
||||
} |
||||
} |
||||
|
||||
void Error(Token la) |
||||
{ |
||||
output.AppendLine("not expected: " + la); |
||||
//Console.WriteLine("not expected: " + la); |
||||
errors.Add(la); |
||||
} |
||||
|
||||
Token t; |
||||
|
||||
public void InformToken(Token la) |
||||
{ |
||||
-->informToken |
||||
if (la != null) { |
||||
t = la; |
||||
nextTokenIsPotentialStartOfExpression = false; |
||||
readXmlIdentifier = false; |
||||
nextTokenIsStartOfImportsOrAccessExpression = false; |
||||
wasQualifierTokenAtStart = false; |
||||
identifierExpected = false; |
||||
} |
||||
} |
||||
|
||||
public void Advance() |
||||
{ |
||||
//Console.WriteLine("Advance"); |
||||
InformToken(null); |
||||
} |
||||
|
||||
public BitArray GetExpectedSet() { return GetExpectedSet(currentState); } |
||||
|
||||
static readonly BitArray[] set = { |
||||
-->initialization |
||||
}; |
||||
|
||||
} // end Parser |
||||
|
||||
|
||||
$$$ |
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public class SavepointEventArgs : EventArgs |
||||
{ |
||||
public Location SavepointLocation { get; private set; } |
||||
public LexerMemento State { get; private set; } |
||||
|
||||
public SavepointEventArgs(Location savepointLocation, LexerMemento state) |
||||
{ |
||||
this.SavepointLocation = savepointLocation; |
||||
this.State = state; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public class BlankLine : AbstractSpecial |
||||
{ |
||||
public BlankLine(Location point) : base(point) |
||||
{ |
||||
} |
||||
|
||||
public override object AcceptVisitor(ISpecialVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
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; |
||||
} |
||||
} |
||||
|
||||
/// <value>
|
||||
/// Is true, when the comment is at line start or only whitespaces
|
||||
/// between line and comment start.
|
||||
/// </value>
|
||||
public bool CommentStartsLine { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Comment(CommentType commentType, string comment, bool commentStartsLine, Location startPosition, Location endPosition) |
||||
: base(startPosition, endPosition) |
||||
{ |
||||
this.commentType = commentType; |
||||
this.comment = comment; |
||||
this.CommentStartsLine = commentStartsLine; |
||||
} |
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public enum CommentType |
||||
{ |
||||
Block, |
||||
SingleLine, |
||||
Documentation |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Interface for all specials.
|
||||
/// </summary>
|
||||
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); |
||||
|
||||
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; set; } |
||||
public Location EndPosition { get; set; } |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[{0}: Start = {1}, End = {2}]", |
||||
GetType().Name, StartPosition, EndPosition); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,156 @@
@@ -0,0 +1,156 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public class PreprocessingDirective : AbstractSpecial |
||||
{ |
||||
#region Conversion C# <-> VB
|
||||
public static void VBToCSharp(IList<ISpecial> 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); |
||||
} else if (cmd.Equals("#Else", StringComparison.InvariantCultureIgnoreCase)) { |
||||
if (dir.Expression != null) |
||||
cmd = "#elif"; |
||||
else |
||||
cmd = "#else"; |
||||
} else if (cmd.Equals("#ElseIf", StringComparison.InvariantCultureIgnoreCase)) { |
||||
cmd = "#elif"; |
||||
} |
||||
return new PreprocessingDirective(cmd, arg, dir.StartPosition, dir.EndPosition) { |
||||
Expression = dir.Expression |
||||
}; |
||||
} |
||||
|
||||
public static void CSharpToVB(List<ISpecial> 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) { |
||||
Expression = dir.Expression |
||||
}; |
||||
} |
||||
#endregion
|
||||
|
||||
string cmd; |
||||
string arg; |
||||
VB.Dom.Expression expression = Dom.Expression.Null; |
||||
|
||||
/// <summary>
|
||||
/// Gets the directive name, including '#'.
|
||||
/// </summary>
|
||||
public string Cmd { |
||||
get { |
||||
return cmd; |
||||
} |
||||
set { |
||||
cmd = value ?? string.Empty; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the directive argument.
|
||||
/// </summary>
|
||||
public string Arg { |
||||
get { |
||||
return arg; |
||||
} |
||||
set { |
||||
arg = value ?? string.Empty; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the expression (for directives that take an expression, e.g. #if and #elif).
|
||||
/// </summary>
|
||||
public Dom.Expression Expression { |
||||
get { return expression; } |
||||
set { expression = value ?? Dom.Expression.Null; } |
||||
} |
||||
|
||||
/// <value>
|
||||
/// The end position of the pre processor directive line.
|
||||
/// May be != EndPosition.
|
||||
/// </value>
|
||||
public Location LastLineEnd { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
|
||||
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); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public class SpecialTracker |
||||
{ |
||||
List<ISpecial> currentSpecials = new List<ISpecial>(); |
||||
|
||||
CommentType currentCommentType; |
||||
StringBuilder sb = new StringBuilder(); |
||||
Location startPosition; |
||||
bool commentStartsLine; |
||||
|
||||
public List<ISpecial> CurrentSpecials { |
||||
get { |
||||
return currentSpecials; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the specials from the SpecialTracker and resets the lists.
|
||||
/// </summary>
|
||||
public List<ISpecial> RetrieveSpecials() |
||||
{ |
||||
List<ISpecial> tmp = currentSpecials; |
||||
currentSpecials = new List<ISpecial>(); |
||||
return tmp; |
||||
} |
||||
|
||||
public void AddEndOfLine(Location point) |
||||
{ |
||||
currentSpecials.Add(new BlankLine(point)); |
||||
} |
||||
|
||||
public void AddPreprocessingDirective(PreprocessingDirective directive) |
||||
{ |
||||
if (directive == null) |
||||
throw new ArgumentNullException("directive"); |
||||
currentSpecials.Add(directive); |
||||
} |
||||
|
||||
// used for comment tracking
|
||||
public void StartComment(CommentType commentType, bool commentStartsLine, Location startPosition) |
||||
{ |
||||
this.currentCommentType = commentType; |
||||
this.startPosition = startPosition; |
||||
this.sb.Length = 0; |
||||
this.commentStartsLine = commentStartsLine; |
||||
} |
||||
|
||||
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(), commentStartsLine, startPosition, endPosition)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
/// <summary>
|
||||
/// Description of TagComment.
|
||||
/// </summary>
|
||||
public class TagComment : Comment |
||||
{ |
||||
string tag; |
||||
|
||||
public string Tag { |
||||
get { |
||||
return tag; |
||||
} |
||||
set { |
||||
tag = value; |
||||
} |
||||
} |
||||
|
||||
public TagComment(string tag, string comment, bool commentStartsLine, Location startPosition, Location endPosition) : base(CommentType.SingleLine, comment, commentStartsLine, startPosition, endPosition) |
||||
{ |
||||
this.tag = tag; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public enum LiteralFormat : byte |
||||
{ |
||||
None, |
||||
DecimalNumber, |
||||
HexadecimalNumber, |
||||
OctalNumber, |
||||
StringLiteral, |
||||
VerbatimStringLiteral, |
||||
CharLiteral, |
||||
DateTimeLiteral |
||||
} |
||||
|
||||
public class Token |
||||
{ |
||||
internal readonly int kind; |
||||
|
||||
internal readonly int col; |
||||
internal readonly int line; |
||||
|
||||
internal readonly LiteralFormat literalFormat; |
||||
internal readonly object literalValue; |
||||
internal readonly string val; |
||||
internal Token next; |
||||
readonly Location endLocation; |
||||
|
||||
public int Kind { |
||||
get { return kind; } |
||||
} |
||||
|
||||
public LiteralFormat LiteralFormat { |
||||
get { return literalFormat; } |
||||
} |
||||
|
||||
public object LiteralValue { |
||||
get { return literalValue; } |
||||
} |
||||
|
||||
public string Value { |
||||
get { return val; } |
||||
} |
||||
|
||||
public Location EndLocation { |
||||
get { return endLocation; } |
||||
} |
||||
|
||||
public Location Location { |
||||
get { |
||||
return new Location(col, line); |
||||
} |
||||
} |
||||
|
||||
public Token(int kind, int col, int line) : this (kind, col, line, null) |
||||
{ |
||||
} |
||||
|
||||
public Token(int kind, Location startLocation, Location endLocation) : this(kind, startLocation, endLocation, "", null, LiteralFormat.None) |
||||
{ |
||||
} |
||||
|
||||
public Token(int kind, int col, int line, string val) |
||||
{ |
||||
this.kind = kind; |
||||
this.col = col; |
||||
this.line = line; |
||||
this.val = val; |
||||
this.endLocation = new Location(col + (val == null ? 1 : val.Length), line); |
||||
} |
||||
|
||||
internal Token(int kind, int x, int y, string val, object literalValue, LiteralFormat literalFormat) |
||||
: this(kind, new Location(x, y), new Location(x + val.Length, y), val, literalValue, literalFormat) |
||||
{ |
||||
} |
||||
|
||||
public Token(int kind, Location startLocation, Location endLocation, string val, object literalValue, LiteralFormat literalFormat) |
||||
{ |
||||
this.kind = kind; |
||||
this.col = startLocation.Column; |
||||
this.line = startLocation.Line; |
||||
this.endLocation = endLocation; |
||||
this.val = val; |
||||
this.literalValue = literalValue; |
||||
this.literalFormat = literalFormat; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
string vbToken; |
||||
|
||||
try { |
||||
vbToken = Tokens.GetTokenString(kind); |
||||
} catch (NotSupportedException) { |
||||
vbToken = "<unknown>"; |
||||
} |
||||
|
||||
return string.Format("[Token {1} Location={2} EndLocation={3} val={4}]", |
||||
vbToken, Location, EndLocation, val); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,527 @@
@@ -0,0 +1,527 @@
|
||||
// this file was autogenerated by a tool.
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
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; |
||||
public const int XmlOpenTag = 10; |
||||
public const int XmlCloseTag = 11; |
||||
public const int XmlStartInlineVB = 12; |
||||
public const int XmlEndInlineVB = 13; |
||||
public const int XmlCloseTagEmptyElement = 14; |
||||
public const int XmlOpenEndTag = 15; |
||||
public const int XmlContent = 16; |
||||
public const int XmlComment = 17; |
||||
public const int XmlCData = 18; |
||||
public const int XmlProcessingInstruction = 19; |
||||
|
||||
// ----- special character -----
|
||||
public const int Assign = 20; |
||||
public const int Colon = 21; |
||||
public const int Comma = 22; |
||||
public const int ConcatString = 23; |
||||
public const int Div = 24; |
||||
public const int DivInteger = 25; |
||||
public const int Dot = 26; |
||||
public const int TripleDot = 27; |
||||
public const int DotAt = 28; |
||||
public const int ExclamationMark = 29; |
||||
public const int Minus = 30; |
||||
public const int Plus = 31; |
||||
public const int Power = 32; |
||||
public const int QuestionMark = 33; |
||||
public const int Times = 34; |
||||
public const int OpenCurlyBrace = 35; |
||||
public const int CloseCurlyBrace = 36; |
||||
public const int OpenParenthesis = 37; |
||||
public const int CloseParenthesis = 38; |
||||
public const int GreaterThan = 39; |
||||
public const int LessThan = 40; |
||||
public const int NotEqual = 41; |
||||
public const int GreaterEqual = 42; |
||||
public const int LessEqual = 43; |
||||
public const int ShiftLeft = 44; |
||||
public const int ShiftRight = 45; |
||||
public const int PlusAssign = 46; |
||||
public const int PowerAssign = 47; |
||||
public const int MinusAssign = 48; |
||||
public const int TimesAssign = 49; |
||||
public const int DivAssign = 50; |
||||
public const int DivIntegerAssign = 51; |
||||
public const int ShiftLeftAssign = 52; |
||||
public const int ShiftRightAssign = 53; |
||||
public const int ConcatStringAssign = 54; |
||||
public const int ColonAssign = 55; |
||||
|
||||
// ----- keywords -----
|
||||
public const int AddHandler = 56; |
||||
public const int AddressOf = 57; |
||||
public const int Aggregate = 58; |
||||
public const int Alias = 59; |
||||
public const int And = 60; |
||||
public const int AndAlso = 61; |
||||
public const int Ansi = 62; |
||||
public const int As = 63; |
||||
public const int Ascending = 64; |
||||
public const int Assembly = 65; |
||||
public const int Auto = 66; |
||||
public const int Binary = 67; |
||||
public const int Boolean = 68; |
||||
public const int ByRef = 69; |
||||
public const int By = 70; |
||||
public const int Byte = 71; |
||||
public const int ByVal = 72; |
||||
public const int Call = 73; |
||||
public const int Case = 74; |
||||
public const int Catch = 75; |
||||
public const int CBool = 76; |
||||
public const int CByte = 77; |
||||
public const int CChar = 78; |
||||
public const int CDate = 79; |
||||
public const int CDbl = 80; |
||||
public const int CDec = 81; |
||||
public const int Char = 82; |
||||
public const int CInt = 83; |
||||
public const int Class = 84; |
||||
public const int CLng = 85; |
||||
public const int CObj = 86; |
||||
public const int Compare = 87; |
||||
public const int Const = 88; |
||||
public const int Continue = 89; |
||||
public const int CSByte = 90; |
||||
public const int CShort = 91; |
||||
public const int CSng = 92; |
||||
public const int CStr = 93; |
||||
public const int CType = 94; |
||||
public const int CUInt = 95; |
||||
public const int CULng = 96; |
||||
public const int CUShort = 97; |
||||
public const int Custom = 98; |
||||
public const int Date = 99; |
||||
public const int Decimal = 100; |
||||
public const int Declare = 101; |
||||
public const int Default = 102; |
||||
public const int Delegate = 103; |
||||
public const int Descending = 104; |
||||
public const int Dim = 105; |
||||
public const int DirectCast = 106; |
||||
public const int Distinct = 107; |
||||
public const int Do = 108; |
||||
public const int Double = 109; |
||||
public const int Each = 110; |
||||
public const int Else = 111; |
||||
public const int ElseIf = 112; |
||||
public const int End = 113; |
||||
public const int EndIf = 114; |
||||
public const int Enum = 115; |
||||
new public const int Equals = 116; |
||||
public const int Erase = 117; |
||||
public const int Error = 118; |
||||
public const int Event = 119; |
||||
public const int Exit = 120; |
||||
public const int Explicit = 121; |
||||
public const int False = 122; |
||||
public const int Finally = 123; |
||||
public const int For = 124; |
||||
public const int Friend = 125; |
||||
public const int From = 126; |
||||
public const int Function = 127; |
||||
public const int Get = 128; |
||||
new public const int GetType = 129; |
||||
public const int Global = 130; |
||||
public const int GoSub = 131; |
||||
public const int GoTo = 132; |
||||
public const int Group = 133; |
||||
public const int Handles = 134; |
||||
public const int If = 135; |
||||
public const int Implements = 136; |
||||
public const int Imports = 137; |
||||
public const int In = 138; |
||||
public const int Infer = 139; |
||||
public const int Inherits = 140; |
||||
public const int Integer = 141; |
||||
public const int Interface = 142; |
||||
public const int Into = 143; |
||||
public const int Is = 144; |
||||
public const int IsNot = 145; |
||||
public const int Join = 146; |
||||
public const int Key = 147; |
||||
public const int Let = 148; |
||||
public const int Lib = 149; |
||||
public const int Like = 150; |
||||
public const int Long = 151; |
||||
public const int Loop = 152; |
||||
public const int Me = 153; |
||||
public const int Mod = 154; |
||||
public const int Module = 155; |
||||
public const int MustInherit = 156; |
||||
public const int MustOverride = 157; |
||||
public const int MyBase = 158; |
||||
public const int MyClass = 159; |
||||
public const int Namespace = 160; |
||||
public const int Narrowing = 161; |
||||
public const int New = 162; |
||||
public const int Next = 163; |
||||
public const int Not = 164; |
||||
public const int Nothing = 165; |
||||
public const int NotInheritable = 166; |
||||
public const int NotOverridable = 167; |
||||
public const int Object = 168; |
||||
public const int Of = 169; |
||||
public const int Off = 170; |
||||
public const int On = 171; |
||||
public const int Operator = 172; |
||||
public const int Option = 173; |
||||
public const int Optional = 174; |
||||
public const int Or = 175; |
||||
public const int Order = 176; |
||||
public const int OrElse = 177; |
||||
public const int Out = 178; |
||||
public const int Overloads = 179; |
||||
public const int Overridable = 180; |
||||
public const int Overrides = 181; |
||||
public const int ParamArray = 182; |
||||
public const int Partial = 183; |
||||
public const int Preserve = 184; |
||||
public const int Private = 185; |
||||
public const int Property = 186; |
||||
public const int Protected = 187; |
||||
public const int Public = 188; |
||||
public const int RaiseEvent = 189; |
||||
public const int ReadOnly = 190; |
||||
public const int ReDim = 191; |
||||
public const int Rem = 192; |
||||
public const int RemoveHandler = 193; |
||||
public const int Resume = 194; |
||||
public const int Return = 195; |
||||
public const int SByte = 196; |
||||
public const int Select = 197; |
||||
public const int Set = 198; |
||||
public const int Shadows = 199; |
||||
public const int Shared = 200; |
||||
public const int Short = 201; |
||||
public const int Single = 202; |
||||
public const int Skip = 203; |
||||
public const int Static = 204; |
||||
public const int Step = 205; |
||||
public const int Stop = 206; |
||||
public const int Strict = 207; |
||||
public const int String = 208; |
||||
public const int Structure = 209; |
||||
public const int Sub = 210; |
||||
public const int SyncLock = 211; |
||||
public const int Take = 212; |
||||
public const int Text = 213; |
||||
public const int Then = 214; |
||||
public const int Throw = 215; |
||||
public const int To = 216; |
||||
public const int True = 217; |
||||
public const int Try = 218; |
||||
public const int TryCast = 219; |
||||
public const int TypeOf = 220; |
||||
public const int UInteger = 221; |
||||
public const int ULong = 222; |
||||
public const int Unicode = 223; |
||||
public const int Until = 224; |
||||
public const int UShort = 225; |
||||
public const int Using = 226; |
||||
public const int Variant = 227; |
||||
public const int Wend = 228; |
||||
public const int When = 229; |
||||
public const int Where = 230; |
||||
public const int While = 231; |
||||
public const int Widening = 232; |
||||
public const int With = 233; |
||||
public const int WithEvents = 234; |
||||
public const int WriteOnly = 235; |
||||
public const int Xor = 236; |
||||
public const int GetXmlNamespace = 237; |
||||
|
||||
public const int MaxToken = 238; |
||||
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 GlobalLevel = NewSet(Namespace, Module, Class, Structure, Imports, Option); |
||||
public static BitArray TypeLevel = NewSet(Sub, Function, Property); |
||||
public static BitArray IdentifierTokens = NewSet(Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Off, Out, Key, Explicit, Infer, From, Join, Equals, Distinct, Where, Take, Skip, Order, By, Ascending, Descending, Group, Into, Aggregate); |
||||
public static BitArray ExpressionStart = NewSet(Me, MyBase, MyClass, True, False, Not, From, Aggregate, New, Nothing, AddressOf, GetType, TypeOf, GetXmlNamespace, Global, Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Sub, Function, DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort); |
||||
public static BitArray StatementStart = NewSet(Nothing, Me, MyBase, MyClass, True, False, Not, From, Aggregate, New, Nothing, AddressOf, GetType, TypeOf, GetXmlNamespace, Global, Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Sub, Function, DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort, Dim, Const, Static, For, While, Do, Select); |
||||
public static BitArray SimpleTypeName = NewSet(Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte, Text, Binary, Compare, Assembly, Ansi, Auto, Preserve, Unicode, Until, Off, Out, Key, Explicit, Infer, From, Join, Equals, Distinct, Where, Take, Skip, Order, By, Ascending, Descending, Group, Into, Aggregate); |
||||
public static BitArray CastExpressions = NewSet(DirectCast, TryCast, CType, CBool, CByte, CChar, CDate, CDec, CDbl, CInt, CLng, CObj, CSByte, CShort, CSng, CStr, CUInt, CULng, CUShort); |
||||
public static BitArray BooleanExpressions = NewSet(True, False); |
||||
public static BitArray LambdaStart = NewSet(Sub, Function); |
||||
public static BitArray OperatorsAtStart = NewSet(Not, From, Aggregate); |
||||
public static BitArray TypeKW = NewSet(Boolean, Date, Char, String, Decimal, Byte, Short, Integer, Long, Single, Double, UInteger, ULong, UShort, SByte); |
||||
|
||||
static string[] tokenList = new string[] { |
||||
// ----- terminal classes -----
|
||||
"<EOF>", |
||||
"<EOL>", |
||||
"<Identifier>", |
||||
"<LiteralString>", |
||||
"<LiteralCharacter>", |
||||
"<LiteralInteger>", |
||||
"<LiteralDouble>", |
||||
"<LiteralSingle>", |
||||
"<LiteralDecimal>", |
||||
"<LiteralDate>", |
||||
"<XmlOpenTag>", |
||||
"<XmlCloseTag>", |
||||
"<XmlStartInlineVB>", |
||||
"<XmlEndInlineVB>", |
||||
"<XmlCloseTagEmptyElement>", |
||||
"<XmlOpenEndTag>", |
||||
"<XmlContent>", |
||||
"<XmlComment>", |
||||
"<XmlCData>", |
||||
"<XmlProcessingInstruction>", |
||||
// ----- special character -----
|
||||
"=", |
||||
":", |
||||
",", |
||||
"&", |
||||
"/", |
||||
"\\", |
||||
".", |
||||
"...", |
||||
".@", |
||||
"!", |
||||
"-", |
||||
"+", |
||||
"^", |
||||
"?", |
||||
"*", |
||||
"{", |
||||
"}", |
||||
"(", |
||||
")", |
||||
">", |
||||
"<", |
||||
"<>", |
||||
">=", |
||||
"<=", |
||||
"<<", |
||||
">>", |
||||
"+=", |
||||
"^=", |
||||
"-=", |
||||
"*=", |
||||
"/=", |
||||
"\\=", |
||||
"<<=", |
||||
">>=", |
||||
"&=", |
||||
":=", |
||||
// ----- keywords -----
|
||||
"AddHandler", |
||||
"AddressOf", |
||||
"Aggregate", |
||||
"Alias", |
||||
"And", |
||||
"AndAlso", |
||||
"Ansi", |
||||
"As", |
||||
"Ascending", |
||||
"Assembly", |
||||
"Auto", |
||||
"Binary", |
||||
"Boolean", |
||||
"ByRef", |
||||
"By", |
||||
"Byte", |
||||
"ByVal", |
||||
"Call", |
||||
"Case", |
||||
"Catch", |
||||
"CBool", |
||||
"CByte", |
||||
"CChar", |
||||
"CDate", |
||||
"CDbl", |
||||
"CDec", |
||||
"Char", |
||||
"CInt", |
||||
"Class", |
||||
"CLng", |
||||
"CObj", |
||||
"Compare", |
||||
"Const", |
||||
"Continue", |
||||
"CSByte", |
||||
"CShort", |
||||
"CSng", |
||||
"CStr", |
||||
"CType", |
||||
"CUInt", |
||||
"CULng", |
||||
"CUShort", |
||||
"Custom", |
||||
"Date", |
||||
"Decimal", |
||||
"Declare", |
||||
"Default", |
||||
"Delegate", |
||||
"Descending", |
||||
"Dim", |
||||
"DirectCast", |
||||
"Distinct", |
||||
"Do", |
||||
"Double", |
||||
"Each", |
||||
"Else", |
||||
"ElseIf", |
||||
"End", |
||||
"EndIf", |
||||
"Enum", |
||||
"Equals", |
||||
"Erase", |
||||
"Error", |
||||
"Event", |
||||
"Exit", |
||||
"Explicit", |
||||
"False", |
||||
"Finally", |
||||
"For", |
||||
"Friend", |
||||
"From", |
||||
"Function", |
||||
"Get", |
||||
"GetType", |
||||
"Global", |
||||
"GoSub", |
||||
"GoTo", |
||||
"Group", |
||||
"Handles", |
||||
"If", |
||||
"Implements", |
||||
"Imports", |
||||
"In", |
||||
"Infer", |
||||
"Inherits", |
||||
"Integer", |
||||
"Interface", |
||||
"Into", |
||||
"Is", |
||||
"IsNot", |
||||
"Join", |
||||
"Key", |
||||
"Let", |
||||
"Lib", |
||||
"Like", |
||||
"Long", |
||||
"Loop", |
||||
"Me", |
||||
"Mod", |
||||
"Module", |
||||
"MustInherit", |
||||
"MustOverride", |
||||
"MyBase", |
||||
"MyClass", |
||||
"Namespace", |
||||
"Narrowing", |
||||
"New", |
||||
"Next", |
||||
"Not", |
||||
"Nothing", |
||||
"NotInheritable", |
||||
"NotOverridable", |
||||
"Object", |
||||
"Of", |
||||
"Off", |
||||
"On", |
||||
"Operator", |
||||
"Option", |
||||
"Optional", |
||||
"Or", |
||||
"Order", |
||||
"OrElse", |
||||
"Out", |
||||
"Overloads", |
||||
"Overridable", |
||||
"Overrides", |
||||
"ParamArray", |
||||
"Partial", |
||||
"Preserve", |
||||
"Private", |
||||
"Property", |
||||
"Protected", |
||||
"Public", |
||||
"RaiseEvent", |
||||
"ReadOnly", |
||||
"ReDim", |
||||
"Rem", |
||||
"RemoveHandler", |
||||
"Resume", |
||||
"Return", |
||||
"SByte", |
||||
"Select", |
||||
"Set", |
||||
"Shadows", |
||||
"Shared", |
||||
"Short", |
||||
"Single", |
||||
"Skip", |
||||
"Static", |
||||
"Step", |
||||
"Stop", |
||||
"Strict", |
||||
"String", |
||||
"Structure", |
||||
"Sub", |
||||
"SyncLock", |
||||
"Take", |
||||
"Text", |
||||
"Then", |
||||
"Throw", |
||||
"To", |
||||
"True", |
||||
"Try", |
||||
"TryCast", |
||||
"TypeOf", |
||||
"UInteger", |
||||
"ULong", |
||||
"Unicode", |
||||
"Until", |
||||
"UShort", |
||||
"Using", |
||||
"Variant", |
||||
"Wend", |
||||
"When", |
||||
"Where", |
||||
"While", |
||||
"Widening", |
||||
"With", |
||||
"WithEvents", |
||||
"WriteOnly", |
||||
"Xor", |
||||
"GetXmlNamespace", |
||||
}; |
||||
public static string GetTokenString(int token) |
||||
{ |
||||
if (token >= 0 && token < tokenList.Length) { |
||||
return tokenList[token]; |
||||
} |
||||
throw new System.NotSupportedException("Unknown token:" + token); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public sealed class VBLexerMemento : LexerMemento |
||||
{ |
||||
public bool LineEnd { get; set; } |
||||
public bool IsAtLineBegin { get; set; } |
||||
public bool MisreadExclamationMarkAsTypeCharacter { get; set; } |
||||
public bool EncounteredLineContinuation { get; set; } |
||||
public ExpressionFinderState ExpressionFinder { get; set; } |
||||
public Stack<XmlModeInfo> XmlModeInfoStack { get; set; } |
||||
public bool InXmlMode { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,29 @@
@@ -0,0 +1,29 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
public class XmlModeInfo : ICloneable |
||||
{ |
||||
public bool inXmlTag, inXmlCloseTag, isDocumentStart; |
||||
public int level; |
||||
|
||||
public XmlModeInfo(bool isSpecial) |
||||
{ |
||||
level = isSpecial ? -1 : 0; |
||||
inXmlTag = inXmlCloseTag = isDocumentStart = false; |
||||
} |
||||
|
||||
public object Clone() |
||||
{ |
||||
return new XmlModeInfo(false) { |
||||
inXmlCloseTag = this.inXmlCloseTag, |
||||
inXmlTag = this.inXmlTag, |
||||
isDocumentStart = this.isDocumentStart, |
||||
level = this.level |
||||
}; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,121 @@
@@ -0,0 +1,121 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// A line/column position.
|
||||
/// NRefactory lines/columns are counting from one.
|
||||
/// </summary>
|
||||
public struct Location : IComparable<Location>, IEquatable<Location> |
||||
{ |
||||
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; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Stores the operator precedences for the output visitor.
|
||||
/// </summary>
|
||||
static class OperatorPrecedence |
||||
{ |
||||
static readonly Dictionary<BinaryOperatorType, int> 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<BinaryOperatorType, int> 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<BinaryOperatorType, int> MakePrecedenceTable(params BinaryOperatorType[][] input) |
||||
{ |
||||
Dictionary<BinaryOperatorType, int> dict = new Dictionary<BinaryOperatorType, int>(); |
||||
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(csharpDict, op1); |
||||
int p2 = GetOperatorPrecedence(csharpDict, op2); |
||||
return p1.CompareTo(p2); |
||||
} |
||||
|
||||
static int GetOperatorPrecedence(Dictionary<BinaryOperatorType, int> dict, BinaryOperatorType op) |
||||
{ |
||||
int p; |
||||
dict.TryGetValue(op, out p); |
||||
return p; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,106 @@
@@ -0,0 +1,106 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.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 TypeReference ParseTypeReference (); |
||||
public abstract Expression ParseExpression(); |
||||
public abstract BlockStatement ParseBlock(); |
||||
public abstract List<INode> 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
|
||||
} |
||||
} |
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.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; |
||||
} |
||||
} |
||||
|
||||
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
|
||||
} |
@ -0,0 +1,50 @@
@@ -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 |
||||
|
||||
void ParseRoot() |
||||
{ |
||||
-->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 |
||||
|
||||
$$$ |
@ -0,0 +1,202 @@
@@ -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 |
||||
|
||||
$$$ |
Binary file not shown.
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Parser interface.
|
||||
/// </summary>
|
||||
public interface IParser : IDisposable |
||||
{ |
||||
Parser.Errors Errors { |
||||
get; |
||||
} |
||||
|
||||
Parser.ILexer Lexer { |
||||
get; |
||||
} |
||||
|
||||
CompilationUnit CompilationUnit { |
||||
get; |
||||
} |
||||
|
||||
bool ParseMethodBodies { |
||||
get; set; |
||||
} |
||||
|
||||
void Parse(); |
||||
|
||||
Expression ParseExpression(); |
||||
TypeReference ParseTypeReference (); |
||||
BlockStatement ParseBlock(); |
||||
List<INode> ParseTypeMembers(); |
||||
} |
||||
} |
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.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.IsEmpty) { |
||||
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.IsEmpty) { |
||||
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");
|
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
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."); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,387 @@
@@ -0,0 +1,387 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Text; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Parser |
||||
{ |
||||
internal sealed partial class Parser : AbstractParser |
||||
{ |
||||
Lexer lexer; |
||||
Stack<INode> blockStack; |
||||
|
||||
public Parser(ILexer lexer) : base(lexer) |
||||
{ |
||||
this.lexer = (Lexer)lexer; |
||||
this.blockStack = new Stack<INode>(); |
||||
} |
||||
|
||||
void BlockStart(INode block) |
||||
{ |
||||
blockStack.Push(block); |
||||
} |
||||
|
||||
void BlockEnd() |
||||
{ |
||||
blockStack.Pop(); |
||||
} |
||||
|
||||
void AddChild(INode childNode) |
||||
{ |
||||
if (childNode != null) { |
||||
INode parent = (INode)blockStack.Peek(); |
||||
parent.Children.Add(childNode); |
||||
childNode.Parent = parent; |
||||
} |
||||
} |
||||
|
||||
private StringBuilder qualidentBuilder = new StringBuilder(); |
||||
|
||||
Token t |
||||
{ |
||||
[System.Diagnostics.DebuggerStepThrough] |
||||
get { |
||||
return lexer.Token; |
||||
} |
||||
} |
||||
Token la |
||||
{ |
||||
[System.Diagnostics.DebuggerStepThrough] |
||||
get { |
||||
return lexer.LookAhead; |
||||
} |
||||
} |
||||
|
||||
Token Peek (int n) |
||||
{ |
||||
lexer.StartPeek(); |
||||
Token x = la; |
||||
while (n > 0) { |
||||
x = lexer.Peek(); |
||||
n--; |
||||
} |
||||
return x; |
||||
} |
||||
|
||||
public void Error(string s) |
||||
{ |
||||
if (errDist >= MinErrDist) { |
||||
this.Errors.Error(la.line, la.col, s); |
||||
} |
||||
errDist = 0; |
||||
} |
||||
|
||||
public override void Parse() |
||||
{ |
||||
ParseRoot(); |
||||
compilationUnit.AcceptVisitor(new SetParentVisitor(), null); |
||||
} |
||||
|
||||
public override TypeReference ParseTypeReference () |
||||
{ |
||||
// TODO
|
||||
return null; |
||||
} |
||||
|
||||
public override Expression ParseExpression() |
||||
{ |
||||
lexer.SetInitialContext(SnippetType.Expression); |
||||
lexer.NextToken(); |
||||
Location startLocation = la.Location; |
||||
Expression expr; |
||||
Expr(out expr); |
||||
while (la.kind == Tokens.EOL) lexer.NextToken(); |
||||
if (expr != null) { |
||||
expr.StartLocation = startLocation; |
||||
expr.EndLocation = t.EndLocation; |
||||
expr.AcceptVisitor(new SetParentVisitor(), null); |
||||
} |
||||
Expect(Tokens.EOF); |
||||
return expr; |
||||
} |
||||
|
||||
public override BlockStatement ParseBlock() |
||||
{ |
||||
lexer.NextToken(); |
||||
compilationUnit = new CompilationUnit(); |
||||
|
||||
Location startLocation = la.Location; |
||||
Statement st; |
||||
Block(out st); |
||||
if (st != null) { |
||||
st.StartLocation = startLocation; |
||||
if (t != null) |
||||
st.EndLocation = t.EndLocation; |
||||
else |
||||
st.EndLocation = la.Location; |
||||
st.AcceptVisitor(new SetParentVisitor(), null); |
||||
} |
||||
Expect(Tokens.EOF); |
||||
return st as BlockStatement; |
||||
} |
||||
|
||||
public override List<INode> ParseTypeMembers() |
||||
{ |
||||
lexer.NextToken(); |
||||
TypeDeclaration newType = new TypeDeclaration(Modifiers.None, null); |
||||
BlockStart(newType); |
||||
ClassBody(newType); |
||||
BlockEnd(); |
||||
Expect(Tokens.EOF); |
||||
newType.AcceptVisitor(new SetParentVisitor(), null); |
||||
return newType.Children; |
||||
} |
||||
|
||||
bool LeaveBlock() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return Tokens.BlockSucc[la.kind] && (la.kind != Tokens.End || peek == Tokens.EOL || peek == Tokens.Colon); |
||||
} |
||||
|
||||
/* True, if "." is followed by an ident */ |
||||
bool DotAndIdentOrKw () { |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.Dot && (peek == Tokens.Identifier || peek >= Tokens.AddHandler); |
||||
} |
||||
|
||||
static bool IsIdentifierToken(Token tk) |
||||
{ |
||||
return Tokens.IdentifierTokens[tk.kind] || tk.kind == Tokens.Identifier; |
||||
} |
||||
|
||||
bool IsIdentifiedExpressionRange() |
||||
{ |
||||
// t = Select
|
||||
// la = Identifier
|
||||
// Peek(1) = As or Assign
|
||||
Token token = Peek(1); |
||||
return IsIdentifierToken(la) && (token.kind == Tokens.As || token.kind == Tokens.Assign); |
||||
} |
||||
|
||||
bool IsQueryExpression() |
||||
{ |
||||
return (la.kind == Tokens.From || la.kind == Tokens.Aggregate) && IsIdentifierToken(Peek(1)); |
||||
} |
||||
|
||||
bool IsEndStmtAhead() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.End && (peek == Tokens.EOL || peek == Tokens.Colon); |
||||
} |
||||
|
||||
bool IsNotClosingParenthesis() { |
||||
return la.kind != Tokens.CloseParenthesis; |
||||
} |
||||
|
||||
/* |
||||
True, if ident is followed by "=" or by ":" and "=" |
||||
*/ |
||||
bool IsNamedAssign() { |
||||
return Peek(1).kind == Tokens.ColonAssign; |
||||
} |
||||
|
||||
bool IsObjectCreation() { |
||||
return la.kind == Tokens.As && Peek(1).kind == Tokens.New; |
||||
} |
||||
|
||||
bool IsNewExpression() { |
||||
return la.kind == Tokens.New; |
||||
} |
||||
|
||||
/* |
||||
True, if "<" is followed by the ident "assembly" or "module" |
||||
*/ |
||||
bool IsGlobalAttrTarget () { |
||||
Token pt = Peek(1); |
||||
return la.kind == Tokens.LessThan && ( string.Equals(pt.val, "assembly", StringComparison.InvariantCultureIgnoreCase) || string.Equals(pt.val, "module", StringComparison.InvariantCultureIgnoreCase)); |
||||
} |
||||
|
||||
/* |
||||
True if the next token is a "(" and is followed by "," or ")" |
||||
*/ |
||||
bool IsDims() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.OpenParenthesis |
||||
&& (peek == Tokens.Comma || peek == Tokens.CloseParenthesis); |
||||
} |
||||
|
||||
/* |
||||
True if the next token is an identifier |
||||
*/ |
||||
bool IsLoopVariableDeclaration() |
||||
{ |
||||
if (!IsIdentifierToken(la)) |
||||
return false; |
||||
lexer.StartPeek(); |
||||
Token x = lexer.Peek(); |
||||
if (x.kind == Tokens.OpenParenthesis) { |
||||
do { |
||||
x = lexer.Peek(); |
||||
} while (x.kind == Tokens.Comma); |
||||
if (x.kind != Tokens.CloseParenthesis) |
||||
return false; |
||||
x = lexer.Peek(); |
||||
} |
||||
return x.kind == Tokens.As || x.kind == Tokens.Assign; |
||||
} |
||||
|
||||
bool IsSize() |
||||
{ |
||||
return la.kind == Tokens.OpenParenthesis; |
||||
} |
||||
|
||||
/* |
||||
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; |
||||
} |
||||
|
||||
/* |
||||
True, if the next token is "Else" and this one |
||||
if followed by "If" |
||||
*/ |
||||
bool IsElseIf() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.Else && peek == Tokens.If; |
||||
} |
||||
|
||||
/* |
||||
True if the next token is goto and this one is |
||||
followed by minus ("-") (this is allowd in in |
||||
error clauses) |
||||
*/ |
||||
bool IsNegativeLabelName() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.GoTo && peek == Tokens.Minus; |
||||
} |
||||
|
||||
/* |
||||
True if the next statement is a "Resume next" statement |
||||
*/ |
||||
bool IsResumeNext() |
||||
{ |
||||
int peek = Peek(1).kind; |
||||
return la.kind == Tokens.Resume && peek == Tokens.Next; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns True, if ident/literal integer is followed by ":"
|
||||
/// </summary>
|
||||
bool IsLabel() |
||||
{ |
||||
return (la.kind == Tokens.Identifier || la.kind == Tokens.LiteralInteger) |
||||
&& Peek(1).kind == Tokens.Colon; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if a property declaration is an automatic property.
|
||||
/// </summary>
|
||||
bool IsAutomaticProperty() |
||||
{ |
||||
lexer.StartPeek(); |
||||
Token tn = la; |
||||
int braceCount = 0; |
||||
|
||||
// look for attributes
|
||||
while (tn.kind == Tokens.LessThan) { |
||||
while (braceCount > 0 || tn.kind != Tokens.GreaterThan) { |
||||
tn = lexer.Peek(); |
||||
if (tn.kind == Tokens.OpenParenthesis) |
||||
braceCount++; |
||||
if (tn.kind == Tokens.CloseParenthesis) |
||||
braceCount--; |
||||
} |
||||
Debug.Assert(tn.kind == Tokens.GreaterThan); |
||||
tn = lexer.Peek(); |
||||
} |
||||
|
||||
// look for modifiers
|
||||
var allowedTokens = new[] { |
||||
Tokens.Public, Tokens.Protected, |
||||
Tokens.Friend, Tokens.Private |
||||
}; |
||||
|
||||
while (allowedTokens.Contains(tn.kind)) |
||||
tn = lexer.Peek(); |
||||
|
||||
if (tn.Kind != Tokens.Get && tn.Kind != Tokens.Set) |
||||
return true; |
||||
|
||||
return false; |
||||
} |
||||
|
||||
bool IsNotStatementSeparator() |
||||
{ |
||||
return la.kind == Tokens.Colon && Peek(1).kind == Tokens.EOL; |
||||
} |
||||
|
||||
static bool IsMustOverride(ModifierList m) |
||||
{ |
||||
return m.Contains(Modifiers.Abstract); |
||||
} |
||||
|
||||
/* Writes the type name represented through the expression into the string builder. */ |
||||
/* Returns true when the expression was converted successfully, returns false when */ |
||||
/* There was an unknown expression (e.g. TypeReferenceExpression) in it */ |
||||
bool WriteFullTypeName(StringBuilder b, Expression expr) |
||||
{ |
||||
MemberReferenceExpression fre = expr as MemberReferenceExpression; |
||||
if (fre != null) { |
||||
bool result = WriteFullTypeName(b, fre.TargetObject); |
||||
if (b.Length > 0) b.Append('.'); |
||||
b.Append(fre.MemberName); |
||||
return result; |
||||
} else if (expr is IdentifierExpression) { |
||||
b.Append(((IdentifierExpression)expr).Identifier); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/* |
||||
True, if lookahead is a local attribute target specifier, |
||||
i.e. one of "event", "return", "field", "method", |
||||
"module", "param", "property", or "type" |
||||
*/ |
||||
bool IsLocalAttrTarget() { |
||||
// TODO
|
||||
return false; |
||||
} |
||||
|
||||
void EnsureIsZero(Expression expr) |
||||
{ |
||||
if (!(expr is PrimitiveExpression) || (expr as PrimitiveExpression).StringValue != "0") |
||||
Error("lower bound of array must be zero"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a child item to a collection stored in the parent node.
|
||||
/// Also set's the item's parent to <paramref name="parent"/>.
|
||||
/// Does nothing if item is null.
|
||||
/// </summary>
|
||||
static void SafeAdd<T>(INode parent, List<T> 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; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
@echo off |
||||
|
||||
echo Generating with #Coco |
||||
|
||||
cd Frames |
||||
|
||||
copy ..\VBNet\VBNET.ATG |
||||
SharpCoco -namespace ICSharpCode.NRefactory.VB.Parser VBNET.ATG |
||||
move Parser.cs ..\VBNet |
||||
|
||||
del VBNET.ATG |
||||
|
||||
pause |
||||
cd .. |
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
@echo off |
||||
|
||||
echo Generating with #Coco |
||||
|
||||
cd Frames |
||||
|
||||
cp ../CSharp/cs.ATG . |
||||
mono SharpCoco.exe -namespace ICSharpCode.NRefactory.Parser.CSharp cs.ATG |
||||
mv Parser.cs ../CSharp |
||||
|
||||
cp ../VBNet/VBNET.ATG . |
||||
mono SharpCoco.exe -trace GIPXA -namespace ICSharpCode.NRefactory.Parser.VB VBNET.ATG |
||||
mv Parser.cs ../VBNet |
||||
|
||||
rm cs.ATG |
||||
rm VBNET.ATG |
||||
|
||||
cd .. |
@ -0,0 +1,45 @@
@@ -0,0 +1,45 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
/// <summary>
|
||||
/// Static helper class that constructs lexer and parser objects.
|
||||
/// </summary>
|
||||
public static class ParserFactory |
||||
{ |
||||
public static Parser.ILexer CreateLexer(TextReader textReader) |
||||
{ |
||||
return new ICSharpCode.NRefactory.VB.Parser.Lexer(textReader); |
||||
} |
||||
|
||||
public static Parser.ILexer CreateLexer(TextReader textReader, LexerMemento state) |
||||
{ |
||||
return new ICSharpCode.NRefactory.VB.Parser.Lexer(textReader, state); |
||||
} |
||||
|
||||
public static IParser CreateParser(TextReader textReader) |
||||
{ |
||||
Parser.ILexer lexer = CreateLexer(textReader); |
||||
return new ICSharpCode.NRefactory.VB.Parser.Parser(lexer); |
||||
} |
||||
|
||||
public static IParser CreateParser(string fileName) |
||||
{ |
||||
return CreateParser(fileName, Encoding.UTF8); |
||||
} |
||||
|
||||
public static IParser CreateParser(string fileName, Encoding encoding) |
||||
{ |
||||
string ext = Path.GetExtension(fileName); |
||||
if (ext.Equals(".vb", StringComparison.OrdinalIgnoreCase)) |
||||
return CreateParser(new StreamReader(fileName, encoding)); |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,228 @@
@@ -0,0 +1,228 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
/// <summary>
|
||||
/// Base class of output formatters.
|
||||
/// </summary>
|
||||
public abstract class AbstractOutputFormatter : IOutputFormatter |
||||
{ |
||||
StringBuilder text = new StringBuilder(); |
||||
|
||||
int indentationLevel = 0; |
||||
bool indent = true; |
||||
bool doNewLine = true; |
||||
AbstractPrettyPrintOptions prettyPrintOptions; |
||||
|
||||
public bool IsInMemberBody { get; set; } |
||||
|
||||
public int IndentationLevel { |
||||
get { |
||||
return indentationLevel; |
||||
} |
||||
set { |
||||
indentationLevel = value; |
||||
} |
||||
} |
||||
|
||||
public string Text { |
||||
get { |
||||
return text.ToString(); |
||||
} |
||||
} |
||||
|
||||
public int TextLength { |
||||
get { |
||||
return text.Length; |
||||
} |
||||
} |
||||
|
||||
|
||||
public bool DoIndent { |
||||
get { |
||||
return indent; |
||||
} |
||||
set { |
||||
indent = value; |
||||
} |
||||
} |
||||
|
||||
public bool DoNewLine { |
||||
get { |
||||
return doNewLine; |
||||
} |
||||
set { |
||||
doNewLine = value; |
||||
} |
||||
} |
||||
|
||||
protected AbstractOutputFormatter(AbstractPrettyPrintOptions prettyPrintOptions) |
||||
{ |
||||
this.prettyPrintOptions = prettyPrintOptions; |
||||
} |
||||
|
||||
internal bool isIndented = false; |
||||
public void Indent() |
||||
{ |
||||
if (DoIndent) { |
||||
int indent = 0; |
||||
while (indent < prettyPrintOptions.IndentSize * indentationLevel) { |
||||
char ch = prettyPrintOptions.IndentationChar; |
||||
if (ch == '\t' && indent + prettyPrintOptions.TabSize > prettyPrintOptions.IndentSize * indentationLevel) { |
||||
ch = ' '; |
||||
} |
||||
text.Append(ch); |
||||
if (ch == '\t') { |
||||
indent += prettyPrintOptions.TabSize; |
||||
} else { |
||||
++indent; |
||||
} |
||||
} |
||||
isIndented = true; |
||||
} |
||||
} |
||||
|
||||
public void Reset () |
||||
{ |
||||
text.Length = 0; |
||||
isIndented = false; |
||||
} |
||||
|
||||
public void Space() |
||||
{ |
||||
text.Append(' '); |
||||
isIndented = false; |
||||
} |
||||
|
||||
internal int lastLineStart = 0; |
||||
internal int lineBeforeLastStart = 0; |
||||
|
||||
public bool LastCharacterIsNewLine { |
||||
get { |
||||
return text.Length == lastLineStart; |
||||
} |
||||
} |
||||
|
||||
public bool LastCharacterIsWhiteSpace { |
||||
get { |
||||
return text.Length == 0 || char.IsWhiteSpace(text[text.Length - 1]); |
||||
} |
||||
} |
||||
|
||||
public virtual void NewLine() |
||||
{ |
||||
if (DoNewLine) { |
||||
if (!LastCharacterIsNewLine) { |
||||
lineBeforeLastStart = lastLineStart; |
||||
} |
||||
text.AppendLine(); |
||||
lastLineStart = text.Length; |
||||
isIndented = false; |
||||
} |
||||
} |
||||
|
||||
public virtual void EndFile() |
||||
{ |
||||
} |
||||
|
||||
protected void WriteLineInPreviousLine(string txt, bool forceWriteInPreviousBlock) |
||||
{ |
||||
WriteInPreviousLine(txt + Environment.NewLine, forceWriteInPreviousBlock); |
||||
} |
||||
protected void WriteLineInPreviousLine(string txt, bool forceWriteInPreviousBlock, bool indent) |
||||
{ |
||||
WriteInPreviousLine(txt + Environment.NewLine, forceWriteInPreviousBlock, indent); |
||||
} |
||||
|
||||
protected void WriteInPreviousLine(string txt, bool forceWriteInPreviousBlock) |
||||
{ |
||||
WriteInPreviousLine(txt, forceWriteInPreviousBlock, true); |
||||
} |
||||
protected void WriteInPreviousLine(string txt, bool forceWriteInPreviousBlock, bool indent) |
||||
{ |
||||
if (txt.Length == 0) return; |
||||
|
||||
bool lastCharacterWasNewLine = LastCharacterIsNewLine; |
||||
if (lastCharacterWasNewLine) { |
||||
if (forceWriteInPreviousBlock == false) { |
||||
if (indent && txt != Environment.NewLine) Indent(); |
||||
text.Append(txt); |
||||
lineBeforeLastStart = lastLineStart; |
||||
lastLineStart = text.Length; |
||||
return; |
||||
} |
||||
lastLineStart = lineBeforeLastStart; |
||||
} |
||||
string lastLine = text.ToString(lastLineStart, text.Length - lastLineStart); |
||||
text.Remove(lastLineStart, text.Length - lastLineStart); |
||||
if (indent && txt != Environment.NewLine) { |
||||
if (forceWriteInPreviousBlock) ++indentationLevel; |
||||
Indent(); |
||||
if (forceWriteInPreviousBlock) --indentationLevel; |
||||
} |
||||
text.Append(txt); |
||||
lineBeforeLastStart = lastLineStart; |
||||
lastLineStart = text.Length; |
||||
text.Append(lastLine); |
||||
if (lastCharacterWasNewLine) { |
||||
lineBeforeLastStart = lastLineStart; |
||||
lastLineStart = text.Length; |
||||
} |
||||
isIndented = false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Prints a text that cannot be inserted before using WriteInPreviousLine
|
||||
/// into the current line
|
||||
/// </summary>
|
||||
protected void PrintSpecialText(string specialText) |
||||
{ |
||||
lineBeforeLastStart = text.Length; |
||||
text.Append(specialText); |
||||
lastLineStart = text.Length; |
||||
isIndented = false; |
||||
} |
||||
|
||||
public void PrintTokenList(ArrayList tokenList) |
||||
{ |
||||
foreach (int token in tokenList) { |
||||
PrintToken(token); |
||||
Space(); |
||||
} |
||||
} |
||||
|
||||
public abstract void PrintComment(Comment comment, bool forceWriteInPreviousBlock); |
||||
|
||||
public virtual void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock) |
||||
{ |
||||
if (!directive.Expression.IsNull) { |
||||
// CSharpOutputVisitor visitor = new CSharpOutputVisitor();
|
||||
// directive.Expression.AcceptVisitor(visitor, null);
|
||||
// WriteLineInPreviousLine(directive.Cmd + " " + visitor.Text, forceWriteInPreviousBlock);
|
||||
} else if (string.IsNullOrEmpty(directive.Arg)) |
||||
WriteLineInPreviousLine(directive.Cmd, forceWriteInPreviousBlock); |
||||
else |
||||
WriteLineInPreviousLine(directive.Cmd + " " + directive.Arg, forceWriteInPreviousBlock); |
||||
} |
||||
|
||||
public void PrintBlankLine(bool forceWriteInPreviousBlock) |
||||
{ |
||||
WriteInPreviousLine(Environment.NewLine, forceWriteInPreviousBlock); |
||||
} |
||||
|
||||
public abstract void PrintToken(int token); |
||||
|
||||
public void PrintText(string text) |
||||
{ |
||||
this.text.Append(text); |
||||
isIndented = false; |
||||
} |
||||
|
||||
public abstract void PrintIdentifier(string identifier); |
||||
} |
||||
} |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of PrettyPrintOptions.
|
||||
/// </summary>
|
||||
public class AbstractPrettyPrintOptions |
||||
{ |
||||
char indentationChar = '\t'; |
||||
int tabSize = 4; |
||||
int indentSize = 4; |
||||
|
||||
public char IndentationChar { |
||||
get { |
||||
return indentationChar; |
||||
} |
||||
set { |
||||
indentationChar = value; |
||||
} |
||||
} |
||||
|
||||
public int TabSize { |
||||
get { |
||||
return tabSize; |
||||
} |
||||
set { |
||||
tabSize = value; |
||||
} |
||||
} |
||||
|
||||
public int IndentSize { |
||||
get { |
||||
return indentSize; |
||||
} |
||||
set { |
||||
indentSize = value; |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of IOutputASTVisitor.
|
||||
/// </summary>
|
||||
public interface IOutputAstVisitor : IAstVisitor |
||||
{ |
||||
event Action<INode> BeforeNodeVisit; |
||||
event Action<INode> AfterNodeVisit; |
||||
|
||||
string Text { |
||||
get; |
||||
} |
||||
|
||||
Errors Errors { |
||||
get; |
||||
} |
||||
|
||||
AbstractPrettyPrintOptions Options { |
||||
get; |
||||
} |
||||
IOutputFormatter OutputFormatter { |
||||
get; |
||||
} |
||||
} |
||||
public interface IOutputFormatter |
||||
{ |
||||
int IndentationLevel { |
||||
get; |
||||
set; |
||||
} |
||||
string Text { |
||||
get; |
||||
} |
||||
bool IsInMemberBody { |
||||
get; |
||||
set; |
||||
} |
||||
void NewLine(); |
||||
void Indent(); |
||||
void PrintComment(Comment comment, bool forceWriteInPreviousBlock); |
||||
void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock); |
||||
void PrintBlankLine(bool forceWriteInPreviousBlock); |
||||
} |
||||
} |
@ -0,0 +1,142 @@
@@ -0,0 +1,142 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
public class SpecialOutputVisitor : ISpecialVisitor |
||||
{ |
||||
readonly IOutputFormatter formatter; |
||||
|
||||
public SpecialOutputVisitor(IOutputFormatter formatter) |
||||
{ |
||||
this.formatter = formatter; |
||||
} |
||||
|
||||
public bool ForceWriteInPreviousLine; |
||||
|
||||
public object Visit(ISpecial special, object data) |
||||
{ |
||||
Console.WriteLine("Warning: SpecialOutputVisitor.Visit(ISpecial) called with " + special); |
||||
return data; |
||||
} |
||||
|
||||
public object Visit(BlankLine special, object data) |
||||
{ |
||||
formatter.PrintBlankLine(ForceWriteInPreviousLine); |
||||
return data; |
||||
} |
||||
|
||||
public object Visit(Comment special, object data) |
||||
{ |
||||
formatter.PrintComment(special, ForceWriteInPreviousLine); |
||||
return data; |
||||
} |
||||
|
||||
public object Visit(PreprocessingDirective special, object data) |
||||
{ |
||||
formatter.PrintPreprocessingDirective(special, ForceWriteInPreviousLine); |
||||
return data; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// This class inserts specials between INodes.
|
||||
/// </summary>
|
||||
public sealed class SpecialNodesInserter : IDisposable |
||||
{ |
||||
IEnumerator<ISpecial> enumerator; |
||||
SpecialOutputVisitor visitor; |
||||
bool available; // true when more specials are available
|
||||
|
||||
public SpecialNodesInserter(IEnumerable<ISpecial> specials, SpecialOutputVisitor visitor) |
||||
{ |
||||
if (specials == null) throw new ArgumentNullException("specials"); |
||||
if (visitor == null) throw new ArgumentNullException("visitor"); |
||||
enumerator = specials.GetEnumerator(); |
||||
this.visitor = visitor; |
||||
available = enumerator.MoveNext(); |
||||
} |
||||
|
||||
void WriteCurrent() |
||||
{ |
||||
enumerator.Current.AcceptVisitor(visitor, null); |
||||
available = enumerator.MoveNext(); |
||||
} |
||||
|
||||
AttributedNode currentAttributedNode; |
||||
|
||||
/// <summary>
|
||||
/// Writes all specials up to the start position of the node.
|
||||
/// </summary>
|
||||
public void AcceptNodeStart(INode node) |
||||
{ |
||||
if (node is AttributedNode) { |
||||
currentAttributedNode = node as AttributedNode; |
||||
if (currentAttributedNode.Attributes.Count == 0) { |
||||
AcceptPoint(node.StartLocation); |
||||
currentAttributedNode = null; |
||||
} |
||||
} else { |
||||
AcceptPoint(node.StartLocation); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes all specials up to the end position of the node.
|
||||
/// </summary>
|
||||
public void AcceptNodeEnd(INode node) |
||||
{ |
||||
visitor.ForceWriteInPreviousLine = true; |
||||
AcceptPoint(node.EndLocation); |
||||
visitor.ForceWriteInPreviousLine = false; |
||||
if (currentAttributedNode != null) { |
||||
if (node == currentAttributedNode.Attributes[currentAttributedNode.Attributes.Count - 1]) { |
||||
AcceptPoint(currentAttributedNode.StartLocation); |
||||
currentAttributedNode = null; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes all specials up to the specified location.
|
||||
/// </summary>
|
||||
public void AcceptPoint(Location loc) |
||||
{ |
||||
while (available && enumerator.Current.StartPosition <= loc) { |
||||
WriteCurrent(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Outputs all missing specials to the writer.
|
||||
/// </summary>
|
||||
public void Finish() |
||||
{ |
||||
while (available) { |
||||
WriteCurrent(); |
||||
} |
||||
} |
||||
|
||||
void IDisposable.Dispose() |
||||
{ |
||||
Finish(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Registers a new SpecialNodesInserter with the output visitor.
|
||||
/// Make sure to call Finish() (or Dispose()) on the returned SpecialNodesInserter
|
||||
/// when the output is finished.
|
||||
/// </summary>
|
||||
public static SpecialNodesInserter Install(IEnumerable<ISpecial> specials, IOutputAstVisitor outputVisitor) |
||||
{ |
||||
SpecialNodesInserter sni = new SpecialNodesInserter(specials, new SpecialOutputVisitor(outputVisitor.OutputFormatter)); |
||||
outputVisitor.BeforeNodeVisit += sni.AcceptNodeStart; |
||||
outputVisitor.AfterNodeVisit += sni.AcceptNodeEnd; |
||||
return sni; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of VBNetOutputFormatter.
|
||||
/// </summary>
|
||||
public sealed class VBNetOutputFormatter : AbstractOutputFormatter |
||||
{ |
||||
public VBNetOutputFormatter(VBNetPrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions) |
||||
{ |
||||
} |
||||
|
||||
public override void PrintToken(int token) |
||||
{ |
||||
PrintText(Tokens.GetTokenString(token)); |
||||
} |
||||
|
||||
public override void PrintIdentifier(string identifier) |
||||
{ |
||||
if (Keywords.IsNonIdentifierKeyword(identifier)) { |
||||
PrintText("["); |
||||
PrintText(identifier); |
||||
PrintText("]"); |
||||
} else { |
||||
PrintText(identifier); |
||||
} |
||||
} |
||||
|
||||
public override void PrintComment(Comment comment, bool forceWriteInPreviousBlock) |
||||
{ |
||||
switch (comment.CommentType) { |
||||
case CommentType.Block: |
||||
WriteLineInPreviousLine("'" + comment.CommentText.Replace("\n", "\n'"), forceWriteInPreviousBlock); |
||||
break; |
||||
case CommentType.Documentation: |
||||
WriteLineInPreviousLine("'''" + comment.CommentText, forceWriteInPreviousBlock); |
||||
break; |
||||
default: |
||||
WriteLineInPreviousLine("'" + comment.CommentText, forceWriteInPreviousBlock); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
public override void PrintPreprocessingDirective(PreprocessingDirective directive, bool forceWriteInPreviousBlock) |
||||
{ |
||||
if (IsInMemberBody |
||||
&& (string.Equals(directive.Cmd, "#Region", StringComparison.InvariantCultureIgnoreCase) |
||||
|| string.Equals(directive.Cmd, "#End", StringComparison.InvariantCultureIgnoreCase) |
||||
&& directive.Arg.StartsWith("Region", StringComparison.InvariantCultureIgnoreCase))) |
||||
{ |
||||
WriteLineInPreviousLine("'" + directive.Cmd + " " + directive.Arg, forceWriteInPreviousBlock); |
||||
} else if (!directive.Expression.IsNull) { |
||||
VBNetOutputVisitor visitor = new VBNetOutputVisitor(); |
||||
directive.Expression.AcceptVisitor(visitor, null); |
||||
WriteLineInPreviousLine(directive.Cmd + " " + visitor.Text + " Then", forceWriteInPreviousBlock); |
||||
} else { |
||||
base.PrintPreprocessingDirective(directive, forceWriteInPreviousBlock); |
||||
} |
||||
} |
||||
|
||||
public void PrintLineContinuation() |
||||
{ |
||||
if (!LastCharacterIsWhiteSpace) |
||||
Space(); |
||||
PrintText("_" + Environment.NewLine); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,18 @@
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.PrettyPrinter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of VBNetPrettyPrintOptions.
|
||||
/// </summary>
|
||||
public class VBNetPrettyPrintOptions : AbstractPrettyPrintOptions |
||||
{ |
||||
/// <summary>
|
||||
/// Gets/Sets if the optional "ByVal" modifier should be written.
|
||||
/// </summary>
|
||||
public bool OutputByValModifier { get; set; } |
||||
} |
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ICSharpCode.NRefactory.VB")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ICSharpCode.NRefactory.VB")] |
||||
[assembly: AssemblyCopyright("Copyright 2010")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,130 @@
@@ -0,0 +1,130 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB |
||||
{ |
||||
public enum SnippetType |
||||
{ |
||||
None, |
||||
CompilationUnit, |
||||
Expression, |
||||
Statements, |
||||
TypeMembers |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The snippet parser supports parsing code snippets that are not valid as a full compilation unit.
|
||||
/// </summary>
|
||||
public class SnippetParser |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the errors of the last call to Parse(). Returns null if parse was not yet called.
|
||||
/// </summary>
|
||||
public Errors Errors { get; private set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the specials of the last call to Parse(). Returns null if parse was not yet called.
|
||||
/// </summary>
|
||||
public List<ISpecial> Specials { get; private set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the snippet type of the last call to Parse(). Returns None if parse was not yet called.
|
||||
/// </summary>
|
||||
public SnippetType SnippetType { get; private set; } |
||||
|
||||
/// <summary>
|
||||
/// Parse the code. The result may be a CompilationUnit, an Expression, a list of statements or a list of class
|
||||
/// members.
|
||||
/// </summary>
|
||||
public INode Parse(string code) |
||||
{ |
||||
IParser parser = ParserFactory.CreateParser(new StringReader(code)); |
||||
parser.Parse(); |
||||
this.Errors = parser.Errors; |
||||
this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials(); |
||||
this.SnippetType = SnippetType.CompilationUnit; |
||||
INode result = parser.CompilationUnit; |
||||
|
||||
if (this.Errors.Count > 0) { |
||||
parser = ParserFactory.CreateParser(new StringReader(code)); |
||||
Expression expression = parser.ParseExpression(); |
||||
if (expression != null && parser.Errors.Count < this.Errors.Count) { |
||||
this.Errors = parser.Errors; |
||||
this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials(); |
||||
this.SnippetType = SnippetType.Expression; |
||||
result = expression; |
||||
} |
||||
} |
||||
if (this.Errors.Count > 0) { |
||||
parser = ParserFactory.CreateParser(new StringReader(code)); |
||||
BlockStatement block = parser.ParseBlock(); |
||||
if (block != null && parser.Errors.Count < this.Errors.Count) { |
||||
this.Errors = parser.Errors; |
||||
this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials(); |
||||
this.SnippetType = SnippetType.Statements; |
||||
result = block; |
||||
} |
||||
} |
||||
if (this.Errors.Count > 0) { |
||||
parser = ParserFactory.CreateParser(new StringReader(code)); |
||||
List<INode> members = parser.ParseTypeMembers(); |
||||
if (members != null && members.Count > 0 && parser.Errors.Count < this.Errors.Count) { |
||||
this.Errors = parser.Errors; |
||||
this.Specials = parser.Lexer.SpecialTracker.RetrieveSpecials(); |
||||
this.SnippetType = SnippetType.TypeMembers; |
||||
result = new NodeListNode(members); |
||||
result.StartLocation = members[0].StartLocation; |
||||
result.EndLocation = members[members.Count - 1].EndLocation; |
||||
} |
||||
} |
||||
Debug.Assert(result is CompilationUnit || !result.StartLocation.IsEmpty); |
||||
Debug.Assert(result is CompilationUnit || !result.EndLocation.IsEmpty); |
||||
return result; |
||||
} |
||||
|
||||
sealed class NodeListNode : INode |
||||
{ |
||||
List<INode> nodes; |
||||
|
||||
public NodeListNode(List<INode> nodes) |
||||
{ |
||||
this.nodes = nodes; |
||||
} |
||||
|
||||
public INode Parent { |
||||
get { return null; } |
||||
set { throw new NotSupportedException(); } |
||||
} |
||||
|
||||
public List<INode> Children { |
||||
get { return nodes; } |
||||
} |
||||
|
||||
public Location StartLocation { get; set; } |
||||
public Location EndLocation { get; set; } |
||||
|
||||
public object UserData { get; set; } |
||||
|
||||
public object AcceptChildren(IAstVisitor visitor, object data) |
||||
{ |
||||
foreach (INode n in nodes) { |
||||
n.AcceptVisitor(visitor, data); |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
public object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return AcceptChildren(visitor, data); |
||||
} |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,356 @@
@@ -0,0 +1,356 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
using System.CodeDom.Compiler; |
||||
using System.IO; |
||||
using System.Security.Permissions; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
[PermissionSet(SecurityAction.InheritanceDemand, Name = "FullTrust")] |
||||
[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] |
||||
public class CodeDomVerboseOutputGenerator : System.CodeDom.Compiler.CodeGenerator |
||||
{ |
||||
#region System.CodeDom.Compiler.CodeGenerator abstract class implementation
|
||||
protected override string NullToken { |
||||
get { |
||||
return "[NULL]"; |
||||
} |
||||
} |
||||
|
||||
protected override void OutputType(CodeTypeReference typeRef) |
||||
{ |
||||
Output.Write("[CodeTypeReference: {0}", typeRef.BaseType); |
||||
if (typeRef.ArrayRank > 0) { |
||||
Output.Write(" Rank:" + typeRef.ArrayRank); |
||||
} |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GenerateArrayCreateExpression(CodeArrayCreateExpression e) |
||||
{ |
||||
Output.Write("[CodeArrayCreateExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateBaseReferenceExpression(CodeBaseReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeBaseReferenceExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateCastExpression(CodeCastExpression e) |
||||
{ |
||||
Output.Write("[CodeCastExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateDelegateCreateExpression(CodeDelegateCreateExpression e) |
||||
{ |
||||
Output.Write("[CodeDelegateCreateExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateFieldReferenceExpression(CodeFieldReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeFieldReferenceExpression: Name={0}, Target=", e.FieldName); |
||||
this.GenerateExpression(e.TargetObject); |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GenerateMethodReferenceExpression(CodeMethodReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeMethodReferenceExpression: Name={0}, Target=", e.MethodName); |
||||
this.GenerateExpression(e.TargetObject); |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GenerateEventReferenceExpression(CodeEventReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeEventReferenceExpression: Name={0}, Target=", e.EventName); |
||||
this.GenerateExpression(e.TargetObject); |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GenerateArgumentReferenceExpression(CodeArgumentReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeArgumentReferenceExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateVariableReferenceExpression(CodeVariableReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeVariableReferenceExpression: Name={0}]", e.VariableName); |
||||
} |
||||
|
||||
protected override void GenerateIndexerExpression(CodeIndexerExpression e) |
||||
{ |
||||
Output.Write("[CodeIndexerExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateArrayIndexerExpression(CodeArrayIndexerExpression e) |
||||
{ |
||||
Output.Write("[CodeArrayIndexerExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateSnippetExpression(CodeSnippetExpression e) |
||||
{ |
||||
Output.Write("[CodeSnippetExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateMethodInvokeExpression(CodeMethodInvokeExpression e) |
||||
{ |
||||
Output.Write("[CodeMethodInvokeExpression: Method="); |
||||
GenerateMethodReferenceExpression(e.Method); |
||||
Output.Write(", Parameters="); |
||||
bool first = true; |
||||
foreach (CodeExpression expr in e.Parameters) { |
||||
if (first) first = false; else Output.Write(", "); |
||||
this.GenerateExpression(expr); |
||||
} |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GenerateDelegateInvokeExpression(CodeDelegateInvokeExpression e) |
||||
{ |
||||
Output.Write("[CodeDelegateInvokeExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateObjectCreateExpression(CodeObjectCreateExpression e) |
||||
{ |
||||
Output.Write("[CodeObjectCreateExpression: Type={0}, Parameters=", e.CreateType.BaseType); |
||||
bool first = true; |
||||
foreach (CodeExpression expr in e.Parameters) { |
||||
if (first) first = false; else Output.Write(", "); |
||||
this.GenerateExpression(expr); |
||||
} |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GeneratePropertyReferenceExpression(CodePropertyReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodePropertyReferenceExpression: Name={0}, Target=", e.PropertyName); |
||||
this.GenerateExpression(e.TargetObject); |
||||
Output.Write("]"); |
||||
} |
||||
|
||||
protected override void GeneratePropertySetValueReferenceExpression(CodePropertySetValueReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodePropertySetValueReferenceExpression: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateThisReferenceExpression(CodeThisReferenceExpression e) |
||||
{ |
||||
Output.Write("[CodeThisReferenceExpression]"); |
||||
} |
||||
|
||||
protected override void GenerateExpressionStatement(CodeExpressionStatement e) |
||||
{ |
||||
Output.Write("[CodeExpressionStatement:"); |
||||
base.GenerateExpression(e.Expression); |
||||
Output.WriteLine("]"); |
||||
} |
||||
|
||||
protected override void GenerateIterationStatement(CodeIterationStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeIterationStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateThrowExceptionStatement(CodeThrowExceptionStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeThrowExceptionStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateComment(CodeComment e) |
||||
{ |
||||
Output.WriteLine("[CodeComment: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateMethodReturnStatement(CodeMethodReturnStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeMethodReturnStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateConditionStatement(CodeConditionStatement e) |
||||
{ |
||||
Output.WriteLine("[GenerateConditionStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateTryCatchFinallyStatement(CodeTryCatchFinallyStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeTryCatchFinallyStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateAssignStatement(CodeAssignStatement e) |
||||
{ |
||||
Output.Write("[CodeAssignStatement: Left="); |
||||
base.GenerateExpression(e.Left); |
||||
Output.Write(", Right="); |
||||
base.GenerateExpression(e.Right); |
||||
Output.WriteLine("]"); |
||||
} |
||||
|
||||
protected override void GenerateAttachEventStatement(CodeAttachEventStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeAttachEventStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateRemoveEventStatement(CodeRemoveEventStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeRemoveEventStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateGotoStatement(CodeGotoStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeGotoStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateLabeledStatement(CodeLabeledStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeLabeledStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateVariableDeclarationStatement(CodeVariableDeclarationStatement e) |
||||
{ |
||||
Output.WriteLine("[CodeVariableDeclarationStatement: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateLinePragmaStart(CodeLinePragma e) |
||||
{ |
||||
Output.WriteLine("[CodeLinePragma: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateLinePragmaEnd(CodeLinePragma e) |
||||
{ |
||||
Output.WriteLine("[CodeLinePragma: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateEvent(CodeMemberEvent e, CodeTypeDeclaration c) |
||||
{ |
||||
Output.WriteLine("[CodeMemberEvent: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateField(CodeMemberField e) |
||||
{ |
||||
Output.Write("[CodeMemberField: Name={0}, Type=", e.Name); |
||||
Output.Write(e.Type.BaseType); |
||||
Output.WriteLine("]"); |
||||
} |
||||
|
||||
protected override void GenerateSnippetMember(CodeSnippetTypeMember e) |
||||
{ |
||||
Output.WriteLine("[CodeSnippetTypeMember: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateEntryPointMethod(CodeEntryPointMethod e, CodeTypeDeclaration c) |
||||
{ |
||||
Output.WriteLine("[CodeEntryPointMethod: {0}]", e.ToString()); |
||||
} |
||||
|
||||
public void PublicGenerateCodeFromStatement(CodeStatement e, TextWriter w, CodeGeneratorOptions o) |
||||
{ |
||||
((ICodeGenerator)this).GenerateCodeFromStatement(e, w, o); |
||||
} |
||||
|
||||
protected override void GenerateMethod(CodeMemberMethod e, CodeTypeDeclaration c) |
||||
{ |
||||
Output.WriteLine("[CodeMemberMethod: Name={0}, Parameterns={1}]", e.Name, e.Parameters.Count); |
||||
++Indent; |
||||
GenerateStatements(e.Statements); |
||||
--Indent; |
||||
} |
||||
|
||||
protected override void GenerateProperty(CodeMemberProperty e, CodeTypeDeclaration c) |
||||
{ |
||||
Output.WriteLine("[CodeMemberProperty : {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateConstructor(CodeConstructor e, CodeTypeDeclaration c) |
||||
{ |
||||
Output.WriteLine("[CodeConstructor : {0}]", e.ToString()); |
||||
++Indent; |
||||
GenerateStatements(e.Statements); |
||||
--Indent; |
||||
} |
||||
|
||||
protected override void GenerateTypeConstructor(CodeTypeConstructor e) |
||||
{ |
||||
Output.WriteLine("[CodeTypeConstructor : {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateTypeStart(CodeTypeDeclaration e) |
||||
{ |
||||
Output.WriteLine("[CodeTypeDeclaration : {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateTypeEnd(CodeTypeDeclaration e) |
||||
{ |
||||
Output.WriteLine("[CodeTypeDeclaration: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateNamespaceStart(CodeNamespace e) |
||||
{ |
||||
Output.WriteLine("[CodeNamespaceStart: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateNamespaceEnd(CodeNamespace e) |
||||
{ |
||||
Output.WriteLine("[CodeNamespaceEnd: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateNamespaceImport(CodeNamespaceImport e) |
||||
{ |
||||
Output.WriteLine("[CodeNamespaceImport: {0}]", e.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateAttributeDeclarationsStart(CodeAttributeDeclarationCollection attributes) |
||||
{ |
||||
Output.WriteLine("[CodeAttributeDeclarationCollection: {0}]", attributes.ToString()); |
||||
} |
||||
|
||||
protected override void GenerateAttributeDeclarationsEnd(CodeAttributeDeclarationCollection attributes) |
||||
{ |
||||
Output.WriteLine("[CodeAttributeDeclarationCollection: {0}]", attributes.ToString()); |
||||
} |
||||
|
||||
protected override void GeneratePrimitiveExpression(CodePrimitiveExpression e) |
||||
{ |
||||
if (e.Value == null) { |
||||
Output.WriteLine("[CodePrimitiveExpression: null]"); |
||||
} else { |
||||
Output.Write("[CodePrimitiveExpression: "); |
||||
base.GeneratePrimitiveExpression(e); |
||||
Output.WriteLine(" (" + e.Value.GetType().Name + ")]"); |
||||
} |
||||
} |
||||
|
||||
protected override bool Supports(GeneratorSupport support) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
protected override bool IsValidIdentifier(string value) |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
protected override string CreateEscapedIdentifier(string value) |
||||
{ |
||||
return value; |
||||
} |
||||
|
||||
protected override string CreateValidIdentifier(string value) |
||||
{ |
||||
return value; |
||||
} |
||||
|
||||
protected override string GetTypeOutput(CodeTypeReference value) |
||||
{ |
||||
return value.ToString(); |
||||
} |
||||
|
||||
protected override string QuoteSnippetString(string value) |
||||
{ |
||||
return "\"" + value + "\""; |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,308 @@
@@ -0,0 +1,308 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
public sealed class LocalLookupVariable |
||||
{ |
||||
public readonly string Name; |
||||
public readonly TypeReference TypeRef; |
||||
public readonly Location StartPos; |
||||
public readonly Location EndPos; |
||||
public readonly bool IsConst; |
||||
public readonly bool IsLoopVariable; |
||||
public readonly Expression Initializer; |
||||
public readonly LambdaExpression ParentLambdaExpression; |
||||
public readonly bool IsQueryContinuation; |
||||
|
||||
public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation) |
||||
{ |
||||
this.Name = name; |
||||
this.TypeRef = typeRef; |
||||
this.StartPos = startPos; |
||||
this.EndPos = endPos; |
||||
this.IsConst = isConst; |
||||
this.IsLoopVariable = isLoopVariable; |
||||
this.Initializer = initializer; |
||||
this.ParentLambdaExpression = parentLambdaExpression; |
||||
this.IsQueryContinuation = isQueryContinuation; |
||||
} |
||||
|
||||
} |
||||
|
||||
public sealed class LookupTableVisitor : AbstractAstVisitor |
||||
{ |
||||
Dictionary<string, List<LocalLookupVariable>> variables; |
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] |
||||
public Dictionary<string, List<LocalLookupVariable>> Variables { |
||||
get { |
||||
return variables; |
||||
} |
||||
} |
||||
|
||||
List<WithStatement> withStatements = new List<WithStatement>(); |
||||
|
||||
public List<WithStatement> WithStatements { |
||||
get { |
||||
return withStatements; |
||||
} |
||||
} |
||||
|
||||
public LookupTableVisitor() |
||||
{ |
||||
variables = new Dictionary<string, List<LocalLookupVariable>>(StringComparer.InvariantCultureIgnoreCase); |
||||
} |
||||
|
||||
public void AddVariable(TypeReference typeRef, string name, |
||||
Location startPos, Location endPos, bool isConst, |
||||
bool isLoopVariable, Expression initializer, |
||||
LambdaExpression parentLambdaExpression, |
||||
bool isQueryContinuation) |
||||
{ |
||||
if (name == null || name.Length == 0) { |
||||
return; |
||||
} |
||||
List<LocalLookupVariable> list; |
||||
if (!variables.ContainsKey(name)) { |
||||
variables[name] = list = new List<LocalLookupVariable>(); |
||||
} else { |
||||
list = (List<LocalLookupVariable>)variables[name]; |
||||
} |
||||
list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation)); |
||||
} |
||||
|
||||
public override object VisitWithStatement(WithStatement withStatement, object data) |
||||
{ |
||||
withStatements.Add(withStatement); |
||||
return base.VisitWithStatement(withStatement, data); |
||||
} |
||||
|
||||
Stack<Location> endLocationStack = new Stack<Location>(); |
||||
|
||||
Location CurrentEndLocation { |
||||
get { |
||||
return (endLocationStack.Count == 0) ? Location.Empty : endLocationStack.Peek(); |
||||
} |
||||
} |
||||
|
||||
public override object VisitCompilationUnit (ICSharpCode.NRefactory.VB.Dom.CompilationUnit compilationUnit, object data) |
||||
{ |
||||
variables.Clear (); |
||||
return base.VisitCompilationUnit (compilationUnit, data); |
||||
} |
||||
|
||||
public override object VisitBlockStatement(BlockStatement blockStatement, object data) |
||||
{ |
||||
endLocationStack.Push(blockStatement.EndLocation); |
||||
base.VisitBlockStatement(blockStatement, data); |
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
|
||||
public override object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) |
||||
{ |
||||
for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) { |
||||
VariableDeclaration varDecl = (VariableDeclaration)localVariableDeclaration.Variables[i]; |
||||
|
||||
AddVariable(localVariableDeclaration.GetTypeForVariable(i), |
||||
varDecl.Name, |
||||
localVariableDeclaration.StartLocation, |
||||
CurrentEndLocation, |
||||
(localVariableDeclaration.Modifier & Modifiers.Const) == Modifiers.Const, |
||||
false, varDecl.Initializer, null, false); |
||||
} |
||||
return base.VisitLocalVariableDeclaration(localVariableDeclaration, data); |
||||
} |
||||
|
||||
public override object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) |
||||
{ |
||||
foreach (ParameterDeclarationExpression p in anonymousMethodExpression.Parameters) { |
||||
AddVariable(p.TypeReference, p.ParameterName, |
||||
anonymousMethodExpression.StartLocation, anonymousMethodExpression.EndLocation, |
||||
false, false, null, null, false); |
||||
} |
||||
return base.VisitAnonymousMethodExpression(anonymousMethodExpression, data); |
||||
} |
||||
|
||||
public override object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) |
||||
{ |
||||
foreach (ParameterDeclarationExpression p in lambdaExpression.Parameters) { |
||||
AddVariable(p.TypeReference, p.ParameterName, |
||||
lambdaExpression.StartLocation, lambdaExpression.ExtendedEndLocation, |
||||
false, false, null, lambdaExpression, false); |
||||
} |
||||
return base.VisitLambdaExpression(lambdaExpression, data); |
||||
} |
||||
|
||||
public override object VisitQueryExpression(QueryExpression queryExpression, object data) |
||||
{ |
||||
endLocationStack.Push(GetQueryVariableEndScope(queryExpression)); |
||||
base.VisitQueryExpression(queryExpression, data); |
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
|
||||
Location GetQueryVariableEndScope(QueryExpression queryExpression) |
||||
{ |
||||
return queryExpression.EndLocation; |
||||
} |
||||
|
||||
public override object VisitQueryExpressionFromClause(QueryExpressionFromClause fromClause, object data) |
||||
{ |
||||
QueryExpression parent = fromClause.Parent as QueryExpression; |
||||
foreach (CollectionRangeVariable variable in fromClause.Sources) { |
||||
AddVariable(variable.Type, variable.Identifier, |
||||
variable.StartLocation, CurrentEndLocation, |
||||
false, true, variable.Expression, null, parent != null && parent.IsQueryContinuation); |
||||
} |
||||
|
||||
return base.VisitQueryExpressionFromClause(fromClause, data); |
||||
} |
||||
|
||||
public override object VisitQueryExpressionJoinClause(QueryExpressionJoinClause joinClause, object data) |
||||
{ |
||||
if (string.IsNullOrEmpty(joinClause.IntoIdentifier)) { |
||||
AddVariable(joinClause.Source.Type, joinClause.Source.Identifier, |
||||
joinClause.Source.StartLocation, CurrentEndLocation, |
||||
false, true, joinClause.Source.Expression, null, false); |
||||
} else { |
||||
AddVariable(joinClause.Source.Type, joinClause.Source.Identifier, |
||||
joinClause.Source.StartLocation, joinClause.Source.EndLocation, |
||||
false, true, joinClause.Source.Expression, null, false); |
||||
|
||||
AddVariable(joinClause.Source.Type, joinClause.IntoIdentifier, |
||||
joinClause.Source.StartLocation, CurrentEndLocation, |
||||
false, false, joinClause.Source.Expression, null, false); |
||||
} |
||||
return base.VisitQueryExpressionJoinClause(joinClause, data); |
||||
} |
||||
|
||||
public override object VisitQueryExpressionLetClause(QueryExpressionLetClause letClause, object data) |
||||
{ |
||||
AddVariable(null, letClause.Identifier, |
||||
letClause.StartLocation, CurrentEndLocation, |
||||
false, false, letClause.Expression, null, false); |
||||
return base.VisitQueryExpressionLetClause(letClause, data); |
||||
} |
||||
|
||||
public override object VisitForNextStatement(ForNextStatement forNextStatement, object data) |
||||
{ |
||||
if (forNextStatement.EmbeddedStatement.EndLocation.IsEmpty) { |
||||
return base.VisitForNextStatement(forNextStatement, data); |
||||
} else { |
||||
endLocationStack.Push(forNextStatement.EmbeddedStatement.EndLocation); |
||||
AddVariable(forNextStatement.TypeReference, |
||||
forNextStatement.VariableName, |
||||
forNextStatement.StartLocation, |
||||
forNextStatement.EndLocation, |
||||
false, false, |
||||
forNextStatement.Start, |
||||
null, |
||||
false); |
||||
|
||||
base.VisitForNextStatement(forNextStatement, data); |
||||
|
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override object VisitFixedStatement(FixedStatement fixedStatement, object data) |
||||
{ |
||||
// uses LocalVariableDeclaration, we just have to put the end location on the stack
|
||||
if (fixedStatement.EmbeddedStatement.EndLocation.IsEmpty) { |
||||
return base.VisitFixedStatement(fixedStatement, data); |
||||
} else { |
||||
endLocationStack.Push(fixedStatement.EmbeddedStatement.EndLocation); |
||||
base.VisitFixedStatement(fixedStatement, data); |
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override object VisitForStatement(ForStatement forStatement, object data) |
||||
{ |
||||
// uses LocalVariableDeclaration, we just have to put the end location on the stack
|
||||
if (forStatement.EmbeddedStatement.EndLocation.IsEmpty) { |
||||
return base.VisitForStatement(forStatement, data); |
||||
} else { |
||||
endLocationStack.Push(forStatement.EmbeddedStatement.EndLocation); |
||||
base.VisitForStatement(forStatement, data); |
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override object VisitUsingStatement(UsingStatement usingStatement, object data) |
||||
{ |
||||
// uses LocalVariableDeclaration, we just have to put the end location on the stack
|
||||
if (usingStatement.EmbeddedStatement.EndLocation.IsEmpty) { |
||||
return base.VisitUsingStatement(usingStatement, data); |
||||
} else { |
||||
endLocationStack.Push(usingStatement.EmbeddedStatement.EndLocation); |
||||
base.VisitUsingStatement(usingStatement, data); |
||||
endLocationStack.Pop(); |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public override object VisitSwitchSection(SwitchSection switchSection, object data) |
||||
{ |
||||
return VisitBlockStatement(switchSection, data); |
||||
} |
||||
|
||||
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) |
||||
{ |
||||
AddVariable(foreachStatement.TypeReference, |
||||
foreachStatement.VariableName, |
||||
foreachStatement.StartLocation, |
||||
foreachStatement.EndLocation, |
||||
false, true, |
||||
foreachStatement.Expression, |
||||
null, |
||||
false); |
||||
|
||||
if (foreachStatement.Expression != null) { |
||||
foreachStatement.Expression.AcceptVisitor(this, data); |
||||
} |
||||
if (foreachStatement.EmbeddedStatement == null) { |
||||
return data; |
||||
} |
||||
return foreachStatement.EmbeddedStatement.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) |
||||
{ |
||||
if (tryCatchStatement == null) { |
||||
return data; |
||||
} |
||||
if (tryCatchStatement.StatementBlock != null) { |
||||
tryCatchStatement.StatementBlock.AcceptVisitor(this, data); |
||||
} |
||||
if (tryCatchStatement.CatchClauses != null) { |
||||
foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) { |
||||
if (catchClause != null) { |
||||
if (catchClause.TypeReference != null && catchClause.VariableName != null) { |
||||
AddVariable(catchClause.TypeReference, |
||||
catchClause.VariableName, |
||||
catchClause.StartLocation, |
||||
catchClause.StatementBlock.EndLocation, |
||||
false, false, null, null, false); |
||||
} |
||||
catchClause.StatementBlock.AcceptVisitor(this, data); |
||||
} |
||||
} |
||||
} |
||||
if (tryCatchStatement.FinallyBlock != null) { |
||||
return tryCatchStatement.FinallyBlock.AcceptVisitor(this, data); |
||||
} |
||||
return data; |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,541 @@
@@ -0,0 +1,541 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.1
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors { |
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
|
||||
/// <summary>
|
||||
/// IAstVisitor implementation that always throws NotImplementedExceptions.
|
||||
/// </summary>
|
||||
public class NotImplementedAstVisitor : IAstVisitor { |
||||
|
||||
public virtual object VisitAddHandlerStatement(AddHandlerStatement addHandlerStatement, object data) { |
||||
throw new global::System.NotImplementedException("AddHandlerStatement"); |
||||
} |
||||
|
||||
public virtual object VisitAddressOfExpression(AddressOfExpression addressOfExpression, object data) { |
||||
throw new global::System.NotImplementedException("AddressOfExpression"); |
||||
} |
||||
|
||||
public virtual object VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, object data) { |
||||
throw new global::System.NotImplementedException("AnonymousMethodExpression"); |
||||
} |
||||
|
||||
public virtual object VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, object data) { |
||||
throw new global::System.NotImplementedException("ArrayCreateExpression"); |
||||
} |
||||
|
||||
public virtual object VisitAssignmentExpression(AssignmentExpression assignmentExpression, object data) { |
||||
throw new global::System.NotImplementedException("AssignmentExpression"); |
||||
} |
||||
|
||||
public virtual object VisitAttribute(ICSharpCode.NRefactory.VB.Dom.Attribute attribute, object data) { |
||||
throw new global::System.NotImplementedException("Attribute"); |
||||
} |
||||
|
||||
public virtual object VisitAttributeSection(AttributeSection attributeSection, object data) { |
||||
throw new global::System.NotImplementedException("AttributeSection"); |
||||
} |
||||
|
||||
public virtual object VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("BaseReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data) { |
||||
throw new global::System.NotImplementedException("BinaryOperatorExpression"); |
||||
} |
||||
|
||||
public virtual object VisitBlockStatement(BlockStatement blockStatement, object data) { |
||||
throw new global::System.NotImplementedException("BlockStatement"); |
||||
} |
||||
|
||||
public virtual object VisitBreakStatement(BreakStatement breakStatement, object data) { |
||||
throw new global::System.NotImplementedException("BreakStatement"); |
||||
} |
||||
|
||||
public virtual object VisitCaseLabel(CaseLabel caseLabel, object data) { |
||||
throw new global::System.NotImplementedException("CaseLabel"); |
||||
} |
||||
|
||||
public virtual object VisitCastExpression(CastExpression castExpression, object data) { |
||||
throw new global::System.NotImplementedException("CastExpression"); |
||||
} |
||||
|
||||
public virtual object VisitCatchClause(CatchClause catchClause, object data) { |
||||
throw new global::System.NotImplementedException("CatchClause"); |
||||
} |
||||
|
||||
public virtual object VisitCheckedExpression(CheckedExpression checkedExpression, object data) { |
||||
throw new global::System.NotImplementedException("CheckedExpression"); |
||||
} |
||||
|
||||
public virtual object VisitCheckedStatement(CheckedStatement checkedStatement, object data) { |
||||
throw new global::System.NotImplementedException("CheckedStatement"); |
||||
} |
||||
|
||||
public virtual object VisitClassReferenceExpression(ClassReferenceExpression classReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("ClassReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data) { |
||||
throw new global::System.NotImplementedException("CollectionInitializerExpression"); |
||||
} |
||||
|
||||
public virtual object VisitCollectionRangeVariable(CollectionRangeVariable collectionRangeVariable, object data) { |
||||
throw new global::System.NotImplementedException("CollectionRangeVariable"); |
||||
} |
||||
|
||||
public virtual object VisitCompilationUnit(CompilationUnit compilationUnit, object data) { |
||||
throw new global::System.NotImplementedException("CompilationUnit"); |
||||
} |
||||
|
||||
public virtual object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) { |
||||
throw new global::System.NotImplementedException("ConditionalExpression"); |
||||
} |
||||
|
||||
public virtual object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("ConstructorDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitConstructorInitializer(ConstructorInitializer constructorInitializer, object data) { |
||||
throw new global::System.NotImplementedException("ConstructorInitializer"); |
||||
} |
||||
|
||||
public virtual object VisitContinueStatement(ContinueStatement continueStatement, object data) { |
||||
throw new global::System.NotImplementedException("ContinueStatement"); |
||||
} |
||||
|
||||
public virtual object VisitDeclareDeclaration(DeclareDeclaration declareDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("DeclareDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, object data) { |
||||
throw new global::System.NotImplementedException("DefaultValueExpression"); |
||||
} |
||||
|
||||
public virtual object VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("DelegateDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("DestructorDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitDirectionExpression(DirectionExpression directionExpression, object data) { |
||||
throw new global::System.NotImplementedException("DirectionExpression"); |
||||
} |
||||
|
||||
public virtual object VisitDoLoopStatement(DoLoopStatement doLoopStatement, object data) { |
||||
throw new global::System.NotImplementedException("DoLoopStatement"); |
||||
} |
||||
|
||||
public virtual object VisitElseIfSection(ElseIfSection elseIfSection, object data) { |
||||
throw new global::System.NotImplementedException("ElseIfSection"); |
||||
} |
||||
|
||||
public virtual object VisitEmptyStatement(EmptyStatement emptyStatement, object data) { |
||||
throw new global::System.NotImplementedException("EmptyStatement"); |
||||
} |
||||
|
||||
public virtual object VisitEndStatement(EndStatement endStatement, object data) { |
||||
throw new global::System.NotImplementedException("EndStatement"); |
||||
} |
||||
|
||||
public virtual object VisitEraseStatement(EraseStatement eraseStatement, object data) { |
||||
throw new global::System.NotImplementedException("EraseStatement"); |
||||
} |
||||
|
||||
public virtual object VisitErrorStatement(ErrorStatement errorStatement, object data) { |
||||
throw new global::System.NotImplementedException("ErrorStatement"); |
||||
} |
||||
|
||||
public virtual object VisitEventAddRegion(EventAddRegion eventAddRegion, object data) { |
||||
throw new global::System.NotImplementedException("EventAddRegion"); |
||||
} |
||||
|
||||
public virtual object VisitEventDeclaration(EventDeclaration eventDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("EventDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitEventRaiseRegion(EventRaiseRegion eventRaiseRegion, object data) { |
||||
throw new global::System.NotImplementedException("EventRaiseRegion"); |
||||
} |
||||
|
||||
public virtual object VisitEventRemoveRegion(EventRemoveRegion eventRemoveRegion, object data) { |
||||
throw new global::System.NotImplementedException("EventRemoveRegion"); |
||||
} |
||||
|
||||
public virtual object VisitExitStatement(ExitStatement exitStatement, object data) { |
||||
throw new global::System.NotImplementedException("ExitStatement"); |
||||
} |
||||
|
||||
public virtual object VisitExpressionRangeVariable(ExpressionRangeVariable expressionRangeVariable, object data) { |
||||
throw new global::System.NotImplementedException("ExpressionRangeVariable"); |
||||
} |
||||
|
||||
public virtual object VisitExpressionStatement(ExpressionStatement expressionStatement, object data) { |
||||
throw new global::System.NotImplementedException("ExpressionStatement"); |
||||
} |
||||
|
||||
public virtual object VisitExternAliasDirective(ExternAliasDirective externAliasDirective, object data) { |
||||
throw new global::System.NotImplementedException("ExternAliasDirective"); |
||||
} |
||||
|
||||
public virtual object VisitFieldDeclaration(FieldDeclaration fieldDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("FieldDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitFixedStatement(FixedStatement fixedStatement, object data) { |
||||
throw new global::System.NotImplementedException("FixedStatement"); |
||||
} |
||||
|
||||
public virtual object VisitForeachStatement(ForeachStatement foreachStatement, object data) { |
||||
throw new global::System.NotImplementedException("ForeachStatement"); |
||||
} |
||||
|
||||
public virtual object VisitForNextStatement(ForNextStatement forNextStatement, object data) { |
||||
throw new global::System.NotImplementedException("ForNextStatement"); |
||||
} |
||||
|
||||
public virtual object VisitForStatement(ForStatement forStatement, object data) { |
||||
throw new global::System.NotImplementedException("ForStatement"); |
||||
} |
||||
|
||||
public virtual object VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, object data) { |
||||
throw new global::System.NotImplementedException("GotoCaseStatement"); |
||||
} |
||||
|
||||
public virtual object VisitGotoStatement(GotoStatement gotoStatement, object data) { |
||||
throw new global::System.NotImplementedException("GotoStatement"); |
||||
} |
||||
|
||||
public virtual object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { |
||||
throw new global::System.NotImplementedException("IdentifierExpression"); |
||||
} |
||||
|
||||
public virtual object VisitIfElseStatement(IfElseStatement ifElseStatement, object data) { |
||||
throw new global::System.NotImplementedException("IfElseStatement"); |
||||
} |
||||
|
||||
public virtual object VisitIndexerExpression(IndexerExpression indexerExpression, object data) { |
||||
throw new global::System.NotImplementedException("IndexerExpression"); |
||||
} |
||||
|
||||
public virtual object VisitInnerClassTypeReference(InnerClassTypeReference innerClassTypeReference, object data) { |
||||
throw new global::System.NotImplementedException("InnerClassTypeReference"); |
||||
} |
||||
|
||||
public virtual object VisitInterfaceImplementation(InterfaceImplementation interfaceImplementation, object data) { |
||||
throw new global::System.NotImplementedException("InterfaceImplementation"); |
||||
} |
||||
|
||||
public virtual object VisitInvocationExpression(InvocationExpression invocationExpression, object data) { |
||||
throw new global::System.NotImplementedException("InvocationExpression"); |
||||
} |
||||
|
||||
public virtual object VisitLabelStatement(LabelStatement labelStatement, object data) { |
||||
throw new global::System.NotImplementedException("LabelStatement"); |
||||
} |
||||
|
||||
public virtual object VisitLambdaExpression(LambdaExpression lambdaExpression, object data) { |
||||
throw new global::System.NotImplementedException("LambdaExpression"); |
||||
} |
||||
|
||||
public virtual object VisitLocalVariableDeclaration(LocalVariableDeclaration localVariableDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("LocalVariableDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitLockStatement(LockStatement lockStatement, object data) { |
||||
throw new global::System.NotImplementedException("LockStatement"); |
||||
} |
||||
|
||||
public virtual object VisitMemberInitializerExpression(MemberInitializerExpression memberInitializerExpression, object data) { |
||||
throw new global::System.NotImplementedException("MemberInitializerExpression"); |
||||
} |
||||
|
||||
public virtual object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("MemberReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("MethodDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, object data) { |
||||
throw new global::System.NotImplementedException("NamedArgumentExpression"); |
||||
} |
||||
|
||||
public virtual object VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("NamespaceDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, object data) { |
||||
throw new global::System.NotImplementedException("ObjectCreateExpression"); |
||||
} |
||||
|
||||
public virtual object VisitOnErrorStatement(OnErrorStatement onErrorStatement, object data) { |
||||
throw new global::System.NotImplementedException("OnErrorStatement"); |
||||
} |
||||
|
||||
public virtual object VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("OperatorDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitOptionDeclaration(OptionDeclaration optionDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("OptionDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) { |
||||
throw new global::System.NotImplementedException("ParameterDeclarationExpression"); |
||||
} |
||||
|
||||
public virtual object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) { |
||||
throw new global::System.NotImplementedException("ParenthesizedExpression"); |
||||
} |
||||
|
||||
public virtual object VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("PointerReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, object data) { |
||||
throw new global::System.NotImplementedException("PrimitiveExpression"); |
||||
} |
||||
|
||||
public virtual object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("PropertyDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitPropertyGetRegion(PropertyGetRegion propertyGetRegion, object data) { |
||||
throw new global::System.NotImplementedException("PropertyGetRegion"); |
||||
} |
||||
|
||||
public virtual object VisitPropertySetRegion(PropertySetRegion propertySetRegion, object data) { |
||||
throw new global::System.NotImplementedException("PropertySetRegion"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpression(QueryExpression queryExpression, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpression"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionAggregateClause(QueryExpressionAggregateClause queryExpressionAggregateClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionAggregateClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionDistinctClause(QueryExpressionDistinctClause queryExpressionDistinctClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionDistinctClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionFromClause(QueryExpressionFromClause queryExpressionFromClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionFromClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionGroupClause(QueryExpressionGroupClause queryExpressionGroupClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionGroupClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionGroupJoinVBClause(QueryExpressionGroupJoinVBClause queryExpressionGroupJoinVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionGroupJoinVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionGroupVBClause(QueryExpressionGroupVBClause queryExpressionGroupVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionGroupVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionJoinClause(QueryExpressionJoinClause queryExpressionJoinClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionJoinClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionJoinConditionVB(QueryExpressionJoinConditionVB queryExpressionJoinConditionVB, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionJoinConditionVB"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionJoinVBClause(QueryExpressionJoinVBClause queryExpressionJoinVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionJoinVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionLetClause(QueryExpressionLetClause queryExpressionLetClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionLetClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionLetVBClause(QueryExpressionLetVBClause queryExpressionLetVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionLetVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionOrderClause(QueryExpressionOrderClause queryExpressionOrderClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionOrderClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionOrdering(QueryExpressionOrdering queryExpressionOrdering, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionOrdering"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionPartitionVBClause(QueryExpressionPartitionVBClause queryExpressionPartitionVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionPartitionVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionSelectClause(QueryExpressionSelectClause queryExpressionSelectClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionSelectClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionSelectVBClause(QueryExpressionSelectVBClause queryExpressionSelectVBClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionSelectVBClause"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionVB(QueryExpressionVB queryExpressionVB, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionVB"); |
||||
} |
||||
|
||||
public virtual object VisitQueryExpressionWhereClause(QueryExpressionWhereClause queryExpressionWhereClause, object data) { |
||||
throw new global::System.NotImplementedException("QueryExpressionWhereClause"); |
||||
} |
||||
|
||||
public virtual object VisitRaiseEventStatement(RaiseEventStatement raiseEventStatement, object data) { |
||||
throw new global::System.NotImplementedException("RaiseEventStatement"); |
||||
} |
||||
|
||||
public virtual object VisitReDimStatement(ReDimStatement reDimStatement, object data) { |
||||
throw new global::System.NotImplementedException("ReDimStatement"); |
||||
} |
||||
|
||||
public virtual object VisitRemoveHandlerStatement(RemoveHandlerStatement removeHandlerStatement, object data) { |
||||
throw new global::System.NotImplementedException("RemoveHandlerStatement"); |
||||
} |
||||
|
||||
public virtual object VisitResumeStatement(ResumeStatement resumeStatement, object data) { |
||||
throw new global::System.NotImplementedException("ResumeStatement"); |
||||
} |
||||
|
||||
public virtual object VisitReturnStatement(ReturnStatement returnStatement, object data) { |
||||
throw new global::System.NotImplementedException("ReturnStatement"); |
||||
} |
||||
|
||||
public virtual object VisitSizeOfExpression(SizeOfExpression sizeOfExpression, object data) { |
||||
throw new global::System.NotImplementedException("SizeOfExpression"); |
||||
} |
||||
|
||||
public virtual object VisitStackAllocExpression(StackAllocExpression stackAllocExpression, object data) { |
||||
throw new global::System.NotImplementedException("StackAllocExpression"); |
||||
} |
||||
|
||||
public virtual object VisitStopStatement(StopStatement stopStatement, object data) { |
||||
throw new global::System.NotImplementedException("StopStatement"); |
||||
} |
||||
|
||||
public virtual object VisitSwitchSection(SwitchSection switchSection, object data) { |
||||
throw new global::System.NotImplementedException("SwitchSection"); |
||||
} |
||||
|
||||
public virtual object VisitSwitchStatement(SwitchStatement switchStatement, object data) { |
||||
throw new global::System.NotImplementedException("SwitchStatement"); |
||||
} |
||||
|
||||
public virtual object VisitTemplateDefinition(TemplateDefinition templateDefinition, object data) { |
||||
throw new global::System.NotImplementedException("TemplateDefinition"); |
||||
} |
||||
|
||||
public virtual object VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("ThisReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitThrowStatement(ThrowStatement throwStatement, object data) { |
||||
throw new global::System.NotImplementedException("ThrowStatement"); |
||||
} |
||||
|
||||
public virtual object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data) { |
||||
throw new global::System.NotImplementedException("TryCatchStatement"); |
||||
} |
||||
|
||||
public virtual object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("TypeDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitTypeOfExpression(TypeOfExpression typeOfExpression, object data) { |
||||
throw new global::System.NotImplementedException("TypeOfExpression"); |
||||
} |
||||
|
||||
public virtual object VisitTypeOfIsExpression(TypeOfIsExpression typeOfIsExpression, object data) { |
||||
throw new global::System.NotImplementedException("TypeOfIsExpression"); |
||||
} |
||||
|
||||
public virtual object VisitTypeReference(TypeReference typeReference, object data) { |
||||
throw new global::System.NotImplementedException("TypeReference"); |
||||
} |
||||
|
||||
public virtual object VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, object data) { |
||||
throw new global::System.NotImplementedException("TypeReferenceExpression"); |
||||
} |
||||
|
||||
public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) { |
||||
throw new global::System.NotImplementedException("UnaryOperatorExpression"); |
||||
} |
||||
|
||||
public virtual object VisitUncheckedExpression(UncheckedExpression uncheckedExpression, object data) { |
||||
throw new global::System.NotImplementedException("UncheckedExpression"); |
||||
} |
||||
|
||||
public virtual object VisitUncheckedStatement(UncheckedStatement uncheckedStatement, object data) { |
||||
throw new global::System.NotImplementedException("UncheckedStatement"); |
||||
} |
||||
|
||||
public virtual object VisitUnsafeStatement(UnsafeStatement unsafeStatement, object data) { |
||||
throw new global::System.NotImplementedException("UnsafeStatement"); |
||||
} |
||||
|
||||
public virtual object VisitUsing(Using @using, object data) { |
||||
throw new global::System.NotImplementedException("Using"); |
||||
} |
||||
|
||||
public virtual object VisitUsingDeclaration(UsingDeclaration usingDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("UsingDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitUsingStatement(UsingStatement usingStatement, object data) { |
||||
throw new global::System.NotImplementedException("UsingStatement"); |
||||
} |
||||
|
||||
public virtual object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) { |
||||
throw new global::System.NotImplementedException("VariableDeclaration"); |
||||
} |
||||
|
||||
public virtual object VisitWithStatement(WithStatement withStatement, object data) { |
||||
throw new global::System.NotImplementedException("WithStatement"); |
||||
} |
||||
|
||||
public virtual object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlAttributeExpression"); |
||||
} |
||||
|
||||
public virtual object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlContentExpression"); |
||||
} |
||||
|
||||
public virtual object VisitXmlDocumentExpression(XmlDocumentExpression xmlDocumentExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlDocumentExpression"); |
||||
} |
||||
|
||||
public virtual object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlElementExpression"); |
||||
} |
||||
|
||||
public virtual object VisitXmlEmbeddedExpression(XmlEmbeddedExpression xmlEmbeddedExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlEmbeddedExpression"); |
||||
} |
||||
|
||||
public virtual object VisitXmlMemberAccessExpression(XmlMemberAccessExpression xmlMemberAccessExpression, object data) { |
||||
throw new global::System.NotImplementedException("XmlMemberAccessExpression"); |
||||
} |
||||
|
||||
public virtual object VisitYieldStatement(YieldStatement yieldStatement, object data) { |
||||
throw new global::System.NotImplementedException("YieldStatement"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,143 @@
@@ -0,0 +1,143 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// Prefixes the names of the specified fields with the prefix and replaces the use.
|
||||
/// </summary>
|
||||
public class PrefixFieldsVisitor : AbstractAstVisitor |
||||
{ |
||||
List<VariableDeclaration> fields; |
||||
List<string> curBlock = new List<string>(); |
||||
Stack<List<string>> blocks = new Stack<List<string>>(); |
||||
string prefix; |
||||
|
||||
public PrefixFieldsVisitor(List<VariableDeclaration> fields, string prefix) |
||||
{ |
||||
this.fields = fields; |
||||
this.prefix = prefix; |
||||
} |
||||
|
||||
public void Run(INode typeDeclaration) |
||||
{ |
||||
typeDeclaration.AcceptVisitor(this, null); |
||||
foreach (VariableDeclaration decl in fields) { |
||||
decl.Name = prefix + decl.Name; |
||||
} |
||||
} |
||||
|
||||
public override object VisitTypeDeclaration(TypeDeclaration typeDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.VisitTypeDeclaration(typeDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object VisitBlockStatement(BlockStatement blockStatement, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.VisitBlockStatement(blockStatement, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.VisitMethodDeclaration(methodDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.VisitPropertyDeclaration(propertyDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
public override object VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, object data) |
||||
{ |
||||
Push(); |
||||
object result = base.VisitConstructorDeclaration(constructorDeclaration, data); |
||||
Pop(); |
||||
return result; |
||||
} |
||||
|
||||
private void Push() |
||||
{ |
||||
blocks.Push(curBlock); |
||||
curBlock = new List<string>(); |
||||
} |
||||
|
||||
private void Pop() |
||||
{ |
||||
curBlock = blocks.Pop(); |
||||
} |
||||
|
||||
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) |
||||
{ |
||||
// process local variables only
|
||||
if (fields.Contains(variableDeclaration)) { |
||||
return null; |
||||
} |
||||
curBlock.Add(variableDeclaration.Name); |
||||
return base.VisitVariableDeclaration(variableDeclaration, data); |
||||
} |
||||
|
||||
public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) |
||||
{ |
||||
curBlock.Add(parameterDeclarationExpression.ParameterName); |
||||
//print("add parameter ${parameterDeclarationExpression.ParameterName} to block")
|
||||
return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data); |
||||
} |
||||
|
||||
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) |
||||
{ |
||||
curBlock.Add(foreachStatement.VariableName); |
||||
return base.VisitForeachStatement(foreachStatement, data); |
||||
} |
||||
|
||||
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) |
||||
{ |
||||
string name = identifierExpression.Identifier; |
||||
foreach (VariableDeclaration var in fields) { |
||||
if (var.Name == name && !IsLocal(name)) { |
||||
identifierExpression.Identifier = prefix + name; |
||||
break; |
||||
} |
||||
} |
||||
return base.VisitIdentifierExpression(identifierExpression, data); |
||||
} |
||||
|
||||
public override object VisitMemberReferenceExpression(MemberReferenceExpression fieldReferenceExpression, object data) |
||||
{ |
||||
if (fieldReferenceExpression.TargetObject is ThisReferenceExpression) { |
||||
string name = fieldReferenceExpression.MemberName; |
||||
foreach (VariableDeclaration var in fields) { |
||||
if (var.Name == name) { |
||||
fieldReferenceExpression.MemberName = prefix + name; |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
return base.VisitMemberReferenceExpression(fieldReferenceExpression, data); |
||||
} |
||||
|
||||
bool IsLocal(string name) |
||||
{ |
||||
foreach (List<string> block in blocks) { |
||||
if (block.Contains(name)) |
||||
return true; |
||||
} |
||||
return curBlock.Contains(name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,61 @@
@@ -0,0 +1,61 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
class RenameIdentifierVisitor : AbstractAstVisitor |
||||
{ |
||||
protected StringComparer nameComparer; |
||||
protected string from, to; |
||||
|
||||
public RenameIdentifierVisitor(string from, string to, StringComparer nameComparer) |
||||
{ |
||||
this.nameComparer = nameComparer; |
||||
this.from = from; |
||||
this.to = to; |
||||
} |
||||
|
||||
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) |
||||
{ |
||||
if (nameComparer.Equals(identifierExpression.Identifier, from)) { |
||||
identifierExpression.Identifier = to; |
||||
} |
||||
return base.VisitIdentifierExpression(identifierExpression, data); |
||||
} |
||||
} |
||||
|
||||
sealed class RenameLocalVariableVisitor : RenameIdentifierVisitor |
||||
{ |
||||
public RenameLocalVariableVisitor(string from, string to, StringComparer nameComparer) |
||||
: base(from, to, nameComparer) |
||||
{ |
||||
} |
||||
|
||||
public override object VisitVariableDeclaration(VariableDeclaration variableDeclaration, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, variableDeclaration.Name)) { |
||||
variableDeclaration.Name = to; |
||||
} |
||||
return base.VisitVariableDeclaration(variableDeclaration, data); |
||||
} |
||||
|
||||
public override object VisitParameterDeclarationExpression(ParameterDeclarationExpression parameterDeclarationExpression, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, parameterDeclarationExpression.ParameterName)) { |
||||
parameterDeclarationExpression.ParameterName = to; |
||||
} |
||||
return base.VisitParameterDeclarationExpression(parameterDeclarationExpression, data); |
||||
} |
||||
|
||||
public override object VisitForeachStatement(ForeachStatement foreachStatement, object data) |
||||
{ |
||||
if (nameComparer.Equals(from, foreachStatement.VariableName)) { |
||||
foreachStatement.VariableName = to; |
||||
} |
||||
return base.VisitForeachStatement(foreachStatement, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// Sets the parent property on all nodes in the tree.
|
||||
/// </summary>
|
||||
public class SetParentVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
Stack<INode> nodeStack = new Stack<INode>(); |
||||
|
||||
public SetParentVisitor() |
||||
{ |
||||
nodeStack.Push(null); |
||||
} |
||||
|
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
node.Parent = nodeStack.Peek(); |
||||
nodeStack.Push(node); |
||||
} |
||||
|
||||
protected override void EndVisit(INode node) |
||||
{ |
||||
nodeStack.Pop(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Visitors |
||||
{ |
||||
/// <summary>
|
||||
/// Sets StartLocation and EndLocation (region) of every node to union of regions of its children.
|
||||
/// Parsers don't do this by default:
|
||||
/// e.g. "a.Foo()" is InvocationExpression, its region includes only the "()" and it has a child MemberReferenceExpression, with region ".Foo".
|
||||
/// </summary>
|
||||
public class SetRegionInclusionVisitor : NodeTrackingAstVisitor |
||||
{ |
||||
Stack<INode> parentNodes = new Stack<INode>(); |
||||
|
||||
public SetRegionInclusionVisitor() |
||||
{ |
||||
parentNodes.Push(null); |
||||
} |
||||
|
||||
protected override void BeginVisit(INode node) |
||||
{ |
||||
base.BeginVisit(node); |
||||
|
||||
// Only push nodes on the stack which have valid position information.
|
||||
if (node != null && |
||||
node.StartLocation.X >= 1 && node.StartLocation.Y >= 1 && |
||||
node.EndLocation.X >= 1 && node.EndLocation.Y >= 1) { |
||||
|
||||
if (node is PropertyDeclaration) { |
||||
// PropertyDeclaration has correctly set BodyStart and BodyEnd by the parser,
|
||||
// but it has no subnode "body", just 2 children GetRegion and SetRegion which don't span
|
||||
// the whole (BodyStart, BodyEnd) region => We have to handle PropertyDeclaration as a special case.
|
||||
node.EndLocation = ((PropertyDeclaration)node).BodyEnd; |
||||
} |
||||
|
||||
this.parentNodes.Push(node); |
||||
} |
||||
} |
||||
|
||||
protected override void EndVisit(INode node) |
||||
{ |
||||
base.EndVisit(node); |
||||
|
||||
// Only remove those nodes which have actually been pushed before.
|
||||
if (this.parentNodes.Count > 0 && INode.ReferenceEquals(this.parentNodes.Peek(), node)) { |
||||
// remove this node
|
||||
this.parentNodes.Pop(); |
||||
// fix region of parent
|
||||
var parent = this.parentNodes.Peek(); |
||||
if (parent == null) |
||||
return; |
||||
if (node.StartLocation < parent.StartLocation) |
||||
parent.StartLocation = node.StartLocation; |
||||
if (node.EndLocation > parent.EndLocation) |
||||
parent.EndLocation = node.EndLocation; |
||||
} |
||||
|
||||
// Block statement as a special case - we want it without the '{' and '}'
|
||||
if (node is BlockStatement) { |
||||
var firstSatement = node.Children.FirstOrDefault(); |
||||
if (firstSatement != null) { |
||||
node.StartLocation = firstSatement.StartLocation; |
||||
node.EndLocation = node.Children.Last().EndLocation; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
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 Test")] |
||||
[assembly: AssemblyDescription("Unit tests for the parser and refactoring library for C# and VB.NET")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("ic#code")] |
||||
[assembly: AssemblyProduct("SharpDevelop")] |
||||
[assembly: AssemblyCopyright("2004-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")] |
||||
|
||||
// The following attributes specify the key for the sign of your assembly. See the
|
||||
// .NET Framework documentation for more information about signing.
|
||||
// This is not required, if you don't want signing let these attributes like they're.
|
||||
[assembly: AssemblyDelaySign(false)] |
||||
[assembly: AssemblyKeyFile("")] |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Dom; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using ICSharpCode.NRefactory.VB.Visitors; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class StructuralTest |
||||
{ |
||||
[Test] |
||||
public void TestToStringMethods() |
||||
{ |
||||
Type[] allTypes = typeof(INode).Assembly.GetTypes(); |
||||
|
||||
foreach (Type type in allTypes) { |
||||
if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null) { |
||||
MethodInfo methodInfo = type.GetMethod("ToString", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public); |
||||
Assert.IsNotNull(methodInfo, "ToString() not found in " + type.FullName); |
||||
} |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void TestUnitTests() |
||||
{ |
||||
Type[] allTypes = typeof(StructuralTest).Assembly.GetTypes(); |
||||
|
||||
foreach (Type type in allTypes) { |
||||
if (type.GetCustomAttributes(typeof(TestFixtureAttribute), true).Length > 0) { |
||||
foreach (MethodInfo m in type.GetMethods()) { |
||||
if (m.IsPublic && m.ReturnType == typeof(void) && m.GetParameters().Length == 0) { |
||||
if (m.GetCustomAttributes(typeof(TestAttribute), true).Length == 0) { |
||||
Assert.Fail(type.Name + "." + m.Name + " should have the [Test] attribute!"); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
// [Test]
|
||||
// public void TestAcceptVisitorMethods()
|
||||
// {
|
||||
// Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
|
||||
//
|
||||
// foreach (Type type in allTypes) {
|
||||
// if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null) {
|
||||
// MethodInfo methodInfo = type.GetMethod("AcceptVisitor", BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
|
||||
// Assertion.AssertNotNull("AcceptVisitor() not found in " + type.FullName, methodInfo);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
[Test] |
||||
public void TestIAstVisitor() |
||||
{ |
||||
Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); |
||||
Type visitor = typeof(IAstVisitor); |
||||
|
||||
foreach (Type type in allTypes) { |
||||
if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { |
||||
MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); |
||||
Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); |
||||
Assert.AreEqual(2, methodInfo.GetParameters().Length); |
||||
ParameterInfo first = methodInfo.GetParameters()[0]; |
||||
Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); |
||||
|
||||
ParameterInfo second = methodInfo.GetParameters()[1]; |
||||
Assert.AreEqual(typeof(System.Object), second.ParameterType); |
||||
Assert.AreEqual("data", second.Name); |
||||
} |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void TestAbstractASTVisitorVisitor() |
||||
{ |
||||
Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes(); |
||||
Type visitor = typeof(AbstractAstVisitor); |
||||
|
||||
foreach (Type type in allTypes) { |
||||
if (type.IsClass && !type.IsAbstract && !type.IsNested && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) { |
||||
MethodInfo methodInfo = visitor.GetMethod("Visit" + type.Name, BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.ExactBinding, null, new Type[] {type, typeof(object)}, null); |
||||
Assert.IsNotNull(methodInfo, "Visit with parameter " + type.FullName + " not found"); |
||||
|
||||
Assert.AreEqual(2, methodInfo.GetParameters().Length); |
||||
ParameterInfo first = methodInfo.GetParameters()[0]; |
||||
Assert.AreEqual(Char.ToLower(first.ParameterType.Name[0]) + first.ParameterType.Name.Substring(1), first.Name); |
||||
|
||||
ParameterInfo second = methodInfo.GetParameters()[1]; |
||||
Assert.AreEqual(typeof(System.Object), second.ParameterType); |
||||
Assert.AreEqual("data", second.Name); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,175 @@
@@ -0,0 +1,175 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<ProductVersion>8.0.50215</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{870115DD-960A-4406-A6B9-600BCDC36A03}</ProjectGuid> |
||||
<RootNamespace>ICSharpCode.NRefactory.VB.Tests</RootNamespace> |
||||
<AssemblyName>ICSharpCode.NRefactory.VB.Tests</AssemblyName> |
||||
<OutputTarget>Library</OutputTarget> |
||||
<NoStdLib>False</NoStdLib> |
||||
<NoConfig>False</NoConfig> |
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> |
||||
<OutputType>Library</OutputType> |
||||
<OutputPath>..\..\..\..\bin\UnitTests\</OutputPath> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG</DefineConstants> |
||||
<Optimize>False</Optimize> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<DebugType>Full</DebugType> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<StartAction>Project</StartAction> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="nunit.framework"> |
||||
<HintPath>..\..\lib\nunit.framework.dll</HintPath> |
||||
<Private>True</Private> |
||||
</Reference> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AssemblyInfo.cs" /> |
||||
<Compile Include="General\UnitTest.cs" /> |
||||
<Compile Include="Lexer\CustomLexerTests.cs" /> |
||||
<Compile Include="Lexer\ImplicitLineContinuationTests.cs" /> |
||||
<Compile Include="Lexer\LATextReaderTests.cs" /> |
||||
<Compile Include="Lexer\LexerContextTests.cs" /> |
||||
<Compile Include="Lexer\LexerPositionTests.cs" /> |
||||
<Compile Include="Lexer\LexerTests.cs" /> |
||||
<Compile Include="Lexer\LiteralsTests.cs" /> |
||||
<Compile Include="Lexer\TokenTests.cs" /> |
||||
<Compile Include="Lexer\XmlModeLexerTests.cs" /> |
||||
<Compile Include="Output\CodeDOM\CodeDOMTypeReferenceTest.cs" /> |
||||
<Compile Include="Parser\CheckParentVisitor.cs" /> |
||||
<Compile Include="Parser\Expressions\AddressOfExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\LambdaExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\QueryExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\QueryExpressionVBTests.cs" /> |
||||
<Compile Include="Parser\Expressions\XmlExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\XmlMemberAccessExpressionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\AttributeSectionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\PrimitiveExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\ParenthesizedExpressionTest.cs" /> |
||||
<Compile Include="Parser\Expressions\ThisReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\BaseReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\IdentifierExpressionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\NamespaceDeclarationTests.cs" /> |
||||
<Compile Include="Parser\Expressions\AssignmentExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\BinaryOperatorExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\UnaryOperatorExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\CastExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\MemberReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\InvocationExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\TypeOfExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\ArrayCreateExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\ObjectCreateExpressionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\DelegateDeclarationTests.cs" /> |
||||
<Compile Include="Parser\Expressions\CheckedExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\UncheckedExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\ConditionalExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\PointerReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\IndexerExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\SizeOfExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\StackAllocExpressionTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\UsingDeclarationTests.cs" /> |
||||
<Compile Include="Parser\GlobalScope\TypeDeclarationTests.cs" /> |
||||
<Compile Include="Parser\LocationAssignmentCheckVisitor.cs" /> |
||||
<Compile Include="Parser\SnippetParserTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\ConstructorDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\EventDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\FieldDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\MethodDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\PropertyDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\DestructorDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\IndexerDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\OperatorDeclarationTests.cs" /> |
||||
<Compile Include="Parser\Statements\BlockStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\BreakStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ContinueStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\EmptyStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\DoLoopStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ForeachStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ForStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\GotoStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\IfElseStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\LabelStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\LocalVariableDeclarationTests.cs" /> |
||||
<Compile Include="Parser\Statements\LockStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ReturnStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ExpressionStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\SwitchStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ThrowStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\TryCatchStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\CheckedStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\UncheckedStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\UnsafeStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\FixedStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\GotoCaseStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\UsingStatementTests.cs" /> |
||||
<Compile Include="Parser\Expressions\ClassReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\TypeOfIsExpressionTests.cs" /> |
||||
<Compile Include="Parser\ParseUtilVBNet.cs" /> |
||||
<Compile Include="Parser\GlobalScope\OptionDeclarationTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\DeclareDeclarationTests.cs" /> |
||||
<Compile Include="Parser\Statements\AddHandlerStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\EndStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\EraseStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ErrorStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\ForNextStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\OnErrorStatementTest.cs" /> |
||||
<Compile Include="Parser\Statements\RaiseEventStatementTest.cs" /> |
||||
<Compile Include="Parser\Statements\ReDimStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\RemoveHandlerStatement.cs" /> |
||||
<Compile Include="Parser\Statements\ResumeStatement.cs" /> |
||||
<Compile Include="Parser\Statements\StopStatementTests.cs" /> |
||||
<Compile Include="Parser\Statements\WithStatementTests.cs" /> |
||||
<Compile Include="Output\CodeDOM\CodeDOMPrimitiveExpressionTest.cs" /> |
||||
<Compile Include="Output\CodeDOM\CodeDOMParenthesizedExpressionTest.cs" /> |
||||
<Compile Include="Parser\Statements\YieldStatementTests.cs" /> |
||||
<Compile Include="Parser\SkipMethodBodiesTest.cs" /> |
||||
<Compile Include="Parser\Expressions\AnonymousMethodTests.cs" /> |
||||
<Compile Include="Output\CodeDOM\InvocationExpressionTest.cs" /> |
||||
<Compile Include="Parser\Expressions\TypeReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\Expressions\GlobalReferenceExpressionTests.cs" /> |
||||
<Compile Include="Parser\TypeLevel\CustomEventTests.cs" /> |
||||
<Compile Include="Output\VBNet\VBNetOutputTest.cs" /> |
||||
<Compile Include="Output\SpecialOutputVisitorTest.cs" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="Output\VBNet" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ProjectReference Include="..\Project\ICSharpCode.NRefactory.VB.csproj"> |
||||
<Project>{7B82B671-419F-45F4-B778-D9286F996EFA}</Project> |
||||
<Name>ICSharpCode.NRefactory.VB</Name> |
||||
<Private>True</Private> |
||||
</ProjectReference> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
||||
</Project> |
@ -0,0 +1,118 @@
@@ -0,0 +1,118 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class CustomLexerTests |
||||
{ |
||||
ILexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return ParserFactory.CreateLexer(sr); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLines() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("Stop\n\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestSingleEOLForMulitpleLinesWithContinuation() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("Stop\n _\n\nEnd")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Stop)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.End)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void EscapedIdentifier() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("[Stop]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void IdentifierWithTypeCharacter() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("Stop$")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("a!=b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Assign)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsTypeCharacter2() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("a! b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("a!b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExclamationMarkIsIdentifier2() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("a![b]")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.ExclamationMark)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("a rem b")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.Identifier)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOL)); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
|
||||
[Test] |
||||
public void RemCommentTest2() |
||||
{ |
||||
ILexer lexer = GenerateLexer(new StringReader("REM c")); |
||||
Assert.That(lexer.NextToken().Kind, Is.EqualTo(Tokens.EOF)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,230 @@
@@ -0,0 +1,230 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class ImplicitLineContinuationTests |
||||
{ |
||||
[Test] |
||||
public void Example1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print( |
||||
Param1 As Integer, |
||||
Param2 As Integer) |
||||
|
||||
If (Param1 < Param2) Or |
||||
(Param1 > Param2) Then |
||||
Console.WriteLine(""Not equal"") |
||||
End If |
||||
End Sub |
||||
End Module";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.Comma, |
||||
Tokens.Identifier, Tokens.As, Tokens.Integer, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.If, Tokens.OpenParenthesis, Tokens.Identifier, Tokens.LessThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Or, |
||||
Tokens.OpenParenthesis, Tokens.Identifier, Tokens.GreaterThan, Tokens.Identifier, Tokens.CloseParenthesis, Tokens.Then, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.End, Tokens.If, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void QualifierInWith() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
With xml |
||||
Dim a = b. |
||||
d |
||||
Dim c = . |
||||
Count |
||||
End With |
||||
End Sub |
||||
End Module";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.With, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.Dot, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.With, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Example2() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub Print |
||||
Dim a = _ |
||||
|
||||
y |
||||
End Sub |
||||
End Module";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.EOL, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim q = From x In a |
||||
Select x |
||||
End Sub |
||||
End Module";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
[Test] |
||||
public void Query1() |
||||
{ |
||||
string code = @"Module Test
|
||||
Sub A |
||||
Dim actions = From a in b Select Sub() |
||||
Dim i = 1 |
||||
Select Case i |
||||
End Select |
||||
End Sub |
||||
End Sub |
||||
End Module";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens(lexer, Tokens.Module, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, Tokens.Select, Tokens.Sub, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.LiteralInteger, Tokens.EOL, |
||||
Tokens.Select, Tokens.Case, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Select, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Module); |
||||
} |
||||
|
||||
/// <remarks>tests http://community.sharpdevelop.net/forums/p/12068/32893.aspx#32893</remarks>
|
||||
[Test] |
||||
public void Bug_Thread12068() |
||||
{ |
||||
string code = @"Class MainClass
|
||||
Public Shared Sub Main() |
||||
Dim categoryNames = From p In AList _ |
||||
Select p.AFunction(1,2,3) _ |
||||
Distinct |
||||
End Sub |
||||
End Class";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Public, Tokens.Shared, Tokens.Sub, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.CloseParenthesis, Tokens.EOL, |
||||
Tokens.Dim, Tokens.Identifier, Tokens.Assign, Tokens.From, Tokens.Identifier, Tokens.In, Tokens.Identifier, |
||||
Tokens.Select, Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralInteger, |
||||
Tokens.Comma, Tokens.LiteralInteger, Tokens.Comma, Tokens.LiteralInteger, Tokens.CloseParenthesis, |
||||
Tokens.Distinct, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void LineContinuationAfterAttributes() |
||||
{ |
||||
string code = @"<TestFixture>
|
||||
Public Class TestContinuation |
||||
<Test> |
||||
Public Sub TestMethod |
||||
Assert.Fail |
||||
End Sub |
||||
|
||||
<Test> _ |
||||
Public Sub TestMethod2 |
||||
Assert.Fail |
||||
End Sub |
||||
End Class";
|
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Class, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Identifier, Tokens.GreaterThan, |
||||
Tokens.Public, Tokens.Sub, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.Identifier, Tokens.Dot, Tokens.Identifier, Tokens.EOL, |
||||
Tokens.End, Tokens.Sub, Tokens.EOL, |
||||
Tokens.End, Tokens.Class |
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoILCAfterGlobalAttributes() |
||||
{ |
||||
string code = "<Assembly: AssemblyTitle(\"My.UnitTests\")>" + Environment.NewLine + |
||||
"<Assembly: AssemblyDescription(\"\")>"; |
||||
|
||||
ILexer lexer = GenerateLexer(new StringReader(code)); |
||||
|
||||
CheckTokens( |
||||
lexer, Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan, Tokens.EOL, |
||||
Tokens.LessThan, Tokens.Assembly, Tokens.Colon, |
||||
Tokens.Identifier, Tokens.OpenParenthesis, Tokens.LiteralString, |
||||
Tokens.CloseParenthesis, Tokens.GreaterThan |
||||
); |
||||
} |
||||
|
||||
#region Helpers
|
||||
ILexer GenerateLexer(StringReader sr) |
||||
{ |
||||
return ParserFactory.CreateLexer(sr); |
||||
} |
||||
|
||||
void CheckTokens(ILexer lexer, params int[] tokens) |
||||
{ |
||||
for (int i = 0; i < tokens.Length; i++) { |
||||
int token = tokens[i]; |
||||
Token t = lexer.NextToken(); |
||||
int next = t.Kind; |
||||
Assert.AreEqual(token, next, "{2} of {3}: {0} != {1}; at {4}", Tokens.GetTokenString(token), Tokens.GetTokenString(next), i + 1, tokens.Length, t.Location); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LATextReaderTests |
||||
{ |
||||
[Test] |
||||
public void TestPeek() |
||||
{ |
||||
LATextReader reader = new LATextReader(new StringReader("abcd")); |
||||
|
||||
CheckPeek(reader, 0, 'a'); |
||||
CheckPeek(reader, 2, 'c'); |
||||
CheckPeek(reader, 3, 'd'); |
||||
CheckPeek(reader, 1, 'b'); |
||||
CheckPeek(reader, 0, 'a'); |
||||
Assert.AreEqual((int)'a', reader.Read()); |
||||
CheckPeek(reader, 1, 'c'); |
||||
CheckPeek(reader, 2, 'd'); |
||||
CheckPeek(reader, 0, 'b'); |
||||
} |
||||
|
||||
void CheckPeek(LATextReader reader, int num1, char char2) |
||||
{ |
||||
Assert.AreEqual((int)char2, reader.Peek(num1)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,572 @@
@@ -0,0 +1,572 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using NUnit.Framework; |
||||
using VBParser = ICSharpCode.NRefactory.VB.Parser; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerContextTests |
||||
{ |
||||
[Test] |
||||
public void SimpleGlobal() |
||||
{ |
||||
RunTest( |
||||
@"Option Explicit", |
||||
@"enter Global
|
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void VariableWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MemberWithXmlLiteral() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Private xml As XElement = <b /> |
||||
|
||||
Public Sub New() |
||||
Dim x = <a /> |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void GlobalAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<assembly: CLSCompliant(True)>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"<Serializable>
|
||||
Class Test |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter Attribute |
||||
exit Attribute |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void MethodAttributeTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
<Test> |
||||
Public Sub New() |
||||
Dim x = 5 |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Attribute |
||||
exit Attribute |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void WithBlockTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
With x |
||||
|
||||
End With |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void StatementsTest() |
||||
{ |
||||
RunTest( |
||||
@"Class Test
|
||||
Public Sub New() |
||||
For i As Integer = 0 To 10 |
||||
|
||||
Next |
||||
|
||||
For Each x As Integer In list |
||||
|
||||
Next |
||||
|
||||
Try |
||||
|
||||
Catch e As Exception |
||||
|
||||
End Try |
||||
End Sub |
||||
End Class |
||||
",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
enter Body |
||||
exit Body |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
"
|
||||
); |
||||
} |
||||
|
||||
[Test] |
||||
public void ClassTest() |
||||
{ |
||||
RunTest( |
||||
@"Class MainClass ' a comment
|
||||
Dim under_score_field As Integer |
||||
Sub SomeMethod() |
||||
simple += 1 |
||||
For Each loopVarName In collection |
||||
Next |
||||
End Sub |
||||
End Class",
|
||||
@"enter Global
|
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Type |
||||
exit Type |
||||
exit Member |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
enter Expression |
||||
exit Expression |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Body |
||||
exit Body |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void CollectionInitializer() |
||||
{ |
||||
RunTest(@"'
|
||||
' Created by SharpDevelop. |
||||
' User: Siegfried |
||||
' Date: 22.06.2010 |
||||
' Time: 21:29 |
||||
' |
||||
' To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
' |
||||
|
||||
Option Infer On |
||||
|
||||
Imports System.Linq |
||||
Imports System.Xml.Linq |
||||
|
||||
Module Program |
||||
Sub Main() |
||||
Console.WriteLine(""Hello World!"") |
||||
|
||||
Dim name = ""Test"" |
||||
Dim content = { 4, 5, New XAttribute(""a"", 3) } |
||||
|
||||
Dim xml = <<%= name %> <%= content %> /> |
||||
|
||||
Console.ReadKey() |
||||
End Sub |
||||
End Module",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter TypeDeclaration |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Member |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Body |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter ObjectCreation |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit ObjectCreation |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Identifier |
||||
exit Identifier |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Xml |
||||
enter Xml |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Xml |
||||
exit Xml |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
enter Expression |
||||
enter Expression |
||||
enter Expression |
||||
exit Expression |
||||
enter Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Expression |
||||
exit Body |
||||
exit Member |
||||
exit TypeDeclaration |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
[Test] |
||||
public void Imports() |
||||
{ |
||||
RunTest(@"Imports System
|
||||
Imports System.Linq |
||||
Imports System.Collections.Generic",
|
||||
@"enter Global
|
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
enter Importable |
||||
exit Importable |
||||
exit Global |
||||
");
|
||||
} |
||||
|
||||
void RunTest(string code, string expectedOutput) |
||||
{ |
||||
ExpressionFinder p = new ExpressionFinder(); |
||||
ILexer lexer = ParserFactory.CreateLexer(new StringReader(code)); |
||||
Token t; |
||||
|
||||
do { |
||||
t = lexer.NextToken(); |
||||
p.InformToken(t); |
||||
} while (t.Kind != VBParser.Tokens.EOF); |
||||
|
||||
Console.WriteLine(p.Output); |
||||
|
||||
Assert.IsEmpty(p.Errors); |
||||
|
||||
Assert.AreEqual(expectedOutput, p.Output); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,87 @@
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.NRefactory.VB.Parser; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.NRefactory.VB.Tests.Lexer |
||||
{ |
||||
[TestFixture] |
||||
public class LexerPositionTests |
||||
{ |
||||
ILexer GenerateLexer(string s) |
||||
{ |
||||
return ParserFactory.CreateLexer(new StringReader(s)); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestNewLine() |
||||
{ |
||||
ILexer l = GenerateLexer("public\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new Location(1, 1), t.Location); |
||||
Assert.AreEqual(new Location(7, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new Location(7, 1), t.Location); |
||||
Assert.AreEqual(new Location(1, 2), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new Location(1, 2), t.Location); |
||||
Assert.AreEqual(new Location(7, 2), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestCarriageReturnNewLine() |
||||
{ |
||||
ILexer l = GenerateLexer("public\r\nstatic"); |
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Public, t.Kind); |
||||
Assert.AreEqual(new Location(1, 1), t.Location); |
||||
Assert.AreEqual(new Location(7, 1), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new Location(7, 1), t.Location); |
||||
Assert.AreEqual(new Location(1, 2), t.EndLocation); |
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.Static, t.Kind); |
||||
Assert.AreEqual(new Location(1, 2), t.Location); |
||||
Assert.AreEqual(new Location(7, 2), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF1() |
||||
{ |
||||
ILexer l = GenerateLexer("public"); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new Location(7, 1), t.Location); |
||||
Assert.AreEqual(new Location(7, 1), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new Location(7, 1), t.Location); |
||||
Assert.AreEqual(new Location(7, 1), t.EndLocation); |
||||
} |
||||
|
||||
[Test] |
||||
public void TestPositionOfEOF2() |
||||
{ |
||||
ILexer l = GenerateLexer("public _\n "); |
||||
l.NextToken(); // public
|
||||
Token t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOL, t.Kind); |
||||
Assert.AreEqual(new Location(2, 2), t.Location); |
||||
Assert.AreEqual(new Location(2, 2), t.EndLocation); |
||||
|
||||
t = l.NextToken(); |
||||
Assert.AreEqual(Tokens.EOF, t.Kind); |
||||
Assert.AreEqual(new Location(2, 2), t.Location); |
||||
Assert.AreEqual(new Location(2, 2), t.EndLocation); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue