Browse Source

Added generator application to generate the NRefactory AST.

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-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
8cd3f6d81c
  1. 2
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs
  2. 5
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorGlobal.cs
  3. 8
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs
  4. 64
      src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs
  5. 1
      src/AddIns/Misc/PInvokeAddIn/Project/Src/PInvokeRepository.cs
  6. 8
      src/Libraries/NRefactory/NRefactory.sln
  7. 237
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  8. 94
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs
  9. 67
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs
  10. 314
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Statements.cs
  11. 284
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs
  12. 33
      src/Libraries/NRefactory/NRefactoryASTGenerator/AssemblyInfo.cs
  13. 198
      src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs
  14. 231
      src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs
  15. 55
      src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj
  16. 2
      src/Libraries/NRefactory/Project/Configuration/AssemblyInfo.cs
  17. 109
      src/Libraries/NRefactory/Project/NRefactory.csproj
  18. 5
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  19. 2
      src/Libraries/NRefactory/Project/Src/Output/IOutputASTVisitor.cs
  20. 6
      src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs
  21. 5
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  22. 4
      src/Libraries/NRefactory/Project/Src/Parser/AST/AbstractNode.cs
  23. 50
      src/Libraries/NRefactory/Project/Src/Parser/AST/AttributedNode.cs
  24. 240
      src/Libraries/NRefactory/Project/Src/Parser/AST/Enums.cs
  25. 180
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/AttributeSection.cs
  26. 79
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/BlockStatement.cs
  27. 56
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/CompilationUnit.cs
  28. 111
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expression.cs
  29. 104
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/LocalVariableDeclaration.cs
  30. 58
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/PrimitiveExpression.cs
  31. 92
      src/Libraries/NRefactory/Project/Src/Parser/AST/General/Statement.cs
  32. 4316
      src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs
  33. 4
      src/Libraries/NRefactory/Project/Src/Parser/AST/INode.cs
  34. 0
      src/Libraries/NRefactory/Project/Src/Parser/AST/INullable.cs
  35. 52
      src/Libraries/NRefactory/Project/Src/Parser/AST/ParametrizedNode.cs
  36. 6
      src/Libraries/NRefactory/Project/Src/Parser/AST/TypeReference.cs
  37. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  38. 4
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  39. 1790
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  40. 28
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  41. 7
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs
  42. 4
      src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs
  43. 10
      src/Libraries/NRefactory/Test/AssemblyInfo.cs
  44. 4
      src/Libraries/NRefactory/Test/General/UnitTest.cs
  45. 4
      src/Libraries/NRefactory/Test/Parser/Statements/YieldStatementTests.cs
  46. 6
      src/Libraries/NRefactory/Test/Parser/TypeLevel/OperatorDeclarationTests.cs
  47. 2
      src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  48. 7
      src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs
  49. 2
      src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/EqualsCodeGenerator.cs

2
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs

@ -15,7 +15,7 @@ using B = Boo.Lang.Compiler.Ast; @@ -15,7 +15,7 @@ using B = Boo.Lang.Compiler.Ast;
namespace NRefactoryToBooConverter
{
public partial class ConvertVisitor : IASTVisitor
public partial class ConvertVisitor : IAstVisitor
{
string fileName;
CompilerErrorCollection errors;

5
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitorGlobal.cs

@ -200,6 +200,11 @@ namespace NRefactoryToBooConverter @@ -200,6 +200,11 @@ namespace NRefactoryToBooConverter
throw new ApplicationException("Visited NamedArgumentExpression.");
}
public object Visit(InterfaceImplementation interfaceImplementation, object data)
{
throw new ApplicationException("Visited InterfaceImplementation.");
}
public object Visit(OptionDeclaration optionDeclaration, object data)
{
AddError(optionDeclaration, "Option statement is not supported.");

8
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Gui/CustomComponentsSideTab.cs

@ -81,7 +81,7 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -81,7 +81,7 @@ namespace ICSharpCode.FormsDesigner.Gui
{
string className;
IProjectContent assemblyLocation;
bool initialized;
Assembly usedAssembly = null;
public CustomComponentToolBoxItem(IClass c)
{
@ -93,14 +93,12 @@ namespace ICSharpCode.FormsDesigner.Gui @@ -93,14 +93,12 @@ namespace ICSharpCode.FormsDesigner.Gui
void Init()
{
if (initialized)
return;
initialized = true;
LoggingService.Debug("Initializing MyToolBoxItem: " + className);
if (assemblyLocation != null) {
Assembly asm = TypeResolutionService.LoadAssembly(assemblyLocation);
if (asm != null) {
if (asm != null && usedAssembly != asm) {
Initialize(asm.GetType(className));
usedAssembly = asm;
}
}
}

64
src/AddIns/DisplayBindings/FormsDesigner/Project/Src/Services/TypeResolutionService.cs

@ -26,7 +26,9 @@ namespace ICSharpCode.FormsDesigner.Services @@ -26,7 +26,9 @@ namespace ICSharpCode.FormsDesigner.Services
public class TypeResolutionService : ITypeResolutionService
{
readonly static List<Assembly> designerAssemblies = new List<Assembly>();
// hash of file content -> Assembly
/// <summary>
/// string "filename:size" -> Assembly
/// </summary>
readonly static Dictionary<string, Assembly> assemblyDict = new Dictionary<string, Assembly>();
/// <summary>
@ -137,7 +139,8 @@ namespace ICSharpCode.FormsDesigner.Services @@ -137,7 +139,8 @@ namespace ICSharpCode.FormsDesigner.Services
if (!File.Exists(fileName))
return null;
byte[] data = File.ReadAllBytes(fileName);
string hash;
string hash = fileName + ":" + File.GetLastWriteTimeUtc(fileName);
using (HashFunction hashFunction = new HashFunction()) {
hash = Convert.ToBase64String(hashFunction.ComputeHash(data));
}
@ -262,18 +265,11 @@ namespace ICSharpCode.FormsDesigner.Services @@ -262,18 +265,11 @@ namespace ICSharpCode.FormsDesigner.Services
return null;
}
try {
lock (designerAssemblies) {
foreach (Assembly asm in DesignerAssemblies) {
Type t = asm.GetType(name, false);
if (t != null) {
return t;
}
}
}
Type type = Type.GetType(name, false, ignoreCase);
Type type = null;
int idx = name.IndexOf(",");
if (type == null) {
if (idx < 0) {
IProjectContent pc = this.CallingProject;
if (pc != null) {
IClass foundClass = pc.GetClass(name);
@ -287,26 +283,34 @@ namespace ICSharpCode.FormsDesigner.Services @@ -287,26 +283,34 @@ namespace ICSharpCode.FormsDesigner.Services
}
// type lookup for typename, assembly, xyz style lookups
if (type == null) {
int idx = name.IndexOf(",");
if (idx > 0) {
string[] splitName = name.Split(',');
string typeName = splitName[0];
string assemblyName = splitName[1].Substring(1);
Assembly assembly = null;
try {
assembly = Assembly.Load(assemblyName);
} catch (Exception e) {
LoggingService.Error(e);
if (type == null && idx > 0) {
string[] splitName = name.Split(',');
string typeName = splitName[0];
string assemblyName = splitName[1].Substring(1);
Assembly assembly = null;
try {
assembly = Assembly.Load(assemblyName);
} catch (Exception e) {
LoggingService.Error(e);
}
if (assembly != null) {
lock (designerAssemblies) {
if (!designerAssemblies.Contains(assembly))
designerAssemblies.Add(assembly);
}
if (assembly != null) {
lock (designerAssemblies) {
if (!designerAssemblies.Contains(assembly))
designerAssemblies.Add(assembly);
type = assembly.GetType(typeName, false, ignoreCase);
} else {
type = Type.GetType(typeName, false, ignoreCase);
}
}
if (type == null) {
lock (designerAssemblies) {
foreach (Assembly asm in DesignerAssemblies) {
Type t = asm.GetType(name, false);
if (t != null) {
return t;
}
type = assembly.GetType(typeName, false, ignoreCase);
} else {
type = Type.GetType(typeName, false, ignoreCase);
}
}
}

1
src/AddIns/Misc/PInvokeAddIn/Project/Src/PInvokeRepository.cs

@ -5,7 +5,6 @@ @@ -5,7 +5,6 @@
// <version>$Revision$</version>
// </file>
using System;
using System.Collections;
using System.IO;

8
src/Libraries/NRefactory/NRefactory.sln

@ -1,11 +1,13 @@ @@ -1,11 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 9.00
# SharpDevelop 2.0.0.825
# SharpDevelop 2.0.0.973
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactory", "Project\NRefactory.csproj", "{3A9AE6AA-BC07-4A2F-972C-581E3AE2F195}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryTests", "Test\NRefactoryTests.csproj", "{870115DD-960A-4406-A6B9-600BCDC36A03}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nunit.framework.dll", "..\NUnit.Framework\nunit.framework.dll.csproj", "{83DD7E12-A705-4DBA-9D71-09C8973D9382}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NRefactoryASTGenerator", "NRefactoryASTGenerator\NRefactoryASTGenerator.csproj", "{B22522AA-B5BF-4A58-AC6D-D4B45805521F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -24,6 +26,10 @@ Global @@ -24,6 +26,10 @@ Global
{83DD7E12-A705-4DBA-9D71-09C8973D9382}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83DD7E12-A705-4DBA-9D71-09C8973D9382}.Release|Any CPU.Build.0 = Release|Any CPU
{83DD7E12-A705-4DBA-9D71-09C8973D9382}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Release|Any CPU.Build.0 = Release|Any CPU
{B22522AA-B5BF-4A58-AC6D-D4B45805521F}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

237
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -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) {}
}
}

94
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/GlobalLevel.cs

@ -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) {}
}
}

67
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Node.cs

@ -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) {}
}
}

314
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Statements.cs

@ -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) {}
}
}

284
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/TypeLevel.cs

@ -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)
{}
}
}

33
src/Libraries/NRefactory/NRefactoryASTGenerator/AssemblyInfo.cs

@ -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")]

198
src/Libraries/NRefactory/NRefactoryASTGenerator/Attributes.cs

@ -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);
}
}
}
}

231
src/Libraries/NRefactory/NRefactoryASTGenerator/Main.cs

@ -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);
}
}
}
}

55
src/Libraries/NRefactory/NRefactoryASTGenerator/NRefactoryASTGenerator.csproj

@ -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>

2
src/Libraries/NRefactory/Project/Configuration/AssemblyInfo.cs

@ -19,7 +19,7 @@ using System.Runtime.CompilerServices; @@ -19,7 +19,7 @@ using System.Runtime.CompilerServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ic#code")]
[assembly: AssemblyProduct("SharpDevelop")]
[assembly: AssemblyCopyright("2004-2005 AlphaSierraPapa")]
[assembly: AssemblyCopyright("2004-2006 AlphaSierraPapa")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

109
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -88,98 +88,7 @@ @@ -88,98 +88,7 @@
<Compile Include="Src\Output\VBNet\VBNetPrettyPrintOptions.cs" />
<Compile Include="Src\Parser\AbstractParser.cs" />
<Compile Include="Src\Parser\AST\AbstractNode.cs" />
<Compile Include="Src\Parser\AST\AttributedNode.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\CheckedExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\ConditionalExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\DirectionExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\IndexerExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\PointerReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\SizeOfExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\StackAllocExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\UncheckedExpression.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\CheckedStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\EmptyStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\FixedStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\GotoCaseStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\UncheckedStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\UnsafeStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\UsingStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\Statements\YieldStatement.cs" />
<Compile Include="Src\Parser\AST\CSharp\TypeLevel\DestructorDeclaration.cs" />
<Compile Include="Src\Parser\AST\CSharp\TypeLevel\IndexerDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\AttributeSection.cs" />
<Compile Include="Src\Parser\AST\General\Enums.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ArrayCreateExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ArrayInitializerExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\AssignmentExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\BaseReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\BinaryOperatorExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\CastExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\Expression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\FieldReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\IdentifierExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\InvocationExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ObjectCreateExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ParenthesizedExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\PrimitiveExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\ThisReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\TypeOfExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\TypeReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\General\Expressions\UnaryOperatorExpression.cs" />
<Compile Include="Src\Parser\AST\General\GlobalScope\CompilationUnit.cs" />
<Compile Include="Src\Parser\AST\General\GlobalScope\DelegateDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\GlobalScope\NamespaceDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\GlobalScope\TypeDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\GlobalScope\UsingDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\INullable.cs" />
<Compile Include="Src\Parser\AST\General\Statements\BlockStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\BreakStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\ContinueStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\DoLoopStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\ForeachStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\ForStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\GotoStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\IfElseStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\LabelStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\LocalVariableDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\Statements\LockStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\ReturnStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\Statement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\StatementExpression.cs" />
<Compile Include="Src\Parser\AST\General\Statements\SwitchStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\ThrowStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\TryCatchStatement.cs" />
<Compile Include="Src\Parser\AST\General\Statements\VariableDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\ConstructorDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\ConstructorInitializer.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\EventAddRemoveRegion.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\EventDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\FieldDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\MethodDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\ParameterDeclarationExpression.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\PropertyDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\PropertyGetSetRegion.cs" />
<Compile Include="Src\Parser\AST\General\TypeReference.cs" />
<Compile Include="Src\Parser\AST\INode.cs" />
<Compile Include="Src\Parser\AST\ParametrizedNode.cs" />
<Compile Include="Src\Parser\AST\VBNet\Expressions\AddressOfExpression.cs" />
<Compile Include="Src\Parser\AST\VBNet\Expressions\ClassReferenceExpression.cs" />
<Compile Include="Src\Parser\AST\VBNet\Expressions\TypeOfIsExpression.cs" />
<Compile Include="Src\Parser\AST\VBNet\GlobalScope\OptionDeclaration.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\AddHandlerStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\EndStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\EraseStatements.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\ErrorStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\ExitStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\ForNextStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\OnErrorStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\RaiseEventStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\ReDimStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\RemoveHandlerStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\ResumeStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\StopStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\Statements\WithStatement.cs" />
<Compile Include="Src\Parser\AST\VBNet\TypeLevel\DeclareDeclaration.cs" />
<Compile Include="Src\Parser\CSharp\Parser.cs" />
<Compile Include="Src\Parser\Errors.cs" />
<Compile Include="Src\Parser\IParser.cs" />
@ -190,21 +99,27 @@ @@ -190,21 +99,27 @@
<Compile Include="Src\Parser\Visitors\AbstractASTVisitor.cs" />
<Compile Include="Src\Parser\Visitors\IASTVisitor.cs" />
<Compile Include="Src\Parser\Visitors\LookupTableVisitor.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\AnonymousMethodExpression.cs" />
<Compile Include="Src\Lexer\Special\ISpecial.cs" />
<Compile Include="Src\Output\SpecialNodesInserter.cs" />
<Compile Include="Src\Parser\Visitors\CSharpToVBNetConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\PrefixFieldsVisitor.cs" />
<Compile Include="Src\Parser\Visitors\VBNetToCSharpConvertVisitor.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\OperatorDeclaration.cs" />
<Compile Include="Src\Output\CodeDOM\CodeDOMVerboseOutputGenerator.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\DefaultValueExpression.cs" />
<Compile Include="Src\Parser\AST\General\TypeLevel\InterfaceImplementation.cs" />
<Compile Include="Src\Parser\Visitors\VBNetConstructsConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\CSharpConstructsVisitor.cs" />
<Compile Include="Src\Parser\Visitors\ToCSharpConvertVisitor.cs" />
<Compile Include="Src\Parser\Visitors\ToVBNetConvertVisitor.cs" />
<Compile Include="Src\Output\EnvironmentInformationProvider.cs" />
<Compile Include="Src\Parser\AST\Generated.cs" />
<Compile Include="Src\Parser\AST\Enums.cs" />
<Compile Include="Src\Parser\AST\INullable.cs" />
<Compile Include="Src\Parser\AST\TypeReference.cs" />
<Compile Include="Src\Parser\AST\General\CompilationUnit.cs" />
<Compile Include="Src\Parser\AST\General\Statement.cs" />
<Compile Include="Src\Parser\AST\General\Expression.cs" />
<Compile Include="Src\Parser\AST\General\BlockStatement.cs" />
<Compile Include="Src\Parser\AST\General\LocalVariableDeclaration.cs" />
<Compile Include="Src\Parser\AST\General\PrimitiveExpression.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Src\Lexer\CSharp\KeywordList.txt" />
@ -213,10 +128,6 @@ @@ -213,10 +128,6 @@
<Content Include="Src\Parser\Frames\OldSharpCoco.exe" />
<Content Include="Src\Parser\Frames\SharpCoco.exe" />
<Content Include="Src\Parser\Frames\trace.txt" />
<Folder Include="Src\Parser\AST\CSharp\GlobalScope\" />
<Folder Include="Src\Parser\AST\VBNet\Expressions\Tests\" />
<Folder Include="Src\Parser\AST\VBNet\GlobalScope\Tests\" />
<Folder Include="Src\Parser\AST\VBNet\Tests\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project>

5
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -639,6 +639,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -639,6 +639,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public object Visit(InterfaceImplementation interfaceImplementation, object data)
{
throw new InvalidOperationException();
}
public object Visit(ConstructorDeclaration constructorDeclaration, object data)
{
VisitAttributes(constructorDeclaration.Attributes, data);

2
src/Libraries/NRefactory/Project/Src/Output/IOutputASTVisitor.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -19,7 +19,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
/// <summary>
/// Description of IOutputASTVisitor.
/// </summary>
public interface IOutputASTVisitor : IASTVisitor
public interface IOutputASTVisitor : IAstVisitor
{
string Text {
get;

6
src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs

@ -20,15 +20,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -20,15 +20,15 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public class NodeTracker
{
IASTVisitor callVisitor;
IAstVisitor callVisitor;
public IASTVisitor CallVisitor {
public IAstVisitor CallVisitor {
get {
return callVisitor;
}
}
public NodeTracker(IASTVisitor callVisitor)
public NodeTracker(IAstVisitor callVisitor)
{
this.callVisitor = callVisitor;
}

5
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -837,6 +837,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -837,6 +837,11 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public object Visit(InterfaceImplementation interfaceImplementation, object data)
{
throw new InvalidOperationException();
}
bool IsAbstract(AttributedNode node)
{
if ((node.Modifier & Modifier.Abstract) == Modifier.Abstract)

4
src/Libraries/NRefactory/Project/Src/Parser/AST/AbstractNode.cs

@ -65,9 +65,9 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -65,9 +65,9 @@ namespace ICSharpCode.NRefactory.Parser.AST
children.Add(childNode);
}
public abstract object AcceptVisitor(IASTVisitor visitor, object data);
public abstract object AcceptVisitor(IAstVisitor visitor, object data);
public virtual object AcceptChildren(IASTVisitor visitor, object data)
public virtual object AcceptChildren(IAstVisitor visitor, object data)
{
foreach (INode child in children) {
Debug.Assert(child != null);

50
src/Libraries/NRefactory/Project/Src/Parser/AST/AttributedNode.cs

@ -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;
}
}
}

240
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Enums.cs → src/Libraries/NRefactory/Project/Src/Parser/AST/Enums.cs

@ -116,4 +116,244 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -116,4 +116,244 @@ namespace ICSharpCode.NRefactory.Parser.AST
Params = 8,
Optional = 16
}
public enum AssignmentOperatorType
{
None,
Assign,
Add,
Subtract,
Multiply,
Divide,
Modulus,
Power, // (VB only)
DivideInteger, // (VB only)
ConcatString, // (VB only)
ShiftLeft,
ShiftRight,
BitwiseAnd,
BitwiseOr,
ExclusiveOr,
}
public enum BinaryOperatorType
{
None,
/// <summary>'&amp;' in C#, 'And' in VB.</summary>
BitwiseAnd,
/// <summary>'|' in C#, 'Or' in VB.</summary>
BitwiseOr,
/// <summary>'&amp;&amp;' in C#, 'AndAlso' in VB.</summary>
LogicalAnd,
/// <summary>'||' in C#, 'OrElse' in VB.</summary>
LogicalOr,
/// <summary>'^' in C#, 'Xor' in VB.</summary>
ExclusiveOr,
/// <summary>&gt;</summary>
GreaterThan,
/// <summary>&gt;=</summary>
GreaterThanOrEqual,
/// <summary>'==' in C#, '=' in VB.</summary>
Equality,
/// <summary>'!=' in C#, '&lt;&gt;' in VB.</summary>
InEquality,
/// <summary>&lt;</summary>
LessThan,
/// <summary>&lt;=</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: &amp;</summary>
Concat,
/// <summary>C#: &lt;&lt;</summary>
ShiftLeft,
/// <summary>C#: &gt;&gt;</summary>
ShiftRight,
/// <summary>VB-only: Is</summary>
ReferenceEquality,
/// <summary>VB-only: IsNot</summary>
ReferenceInequality,
/// <summary>VB-only: Like</summary>
Like,
/// <summary>C#: ??</summary>
NullCoalescing,
}
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,
Star,
BitWiseAnd
}
public enum ContinueType
{
None,
Do,
For,
While
}
public enum ConditionType
{
None,
Until,
While,
DoWhile
}
public enum ConditionPosition
{
None,
Start,
End
}
public enum ExitType
{
None,
Sub,
Function,
Property,
Do,
For,
While,
Select,
Try
}
public enum ConstructorInitializerType
{
None,
Base,
This
}
public enum ConversionType
{
None,
Implicit,
Explicit
}
public enum OverloadableOperatorType
{
None,
Add,
Subtract,
Multiply,
Divide,
Modulus,
Concat,
Not,
BitNot,
BitwiseAnd,
BitwiseOr,
ExclusiveOr,
ShiftLeft,
ShiftRight,
GreaterThan,
GreaterThanOrEqual,
Equality,
InEquality,
LessThan,
LessThanOrEqual,
Increment,
Decrement,
True,
False,
// VB specific
IsTrue,
IsFalse,
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
}
}

180
src/Libraries/NRefactory/Project/Src/Parser/AST/General/AttributeSection.cs

@ -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]");
}
}
}

79
src/Libraries/NRefactory/Project/Src/Parser/AST/General/BlockStatement.cs

@ -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]");
}
}
}

56
src/Libraries/NRefactory/Project/Src/Parser/AST/General/CompilationUnit.cs

@ -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]");
}
}
}

111
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Expression.cs

@ -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]");
}
}
}

104
src/Libraries/NRefactory/Project/Src/Parser/AST/General/LocalVariableDeclaration.cs

@ -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));
}
}
}

58
src/Libraries/NRefactory/Project/Src/Parser/AST/General/PrimitiveExpression.cs

@ -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
);
}
}
}

92
src/Libraries/NRefactory/Project/Src/Parser/AST/General/Statement.cs

@ -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]");
}
}
}

4316
src/Libraries/NRefactory/Project/Src/Parser/AST/Generated.cs

File diff suppressed because it is too large Load Diff

4
src/Libraries/NRefactory/Project/Src/Parser/AST/INode.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -38,7 +38,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
/// <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);
object AcceptChildren(IAstVisitor visitor, object data);
/// <summary>
/// Accept the visitor
@ -46,6 +46,6 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -46,6 +46,6 @@ namespace ICSharpCode.NRefactory.Parser.AST
/// <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);
object AcceptVisitor(IAstVisitor visitor, object data);
}
}

0
src/Libraries/NRefactory/Project/Src/Parser/AST/General/INullable.cs → src/Libraries/NRefactory/Project/Src/Parser/AST/INullable.cs

52
src/Libraries/NRefactory/Project/Src/Parser/AST/ParametrizedNode.cs

@ -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;
}
}
}

6
src/Libraries/NRefactory/Project/Src/Parser/AST/General/TypeReference.cs → src/Libraries/NRefactory/Project/Src/Parser/AST/TypeReference.cs

@ -263,7 +263,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -263,7 +263,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
protected TypeReference()
{}
public override object AcceptVisitor(IASTVisitor visitor, object data)
public override object AcceptVisitor(IAstVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
@ -304,7 +304,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -304,7 +304,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
return true;
}
}
public override object AcceptVisitor(IASTVisitor visitor, object data)
public override object AcceptVisitor(IAstVisitor visitor, object data)
{
return data;
}
@ -349,7 +349,7 @@ namespace ICSharpCode.NRefactory.Parser.AST @@ -349,7 +349,7 @@ namespace ICSharpCode.NRefactory.Parser.AST
this.baseType = outerClass;
}
public override object AcceptVisitor(IASTVisitor visitor, object data)
public override object AcceptVisitor(IAstVisitor visitor, object data)
{
return visitor.Visit(this, data);
}

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

@ -2091,7 +2091,7 @@ out stmt); @@ -2091,7 +2091,7 @@ out stmt);
lexer.NextToken();
#line 1239 "cs.ATG"
EventDeclaration eventDecl = new EventDeclaration(m.Modifier, attributes);
EventDeclaration eventDecl = new EventDeclaration(null, null, m.Modifier, attributes, null);
eventDecl.StartLocation = t.Location;
compilationUnit.AddChild(eventDecl);
compilationUnit.BlockStart(eventDecl);
@ -2685,7 +2685,7 @@ out type); @@ -2685,7 +2685,7 @@ out type);
Expect(1);
#line 1514 "cs.ATG"
EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes);
EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null);
compilationUnit.AddChild(ed);
Expect(11);

4
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1236,7 +1236,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1236,7 +1236,7 @@ StructMemberDecl<Modifiers m, List<AttributeSection> attributes>
.)
| /*--- event declaration: */ (. m.Check(Modifier.PropertysEventsMethods); .)
"event" (. EventDeclaration eventDecl = new EventDeclaration(m.Modifier, attributes);
"event" (. EventDeclaration eventDecl = new EventDeclaration(null, null, m.Modifier, attributes, null);
eventDecl.StartLocation = t.Location;
compilationUnit.AddChild(eventDecl);
compilationUnit.BlockStart(eventDecl);
@ -1511,7 +1511,7 @@ InterfaceMemberDecl @@ -1511,7 +1511,7 @@ InterfaceMemberDecl
"{" (. Point bodyStart = t.Location;.) InterfaceAccessors<out getBlock, out setBlock> "}" (. id.GetRegion = getBlock; id.SetRegion = setBlock; id.StartLocation = startLocation; id.EndLocation = bracketEndLocation; id.BodyStart = bodyStart; id.BodyEnd = t.EndLocation;.)
)
/*--- interface event declaration: */
| "event" (. if (startLocation.X == -1) startLocation = t.Location; .) Type<out type> ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes);
| "event" (. if (startLocation.X == -1) startLocation = t.Location; .) Type<out type> ident (. EventDeclaration ed = new EventDeclaration(type, t.val, mod, attributes, null);
compilationUnit.AddChild(ed);
.)
";" (. ed.StartLocation = startLocation; ed.EndLocation = t.EndLocation; .)

1790
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

File diff suppressed because it is too large Load Diff

28
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -878,7 +878,10 @@ InterfaceMemberDecl @@ -878,7 +878,10 @@ InterfaceMemberDecl
type = new TypeReference("System.Object");
}
MethodDeclaration md = new MethodDeclaration(name, mod.Modifier, type, p, attributes);
md.ReturnTypeAttributeSection = returnTypeAttributeSection;
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
md.Attributes.Add(returnTypeAttributeSection);
}
md.EndLocation = t.EndLocation;
md.Templates = templates;
compilationUnit.AddChild(md);
@ -957,7 +960,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -957,7 +960,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
(
(.
string name = String.Empty;
MethodDeclaration methodDeclaration; ArrayList handlesClause = null;
MethodDeclaration methodDeclaration; List<string> handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
.)
Identifier
@ -1035,7 +1038,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1035,7 +1038,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
m.Check(Modifier.VBMethods);
string name = String.Empty;
Point startPos = t.Location;
MethodDeclaration methodDeclaration;ArrayList handlesClause = null;
MethodDeclaration methodDeclaration;List<string> handlesClause = null;
List<InterfaceImplementation> implementsClause = null;
AttributeSection returnTypeAttributeSection = null;
.)
@ -1067,7 +1070,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1067,7 +1070,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.Templates = templates;
methodDeclaration.InterfaceImplementations = implementsClause;
methodDeclaration.ReturnTypeAttributeSection = returnTypeAttributeSection;
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
.)
|
@ -1079,7 +1085,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1079,7 +1085,10 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
methodDeclaration.Templates = templates;
methodDeclaration.HandlesClause = handlesClause;
methodDeclaration.InterfaceImplementations = implementsClause;
methodDeclaration.ReturnTypeAttributeSection = returnTypeAttributeSection;
if (returnTypeAttributeSection != null) {
returnTypeAttributeSection.AttributeTarget = "return";
methodDeclaration.Attributes.Add(returnTypeAttributeSection);
}
compilationUnit.AddChild(methodDeclaration);
compilationUnit.BlockStart(methodDeclaration);
@ -1293,7 +1302,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1293,7 +1302,7 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
Error("Need to provide RaiseEvent accessor.");
}
EventDeclaration decl = new EventDeclaration(type, customEventName, m.Modifier, attributes);
EventDeclaration decl = new EventDeclaration(type, customEventName, m.Modifier, attributes, null);
decl.StartLocation = m.GetDeclarationLocation(startPos);
decl.EndLocation = t.EndLocation;
decl.AddRegion = addHandlerAccessorDeclaration;
@ -1336,7 +1345,6 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes> @@ -1336,7 +1345,6 @@ StructureMemberDecl<Modifiers m, List<AttributeSection> attributes>
returnType,
operatorType
);
operatorDeclaration.ConvertToType = returnType;
operatorDeclaration.ReturnTypeAttributes = returnTypeAttributes;
operatorDeclaration.Body = (BlockStatement)stmt;
operatorDeclaration.StartLocation = m.GetDeclarationLocation(startPos);
@ -1637,9 +1645,9 @@ Charset<out CharsetModifier charsetModifier> @@ -1637,9 +1645,9 @@ Charset<out CharsetModifier charsetModifier>
.
/* 9.2.6 */
HandlesClause<out ArrayList handlesClause>
HandlesClause<out List<string> handlesClause>
(.
handlesClause = new ArrayList();
handlesClause = new List<string>();
string name;
.) =
"Handles" EventMemberSpecifier<out name> (. handlesClause.Add(name); .)
@ -2536,7 +2544,7 @@ EmbeddedStatement<out Statement statement> @@ -2536,7 +2544,7 @@ EmbeddedStatement<out Statement statement>
| /* 10.12.2 */
"Erase"
Expr<out expr>
(.ArrayList arrays = new ArrayList();
(.List<Expression> arrays = new List<Expression>();
if (expr != null) { arrays.Add(expr);}
EraseStatement eraseStatement = new EraseStatement(arrays);

7
src/Libraries/NRefactory/Project/Src/Parser/Visitors/AbstractASTVisitor.cs

@ -12,7 +12,7 @@ using ICSharpCode.NRefactory.Parser.AST; @@ -12,7 +12,7 @@ using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.Parser
{
public abstract class AbstractASTVisitor : IASTVisitor
public abstract class AbstractASTVisitor : IAstVisitor
{
protected Stack blockStack = new Stack();
@ -25,6 +25,11 @@ namespace ICSharpCode.NRefactory.Parser @@ -25,6 +25,11 @@ namespace ICSharpCode.NRefactory.Parser
}
}
public virtual object Visit(InterfaceImplementation interfaceImplementation, object data)
{
return interfaceImplementation.InterfaceType.AcceptChildren(this, data);
}
public virtual object Visit(INode node, object data)
{
Console.WriteLine("Warning, INode visited!");

4
src/Libraries/NRefactory/Project/Src/Parser/Visitors/IASTVisitor.cs

@ -10,11 +10,13 @@ using ICSharpCode.NRefactory.Parser.AST; @@ -10,11 +10,13 @@ using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.Parser
{
public interface IASTVisitor
public interface IAstVisitor
{
[Obsolete("Warning: you are visiting INode")]
object Visit(INode node, object data);
object Visit(InterfaceImplementation interfaceImplementation, object data);
object Visit(CompilationUnit compilationUnit, object data);
object Visit(TypeReference typeReference, object data);
object Visit(InnerClassTypeReference innerClassTypeReference, object data);

10
src/Libraries/NRefactory/Test/AssemblyInfo.cs

@ -14,12 +14,12 @@ using System.Runtime.CompilerServices; @@ -14,12 +14,12 @@ using System.Runtime.CompilerServices;
// change them to the information which is associated with the assembly
// you compile.
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("NRefactory Test")]
[assembly: AssemblyDescription("Unit tests for the parser and refactoring library for C# and VB.NET")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyCompany("ic#code")]
[assembly: AssemblyProduct("SharpDevelop")]
[assembly: AssemblyCopyright("2004-2006 AlphaSierraPapa")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

4
src/Libraries/NRefactory/Test/General/UnitTest.cs

@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Tests @@ -46,7 +46,7 @@ namespace ICSharpCode.NRefactory.Tests
public void TestIASTVisitor()
{
Type[] allTypes = typeof(AbstractNode).Assembly.GetTypes();
Type visitor = typeof(IASTVisitor);
Type visitor = typeof(IAstVisitor);
foreach (Type type in allTypes) {
if (type.IsClass && !type.IsAbstract && type.GetInterface(typeof(INode).FullName) != null && !type.Name.StartsWith("Null")) {
@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Tests @@ -93,7 +93,7 @@ namespace ICSharpCode.NRefactory.Tests
if (!type.IsInterface &&
!type.IsEnum &&
(type.BaseType == typeof(System.Delegate)) &&
(type.GetInterface(typeof(IASTVisitor).FullName) == null) &&
(type.GetInterface(typeof(IAstVisitor).FullName) == null) &&
(type.FullName != "ICSharpCode.NRefactory.Parser.Error") &&
(type.FullName != "ICSharpCode.NRefactory.Tests.StructuralTest")) {
Assert.IsNotNull(type.GetInterface(typeof(INode).FullName), type.FullName + " is not INode");

4
src/Libraries/NRefactory/Test/Parser/Statements/YieldStatementTests.cs

@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -20,7 +20,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
public void YieldReturnStatementTest()
{
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield return \"Foo\";");
Assert.IsTrue(yieldStmt.IsYieldReturn());
Assert.IsTrue(yieldStmt.IsYieldReturn);
ReturnStatement retStmt = (ReturnStatement)yieldStmt.Statement;
PrimitiveExpression expr = (PrimitiveExpression)retStmt.Expression;
Assert.AreEqual("Foo", expr.Value);
@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -30,7 +30,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
public void YieldBreakStatementTest()
{
YieldStatement yieldStmt = ParseUtilCSharp.ParseStatement<YieldStatement>("yield break;");
Assert.IsTrue(yieldStmt.IsYieldBreak());
Assert.IsTrue(yieldStmt.IsYieldBreak);
}
[Test]

6
src/Libraries/NRefactory/Test/Parser/TypeLevel/OperatorDeclarationTests.cs

@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -27,7 +27,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsTrue(od.IsConversionOperator);
Assert.AreEqual(1, od.Parameters.Count);
Assert.AreEqual(ConversionType.Implicit, od.ConversionType);
Assert.AreEqual("double", od.ConvertToType.Type);
Assert.AreEqual("double", od.TypeReference.Type);
}
[Test]
@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -37,7 +37,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsTrue(od.IsConversionOperator);
Assert.AreEqual(1, od.Parameters.Count);
Assert.AreEqual(ConversionType.Explicit, od.ConversionType);
Assert.AreEqual("double", od.ConvertToType.Type);
Assert.AreEqual("double", od.TypeReference.Type);
}
[Test]
@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.Tests.AST @@ -63,7 +63,7 @@ namespace ICSharpCode.NRefactory.Tests.AST
Assert.IsFalse(od.IsConversionOperator);
Assert.AreEqual(1, od.Parameters.Count);
Assert.AreEqual(ConversionType.None, od.ConversionType);
Assert.AreEqual("Complex", od.ConvertToType.Type);
Assert.AreEqual("Complex", od.TypeReference.Type);
}
#endregion
}

2
src/Main/Base/Project/Src/Dom/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -440,7 +440,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -440,7 +440,7 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
DomRegion region = GetRegion(operatorDeclaration.StartLocation, operatorDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(operatorDeclaration.EndLocation, operatorDeclaration.Body != null ? operatorDeclaration.Body.EndLocation : new Point(-1, -1));
DefaultMethod method = new DefaultMethod(operatorDeclaration.Name, CreateReturnType(operatorDeclaration.ConvertToType), ConvertModifier(operatorDeclaration.Modifier), region, bodyRegion, c);
DefaultMethod method = new DefaultMethod(operatorDeclaration.Name, CreateReturnType(operatorDeclaration.TypeReference), ConvertModifier(operatorDeclaration.Modifier), region, bodyRegion, c);
ConvertAttributes(operatorDeclaration, method);
if(operatorDeclaration.Parameters != null)
{

7
src/Main/Base/Project/Src/Services/RefactoringService/CodeGenerator.cs

@ -104,7 +104,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -104,7 +104,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
public static List<AttributeSection> ConvertAttributes(IList<IAttribute> attributes, ClassFinder targetContext)
{
AttributeSection sec = new AttributeSection();
AttributeSection sec = new AttributeSection(null, null);
foreach (IAttribute att in attributes) {
sec.Attributes.Add(new ICSharpCode.NRefactory.Parser.AST.Attribute(att.Name, null, null));
}
@ -204,7 +204,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -204,7 +204,8 @@ namespace ICSharpCode.SharpDevelop.Refactoring
return new EventDeclaration(ConvertType(e.ReturnType, targetContext),
e.Name,
ConvertModifier(e.Modifiers),
ConvertAttributes(e.Attributes, targetContext));
ConvertAttributes(e.Attributes, targetContext),
null);
}
#endregion
@ -324,7 +325,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring @@ -324,7 +325,7 @@ namespace ICSharpCode.SharpDevelop.Refactoring
string name = property.Name + "Changed";
EventDeclaration ed = new EventDeclaration(new TypeReference("EventHandler"), name,
ConvertModifier(property.Modifiers & (ModifierEnum.VisibilityMask | ModifierEnum.Static))
, null);
, null, null);
InsertCodeAfter(property, document, ed);
List<Expression> arguments = new List<Expression>(2);

2
src/Main/Base/Project/Src/TextEditor/Commands/CodeGenerators/EqualsCodeGenerator.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands @@ -56,7 +56,7 @@ namespace ICSharpCode.SharpDevelop.DefaultEditor.Commands
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));
VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
new CastExpression(currentType, new IdentifierExpression("obj")),
new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
currentType);
method.Body.AddChild(new LocalVariableDeclaration(var));

Loading…
Cancel
Save