Browse Source
This will allow us to automatically generate the IAstVisitor and a future AstTransformer and we don't have to worry about forgetting some AST nodes. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@975 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
49 changed files with 7599 additions and 1355 deletions
@ -0,0 +1,237 @@
@@ -0,0 +1,237 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.AST |
||||
{ |
||||
[CustomImplementation] |
||||
abstract class Expression : AbstractNode {} |
||||
|
||||
[CustomImplementation] |
||||
class PrimitiveExpression : Expression {} |
||||
|
||||
enum ParamModifier { In } |
||||
|
||||
class ParameterDeclarationExpression : Expression { |
||||
List<AttributeSection> attributes; |
||||
[QuestionMarkDefault] |
||||
string parameterName; |
||||
TypeReference typeReference; |
||||
ParamModifier paramModifier; |
||||
Expression defaultValue; |
||||
|
||||
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName) {} |
||||
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParamModifier paramModifier) {} |
||||
public ParameterDeclarationExpression(TypeReference typeReference, string parameterName, ParamModifier paramModifier, Expression defaultValue) {} |
||||
} |
||||
|
||||
class NamedArgumentExpression : Expression { |
||||
string name; |
||||
Expression expression; |
||||
|
||||
public NamedArgumentExpression(string name, Expression expression) {} |
||||
} |
||||
|
||||
class ArrayCreateExpression : Expression { |
||||
TypeReference createType; |
||||
List<Expression> arguments; |
||||
ArrayInitializerExpression arrayInitializer; |
||||
|
||||
public ArrayCreateExpression(TypeReference createType) {} |
||||
public ArrayCreateExpression(TypeReference createType, List<Expression> arguments) {} |
||||
public ArrayCreateExpression(TypeReference createType, ArrayInitializerExpression arrayInitializer) {} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Shadow)] |
||||
class ArrayInitializerExpression : Expression { |
||||
List<Expression> createExpressions; |
||||
|
||||
public ArrayInitializerExpression() {} |
||||
public ArrayInitializerExpression(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(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 FieldReferenceExpression : Expression |
||||
{ |
||||
Expression targetObject; |
||||
string fieldName; |
||||
|
||||
public FieldReferenceExpression(Expression targetObject, string fieldName) {} |
||||
} |
||||
|
||||
class IdentifierExpression : Expression { |
||||
string identifier; |
||||
|
||||
public IdentifierExpression(string identifier) {} |
||||
} |
||||
|
||||
class InvocationExpression : Expression { |
||||
Expression targetObject; |
||||
List<Expression> arguments; |
||||
List<TypeReference> typeArguments; |
||||
|
||||
public InvocationExpression(Expression targetObject) {} |
||||
public InvocationExpression(Expression targetObject, List<Expression> arguments) {} |
||||
public InvocationExpression(Expression targetObject, List<Expression> arguments, List<TypeReference> typeArguments) {} |
||||
} |
||||
|
||||
class ObjectCreateExpression : Expression { |
||||
TypeReference createType; |
||||
List<Expression> parameters; |
||||
|
||||
public ObjectCreateExpression(TypeReference createType, List<Expression> parameters) {} |
||||
} |
||||
|
||||
class ParenthesizedExpression : Expression { |
||||
Expression expression; |
||||
|
||||
public ParenthesizedExpression(Expression expression) {} |
||||
} |
||||
|
||||
class ThisReferenceExpression : Expression {} |
||||
|
||||
class TypeOfExpression : Expression { |
||||
TypeReference typeReference; |
||||
|
||||
public TypeOfExpression(TypeReference typeReference) {} |
||||
} |
||||
|
||||
[IncludeMember("public TypeReferenceExpression(string typeName) : this(new TypeReference(typeName)) {}")] |
||||
class TypeReferenceExpression : Expression { |
||||
TypeReference typeReference; |
||||
|
||||
public TypeReferenceExpression(TypeReference typeReference) {} |
||||
} |
||||
|
||||
enum UnaryOperatorType {} |
||||
|
||||
class UnaryOperatorExpression : Expression { |
||||
UnaryOperatorType op; |
||||
Expression expression; |
||||
|
||||
public UnaryOperatorExpression(UnaryOperatorType op) {} |
||||
public UnaryOperatorExpression(Expression expression, UnaryOperatorType op) {} |
||||
} |
||||
|
||||
class AnonymousMethodExpression : Expression { |
||||
List<ParameterDeclarationExpression> parameters; |
||||
BlockStatement body; |
||||
} |
||||
|
||||
class CheckedExpression : Expression { |
||||
Expression expression; |
||||
|
||||
public CheckedExpression(Expression expression) {} |
||||
} |
||||
|
||||
class ConditionalExpression : Expression { |
||||
Expression condition; |
||||
Expression trueExpression; |
||||
Expression falseExpression; |
||||
|
||||
public ConditionalExpression(Expression condition, Expression trueExpression, Expression falseExpression) {} |
||||
} |
||||
|
||||
class DefaultValueExpression : Expression { |
||||
TypeReference typeReference; |
||||
|
||||
public DefaultValueExpression(TypeReference typeReference) {} |
||||
} |
||||
|
||||
enum FieldDirection {} |
||||
|
||||
class DirectionExpression : Expression { |
||||
FieldDirection fieldDirection; |
||||
Expression expression; |
||||
|
||||
public DirectionExpression(FieldDirection fieldDirection, Expression expression) {} |
||||
} |
||||
|
||||
class IndexerExpression : Expression { |
||||
Expression targetObject; |
||||
List<Expression> indices; |
||||
|
||||
public IndexerExpression(Expression targetObject, List<Expression> indices) {} |
||||
} |
||||
|
||||
class PointerReferenceExpression : Expression { |
||||
Expression targetObject; |
||||
string identifier; |
||||
|
||||
public PointerReferenceExpression(Expression targetObject, string identifier) {} |
||||
} |
||||
|
||||
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) {} |
||||
} |
||||
} |
||||
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.AST |
||||
{ |
||||
[CustomImplementation, HasChildren] |
||||
class CompilationUnit : AbstractNode {} |
||||
|
||||
[HasChildren] |
||||
class NamespaceDeclaration : AbstractNode |
||||
{ |
||||
string name; |
||||
|
||||
public NamespaceDeclaration(string name) {} |
||||
} |
||||
|
||||
class TemplateDefinition : AttributedNode |
||||
{ |
||||
[QuestionMarkDefault] |
||||
string name; |
||||
List<TypeReference> bases; |
||||
|
||||
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(Modifier 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; |
||||
|
||||
public TypeDeclaration(Modifier modifier, List<AttributeSection> attributes) : base(modifier, attributes) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsAlias", "return !alias.IsNull;")] |
||||
class Using : AbstractNode |
||||
{ |
||||
[QuestionMarkDefault] |
||||
string name; |
||||
TypeReference alias; |
||||
|
||||
public Using(string name) {} |
||||
public Using(string name, TypeReference alias) {} |
||||
} |
||||
|
||||
[IncludeMember("public UsingDeclaration(string nameSpace) : this(nameSpace, null) {}")] |
||||
[IncludeMember("public UsingDeclaration(string nameSpace, TypeReference alias) {" + |
||||
" usings = new List<Using>(1);" + |
||||
" usings.Add(new Using(nameSpace, alias)); " + |
||||
"}")] |
||||
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) {} |
||||
} |
||||
} |
||||
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.AST |
||||
{ |
||||
interface INode {} |
||||
interface INullable {} |
||||
struct Point {} |
||||
|
||||
enum Modifier { None } |
||||
|
||||
[CustomImplementation] |
||||
abstract class AbstractNode : INode {} |
||||
|
||||
abstract class AttributedNode : AbstractNode |
||||
{ |
||||
List<AttributeSection> attributes; |
||||
Modifier modifier; |
||||
|
||||
public AttributedNode(List<AttributeSection> attributes) {} |
||||
public AttributedNode(Modifier modifier, List<AttributeSection> attributes) {} |
||||
} |
||||
|
||||
abstract class ParametrizedNode : AttributedNode |
||||
{ |
||||
string name; |
||||
List<ParameterDeclarationExpression> parameters; |
||||
|
||||
public ParametrizedNode(Modifier modifier, List<AttributeSection> attributes, |
||||
string name, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes) |
||||
{} |
||||
|
||||
public ParametrizedNode(Modifier modifier, List<AttributeSection> attributes) |
||||
: base(modifier, attributes) |
||||
{} |
||||
} |
||||
|
||||
[CustomImplementation] |
||||
class TypeReference : AbstractNode {} |
||||
[CustomImplementation] |
||||
class InnerClassTypeReference : TypeReference {} |
||||
|
||||
class AttributeSection : AbstractNode, INullable |
||||
{ |
||||
string attributeTarget; |
||||
List<Attribute> attributes; |
||||
|
||||
public AttributeSection(string attributeTarget, List<Attribute> attributes) {} |
||||
} |
||||
|
||||
class Attribute : AbstractNode |
||||
{ |
||||
string name; |
||||
List<Expression> positionalArguments; |
||||
List<NamedArgumentExpression> namedArguments; |
||||
|
||||
public Attribute(string name, List<Expression> positionalArguments, List<NamedArgumentExpression> namedArguments) {} |
||||
} |
||||
} |
||||
@ -0,0 +1,314 @@
@@ -0,0 +1,314 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.AST |
||||
{ |
||||
[CustomImplementation] |
||||
abstract class Statement : AbstractNode {} |
||||
|
||||
[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)); |
||||
}")]
|
||||
[IncludeMember(@"
|
||||
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement) |
||||
: this(condition) { |
||||
this.trueStatement.Add(Statement.CheckNull(trueStatement)); |
||||
this.falseStatement.Add(Statement.CheckNull(falseStatement)); |
||||
}")]
|
||||
[IncludeBoolProperty("HasElseStatements", "return falseStatement.Count > 0;")] |
||||
[IncludeBoolProperty("HasElseIfSections", "return elseIfSections.Count > 0;")] |
||||
class IfElseStatement : Statement { |
||||
Expression condition; |
||||
List<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; |
||||
Modifier 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 StatementExpression : Statement { |
||||
Expression expression; |
||||
|
||||
public StatementExpression(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 { |
||||
TypeReference typeReference; |
||||
List<VariableDeclaration> pointerDeclarators; |
||||
|
||||
public FixedStatement(TypeReference typeReference, List<VariableDeclaration> pointerDeclarators, Statement embeddedStatement) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsDefaultCase", "return expression.IsNull;")] |
||||
class GotoCaseStatement : Statement { |
||||
Expression expression; |
||||
|
||||
public GotoCaseStatement(Expression expression) {} |
||||
} |
||||
|
||||
class UncheckedStatement : Statement { |
||||
Statement block; |
||||
|
||||
public UncheckedStatement(Statement block) {} |
||||
} |
||||
|
||||
class UnsafeStatement : Statement { |
||||
Statement block; |
||||
|
||||
public UnsafeStatement(Statement block) {} |
||||
} |
||||
|
||||
class UsingStatement : StatementWithEmbeddedStatement { |
||||
Statement resourceAcquisition; |
||||
|
||||
public UsingStatement(Statement resourceAcquisition, Statement embeddedStatement) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("IsYieldReturn", "return statement is ReturnStatement;")] |
||||
[IncludeBoolProperty("IsYieldBreak", "return statement is BreakStatement;")] |
||||
class YieldStatement : Statement { |
||||
Statement statement; |
||||
|
||||
public YieldStatement(Statement statement) {} |
||||
} |
||||
|
||||
class AddHandlerStatement : Statement { |
||||
Expression eventExpression; |
||||
Expression handlerExpression; |
||||
|
||||
public AddHandlerStatement(Expression eventExpression, Expression handlerExpression) {} |
||||
} |
||||
|
||||
class EndStatement : Statement {} |
||||
|
||||
class EraseStatement : Statement { |
||||
List<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; |
||||
TypeReference typeReference; |
||||
string variableName; |
||||
|
||||
public ForNextStatement(TypeReference typeReference, string variableName, Expression start, Expression end, Expression step, Statement embeddedStatement, List<Expression> nextExpressions) {} |
||||
} |
||||
|
||||
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,284 @@
@@ -0,0 +1,284 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace NRefactoryASTGenerator.AST |
||||
{ |
||||
class VariableDeclaration : AbstractNode |
||||
{ |
||||
string name; |
||||
Expression initializer; |
||||
TypeReference typeReference; |
||||
|
||||
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, Modifier modifier, |
||||
List<ParameterDeclarationExpression> parameters, |
||||
List<AttributeSection> attributes) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
|
||||
public ConstructorDeclaration(string name, Modifier modifier, |
||||
List<ParameterDeclarationExpression> parameters, |
||||
ConstructorInitializer constructorInitializer, |
||||
List<AttributeSection> attributes) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
|
||||
enum ConstructorInitializerType { None } |
||||
|
||||
[ImplementNullable] |
||||
class ConstructorInitializer : AbstractNode |
||||
{ |
||||
ConstructorInitializerType constructorInitializerType; |
||||
List<Expression> arguments; |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Abstract)] |
||||
abstract class EventAddRemoveRegion : AttributedNode |
||||
{ |
||||
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 : ParametrizedNode |
||||
{ |
||||
TypeReference typeReference; |
||||
List<InterfaceImplementation> interfaceImplementations; |
||||
EventAddRegion addRegion; |
||||
EventRemoveRegion removeRegion; |
||||
EventRaiseRegion raiseRegion; |
||||
Point bodyStart; |
||||
Point bodyEnd; |
||||
|
||||
public EventDeclaration(TypeReference typeReference, string name, Modifier modifier, List<AttributeSection> attributes, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes, name, parameters) |
||||
{ } |
||||
|
||||
// for VB:
|
||||
public EventDeclaration(TypeReference typeReference, Modifier modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes, string name, List<InterfaceImplementation> interfaceImplementations) |
||||
: base(modifier, attributes, name, parameters) |
||||
{ } |
||||
} |
||||
|
||||
[IncludeMember(@"
|
||||
public TypeReference GetTypeForField(int fieldIndex) |
||||
{ |
||||
if (!typeReference.IsNull) { |
||||
return typeReference; |
||||
} |
||||
|
||||
for (int i = fieldIndex; i < Fields.Count;++i) { |
||||
if (!((VariableDeclaration)Fields[i]).TypeReference.IsNull) { |
||||
return ((VariableDeclaration)Fields[i]).TypeReference; |
||||
} |
||||
} |
||||
return TypeReference.Null; |
||||
}")]
|
||||
[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, Modifier modifier) |
||||
: base(modifier, attributes) |
||||
{} |
||||
} |
||||
|
||||
class MethodDeclaration : ParametrizedNode |
||||
{ |
||||
TypeReference typeReference; |
||||
BlockStatement body; |
||||
List<string> handlesClause; |
||||
List<InterfaceImplementation> interfaceImplementations; |
||||
List<TemplateDefinition> templates; |
||||
|
||||
public MethodDeclaration(string name, Modifier modifier, TypeReference typeReference, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes) : base(modifier, attributes, name, parameters) {} |
||||
} |
||||
|
||||
enum ConversionType { None } |
||||
enum OverloadableOperatorType { None } |
||||
|
||||
[IncludeBoolProperty("IsConversionOperator", "return conversionType != ConversionType.None;")] |
||||
[FixOperatorDeclarationAttribute] |
||||
class OperatorDeclaration : MethodDeclaration |
||||
{ |
||||
ConversionType conversionType; |
||||
List<AttributeSection> returnTypeAttributes; |
||||
OverloadableOperatorType overloadableOperator; |
||||
|
||||
public OperatorDeclaration(Modifier modifier, |
||||
List<AttributeSection> attributes, |
||||
List<ParameterDeclarationExpression> parameters, |
||||
TypeReference typeReference, |
||||
ConversionType conversionType) |
||||
: base(null, modifier, typeReference, parameters, attributes) |
||||
{} |
||||
|
||||
public OperatorDeclaration(Modifier modifier, |
||||
List<AttributeSection> attributes, |
||||
List<ParameterDeclarationExpression> parameters, |
||||
TypeReference typeReference, |
||||
OverloadableOperatorType overloadableOperator) |
||||
: base(null, modifier, typeReference, parameters, attributes) |
||||
{} |
||||
} |
||||
|
||||
[IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")] |
||||
[IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")] |
||||
[IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")] |
||||
[IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")] |
||||
[IncludeMember(@"
|
||||
public PropertyDeclaration(string name, TypeReference typeReference, Modifier modifier, List<AttributeSection> attributes) : this(modifier, attributes, name, null) |
||||
{ |
||||
this.TypeReference = typeReference; |
||||
if ((modifier & Modifier.ReadOnly) == Modifier.ReadOnly) { |
||||
this.GetRegion = new PropertyGetRegion(null, null); |
||||
} else if ((modifier & Modifier.WriteOnly) == Modifier.WriteOnly) { |
||||
this.SetRegion = new PropertySetRegion(null, null); |
||||
} |
||||
}")]
|
||||
class PropertyDeclaration : ParametrizedNode |
||||
{ |
||||
List<InterfaceImplementation> interfaceImplementations; |
||||
TypeReference typeReference; |
||||
Point bodyStart; |
||||
Point bodyEnd; |
||||
PropertyGetRegion getRegion; |
||||
PropertySetRegion setRegion; |
||||
|
||||
public PropertyDeclaration(Modifier modifier, List<AttributeSection> attributes, |
||||
string name, List<ParameterDeclarationExpression> parameters) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
|
||||
[ImplementNullable(NullableImplementation.Abstract)] |
||||
abstract class PropertyGetSetRegion : AttributedNode |
||||
{ |
||||
// can be null if only the definition is there (interface declaration)
|
||||
BlockStatement block; |
||||
|
||||
public PropertyGetSetRegion(BlockStatement block, List<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, Modifier modifier, List<AttributeSection> attributes) : base(modifier, attributes) {} |
||||
} |
||||
|
||||
[IncludeBoolProperty("HasGetRegion", "return !getRegion.IsNull;")] |
||||
[IncludeBoolProperty("HasSetRegion", "return !setRegion.IsNull;")] |
||||
[IncludeBoolProperty("IsReadOnly", "return HasGetRegion && !HasSetRegion;")] |
||||
[IncludeBoolProperty("IsWriteOnly", "return !HasGetRegion && HasSetRegion;")] |
||||
class IndexerDeclaration : AttributedNode |
||||
{ |
||||
List<ParameterDeclarationExpression> parameters; |
||||
List<InterfaceImplementation> interfaceImplementations; |
||||
TypeReference typeReference; |
||||
Point bodyStart; |
||||
Point bodyEnd; |
||||
PropertyGetRegion getRegion; |
||||
PropertySetRegion setRegion; |
||||
|
||||
public IndexerDeclaration(Modifier modifier, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes) |
||||
: base(modifier, attributes) |
||||
{} |
||||
|
||||
public IndexerDeclaration(TypeReference typeReference, List<ParameterDeclarationExpression> parameters, Modifier 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, Modifier modifier, TypeReference typeReference, List<ParameterDeclarationExpression> parameters, List<AttributeSection> attributes, string library, string alias, CharsetModifier charset) |
||||
: base(modifier, attributes, name, parameters) |
||||
{} |
||||
} |
||||
} |
||||
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
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,198 @@
@@ -0,0 +1,198 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.CodeDom; |
||||
|
||||
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)] |
||||
public class FixOperatorDeclarationAttribute : TypeImplementationModifierAttribute |
||||
{ |
||||
public override void ModifyImplementation(CodeNamespace cns, CodeTypeDeclaration ctd, Type type) |
||||
{ |
||||
foreach (object o in ctd.Members) { |
||||
CodeConstructor cc = o as CodeConstructor; |
||||
if (cc != null) { |
||||
cc.BaseConstructorArgs[0] = new CodePrimitiveExpression(null); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
[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(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.BaseTypes.Add(new CodeTypeReference(ctd.Name)); |
||||
cns.Types.Add(newType); |
||||
|
||||
System.Reflection.ConstructorInfo baseCtor = MainClass.GetBaseCtor(type); |
||||
CodeConstructor ctor = new CodeConstructor(); |
||||
ctor.Attributes = MemberAttributes.Private; |
||||
if (baseCtor != null) { |
||||
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; |
||||
field.InitExpression = new CodeObjectCreateExpression(new CodeTypeReference(newType.Name)); |
||||
newType.Members.Add(field); |
||||
|
||||
CodeMemberProperty prop = new CodeMemberProperty(); |
||||
prop.Name = "Instance"; |
||||
prop.Type = new CodeTypeReference(newType.Name); |
||||
prop.Attributes = MemberAttributes.Public | MemberAttributes.Static; |
||||
prop.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("instance"))); |
||||
newType.Members.Add(prop); |
||||
|
||||
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,231 @@
@@ -0,0 +1,231 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.CodeDom; |
||||
using System.Diagnostics; |
||||
using System.Reflection; |
||||
using System.IO; |
||||
using NRefactoryASTGenerator.AST; |
||||
|
||||
namespace NRefactoryASTGenerator |
||||
{ |
||||
class MainClass |
||||
{ |
||||
public static void Main(string[] args) |
||||
{ |
||||
string directory = "../../../Project/Src/Parser/AST/"; |
||||
string visitorsDir = "../../../Project/Src/Parser/Visitors/"; |
||||
Debug.WriteLine("AST Generator running..."); |
||||
if (!File.Exists(directory + "INode.cs")) { |
||||
Debug.WriteLine("did not find output directory"); |
||||
return; |
||||
} |
||||
if (!File.Exists(visitorsDir + "IASTVisitor.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 = new CodeNamespace("ICSharpCode.NRefactory.Parser.AST"); |
||||
ccu.Namespaces.Add(cns); |
||||
cns.Imports.Add(new CodeNamespaceImport("System")); |
||||
cns.Imports.Add(new CodeNamespaceImport("System.Collections.Generic")); |
||||
cns.Imports.Add(new CodeNamespaceImport("System.Diagnostics")); |
||||
cns.Imports.Add(new CodeNamespaceImport("System.Drawing")); |
||||
foreach (Type type in nodeTypes) { |
||||
if (type.GetCustomAttributes(typeof(CustomImplementationAttribute), false).Length == 0) { |
||||
CodeTypeDeclaration ctd = new CodeTypeDeclaration(type.Name); |
||||
if (type.IsAbstract) { |
||||
ctd.TypeAttributes |= TypeAttributes.Abstract; |
||||
} |
||||
ctd.BaseTypes.Add(new CodeTypeReference(type.BaseType.Name)); |
||||
cns.Types.Add(ctd); |
||||
|
||||
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, "Visit", |
||||
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); |
||||
} |
||||
} |
||||
} |
||||
|
||||
using (StringWriter writer = new StringWriter()) { |
||||
new Microsoft.CSharp.CSharpCodeProvider().GenerateCodeFromCompileUnit(ccu, writer, null); |
||||
File.WriteAllText(directory + "Generated.cs", writer.ToString()); |
||||
} |
||||
} |
||||
|
||||
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)) { |
||||
CodeMemberField f = new CodeMemberField(ConvertType(field.FieldType), field.Name); |
||||
f.Attributes = 0; |
||||
ctd.Members.Add(f); |
||||
} |
||||
foreach (FieldInfo field in type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic)) { |
||||
CodeMemberProperty p = new CodeMemberProperty(); |
||||
p.Name = GetPropertyName(field.Name); |
||||
p.Attributes = MemberAttributes.Public | MemberAttributes.Final; |
||||
p.Type = ConvertType(field.FieldType); |
||||
p.GetStatements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression(field.Name))); |
||||
CodeExpression ex; |
||||
if (field.FieldType.IsValueType) |
||||
ex = new CodePropertySetValueReferenceExpression(); |
||||
else |
||||
ex = GetDefaultValue("value", field); |
||||
p.SetStatements.Add(new CodeAssignStatement(new CodeVariableReferenceExpression(field.Name), ex)); |
||||
ctd.Members.Add(p); |
||||
} |
||||
foreach (ConstructorInfo ctor in type.GetConstructors()) { |
||||
CodeConstructor c = new CodeConstructor(); |
||||
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(Point)) |
||||
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(Point)) { |
||||
code = "new Point(-1, -1)"; |
||||
} else { |
||||
code = field.FieldType.Name + ".Null"; |
||||
} |
||||
if (inputVariable != null) { |
||||
code = inputVariable + " ?? " + code; |
||||
} |
||||
return new CodeSnippetExpression(code); |
||||
} |
||||
|
||||
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")) { |
||||
return new CodeTypeReference(type.Name); |
||||
} else { |
||||
return new CodeTypeReference(type); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<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>AnyCPU</PlatformTarget> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<WarningLevel>4</WarningLevel> |
||||
<NoWarn>0169</NoWarn> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
</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.Data" /> |
||||
<Reference Include="System.Xml" /> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<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> |
||||
@ -1,50 +0,0 @@
@@ -1,50 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public abstract class AttributedNode : AbstractNode |
||||
{ |
||||
protected List<AttributeSection> attributes; |
||||
protected Modifier modifier; |
||||
|
||||
public List<AttributeSection> Attributes { |
||||
get { |
||||
return attributes; |
||||
} |
||||
set { |
||||
attributes = value == null ? new List<AttributeSection>(1) : value; |
||||
} |
||||
} |
||||
|
||||
public Modifier Modifier { |
||||
get { |
||||
return modifier; |
||||
} |
||||
set { |
||||
modifier = value; |
||||
} |
||||
} |
||||
|
||||
public AttributedNode(List<AttributeSection> attributes) : this(Modifier.None, attributes) |
||||
{ |
||||
} |
||||
|
||||
public AttributedNode(Modifier modifier, List<AttributeSection> attributes) |
||||
{ |
||||
this.modifier = modifier; |
||||
|
||||
// use property because of the null check.
|
||||
this.Attributes = attributes; |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -1,180 +0,0 @@
@@ -1,180 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public class NamedArgumentExpression : Expression |
||||
{ |
||||
string name; |
||||
Expression expression; |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { |
||||
return expression; |
||||
} |
||||
set { |
||||
expression = Expression.CheckNull(value); |
||||
} |
||||
} |
||||
|
||||
public NamedArgumentExpression(string name, Expression expression) |
||||
{ |
||||
this.Name = name; |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IASTVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NamedArgumentExpression: Name = {0}, Expression = {1}]", |
||||
Name, |
||||
Expression); |
||||
} |
||||
} |
||||
|
||||
public class Attribute : AbstractNode |
||||
{ |
||||
string name = ""; |
||||
List<Expression> positionalArguments; |
||||
List<NamedArgumentExpression> namedArguments; |
||||
|
||||
public Attribute(string name, List<Expression> positionalArguments, List<NamedArgumentExpression> namedArguments) |
||||
{ |
||||
Debug.Assert(name != null); |
||||
Debug.Assert(positionalArguments != null); |
||||
Debug.Assert(namedArguments != null); |
||||
|
||||
this.name = name; |
||||
this.positionalArguments = positionalArguments; |
||||
this.namedArguments = namedArguments; |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
} |
||||
|
||||
public List<Expression> PositionalArguments { |
||||
get { |
||||
return positionalArguments; |
||||
} |
||||
} |
||||
|
||||
public List<NamedArgumentExpression> NamedArguments { |
||||
get { |
||||
return namedArguments; |
||||
} |
||||
} |
||||
|
||||
public override object AcceptVisitor(IASTVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[Attribute: Name = {0}, PositionalArguments = {1}, NamedArguments = {2}]", |
||||
Name, |
||||
PositionalArguments, |
||||
NamedArguments); |
||||
} |
||||
} |
||||
|
||||
public class AttributeSection : AbstractNode, INullable |
||||
{ |
||||
string attributeTarget = ""; |
||||
List<Attribute> attributes; |
||||
static AttributeSection nullSection = new NullAttributeSection(); |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static AttributeSection Null { |
||||
get { |
||||
return nullSection; |
||||
} |
||||
} |
||||
|
||||
public static AttributeSection CheckNull(AttributeSection attributeSection) |
||||
{ |
||||
return attributeSection == null ? AttributeSection.Null : attributeSection; |
||||
} |
||||
|
||||
public string AttributeTarget { |
||||
get { |
||||
return attributeTarget; |
||||
} |
||||
set { |
||||
attributeTarget = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public List<Attribute> Attributes { |
||||
get { |
||||
return attributes; |
||||
} |
||||
set { |
||||
attributes = value == null ? new List<Attribute>(1) : value; |
||||
} |
||||
} |
||||
|
||||
public AttributeSection() : this(null, null) |
||||
{ |
||||
} |
||||
|
||||
public AttributeSection(string attributeTarget, List<Attribute> attributes) |
||||
{ |
||||
this.AttributeTarget = attributeTarget; |
||||
this.Attributes = attributes; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IASTVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[AttributeSection: AttributeTarget={0}, Attributes={1}]", |
||||
AttributeTarget, |
||||
Attributes); |
||||
} |
||||
} |
||||
|
||||
public class NullAttributeSection : AttributeSection |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullAttributeSection]"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public class BlockStatement : Statement |
||||
{ |
||||
// Children in C#: LabelStatement, LocalVariableDeclaration, Statement
|
||||
// Children in VB: LabelStatement, EndStatement, Statement
|
||||
|
||||
public static new NullBlockStatement Null { |
||||
get { |
||||
return NullBlockStatement.Instance; |
||||
} |
||||
} |
||||
|
||||
public static BlockStatement CheckNull(BlockStatement blockStatement) |
||||
{ |
||||
return blockStatement == null ? NullBlockStatement.Instance : blockStatement; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[BlockStatement: Children={0}]", |
||||
GetCollectionString(base.Children)); |
||||
} |
||||
} |
||||
|
||||
public class NullBlockStatement : BlockStatement |
||||
{ |
||||
static NullBlockStatement nullBlockStatement = new NullBlockStatement(); |
||||
|
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public static NullBlockStatement Instance { |
||||
get { |
||||
return nullBlockStatement; |
||||
} |
||||
} |
||||
|
||||
NullBlockStatement() |
||||
{ |
||||
} |
||||
|
||||
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,56 @@
@@ -0,0 +1,56 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Threading; |
||||
using System.Diagnostics; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public class CompilationUnit : AbstractNode |
||||
{ |
||||
// Children in C#: UsingAliasDeclaration, UsingDeclaration, AttributeSection, NamespaceDeclaration
|
||||
// Children in VB: OptionStatements, ImportsStatement, AttributeSection, NamespaceDeclaration
|
||||
|
||||
Stack blockStack = new Stack(); |
||||
|
||||
public CompilationUnit() |
||||
{ |
||||
blockStack.Push(this); |
||||
} |
||||
|
||||
public void BlockStart(INode block) |
||||
{ |
||||
blockStack.Push(block); |
||||
} |
||||
|
||||
public void BlockEnd() |
||||
{ |
||||
blockStack.Pop(); |
||||
} |
||||
|
||||
public override void AddChild(INode childNode) |
||||
{ |
||||
if (childNode != null) { |
||||
INode parent = (INode)blockStack.Peek(); |
||||
parent.Children.Add(childNode); |
||||
childNode.Parent = parent; |
||||
} |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[CompilationUnit]"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public abstract class Expression : AbstractNode, INullable |
||||
{ |
||||
public static NullExpression 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.
|
||||
/// WARNING: This method modifies <paramref name="expr"/> and possibly returns <paramref name="expr"/>
|
||||
/// again, but it might also create a new expression around <paramref name="expr"/>.
|
||||
/// </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) { |
||||
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; |
||||
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))); |
||||
} |
||||
} |
||||
|
||||
public class NullExpression : Expression |
||||
{ |
||||
static NullExpression nullExpression = new NullExpression(); |
||||
|
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public static NullExpression Instance { |
||||
get { |
||||
return nullExpression; |
||||
} |
||||
} |
||||
|
||||
NullExpression() |
||||
{ |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullExpression]"); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public class LocalVariableDeclaration : Statement |
||||
{ |
||||
TypeReference typeReference; |
||||
Modifier modifier = Modifier.None; |
||||
List<VariableDeclaration> variables = new List<VariableDeclaration>(1); |
||||
|
||||
public TypeReference TypeReference { |
||||
get { |
||||
return typeReference; |
||||
} |
||||
set { |
||||
typeReference = TypeReference.CheckNull(value); |
||||
} |
||||
} |
||||
|
||||
public Modifier 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, Modifier modifier) |
||||
{ |
||||
this.TypeReference = typeReference; |
||||
this.modifier = modifier; |
||||
} |
||||
|
||||
public LocalVariableDeclaration(Modifier 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.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[LocalVariableDeclaration: Type={0}, Modifier ={1} Variables={2}]", |
||||
typeReference, |
||||
modifier, |
||||
GetCollectionString(variables)); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="none" email=""/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections; |
||||
using System.Globalization; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST { |
||||
|
||||
public class PrimitiveExpression : Expression |
||||
{ |
||||
object val; |
||||
string stringValue; |
||||
|
||||
public object Value { |
||||
get { |
||||
return val; |
||||
} |
||||
set { |
||||
val = value; |
||||
} |
||||
} |
||||
|
||||
public string StringValue { |
||||
get { |
||||
return stringValue; |
||||
} |
||||
set { |
||||
stringValue = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public PrimitiveExpression(object val, string stringValue) |
||||
{ |
||||
this.Value = val; |
||||
this.StringValue = stringValue; |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return visitor.Visit(this, data); |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[PrimitiveExpression: Value={1}, ValueType={2}, StringValue={0}]", |
||||
stringValue, |
||||
Value, |
||||
Value == null ? "null" : Value.GetType().FullName |
||||
); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public abstract class Statement : AbstractNode, INullable |
||||
{ |
||||
public static NullStatement Null { |
||||
get { |
||||
return NullStatement.Instance; |
||||
} |
||||
} |
||||
|
||||
public virtual bool IsNull { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static Statement CheckNull(Statement statement) |
||||
{ |
||||
return statement == null ? NullStatement.Instance : statement; |
||||
} |
||||
|
||||
public static void Replace(Statement oldStatement, Statement newStatement) |
||||
{ |
||||
INode parent = oldStatement.Parent; |
||||
StatementWithEmbeddedStatement parentStmt = parent as StatementWithEmbeddedStatement; |
||||
if (parentStmt != null && parentStmt.EmbeddedStatement == oldStatement) |
||||
parentStmt.EmbeddedStatement = newStatement; |
||||
int index = parent.Children.IndexOf(oldStatement); |
||||
if (index >= 0) { |
||||
parent.Children[index] = newStatement; |
||||
newStatement.Parent = parent; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public abstract class StatementWithEmbeddedStatement : Statement |
||||
{ |
||||
Statement embeddedStatement; |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { |
||||
return embeddedStatement; |
||||
} |
||||
set { |
||||
embeddedStatement = Statement.CheckNull(value); |
||||
if (value != null) |
||||
value.Parent = this; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public class NullStatement : Statement |
||||
{ |
||||
static NullStatement nullStatement = new NullStatement(); |
||||
|
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public static NullStatement Instance { |
||||
get { |
||||
return nullStatement; |
||||
} |
||||
} |
||||
|
||||
NullStatement() |
||||
{ |
||||
} |
||||
|
||||
public override object AcceptVisitor(IAstVisitor visitor, object data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return String.Format("[NullStatement]"); |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -1,52 +0,0 @@
@@ -1,52 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.Parser.AST |
||||
{ |
||||
public abstract class ParametrizedNode : AttributedNode |
||||
{ |
||||
protected string name = String.Empty; |
||||
protected List<ParameterDeclarationExpression> parameters; |
||||
|
||||
public string Name { |
||||
get { |
||||
return name; |
||||
} |
||||
set { |
||||
name = value == null ? String.Empty : value; |
||||
} |
||||
} |
||||
|
||||
public List<ParameterDeclarationExpression> Parameters { |
||||
get { |
||||
return parameters; |
||||
} |
||||
set { |
||||
parameters = value == null ? new List<ParameterDeclarationExpression>(1) : value; |
||||
} |
||||
} |
||||
|
||||
public ParametrizedNode(Modifier modifier, List<AttributeSection> attributes) : this(modifier, attributes, null) |
||||
{ |
||||
} |
||||
|
||||
public ParametrizedNode(Modifier modifier, List<AttributeSection> attributes, string name) : this(modifier, attributes, name, null) |
||||
{ |
||||
} |
||||
|
||||
public ParametrizedNode(Modifier modifier, List<AttributeSection> attributes, string name, List<ParameterDeclarationExpression> parameters) : base(modifier, attributes) |
||||
{ |
||||
// use properties because of the null check.
|
||||
this.Name = name; |
||||
this.Parameters = parameters; |
||||
} |
||||
} |
||||
} |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue