Skip to content

Commit

Permalink
Merge NRefactory 858d4cc6 into ILSpy master.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrunwald committed Dec 9, 2011
2 parents 49c92cf + 8f45b7e commit 09c2b45
Show file tree
Hide file tree
Showing 93 changed files with 5,878 additions and 4,232 deletions.
2 changes: 1 addition & 1 deletion ICSharpCode.Decompiler/Ast/AstBuilder.cs
Expand Up @@ -797,7 +797,7 @@ IEnumerable<Constraint> MakeConstraints(IEnumerable<GenericParameter> genericPar
{
foreach (var gp in genericParameters) {
Constraint c = new Constraint();
c.TypeParameter = CleanName(gp.Name);
c.TypeParameter = new SimpleType(CleanName(gp.Name));
// class/struct must be first
if (gp.HasReferenceTypeConstraint)
c.BaseTypes.Add(new PrimitiveType("class"));
Expand Down
21 changes: 18 additions & 3 deletions ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
Expand Up @@ -147,7 +147,7 @@ object GetCurrentDefinition()
if (nodeStack == null || nodeStack.Count == 0)
return null;

var node = nodeStack.Peek();
var node = nodeStack.Peek();
if (IsDefinition(node))
return node.Annotation<MemberReference>();

Expand Down Expand Up @@ -246,7 +246,22 @@ public void WriteComment(CommentType commentType, string content)
}
output.WriteLine();
break;
default:
output.Write(content);
break;
}
}

public void WritePreProcessorDirective(PreProcessorDirectiveType type, string argument)
{
// pre-processor directive must start on its own line
output.Write('#');
output.Write(type.ToString().ToLowerInvariant());
if (!string.IsNullOrEmpty(argument)) {
output.Write(' ');
output.Write(argument);
}
output.WriteLine();
}

Stack<TextLocation> startLocations = new Stack<TextLocation>();
Expand Down Expand Up @@ -312,10 +327,10 @@ public void EndNode(AstNode node)

private static bool IsDefinition(AstNode node)
{
return
return
node is FieldDeclaration ||
node is ConstructorDeclaration ||
node is DestructorDeclaration ||
node is DestructorDeclaration ||
node is EventDeclaration ||
node is DelegateDeclaration ||
node is OperatorDeclaration||
Expand Down
Expand Up @@ -436,7 +436,7 @@ public override ControlFlowNode VisitSwitchStatement(SwitchStatement switchState
}
}
}
if (constant.IsCompileTimeConstant && sectionMatchedByConstant == null)
if (constant != null && constant.IsCompileTimeConstant && sectionMatchedByConstant == null)
sectionMatchedByConstant = defaultSection;

int gotoCaseOrDefaultInOuterScope = gotoCaseOrDefault.Count;
Expand Down
Expand Up @@ -27,16 +27,43 @@

namespace ICSharpCode.NRefactory.CSharp
{
public class ErrorExpression : EmptyExpression
public class ErrorExpression : Expression
{
TextLocation location;

public override TextLocation StartLocation {
get {
return location;
}
}

public override TextLocation EndLocation {
get {
return location;
}
}

public ErrorExpression ()
{
}

public ErrorExpression (TextLocation location) : base (location)
public ErrorExpression (TextLocation location)
{
this.location = location;
}


public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
{
// nothing
return default(S);
}

protected internal override bool DoMatch (AstNode other, PatternMatching.Match match)
{
var o = other as ErrorExpression;
return o != null;
}
}
}

Expand Up @@ -38,19 +38,20 @@ public class Constraint : AstNode
{
public readonly static Role<CSharpTokenNode> ColonRole = TypeDeclaration.ColonRole;
public readonly static Role<AstType> BaseTypeRole = TypeDeclaration.BaseTypeRole;
public readonly static Role<SimpleType> TypeParameterRole = new Role<SimpleType> ("TypeParameter", SimpleType.Null);

public override NodeType NodeType {
get {
return NodeType.Unknown;
}
}

public string TypeParameter {
public SimpleType TypeParameter {
get {
return GetChildByRole (Roles.Identifier).Name;
return GetChildByRole (TypeParameterRole);
}
set {
SetChildByRole(Roles.Identifier, Identifier.Create (value, TextLocation.Empty));
SetChildByRole(TypeParameterRole, value);
}
}

Expand All @@ -66,7 +67,7 @@ public class Constraint : AstNode
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Constraint o = other as Constraint;
return o != null && MatchString(this.TypeParameter, o.TypeParameter) && this.BaseTypes.DoMatch(o.BaseTypes, match);
return o != null && this.TypeParameter.DoMatch (o.TypeParameter, match) && this.BaseTypes.DoMatch(o.BaseTypes, match);
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions NRefactory/ICSharpCode.NRefactory.CSharp/Ast/SimpleType.cs
Expand Up @@ -33,6 +33,29 @@ namespace ICSharpCode.NRefactory.CSharp
{
public class SimpleType : AstType
{
#region Null
public new static readonly SimpleType Null = new NullSimpleType ();

sealed class NullSimpleType : SimpleType
{
public override bool IsNull {
get {
return true;
}
}

public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data = default(T))
{
return default (S);
}

protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
return other == null || other.IsNull;
}
}
#endregion

public SimpleType()
{
}
Expand All @@ -42,6 +65,11 @@ public SimpleType(string identifier)
this.Identifier = identifier;
}

public SimpleType (Identifier identifier)
{
this.IdentifierToken = identifier;
}

public SimpleType(string identifier, TextLocation location)
{
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (identifier, location));
Expand Down
13 changes: 12 additions & 1 deletion NRefactory/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
Expand Up @@ -139,7 +139,18 @@ public IProjectContent UpdateProjectContent(IParsedFile oldFile, IParsedFile new

public IProjectContent UpdateProjectContent(IEnumerable<IParsedFile> oldFiles, IEnumerable<IParsedFile> newFiles)
{
throw new NotImplementedException();
CSharpProjectContent pc = new CSharpProjectContent(this);
if (oldFiles != null) {
foreach (var oldFile in oldFiles) {
pc.parsedFiles.Remove(oldFile.FileName);
}
}
if (newFiles != null) {
foreach (var newFile in newFiles) {
pc.parsedFiles.Add(newFile.FileName, newFile);
}
}
return pc;
}

IAssembly IAssemblyReference.Resolve(ITypeResolveContext context)
Expand Down

0 comments on commit 09c2b45

Please sign in to comment.