mirror of https://github.com/icsharpcode/ILSpy.git
177 changed files with 40367 additions and 26 deletions
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Annotations.cs
|
||||
//
|
||||
// Author:
|
||||
// Luís Reis <luiscubal@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2013 Luís Reis
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public static class AnnotationNames |
||||
{ |
||||
//Used const instead of readonly to allow values to be used in switch cases.
|
||||
|
||||
public const string AssertionMethodAttribute = "JetBrains.Annotations.AssertionMethodAttribute"; |
||||
public const string AssertionConditionAttribute = "JetBrains.Annotations.AssertionConditionAttribute"; |
||||
public const string AssertionConditionTypeAttribute = "JetBrains.Annotations.AssertionConditionType"; |
||||
|
||||
public const string AssertionConditionTypeIsTrue = "JetBrains.Annotations.AssertionConditionType.IS_TRUE"; |
||||
public const string AssertionConditionTypeIsFalse = "JetBrains.Annotations.AssertionConditionType.IS_FALSE"; |
||||
public const string AssertionConditionTypeIsNull = "JetBrains.Annotations.AssertionConditionType.IS_NULL"; |
||||
public const string AssertionConditionTypeIsNotNull = "JetBrains.Annotations.AssertionConditionType.IS_NOT_NULL"; |
||||
|
||||
public const string NotNullAttribute = "JetBrains.Annotations.NotNullAttribute"; |
||||
public const string CanBeNullAttribute = "JetBrains.Annotations.CanBeNullAttribute"; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,786 @@
@@ -0,0 +1,786 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||
using ICSharpCode.NRefactory.Semantics; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
using ICSharpCode.NRefactory.Utils; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Analysis |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a node in the control flow graph of a C# method.
|
||||
/// </summary>
|
||||
public class ControlFlowNode |
||||
{ |
||||
public readonly Statement PreviousStatement; |
||||
public readonly Statement NextStatement; |
||||
|
||||
public readonly ControlFlowNodeType Type; |
||||
|
||||
public readonly List<ControlFlowEdge> Outgoing = new List<ControlFlowEdge>(); |
||||
public readonly List<ControlFlowEdge> Incoming = new List<ControlFlowEdge>(); |
||||
|
||||
public ControlFlowNode(Statement previousStatement, Statement nextStatement, ControlFlowNodeType type) |
||||
{ |
||||
if (previousStatement == null && nextStatement == null) |
||||
throw new ArgumentException("previousStatement and nextStatement must not be both null"); |
||||
this.PreviousStatement = previousStatement; |
||||
this.NextStatement = nextStatement; |
||||
this.Type = type; |
||||
} |
||||
} |
||||
|
||||
public enum ControlFlowNodeType |
||||
{ |
||||
/// <summary>
|
||||
/// Unknown node type
|
||||
/// </summary>
|
||||
None, |
||||
/// <summary>
|
||||
/// Node in front of a statement
|
||||
/// </summary>
|
||||
StartNode, |
||||
/// <summary>
|
||||
/// Node between two statements
|
||||
/// </summary>
|
||||
BetweenStatements, |
||||
/// <summary>
|
||||
/// Node at the end of a statement list
|
||||
/// </summary>
|
||||
EndNode, |
||||
/// <summary>
|
||||
/// Node representing the position before evaluating the condition of a loop.
|
||||
/// </summary>
|
||||
LoopCondition |
||||
} |
||||
|
||||
public class ControlFlowEdge |
||||
{ |
||||
public readonly ControlFlowNode From; |
||||
public readonly ControlFlowNode To; |
||||
public readonly ControlFlowEdgeType Type; |
||||
|
||||
List<TryCatchStatement> jumpOutOfTryFinally; |
||||
|
||||
public ControlFlowEdge(ControlFlowNode from, ControlFlowNode to, ControlFlowEdgeType type) |
||||
{ |
||||
if (from == null) |
||||
throw new ArgumentNullException("from"); |
||||
if (to == null) |
||||
throw new ArgumentNullException("to"); |
||||
this.From = from; |
||||
this.To = to; |
||||
this.Type = type; |
||||
} |
||||
|
||||
internal void AddJumpOutOfTryFinally(TryCatchStatement tryFinally) |
||||
{ |
||||
if (jumpOutOfTryFinally == null) |
||||
jumpOutOfTryFinally = new List<TryCatchStatement>(); |
||||
jumpOutOfTryFinally.Add(tryFinally); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets whether this control flow edge is leaving any try-finally statements.
|
||||
/// </summary>
|
||||
public bool IsLeavingTryFinally { |
||||
get { return jumpOutOfTryFinally != null; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the try-finally statements that this control flow edge is leaving.
|
||||
/// </summary>
|
||||
public IEnumerable<TryCatchStatement> TryFinallyStatements { |
||||
get { return jumpOutOfTryFinally ?? Enumerable.Empty<TryCatchStatement>(); } |
||||
} |
||||
} |
||||
|
||||
public enum ControlFlowEdgeType |
||||
{ |
||||
/// <summary>
|
||||
/// Regular control flow.
|
||||
/// </summary>
|
||||
Normal, |
||||
/// <summary>
|
||||
/// Conditional control flow (edge taken if condition is true)
|
||||
/// </summary>
|
||||
ConditionTrue, |
||||
/// <summary>
|
||||
/// Conditional control flow (edge taken if condition is false)
|
||||
/// </summary>
|
||||
ConditionFalse, |
||||
/// <summary>
|
||||
/// A jump statement (goto, goto case, break or continue)
|
||||
/// </summary>
|
||||
Jump |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructs the control flow graph for C# statements.
|
||||
/// </summary>
|
||||
public class ControlFlowGraphBuilder |
||||
{ |
||||
// Written according to the reachability rules in the C# spec (§8.1 End points and reachability)
|
||||
|
||||
protected virtual ControlFlowNode CreateNode(Statement previousStatement, Statement nextStatement, ControlFlowNodeType type) |
||||
{ |
||||
cancellationToken.ThrowIfCancellationRequested(); |
||||
return new ControlFlowNode(previousStatement, nextStatement, type); |
||||
} |
||||
|
||||
protected virtual ControlFlowEdge CreateEdge(ControlFlowNode from, ControlFlowNode to, ControlFlowEdgeType type) |
||||
{ |
||||
cancellationToken.ThrowIfCancellationRequested(); |
||||
return new ControlFlowEdge(from, to, type); |
||||
} |
||||
|
||||
Statement rootStatement; |
||||
CSharpTypeResolveContext typeResolveContext; |
||||
Func<AstNode, CancellationToken, ResolveResult> resolver; |
||||
List<ControlFlowNode> nodes; |
||||
Dictionary<string, ControlFlowNode> labels; |
||||
List<ControlFlowNode> gotoStatements; |
||||
CancellationToken cancellationToken; |
||||
|
||||
internal IList<ControlFlowNode> BuildControlFlowGraph(Statement statement, Func<AstNode, CancellationToken, ResolveResult> resolver, CSharpTypeResolveContext typeResolveContext, CancellationToken cancellationToken) |
||||
{ |
||||
NodeCreationVisitor nodeCreationVisitor = new NodeCreationVisitor(); |
||||
nodeCreationVisitor.builder = this; |
||||
try { |
||||
this.nodes = new List<ControlFlowNode>(); |
||||
this.labels = new Dictionary<string, ControlFlowNode>(); |
||||
this.gotoStatements = new List<ControlFlowNode>(); |
||||
this.rootStatement = statement; |
||||
this.resolver = resolver; |
||||
this.typeResolveContext = typeResolveContext; |
||||
this.cancellationToken = cancellationToken; |
||||
|
||||
ControlFlowNode entryPoint = CreateStartNode(statement); |
||||
statement.AcceptVisitor(nodeCreationVisitor, entryPoint); |
||||
|
||||
// Resolve goto statements:
|
||||
foreach (ControlFlowNode gotoStmt in gotoStatements) { |
||||
string label = ((GotoStatement)gotoStmt.NextStatement).Label; |
||||
ControlFlowNode labelNode; |
||||
if (labels.TryGetValue(label, out labelNode)) |
||||
nodeCreationVisitor.Connect(gotoStmt, labelNode, ControlFlowEdgeType.Jump); |
||||
} |
||||
|
||||
AnnotateLeaveEdgesWithTryFinallyBlocks(); |
||||
|
||||
return nodes; |
||||
} finally { |
||||
this.nodes = null; |
||||
this.labels = null; |
||||
this.gotoStatements = null; |
||||
this.rootStatement = null; |
||||
this.resolver = null; |
||||
this.typeResolveContext = null; |
||||
this.cancellationToken = CancellationToken.None; |
||||
} |
||||
} |
||||
|
||||
void AnnotateLeaveEdgesWithTryFinallyBlocks() |
||||
{ |
||||
foreach (ControlFlowEdge edge in nodes.SelectMany(n => n.Outgoing)) { |
||||
if (edge.Type != ControlFlowEdgeType.Jump) { |
||||
// Only jumps are potential candidates for leaving try-finally blocks.
|
||||
// Note that the regular edges leaving try or catch blocks are already annotated by the visitor.
|
||||
continue; |
||||
} |
||||
Statement gotoStatement = edge.From.NextStatement; |
||||
Debug.Assert(gotoStatement is GotoStatement || gotoStatement is GotoDefaultStatement || gotoStatement is GotoCaseStatement || gotoStatement is BreakStatement || gotoStatement is ContinueStatement); |
||||
Statement targetStatement = edge.To.PreviousStatement ?? edge.To.NextStatement; |
||||
if (gotoStatement.Parent == targetStatement.Parent) |
||||
continue; |
||||
HashSet<TryCatchStatement> targetParentTryCatch = new HashSet<TryCatchStatement>(targetStatement.Ancestors.OfType<TryCatchStatement>()); |
||||
for (AstNode node = gotoStatement.Parent; node != null; node = node.Parent) { |
||||
TryCatchStatement leftTryCatch = node as TryCatchStatement; |
||||
if (leftTryCatch != null) { |
||||
if (targetParentTryCatch.Contains(leftTryCatch)) |
||||
break; |
||||
if (!leftTryCatch.FinallyBlock.IsNull) |
||||
edge.AddJumpOutOfTryFinally(leftTryCatch); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
#region Create*Node
|
||||
ControlFlowNode CreateStartNode(Statement statement) |
||||
{ |
||||
if (statement.IsNull) |
||||
return null; |
||||
ControlFlowNode node = CreateNode(null, statement, ControlFlowNodeType.StartNode); |
||||
nodes.Add(node); |
||||
return node; |
||||
} |
||||
|
||||
ControlFlowNode CreateSpecialNode(Statement statement, ControlFlowNodeType type, bool addToNodeList = true) |
||||
{ |
||||
ControlFlowNode node = CreateNode(null, statement, type); |
||||
if (addToNodeList) |
||||
nodes.Add(node); |
||||
return node; |
||||
} |
||||
|
||||
ControlFlowNode CreateEndNode(Statement statement, bool addToNodeList = true) |
||||
{ |
||||
Statement nextStatement; |
||||
if (statement == rootStatement) { |
||||
nextStatement = null; |
||||
} else { |
||||
// Find the next statement in the same role:
|
||||
AstNode next = statement; |
||||
do { |
||||
next = next.NextSibling; |
||||
} while (next != null && next.Role != statement.Role); |
||||
nextStatement = next as Statement; |
||||
} |
||||
ControlFlowNodeType type = nextStatement != null ? ControlFlowNodeType.BetweenStatements : ControlFlowNodeType.EndNode; |
||||
ControlFlowNode node = CreateNode(statement, nextStatement, type); |
||||
if (addToNodeList) |
||||
nodes.Add(node); |
||||
return node; |
||||
} |
||||
#endregion
|
||||
|
||||
#region Constant evaluation
|
||||
/// <summary>
|
||||
/// Gets/Sets whether to handle only primitive expressions as constants (no complex expressions like "a + b").
|
||||
/// </summary>
|
||||
public bool EvaluateOnlyPrimitiveConstants { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Evaluates an expression.
|
||||
/// </summary>
|
||||
/// <returns>The constant value of the expression; or null if the expression is not a constant.</returns>
|
||||
ResolveResult EvaluateConstant(Expression expr) |
||||
{ |
||||
if (expr.IsNull) |
||||
return null; |
||||
if (EvaluateOnlyPrimitiveConstants) { |
||||
if (!(expr is PrimitiveExpression || expr is NullReferenceExpression)) |
||||
return null; |
||||
} |
||||
return resolver(expr, cancellationToken); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Evaluates an expression.
|
||||
/// </summary>
|
||||
/// <returns>The value of the constant boolean expression; or null if the value is not a constant boolean expression.</returns>
|
||||
bool? EvaluateCondition(Expression expr) |
||||
{ |
||||
ResolveResult rr = EvaluateConstant(expr); |
||||
if (rr != null && rr.IsCompileTimeConstant) |
||||
return rr.ConstantValue as bool?; |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
bool AreEqualConstants(ResolveResult c1, ResolveResult c2) |
||||
{ |
||||
if (c1 == null || c2 == null || !c1.IsCompileTimeConstant || !c2.IsCompileTimeConstant) |
||||
return false; |
||||
CSharpResolver r = new CSharpResolver(typeResolveContext); |
||||
ResolveResult c = r.ResolveBinaryOperator(BinaryOperatorType.Equality, c1, c2); |
||||
return c.IsCompileTimeConstant && (c.ConstantValue as bool?) == true; |
||||
} |
||||
#endregion
|
||||
|
||||
sealed class NodeCreationVisitor : DepthFirstAstVisitor<ControlFlowNode, ControlFlowNode> |
||||
{ |
||||
// 'data' parameter: input control flow node (start of statement being visited)
|
||||
// Return value: result control flow node (end of statement being visited)
|
||||
|
||||
internal ControlFlowGraphBuilder builder; |
||||
Stack<ControlFlowNode> breakTargets = new Stack<ControlFlowNode>(); |
||||
Stack<ControlFlowNode> continueTargets = new Stack<ControlFlowNode>(); |
||||
List<ControlFlowNode> gotoCaseOrDefault = new List<ControlFlowNode>(); |
||||
|
||||
internal ControlFlowEdge Connect(ControlFlowNode from, ControlFlowNode to, ControlFlowEdgeType type = ControlFlowEdgeType.Normal) |
||||
{ |
||||
if (from == null || to == null) |
||||
return null; |
||||
ControlFlowEdge edge = builder.CreateEdge(from, to, type); |
||||
from.Outgoing.Add(edge); |
||||
to.Incoming.Add(edge); |
||||
return edge; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an end node for <c>stmt</c> and connects <c>from</c> with the new node.
|
||||
/// </summary>
|
||||
ControlFlowNode CreateConnectedEndNode(Statement stmt, ControlFlowNode from) |
||||
{ |
||||
ControlFlowNode newNode = builder.CreateEndNode(stmt); |
||||
Connect(from, newNode); |
||||
return newNode; |
||||
} |
||||
|
||||
protected override ControlFlowNode VisitChildren(AstNode node, ControlFlowNode data) |
||||
{ |
||||
// We have overrides for all possible statements and should visit statements only.
|
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitBlockStatement(BlockStatement blockStatement, ControlFlowNode data) |
||||
{ |
||||
// C# 4.0 spec: §8.2 Blocks
|
||||
ControlFlowNode childNode = HandleStatementList(blockStatement.Statements, data); |
||||
return CreateConnectedEndNode(blockStatement, childNode); |
||||
} |
||||
|
||||
ControlFlowNode HandleStatementList(AstNodeCollection<Statement> statements, ControlFlowNode source) |
||||
{ |
||||
ControlFlowNode childNode = null; |
||||
foreach (Statement stmt in statements) { |
||||
if (childNode == null) { |
||||
childNode = builder.CreateStartNode(stmt); |
||||
if (source != null) |
||||
Connect(source, childNode); |
||||
} |
||||
Debug.Assert(childNode.NextStatement == stmt); |
||||
childNode = stmt.AcceptVisitor(this, childNode); |
||||
Debug.Assert(childNode.PreviousStatement == stmt); |
||||
} |
||||
return childNode ?? source; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitEmptyStatement(EmptyStatement emptyStatement, ControlFlowNode data) |
||||
{ |
||||
return CreateConnectedEndNode(emptyStatement, data); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitLabelStatement(LabelStatement labelStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode end = CreateConnectedEndNode(labelStatement, data); |
||||
builder.labels[labelStatement.Label] = end; |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, ControlFlowNode data) |
||||
{ |
||||
return CreateConnectedEndNode(variableDeclarationStatement, data); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitExpressionStatement(ExpressionStatement expressionStatement, ControlFlowNode data) |
||||
{ |
||||
return CreateConnectedEndNode(expressionStatement, data); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitIfElseStatement(IfElseStatement ifElseStatement, ControlFlowNode data) |
||||
{ |
||||
bool? cond = builder.EvaluateCondition(ifElseStatement.Condition); |
||||
|
||||
ControlFlowNode trueBegin = builder.CreateStartNode(ifElseStatement.TrueStatement); |
||||
if (cond != false) |
||||
Connect(data, trueBegin, ControlFlowEdgeType.ConditionTrue); |
||||
ControlFlowNode trueEnd = ifElseStatement.TrueStatement.AcceptVisitor(this, trueBegin); |
||||
|
||||
ControlFlowNode falseBegin = builder.CreateStartNode(ifElseStatement.FalseStatement); |
||||
if (cond != true) |
||||
Connect(data, falseBegin, ControlFlowEdgeType.ConditionFalse); |
||||
ControlFlowNode falseEnd = ifElseStatement.FalseStatement.AcceptVisitor(this, falseBegin); |
||||
// (if no else statement exists, both falseBegin and falseEnd will be null)
|
||||
|
||||
ControlFlowNode end = builder.CreateEndNode(ifElseStatement); |
||||
Connect(trueEnd, end); |
||||
if (falseEnd != null) { |
||||
Connect(falseEnd, end); |
||||
} else if (cond != true) { |
||||
Connect(data, end, ControlFlowEdgeType.ConditionFalse); |
||||
} |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitSwitchStatement(SwitchStatement switchStatement, ControlFlowNode data) |
||||
{ |
||||
// First, figure out which switch section will get called (if the expression is constant):
|
||||
ResolveResult constant = builder.EvaluateConstant(switchStatement.Expression); |
||||
SwitchSection defaultSection = null; |
||||
SwitchSection sectionMatchedByConstant = null; |
||||
foreach (SwitchSection section in switchStatement.SwitchSections) { |
||||
foreach (CaseLabel label in section.CaseLabels) { |
||||
if (label.Expression.IsNull) { |
||||
defaultSection = section; |
||||
} else if (constant != null && constant.IsCompileTimeConstant) { |
||||
ResolveResult labelConstant = builder.EvaluateConstant(label.Expression); |
||||
if (builder.AreEqualConstants(constant, labelConstant)) |
||||
sectionMatchedByConstant = section; |
||||
} |
||||
} |
||||
} |
||||
if (constant != null && constant.IsCompileTimeConstant && sectionMatchedByConstant == null) |
||||
sectionMatchedByConstant = defaultSection; |
||||
|
||||
int gotoCaseOrDefaultInOuterScope = gotoCaseOrDefault.Count; |
||||
List<ControlFlowNode> sectionStartNodes = new List<ControlFlowNode>(); |
||||
|
||||
ControlFlowNode end = builder.CreateEndNode(switchStatement, addToNodeList: false); |
||||
breakTargets.Push(end); |
||||
foreach (SwitchSection section in switchStatement.SwitchSections) { |
||||
int sectionStartNodeID = builder.nodes.Count; |
||||
if (constant == null || !constant.IsCompileTimeConstant || section == sectionMatchedByConstant) { |
||||
HandleStatementList(section.Statements, data); |
||||
} else { |
||||
// This section is unreachable: pass null to HandleStatementList.
|
||||
HandleStatementList(section.Statements, null); |
||||
} |
||||
// Don't bother connecting the ends of the sections: the 'break' statement takes care of that.
|
||||
|
||||
// Store the section start node for 'goto case' statements.
|
||||
sectionStartNodes.Add(sectionStartNodeID < builder.nodes.Count ? builder.nodes[sectionStartNodeID] : null); |
||||
} |
||||
breakTargets.Pop(); |
||||
if (defaultSection == null && sectionMatchedByConstant == null) { |
||||
Connect(data, end); |
||||
} |
||||
|
||||
if (gotoCaseOrDefault.Count > gotoCaseOrDefaultInOuterScope) { |
||||
// Resolve 'goto case' statements:
|
||||
for (int i = gotoCaseOrDefaultInOuterScope; i < gotoCaseOrDefault.Count; i++) { |
||||
ControlFlowNode gotoCaseNode = gotoCaseOrDefault[i]; |
||||
GotoCaseStatement gotoCaseStatement = gotoCaseNode.NextStatement as GotoCaseStatement; |
||||
ResolveResult gotoCaseConstant = null; |
||||
if (gotoCaseStatement != null) { |
||||
gotoCaseConstant = builder.EvaluateConstant(gotoCaseStatement.LabelExpression); |
||||
} |
||||
int targetSectionIndex = -1; |
||||
int currentSectionIndex = 0; |
||||
foreach (SwitchSection section in switchStatement.SwitchSections) { |
||||
foreach (CaseLabel label in section.CaseLabels) { |
||||
if (gotoCaseStatement != null) { |
||||
// goto case
|
||||
if (!label.Expression.IsNull) { |
||||
ResolveResult labelConstant = builder.EvaluateConstant(label.Expression); |
||||
if (builder.AreEqualConstants(gotoCaseConstant, labelConstant)) |
||||
targetSectionIndex = currentSectionIndex; |
||||
} |
||||
} else { |
||||
// goto default
|
||||
if (label.Expression.IsNull) |
||||
targetSectionIndex = currentSectionIndex; |
||||
} |
||||
} |
||||
currentSectionIndex++; |
||||
} |
||||
if (targetSectionIndex >= 0 && sectionStartNodes[targetSectionIndex] != null) |
||||
Connect(gotoCaseNode, sectionStartNodes[targetSectionIndex], ControlFlowEdgeType.Jump); |
||||
else |
||||
Connect(gotoCaseNode, end, ControlFlowEdgeType.Jump); |
||||
} |
||||
gotoCaseOrDefault.RemoveRange(gotoCaseOrDefaultInOuterScope, gotoCaseOrDefault.Count - gotoCaseOrDefaultInOuterScope); |
||||
} |
||||
|
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, ControlFlowNode data) |
||||
{ |
||||
gotoCaseOrDefault.Add(data); |
||||
return builder.CreateEndNode(gotoCaseStatement); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, ControlFlowNode data) |
||||
{ |
||||
gotoCaseOrDefault.Add(data); |
||||
return builder.CreateEndNode(gotoDefaultStatement); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitWhileStatement(WhileStatement whileStatement, ControlFlowNode data) |
||||
{ |
||||
// <data> <condition> while (cond) { <bodyStart> embeddedStmt; <bodyEnd> } <end>
|
||||
ControlFlowNode end = builder.CreateEndNode(whileStatement, addToNodeList: false); |
||||
ControlFlowNode conditionNode = builder.CreateSpecialNode(whileStatement, ControlFlowNodeType.LoopCondition); |
||||
breakTargets.Push(end); |
||||
continueTargets.Push(conditionNode); |
||||
|
||||
Connect(data, conditionNode); |
||||
|
||||
bool? cond = builder.EvaluateCondition(whileStatement.Condition); |
||||
ControlFlowNode bodyStart = builder.CreateStartNode(whileStatement.EmbeddedStatement); |
||||
if (cond != false) |
||||
Connect(conditionNode, bodyStart, ControlFlowEdgeType.ConditionTrue); |
||||
ControlFlowNode bodyEnd = whileStatement.EmbeddedStatement.AcceptVisitor(this, bodyStart); |
||||
Connect(bodyEnd, conditionNode); |
||||
if (cond != true) |
||||
Connect(conditionNode, end, ControlFlowEdgeType.ConditionFalse); |
||||
|
||||
breakTargets.Pop(); |
||||
continueTargets.Pop(); |
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitDoWhileStatement(DoWhileStatement doWhileStatement, ControlFlowNode data) |
||||
{ |
||||
// <data> do { <bodyStart> embeddedStmt; <bodyEnd>} <condition> while(cond); <end>
|
||||
ControlFlowNode end = builder.CreateEndNode(doWhileStatement, addToNodeList: false); |
||||
ControlFlowNode conditionNode = builder.CreateSpecialNode(doWhileStatement, ControlFlowNodeType.LoopCondition, addToNodeList: false); |
||||
breakTargets.Push(end); |
||||
continueTargets.Push(conditionNode); |
||||
|
||||
ControlFlowNode bodyStart = builder.CreateStartNode(doWhileStatement.EmbeddedStatement); |
||||
Connect(data, bodyStart); |
||||
ControlFlowNode bodyEnd = doWhileStatement.EmbeddedStatement.AcceptVisitor(this, bodyStart); |
||||
Connect(bodyEnd, conditionNode); |
||||
|
||||
bool? cond = builder.EvaluateCondition(doWhileStatement.Condition); |
||||
if (cond != false) |
||||
Connect(conditionNode, bodyStart, ControlFlowEdgeType.ConditionTrue); |
||||
if (cond != true) |
||||
Connect(conditionNode, end, ControlFlowEdgeType.ConditionFalse); |
||||
|
||||
breakTargets.Pop(); |
||||
continueTargets.Pop(); |
||||
builder.nodes.Add(conditionNode); |
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitForStatement(ForStatement forStatement, ControlFlowNode data) |
||||
{ |
||||
data = HandleStatementList(forStatement.Initializers, data); |
||||
// for (initializers <data>; <condition>cond; <iteratorStart>iterators<iteratorEnd>) { <bodyStart> embeddedStmt; <bodyEnd> } <end>
|
||||
ControlFlowNode end = builder.CreateEndNode(forStatement, addToNodeList: false); |
||||
ControlFlowNode conditionNode = builder.CreateSpecialNode(forStatement, ControlFlowNodeType.LoopCondition); |
||||
Connect(data, conditionNode); |
||||
|
||||
int iteratorStartNodeID = builder.nodes.Count; |
||||
ControlFlowNode iteratorEnd = HandleStatementList(forStatement.Iterators, null); |
||||
ControlFlowNode iteratorStart; |
||||
if (iteratorEnd != null) { |
||||
iteratorStart = builder.nodes[iteratorStartNodeID]; |
||||
Connect(iteratorEnd, conditionNode); |
||||
} else { |
||||
iteratorStart = conditionNode; |
||||
} |
||||
|
||||
breakTargets.Push(end); |
||||
continueTargets.Push(iteratorStart); |
||||
|
||||
ControlFlowNode bodyStart = builder.CreateStartNode(forStatement.EmbeddedStatement); |
||||
ControlFlowNode bodyEnd = forStatement.EmbeddedStatement.AcceptVisitor(this, bodyStart); |
||||
Connect(bodyEnd, iteratorStart); |
||||
|
||||
breakTargets.Pop(); |
||||
continueTargets.Pop(); |
||||
|
||||
bool? cond = forStatement.Condition.IsNull ? true : builder.EvaluateCondition(forStatement.Condition); |
||||
if (cond != false) |
||||
Connect(conditionNode, bodyStart, ControlFlowEdgeType.ConditionTrue); |
||||
if (cond != true) |
||||
Connect(conditionNode, end, ControlFlowEdgeType.ConditionFalse); |
||||
|
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
ControlFlowNode HandleEmbeddedStatement(Statement embeddedStatement, ControlFlowNode source) |
||||
{ |
||||
if (embeddedStatement == null || embeddedStatement.IsNull) |
||||
return source; |
||||
ControlFlowNode bodyStart = builder.CreateStartNode(embeddedStatement); |
||||
if (source != null) |
||||
Connect(source, bodyStart); |
||||
return embeddedStatement.AcceptVisitor(this, bodyStart); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitForeachStatement(ForeachStatement foreachStatement, ControlFlowNode data) |
||||
{ |
||||
// <data> foreach (<condition>...) { <bodyStart>embeddedStmt<bodyEnd> } <end>
|
||||
ControlFlowNode end = builder.CreateEndNode(foreachStatement, addToNodeList: false); |
||||
ControlFlowNode conditionNode = builder.CreateSpecialNode(foreachStatement, ControlFlowNodeType.LoopCondition); |
||||
Connect(data, conditionNode); |
||||
|
||||
breakTargets.Push(end); |
||||
continueTargets.Push(conditionNode); |
||||
|
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(foreachStatement.EmbeddedStatement, conditionNode); |
||||
Connect(bodyEnd, conditionNode); |
||||
|
||||
breakTargets.Pop(); |
||||
continueTargets.Pop(); |
||||
|
||||
Connect(conditionNode, end); |
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitBreakStatement(BreakStatement breakStatement, ControlFlowNode data) |
||||
{ |
||||
if (breakTargets.Count > 0) |
||||
Connect(data, breakTargets.Peek(), ControlFlowEdgeType.Jump); |
||||
return builder.CreateEndNode(breakStatement); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitContinueStatement(ContinueStatement continueStatement, ControlFlowNode data) |
||||
{ |
||||
if (continueTargets.Count > 0) |
||||
Connect(data, continueTargets.Peek(), ControlFlowEdgeType.Jump); |
||||
return builder.CreateEndNode(continueStatement); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitGotoStatement(GotoStatement gotoStatement, ControlFlowNode data) |
||||
{ |
||||
builder.gotoStatements.Add(data); |
||||
return builder.CreateEndNode(gotoStatement); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitReturnStatement(ReturnStatement returnStatement, ControlFlowNode data) |
||||
{ |
||||
return builder.CreateEndNode(returnStatement); // end not connected with data
|
||||
} |
||||
|
||||
public override ControlFlowNode VisitThrowStatement(ThrowStatement throwStatement, ControlFlowNode data) |
||||
{ |
||||
return builder.CreateEndNode(throwStatement); // end not connected with data
|
||||
} |
||||
|
||||
public override ControlFlowNode VisitTryCatchStatement(TryCatchStatement tryCatchStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode end = builder.CreateEndNode(tryCatchStatement, addToNodeList: false); |
||||
var edge = Connect(HandleEmbeddedStatement(tryCatchStatement.TryBlock, data), end); |
||||
if (!tryCatchStatement.FinallyBlock.IsNull) |
||||
edge.AddJumpOutOfTryFinally(tryCatchStatement); |
||||
foreach (CatchClause cc in tryCatchStatement.CatchClauses) { |
||||
edge = Connect(HandleEmbeddedStatement(cc.Body, data), end); |
||||
if (!tryCatchStatement.FinallyBlock.IsNull) |
||||
edge.AddJumpOutOfTryFinally(tryCatchStatement); |
||||
} |
||||
if (!tryCatchStatement.FinallyBlock.IsNull) { |
||||
// Don't connect the end of the try-finally block to anything.
|
||||
// Consumers of the CFG will have to special-case try-finally.
|
||||
HandleEmbeddedStatement(tryCatchStatement.FinallyBlock, data); |
||||
} |
||||
builder.nodes.Add(end); |
||||
return end; |
||||
} |
||||
|
||||
public override ControlFlowNode VisitCheckedStatement(CheckedStatement checkedStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(checkedStatement.Body, data); |
||||
return CreateConnectedEndNode(checkedStatement, bodyEnd); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitUncheckedStatement(UncheckedStatement uncheckedStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(uncheckedStatement.Body, data); |
||||
return CreateConnectedEndNode(uncheckedStatement, bodyEnd); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitLockStatement(LockStatement lockStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(lockStatement.EmbeddedStatement, data); |
||||
return CreateConnectedEndNode(lockStatement, bodyEnd); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitUsingStatement(UsingStatement usingStatement, ControlFlowNode data) |
||||
{ |
||||
data = HandleEmbeddedStatement(usingStatement.ResourceAcquisition as Statement, data); |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(usingStatement.EmbeddedStatement, data); |
||||
return CreateConnectedEndNode(usingStatement, bodyEnd); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitYieldReturnStatement(YieldReturnStatement yieldStatement, ControlFlowNode data) |
||||
{ |
||||
return CreateConnectedEndNode(yieldStatement, data); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, ControlFlowNode data) |
||||
{ |
||||
return builder.CreateEndNode(yieldBreakStatement); // end not connected with data
|
||||
} |
||||
|
||||
public override ControlFlowNode VisitUnsafeStatement(UnsafeStatement unsafeStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(unsafeStatement.Body, data); |
||||
return CreateConnectedEndNode(unsafeStatement, bodyEnd); |
||||
} |
||||
|
||||
public override ControlFlowNode VisitFixedStatement(FixedStatement fixedStatement, ControlFlowNode data) |
||||
{ |
||||
ControlFlowNode bodyEnd = HandleEmbeddedStatement(fixedStatement.EmbeddedStatement, data); |
||||
return CreateConnectedEndNode(fixedStatement, bodyEnd); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Debugging helper that exports a control flow graph.
|
||||
/// </summary>
|
||||
public static GraphVizGraph ExportGraph(IList<ControlFlowNode> nodes) |
||||
{ |
||||
GraphVizGraph g = new GraphVizGraph(); |
||||
GraphVizNode[] n = new GraphVizNode[nodes.Count]; |
||||
Dictionary<ControlFlowNode, int> dict = new Dictionary<ControlFlowNode, int>(); |
||||
for (int i = 0; i < n.Length; i++) { |
||||
dict.Add(nodes[i], i); |
||||
n[i] = new GraphVizNode(i); |
||||
string name = "#" + i + " = "; |
||||
switch (nodes[i].Type) { |
||||
case ControlFlowNodeType.StartNode: |
||||
case ControlFlowNodeType.BetweenStatements: |
||||
name += nodes[i].NextStatement.DebugToString(); |
||||
break; |
||||
case ControlFlowNodeType.EndNode: |
||||
name += "End of " + nodes[i].PreviousStatement.DebugToString(); |
||||
break; |
||||
case ControlFlowNodeType.LoopCondition: |
||||
name += "Condition in " + nodes[i].NextStatement.DebugToString(); |
||||
break; |
||||
default: |
||||
name += "?"; |
||||
break; |
||||
} |
||||
n[i].label = name; |
||||
g.AddNode(n[i]); |
||||
} |
||||
for (int i = 0; i < n.Length; i++) { |
||||
foreach (ControlFlowEdge edge in nodes[i].Outgoing) { |
||||
GraphVizEdge ge = new GraphVizEdge(i, dict[edge.To]); |
||||
if (edge.IsLeavingTryFinally) |
||||
ge.style = "dashed"; |
||||
switch (edge.Type) { |
||||
case ControlFlowEdgeType.ConditionTrue: |
||||
ge.color = "green"; |
||||
break; |
||||
case ControlFlowEdgeType.ConditionFalse: |
||||
ge.color = "red"; |
||||
break; |
||||
case ControlFlowEdgeType.Jump: |
||||
ge.color = "blue"; |
||||
break; |
||||
} |
||||
g.AddEdge(ge); |
||||
} |
||||
} |
||||
return g; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,157 @@
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// LovalVariableDeclarationSpace.cs
|
||||
//
|
||||
// Author:
|
||||
// Simon Lindgren <simon.n.lindgren@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2013 Simon Lindgren
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using ICSharpCode.NRefactory.Utils; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Analysis |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a declaration space. (§3.3)
|
||||
/// </summary>
|
||||
public class LocalDeclarationSpace |
||||
{ |
||||
/// <summary>
|
||||
/// Maps from variable name to the declarations in this declaration space.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This maps from variable name
|
||||
/// </remarks>
|
||||
MultiDictionary<string, AstNode> declarations = new MultiDictionary<string, AstNode> (); |
||||
|
||||
public LocalDeclarationSpace() |
||||
{ |
||||
Children = new List<LocalDeclarationSpace> (); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The child declaration spaces.
|
||||
/// </summary>
|
||||
public IList<LocalDeclarationSpace> Children { |
||||
get; |
||||
private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The parent declaration space.
|
||||
/// </summary>
|
||||
/// <value>The parent.</value>
|
||||
public LocalDeclarationSpace Parent { |
||||
get; |
||||
private set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The names declared in this declaration space, excluding child spaces.
|
||||
/// </summary>
|
||||
/// <value>The declared names.</value>
|
||||
public ICollection<string> DeclaredNames { |
||||
get { |
||||
return declarations.Keys; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get all nodes declaring the name specified in <paramref name="name"/>.
|
||||
/// </summary>
|
||||
/// <returns>The declaring nodes.</returns>
|
||||
/// <param name="name">The declaration name.</param>
|
||||
public IEnumerable<AstNode> GetNameDeclarations(string name) |
||||
{ |
||||
return declarations [name].Concat(Children.SelectMany(child => child.GetNameDeclarations(name))); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a child declaration space.
|
||||
/// </summary>
|
||||
/// <param name="child">The <see cref="LocalDeclarationSpace"/> to add.</param>
|
||||
public void AddChildSpace(LocalDeclarationSpace child) |
||||
{ |
||||
if (child == null) |
||||
throw new ArgumentNullException("child"); |
||||
if (Children.Contains(child)) |
||||
throw new InvalidOperationException("the child was already added"); |
||||
|
||||
Children.Add(child); |
||||
child.Parent = this; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds a new declaration to the declaration space.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the declared variable.</param>
|
||||
/// <param name="node">A node associated with the declaration.</param>
|
||||
public void AddDeclaration(string name, AstNode node) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
if (node == null) |
||||
throw new ArgumentNullException("node"); |
||||
declarations.Add(name, node); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines if the name exists in the this declaration space.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if the name specified in <paramref name="name"/> is used in this variable declaration space, <c>false</c> otherwise.</returns>
|
||||
/// <param name="name">The name to look for.</param>
|
||||
/// <param name="includeChildren">When <c>true</c>, child declaration spaces are included in the search.</param>
|
||||
public bool ContainsName(string name, bool includeChildren) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
|
||||
if (declarations.Keys.Contains(name)) |
||||
return true; |
||||
return includeChildren && Children.Any(child => child.ContainsName(name, true)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Determines whether the name specified in <paramref name="name"/> is used in surrouding code.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if the name is used, <c>false</c> otherwise.</returns>
|
||||
/// <param name="name">The name to check.</param>
|
||||
/// <remarks>
|
||||
/// Contrary to <see cref="ContainsName"/>, this method also checks parent declaration spaces
|
||||
/// for name conflicts. Typically, this will be the right method to use when determining if a name can be used.
|
||||
/// </remarks>
|
||||
public bool IsNameUsed(string name) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
|
||||
return IsNameUsedBySelfOrParent(name) || Children.Any(child => child.ContainsName(name, true)); |
||||
} |
||||
|
||||
bool IsNameUsedBySelfOrParent(string name) |
||||
{ |
||||
if (declarations.Keys.Contains(name)) |
||||
return true; |
||||
return Parent != null && Parent.IsNameUsedBySelfOrParent(name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,138 @@
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// LocalDeclarationSpaceVisitor.cs
|
||||
//
|
||||
// Author:
|
||||
// Simon Lindgren <simon.n.lindgren@gmail.com>
|
||||
//
|
||||
// Copyright (c) 2013 Simon Lindgren
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Analysis |
||||
{ |
||||
public class LocalDeclarationSpaceVisitor : DepthFirstAstVisitor |
||||
{ |
||||
LocalDeclarationSpace currentDeclarationSpace; |
||||
Dictionary<AstNode, LocalDeclarationSpace> nodeDeclarationSpaces = new Dictionary<AstNode, LocalDeclarationSpace>(); |
||||
|
||||
public LocalDeclarationSpace GetDeclarationSpace(AstNode node) |
||||
{ |
||||
if (node == null) |
||||
throw new ArgumentNullException("node"); |
||||
while (node != null) { |
||||
LocalDeclarationSpace declarationSpace; |
||||
if (nodeDeclarationSpaces.TryGetValue(node, out declarationSpace)) |
||||
return declarationSpace; |
||||
node = node.Parent; |
||||
} |
||||
return null; |
||||
} |
||||
|
||||
#region Visitor
|
||||
|
||||
void AddDeclaration(string name, AstNode node) |
||||
{ |
||||
if (currentDeclarationSpace != null) |
||||
currentDeclarationSpace.AddDeclaration(name, node); |
||||
} |
||||
|
||||
public override void VisitVariableInitializer(VariableInitializer variableInitializer) |
||||
{ |
||||
AddDeclaration(variableInitializer.Name, variableInitializer); |
||||
base.VisitVariableInitializer(variableInitializer); |
||||
} |
||||
|
||||
public override void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration) |
||||
{ |
||||
AddDeclaration(parameterDeclaration.Name, parameterDeclaration); |
||||
base.VisitParameterDeclaration(parameterDeclaration); |
||||
} |
||||
|
||||
void VisitNewDeclarationSpace(AstNode node) |
||||
{ |
||||
var oldDeclarationSpace = currentDeclarationSpace; |
||||
currentDeclarationSpace = new LocalDeclarationSpace(); |
||||
if (oldDeclarationSpace != null) |
||||
oldDeclarationSpace.AddChildSpace(currentDeclarationSpace); |
||||
|
||||
VisitChildren(node); |
||||
|
||||
nodeDeclarationSpaces.Add(node, currentDeclarationSpace); |
||||
currentDeclarationSpace = oldDeclarationSpace; |
||||
} |
||||
|
||||
#region Declaration space creating nodes
|
||||
|
||||
public override void VisitMethodDeclaration(MethodDeclaration methodDeclaration) |
||||
{ |
||||
VisitNewDeclarationSpace(methodDeclaration); |
||||
} |
||||
|
||||
public override void VisitBlockStatement(BlockStatement blockStatement) |
||||
{ |
||||
VisitNewDeclarationSpace(blockStatement); |
||||
} |
||||
|
||||
public override void VisitSwitchStatement(SwitchStatement switchStatement) |
||||
{ |
||||
VisitNewDeclarationSpace(switchStatement); |
||||
} |
||||
|
||||
public override void VisitForeachStatement(ForeachStatement foreachStatement) |
||||
{ |
||||
AddDeclaration(foreachStatement.VariableName, foreachStatement); |
||||
VisitNewDeclarationSpace(foreachStatement); |
||||
} |
||||
|
||||
public override void VisitForStatement(ForStatement forStatement) |
||||
{ |
||||
VisitNewDeclarationSpace(forStatement); |
||||
} |
||||
|
||||
public override void VisitUsingStatement(UsingStatement usingStatement) |
||||
{ |
||||
VisitNewDeclarationSpace(usingStatement); |
||||
} |
||||
|
||||
public override void VisitLambdaExpression(LambdaExpression lambdaExpression) |
||||
{ |
||||
VisitNewDeclarationSpace(lambdaExpression); |
||||
} |
||||
|
||||
public override void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression) |
||||
{ |
||||
VisitNewDeclarationSpace(anonymousMethodExpression); |
||||
} |
||||
|
||||
public override void VisitEventDeclaration(EventDeclaration eventDeclaration) |
||||
{ |
||||
AddDeclaration(eventDeclaration.Name, eventDeclaration); |
||||
} |
||||
|
||||
public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration) |
||||
{ |
||||
VisitNewDeclarationSpace(eventDeclaration); |
||||
} |
||||
|
||||
#endregion
|
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,753 @@
@@ -0,0 +1,753 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using System.Threading; |
||||
|
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.CSharp.TypeSystem; |
||||
using ICSharpCode.NRefactory.Semantics; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
using ICSharpCode.NRefactory.Utils; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp.Analysis |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the definite assignment status of a variable at a specific location.
|
||||
/// </summary>
|
||||
public enum DefiniteAssignmentStatus |
||||
{ |
||||
/// <summary>
|
||||
/// The variable might be assigned or unassigned.
|
||||
/// </summary>
|
||||
PotentiallyAssigned, |
||||
/// <summary>
|
||||
/// The variable is definitely assigned.
|
||||
/// </summary>
|
||||
DefinitelyAssigned, |
||||
/// <summary>
|
||||
/// The variable is definitely assigned iff the expression results in the value 'true'.
|
||||
/// </summary>
|
||||
AssignedAfterTrueExpression, |
||||
/// <summary>
|
||||
/// The variable is definitely assigned iff the expression results in the value 'false'.
|
||||
/// </summary>
|
||||
AssignedAfterFalseExpression, |
||||
/// <summary>
|
||||
/// The code is unreachable.
|
||||
/// </summary>
|
||||
CodeUnreachable |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Implements the C# definite assignment analysis (C# 4.0 Spec: §5.3 Definite assignment)
|
||||
/// </summary>
|
||||
public class DefiniteAssignmentAnalysis |
||||
{ |
||||
sealed class DefiniteAssignmentNode : ControlFlowNode |
||||
{ |
||||
public int Index; |
||||
public DefiniteAssignmentStatus NodeStatus; |
||||
|
||||
public DefiniteAssignmentNode(Statement previousStatement, Statement nextStatement, ControlFlowNodeType type) |
||||
: base(previousStatement, nextStatement, type) |
||||
{ |
||||
} |
||||
} |
||||
|
||||
sealed class DerivedControlFlowGraphBuilder : ControlFlowGraphBuilder |
||||
{ |
||||
protected override ControlFlowNode CreateNode(Statement previousStatement, Statement nextStatement, ControlFlowNodeType type) |
||||
{ |
||||
return new DefiniteAssignmentNode(previousStatement, nextStatement, type); |
||||
} |
||||
} |
||||
|
||||
readonly DefiniteAssignmentVisitor visitor = new DefiniteAssignmentVisitor(); |
||||
readonly List<DefiniteAssignmentNode> allNodes = new List<DefiniteAssignmentNode>(); |
||||
readonly Dictionary<Statement, DefiniteAssignmentNode> beginNodeDict = new Dictionary<Statement, DefiniteAssignmentNode>(); |
||||
readonly Dictionary<Statement, DefiniteAssignmentNode> endNodeDict = new Dictionary<Statement, DefiniteAssignmentNode>(); |
||||
readonly Dictionary<Statement, DefiniteAssignmentNode> conditionNodeDict = new Dictionary<Statement, DefiniteAssignmentNode>(); |
||||
readonly Func<AstNode, CancellationToken, ResolveResult> resolve; |
||||
Dictionary<ControlFlowEdge, DefiniteAssignmentStatus> edgeStatus = new Dictionary<ControlFlowEdge, DefiniteAssignmentStatus>(); |
||||
|
||||
string variableName; |
||||
List<IdentifierExpression> unassignedVariableUses = new List<IdentifierExpression>(); |
||||
int analyzedRangeStart, analyzedRangeEnd; |
||||
CancellationToken analysisCancellationToken; |
||||
|
||||
Queue<DefiniteAssignmentNode> nodesWithModifiedInput = new Queue<DefiniteAssignmentNode>(); |
||||
|
||||
public DefiniteAssignmentAnalysis(Statement rootStatement, Func<AstNode, CancellationToken, ResolveResult> resolve, CSharpTypeResolveContext context, CancellationToken cancellationToken) |
||||
{ |
||||
if (rootStatement == null) |
||||
throw new ArgumentNullException("rootStatement"); |
||||
if (resolve == null) |
||||
throw new ArgumentNullException("resolve"); |
||||
this.resolve = resolve; |
||||
|
||||
visitor.analysis = this; |
||||
DerivedControlFlowGraphBuilder cfgBuilder = new DerivedControlFlowGraphBuilder(); |
||||
if (context.Compilation.MainAssembly.UnresolvedAssembly is MinimalCorlib) { |
||||
cfgBuilder.EvaluateOnlyPrimitiveConstants = true; |
||||
} |
||||
allNodes.AddRange(cfgBuilder.BuildControlFlowGraph(rootStatement, resolve, context, cancellationToken).Cast<DefiniteAssignmentNode>()); |
||||
for (int i = 0; i < allNodes.Count; i++) { |
||||
DefiniteAssignmentNode node = allNodes[i]; |
||||
node.Index = i; // assign numbers to the nodes
|
||||
if (node.Type == ControlFlowNodeType.StartNode || node.Type == ControlFlowNodeType.BetweenStatements) { |
||||
// Anonymous methods have separate control flow graphs, but we also need to analyze those.
|
||||
// Iterate backwards so that anonymous methods are inserted in the correct order
|
||||
for (AstNode child = node.NextStatement.LastChild; child != null; child = child.PrevSibling) { |
||||
InsertAnonymousMethods(i + 1, child, cfgBuilder, context, cancellationToken); |
||||
} |
||||
} |
||||
// Now register the node in the dictionaries:
|
||||
if (node.Type == ControlFlowNodeType.StartNode || node.Type == ControlFlowNodeType.BetweenStatements) |
||||
beginNodeDict.Add(node.NextStatement, node); |
||||
if (node.Type == ControlFlowNodeType.BetweenStatements || node.Type == ControlFlowNodeType.EndNode) |
||||
endNodeDict.Add(node.PreviousStatement, node); |
||||
if (node.Type == ControlFlowNodeType.LoopCondition) |
||||
conditionNodeDict.Add(node.NextStatement, node); |
||||
} |
||||
// Verify that we created nodes for all statements:
|
||||
Debug.Assert(!rootStatement.DescendantsAndSelf.OfType<Statement>().Except(allNodes.Select(n => n.NextStatement)).Any()); |
||||
// Verify that we put all nodes into the dictionaries:
|
||||
Debug.Assert(rootStatement.DescendantsAndSelf.OfType<Statement>().All(stmt => beginNodeDict.ContainsKey(stmt))); |
||||
Debug.Assert(rootStatement.DescendantsAndSelf.OfType<Statement>().All(stmt => endNodeDict.ContainsKey(stmt))); |
||||
|
||||
this.analyzedRangeStart = 0; |
||||
this.analyzedRangeEnd = allNodes.Count - 1; |
||||
} |
||||
|
||||
void InsertAnonymousMethods(int insertPos, AstNode node, ControlFlowGraphBuilder cfgBuilder, CSharpTypeResolveContext context, CancellationToken cancellationToken) |
||||
{ |
||||
// Ignore any statements, as those have their own ControlFlowNode and get handled separately
|
||||
if (node is Statement) |
||||
return; |
||||
AnonymousMethodExpression ame = node as AnonymousMethodExpression; |
||||
if (ame != null) { |
||||
allNodes.InsertRange(insertPos, cfgBuilder.BuildControlFlowGraph(ame.Body, resolve, context, cancellationToken).Cast<DefiniteAssignmentNode>()); |
||||
return; |
||||
} |
||||
LambdaExpression lambda = node as LambdaExpression; |
||||
if (lambda != null && lambda.Body is Statement) { |
||||
allNodes.InsertRange(insertPos, cfgBuilder.BuildControlFlowGraph((Statement)lambda.Body, resolve, context, cancellationToken).Cast<DefiniteAssignmentNode>()); |
||||
return; |
||||
} |
||||
// Descend into child expressions
|
||||
// Iterate backwards so that anonymous methods are inserted in the correct order
|
||||
for (AstNode child = node.LastChild; child != null; child = child.PrevSibling) { |
||||
InsertAnonymousMethods(insertPos, child, cfgBuilder, context, cancellationToken); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the unassigned usages of the previously analyzed variable.
|
||||
/// </summary>
|
||||
public IList<IdentifierExpression> UnassignedVariableUses { |
||||
get { |
||||
return unassignedVariableUses.AsReadOnly(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Sets the range of statements to be analyzed.
|
||||
/// This method can be used to restrict the analysis to only a part of the method.
|
||||
/// Only the control flow paths that are fully contained within the selected part will be analyzed.
|
||||
/// </summary>
|
||||
/// <remarks>By default, both 'start' and 'end' are inclusive.</remarks>
|
||||
public void SetAnalyzedRange(Statement start, Statement end, bool startInclusive = true, bool endInclusive = true) |
||||
{ |
||||
var dictForStart = startInclusive ? beginNodeDict : endNodeDict; |
||||
var dictForEnd = endInclusive ? endNodeDict : beginNodeDict; |
||||
Debug.Assert(dictForStart.ContainsKey(start) && dictForEnd.ContainsKey(end)); |
||||
int startIndex = dictForStart[start].Index; |
||||
int endIndex = dictForEnd[end].Index; |
||||
if (startIndex > endIndex) |
||||
throw new ArgumentException("The start statement must be lexically preceding the end statement"); |
||||
this.analyzedRangeStart = startIndex; |
||||
this.analyzedRangeEnd = endIndex; |
||||
} |
||||
|
||||
public void Analyze(string variable, DefiniteAssignmentStatus initialStatus = DefiniteAssignmentStatus.PotentiallyAssigned, CancellationToken cancellationToken = default(CancellationToken)) |
||||
{ |
||||
this.analysisCancellationToken = cancellationToken; |
||||
this.variableName = variable; |
||||
try { |
||||
// Reset the status:
|
||||
unassignedVariableUses.Clear(); |
||||
foreach (DefiniteAssignmentNode node in allNodes) { |
||||
node.NodeStatus = DefiniteAssignmentStatus.CodeUnreachable; |
||||
foreach (ControlFlowEdge edge in node.Outgoing) |
||||
edgeStatus[edge] = DefiniteAssignmentStatus.CodeUnreachable; |
||||
} |
||||
|
||||
ChangeNodeStatus(allNodes[analyzedRangeStart], initialStatus); |
||||
// Iterate as long as the input status of some nodes is changing:
|
||||
while (nodesWithModifiedInput.Count > 0) { |
||||
DefiniteAssignmentNode node = nodesWithModifiedInput.Dequeue(); |
||||
DefiniteAssignmentStatus inputStatus = DefiniteAssignmentStatus.CodeUnreachable; |
||||
foreach (ControlFlowEdge edge in node.Incoming) { |
||||
inputStatus = MergeStatus(inputStatus, edgeStatus[edge]); |
||||
} |
||||
ChangeNodeStatus(node, inputStatus); |
||||
} |
||||
} finally { |
||||
this.analysisCancellationToken = CancellationToken.None; |
||||
this.variableName = null; |
||||
} |
||||
} |
||||
|
||||
public DefiniteAssignmentStatus GetStatusBefore(Statement statement) |
||||
{ |
||||
return beginNodeDict[statement].NodeStatus; |
||||
} |
||||
|
||||
public DefiniteAssignmentStatus GetStatusAfter(Statement statement) |
||||
{ |
||||
return endNodeDict[statement].NodeStatus; |
||||
} |
||||
|
||||
public DefiniteAssignmentStatus GetStatusBeforeLoopCondition(Statement statement) |
||||
{ |
||||
return conditionNodeDict[statement].NodeStatus; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Exports the CFG. This method is intended to help debugging issues related to definite assignment.
|
||||
/// </summary>
|
||||
public GraphVizGraph ExportGraph() |
||||
{ |
||||
GraphVizGraph g = new GraphVizGraph(); |
||||
g.Title = "DefiniteAssignment - " + variableName; |
||||
for (int i = 0; i < allNodes.Count; i++) { |
||||
string name = "#" + i + " = " + allNodes[i].NodeStatus.ToString() + Environment.NewLine; |
||||
switch (allNodes[i].Type) { |
||||
case ControlFlowNodeType.StartNode: |
||||
case ControlFlowNodeType.BetweenStatements: |
||||
name += allNodes[i].NextStatement.ToString(); |
||||
break; |
||||
case ControlFlowNodeType.EndNode: |
||||
name += "End of " + allNodes[i].PreviousStatement.ToString(); |
||||
break; |
||||
case ControlFlowNodeType.LoopCondition: |
||||
name += "Condition in " + allNodes[i].NextStatement.ToString(); |
||||
break; |
||||
default: |
||||
name += allNodes[i].Type.ToString(); |
||||
break; |
||||
} |
||||
g.AddNode(new GraphVizNode(i) { label = name }); |
||||
foreach (ControlFlowEdge edge in allNodes[i].Outgoing) { |
||||
GraphVizEdge ge = new GraphVizEdge(i, ((DefiniteAssignmentNode)edge.To).Index); |
||||
if (edgeStatus.Count > 0) |
||||
ge.label = edgeStatus[edge].ToString(); |
||||
if (edge.IsLeavingTryFinally) |
||||
ge.style = "dashed"; |
||||
switch (edge.Type) { |
||||
case ControlFlowEdgeType.ConditionTrue: |
||||
ge.color = "green"; |
||||
break; |
||||
case ControlFlowEdgeType.ConditionFalse: |
||||
ge.color = "red"; |
||||
break; |
||||
case ControlFlowEdgeType.Jump: |
||||
ge.color = "blue"; |
||||
break; |
||||
} |
||||
g.AddEdge(ge); |
||||
} |
||||
} |
||||
return g; |
||||
} |
||||
|
||||
static DefiniteAssignmentStatus MergeStatus(DefiniteAssignmentStatus a, DefiniteAssignmentStatus b) |
||||
{ |
||||
// The result will be DefinitelyAssigned if at least one incoming edge is DefinitelyAssigned and all others are unreachable.
|
||||
// The result will be DefinitelyUnassigned if at least one incoming edge is DefinitelyUnassigned and all others are unreachable.
|
||||
// The result will be Unreachable if all incoming edges are unreachable.
|
||||
// Otherwise, the result will be PotentiallyAssigned.
|
||||
|
||||
if (a == b) |
||||
return a; |
||||
else if (a == DefiniteAssignmentStatus.CodeUnreachable) |
||||
return b; |
||||
else if (b == DefiniteAssignmentStatus.CodeUnreachable) |
||||
return a; |
||||
else |
||||
return DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
} |
||||
|
||||
void ChangeNodeStatus (DefiniteAssignmentNode node, DefiniteAssignmentStatus inputStatus) |
||||
{ |
||||
if (node.NodeStatus == inputStatus) |
||||
return; |
||||
node.NodeStatus = inputStatus; |
||||
DefiniteAssignmentStatus outputStatus; |
||||
switch (node.Type) { |
||||
case ControlFlowNodeType.StartNode: |
||||
case ControlFlowNodeType.BetweenStatements: |
||||
if (node.NextStatement is IfElseStatement) { |
||||
// Handle if-else as a condition node
|
||||
goto case ControlFlowNodeType.LoopCondition; |
||||
} |
||||
if (inputStatus == DefiniteAssignmentStatus.DefinitelyAssigned) { |
||||
// There isn't any way to un-assign variables, so we don't have to check the expression
|
||||
// if the status already is definitely assigned.
|
||||
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
} else { |
||||
outputStatus = CleanSpecialValues (node.NextStatement.AcceptVisitor (visitor, inputStatus)); |
||||
} |
||||
break; |
||||
case ControlFlowNodeType.EndNode: |
||||
outputStatus = inputStatus; |
||||
if (node.PreviousStatement.Role == TryCatchStatement.FinallyBlockRole |
||||
&& (outputStatus == DefiniteAssignmentStatus.DefinitelyAssigned || outputStatus == DefiniteAssignmentStatus.PotentiallyAssigned)) { |
||||
TryCatchStatement tryFinally = (TryCatchStatement)node.PreviousStatement.Parent; |
||||
// Changing the status on a finally block potentially changes the status of all edges leaving that finally block:
|
||||
foreach (ControlFlowEdge edge in allNodes.SelectMany(n => n.Outgoing)) { |
||||
if (edge.IsLeavingTryFinally && edge.TryFinallyStatements.Contains (tryFinally)) { |
||||
DefiniteAssignmentStatus s = edgeStatus [edge]; |
||||
if (s == DefiniteAssignmentStatus.PotentiallyAssigned) { |
||||
ChangeEdgeStatus (edge, outputStatus); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
break; |
||||
case ControlFlowNodeType.LoopCondition: |
||||
ForeachStatement foreachStmt = node.NextStatement as ForeachStatement; |
||||
if (foreachStmt != null) { |
||||
outputStatus = CleanSpecialValues (foreachStmt.InExpression.AcceptVisitor (visitor, inputStatus)); |
||||
if (foreachStmt.VariableName == this.variableName) |
||||
outputStatus = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
break; |
||||
} else { |
||||
Debug.Assert (node.NextStatement is IfElseStatement || node.NextStatement is WhileStatement || node.NextStatement is ForStatement || node.NextStatement is DoWhileStatement); |
||||
Expression condition = node.NextStatement.GetChildByRole (Roles.Condition); |
||||
if (condition.IsNull) |
||||
outputStatus = inputStatus; |
||||
else |
||||
outputStatus = condition.AcceptVisitor(visitor, inputStatus); |
||||
foreach (ControlFlowEdge edge in node.Outgoing) { |
||||
if (edge.Type == ControlFlowEdgeType.ConditionTrue && outputStatus == DefiniteAssignmentStatus.AssignedAfterTrueExpression) { |
||||
ChangeEdgeStatus(edge, DefiniteAssignmentStatus.DefinitelyAssigned); |
||||
} else if (edge.Type == ControlFlowEdgeType.ConditionFalse && outputStatus == DefiniteAssignmentStatus.AssignedAfterFalseExpression) { |
||||
ChangeEdgeStatus(edge, DefiniteAssignmentStatus.DefinitelyAssigned); |
||||
} else { |
||||
ChangeEdgeStatus(edge, CleanSpecialValues(outputStatus)); |
||||
} |
||||
} |
||||
return; |
||||
} |
||||
default: |
||||
throw new InvalidOperationException(); |
||||
} |
||||
foreach (ControlFlowEdge edge in node.Outgoing) { |
||||
ChangeEdgeStatus(edge, outputStatus); |
||||
} |
||||
} |
||||
|
||||
void ChangeEdgeStatus(ControlFlowEdge edge, DefiniteAssignmentStatus newStatus) |
||||
{ |
||||
DefiniteAssignmentStatus oldStatus = edgeStatus[edge]; |
||||
if (oldStatus == newStatus) |
||||
return; |
||||
// Ensure that status can cannot change back to CodeUnreachable after it once was reachable.
|
||||
// Also, don't ever use AssignedAfter... for statements.
|
||||
if (newStatus == DefiniteAssignmentStatus.CodeUnreachable |
||||
|| newStatus == DefiniteAssignmentStatus.AssignedAfterFalseExpression |
||||
|| newStatus == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
{ |
||||
throw new InvalidOperationException(); |
||||
} |
||||
// Note that the status can change from DefinitelyAssigned
|
||||
// back to PotentiallyAssigned as unreachable input edges are
|
||||
// discovered to be reachable.
|
||||
|
||||
edgeStatus[edge] = newStatus; |
||||
DefiniteAssignmentNode targetNode = (DefiniteAssignmentNode)edge.To; |
||||
if (analyzedRangeStart <= targetNode.Index && targetNode.Index <= analyzedRangeEnd) { |
||||
// TODO: potential optimization: visit previously unreachable nodes with higher priority
|
||||
// (e.g. use Deque and enqueue previously unreachable nodes at the front, but
|
||||
// other nodes at the end)
|
||||
nodesWithModifiedInput.Enqueue(targetNode); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Evaluates an expression.
|
||||
/// </summary>
|
||||
/// <returns>The constant value of the expression; or null if the expression is not a constant.</returns>
|
||||
ResolveResult EvaluateConstant(Expression expr) |
||||
{ |
||||
return resolve(expr, analysisCancellationToken); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Evaluates an expression.
|
||||
/// </summary>
|
||||
/// <returns>The value of the constant boolean expression; or null if the value is not a constant boolean expression.</returns>
|
||||
bool? EvaluateCondition(Expression expr) |
||||
{ |
||||
ResolveResult rr = EvaluateConstant(expr); |
||||
if (rr != null && rr.IsCompileTimeConstant) |
||||
return rr.ConstantValue as bool?; |
||||
else |
||||
return null; |
||||
} |
||||
|
||||
static DefiniteAssignmentStatus CleanSpecialValues(DefiniteAssignmentStatus status) |
||||
{ |
||||
if (status == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
return DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
else if (status == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
return DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
else |
||||
return status; |
||||
} |
||||
|
||||
sealed class DefiniteAssignmentVisitor : DepthFirstAstVisitor<DefiniteAssignmentStatus, DefiniteAssignmentStatus> |
||||
{ |
||||
internal DefiniteAssignmentAnalysis analysis; |
||||
|
||||
// The general approach for unknown nodes is to pass the status through all child nodes in order
|
||||
protected override DefiniteAssignmentStatus VisitChildren(AstNode node, DefiniteAssignmentStatus data) |
||||
{ |
||||
// the special values are valid as output only, not as input
|
||||
Debug.Assert(data == CleanSpecialValues(data)); |
||||
DefiniteAssignmentStatus status = data; |
||||
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) { |
||||
analysis.analysisCancellationToken.ThrowIfCancellationRequested(); |
||||
|
||||
Debug.Assert(!(child is Statement)); // statements are visited with the CFG, not with the visitor pattern
|
||||
status = child.AcceptVisitor(this, status); |
||||
status = CleanSpecialValues(status); |
||||
} |
||||
return status; |
||||
} |
||||
|
||||
#region Statements
|
||||
// For statements, the visitor only describes the effect of the statement itself;
|
||||
// we do not consider the effect of any nested statements.
|
||||
// This is done because the nested statements will be reached using the control flow graph.
|
||||
|
||||
// In fact, these methods are present so that the default logic in VisitChildren does not try to visit the nested statements.
|
||||
|
||||
public override DefiniteAssignmentStatus VisitBlockStatement(BlockStatement blockStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitCheckedStatement(CheckedStatement checkedStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitUncheckedStatement(UncheckedStatement uncheckedStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
// ExpressionStatement handled by default logic
|
||||
// VariableDeclarationStatement handled by default logic
|
||||
|
||||
public override DefiniteAssignmentStatus VisitVariableInitializer(VariableInitializer variableInitializer, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (variableInitializer.Initializer.IsNull) { |
||||
return data; |
||||
} else { |
||||
DefiniteAssignmentStatus status = variableInitializer.Initializer.AcceptVisitor(this, data); |
||||
if (variableInitializer.Name == analysis.variableName) |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else |
||||
return status; |
||||
} |
||||
} |
||||
|
||||
// IfStatement not handled by visitor, but special-cased in the code consuming the control flow graph
|
||||
|
||||
public override DefiniteAssignmentStatus VisitSwitchStatement(SwitchStatement switchStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return switchStatement.Expression.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitWhileStatement(WhileStatement whileStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; // condition is handled by special condition CFG node
|
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitDoWhileStatement(DoWhileStatement doWhileStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; // condition is handled by special condition CFG node
|
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitForStatement(ForStatement forStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; // condition is handled by special condition CFG node; initializer and iterator statements are handled by CFG
|
||||
} |
||||
|
||||
// Break/Continue/Goto: handled by default logic
|
||||
|
||||
// ThrowStatement: handled by default logic (just visit the expression)
|
||||
// ReturnStatement: handled by default logic (just visit the expression)
|
||||
|
||||
public override DefiniteAssignmentStatus VisitTryCatchStatement(TryCatchStatement tryCatchStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; // no special logic when entering the try-catch-finally statement
|
||||
// TODO: where to put the special logic when exiting the try-finally statement?
|
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitForeachStatement(ForeachStatement foreachStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; // assignment of the foreach loop variable is done when handling the condition node
|
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitUsingStatement(UsingStatement usingStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (usingStatement.ResourceAcquisition is Expression) |
||||
return usingStatement.ResourceAcquisition.AcceptVisitor(this, data); |
||||
else |
||||
return data; // don't handle resource acquisition statements, as those are connected in the control flow graph
|
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitLockStatement(LockStatement lockStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return lockStatement.Expression.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
// Yield statements use the default logic
|
||||
|
||||
public override DefiniteAssignmentStatus VisitUnsafeStatement(UnsafeStatement unsafeStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
return data; |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitFixedStatement(FixedStatement fixedStatement, DefiniteAssignmentStatus data) |
||||
{ |
||||
DefiniteAssignmentStatus status = data; |
||||
foreach (var variable in fixedStatement.Variables) |
||||
status = variable.AcceptVisitor(this, status); |
||||
return status; |
||||
} |
||||
#endregion
|
||||
|
||||
#region Expressions
|
||||
public override DefiniteAssignmentStatus VisitDirectionExpression(DirectionExpression directionExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (directionExpression.FieldDirection == FieldDirection.Out) { |
||||
return HandleAssignment(directionExpression.Expression, null, data); |
||||
} else { |
||||
// use default logic for 'ref'
|
||||
return VisitChildren(directionExpression, data); |
||||
} |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitAssignmentExpression(AssignmentExpression assignmentExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (assignmentExpression.Operator == AssignmentOperatorType.Assign) { |
||||
return HandleAssignment(assignmentExpression.Left, assignmentExpression.Right, data); |
||||
} else { |
||||
// use default logic for compound assignment operators
|
||||
return VisitChildren(assignmentExpression, data); |
||||
} |
||||
} |
||||
|
||||
DefiniteAssignmentStatus HandleAssignment(Expression left, Expression right, DefiniteAssignmentStatus initialStatus) |
||||
{ |
||||
IdentifierExpression ident = left as IdentifierExpression; |
||||
if (ident != null && ident.Identifier == analysis.variableName) { |
||||
// right==null is special case when handling 'out' expressions
|
||||
if (right != null) |
||||
right.AcceptVisitor(this, initialStatus); |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
} else { |
||||
DefiniteAssignmentStatus status = left.AcceptVisitor(this, initialStatus); |
||||
if (right != null) |
||||
status = right.AcceptVisitor(this, CleanSpecialValues(status)); |
||||
return CleanSpecialValues(status); |
||||
} |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
// Don't use the default logic here because we don't want to clean up the special values.
|
||||
return parenthesizedExpression.Expression.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitCheckedExpression(CheckedExpression checkedExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
return checkedExpression.Expression.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitUncheckedExpression(UncheckedExpression uncheckedExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
return uncheckedExpression.Expression.AcceptVisitor(this, data); |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalAnd) { |
||||
// Handle constant left side of && expressions (not in the C# spec, but done by the MS compiler)
|
||||
bool? cond = analysis.EvaluateCondition(binaryOperatorExpression.Left); |
||||
if (cond == true) |
||||
return binaryOperatorExpression.Right.AcceptVisitor(this, data); // right operand gets evaluated unconditionally
|
||||
else if (cond == false) |
||||
return data; // right operand never gets evaluated
|
||||
// C# 4.0 spec: §5.3.3.24 Definite Assignment for && expressions
|
||||
DefiniteAssignmentStatus afterLeft = binaryOperatorExpression.Left.AcceptVisitor(this, data); |
||||
DefiniteAssignmentStatus beforeRight; |
||||
if (afterLeft == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
beforeRight = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else if (afterLeft == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
beforeRight = DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
else |
||||
beforeRight = afterLeft; |
||||
DefiniteAssignmentStatus afterRight = binaryOperatorExpression.Right.AcceptVisitor(this, beforeRight); |
||||
if (afterLeft == DefiniteAssignmentStatus.DefinitelyAssigned) |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else if (afterRight == DefiniteAssignmentStatus.DefinitelyAssigned && afterLeft == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else if (afterRight == DefiniteAssignmentStatus.DefinitelyAssigned || afterRight == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterTrueExpression; |
||||
else if (afterLeft == DefiniteAssignmentStatus.AssignedAfterFalseExpression && afterRight == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterFalseExpression; |
||||
else |
||||
return DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
} else if (binaryOperatorExpression.Operator == BinaryOperatorType.ConditionalOr) { |
||||
// C# 4.0 spec: §5.3.3.25 Definite Assignment for || expressions
|
||||
bool? cond = analysis.EvaluateCondition(binaryOperatorExpression.Left); |
||||
if (cond == false) |
||||
return binaryOperatorExpression.Right.AcceptVisitor(this, data); // right operand gets evaluated unconditionally
|
||||
else if (cond == true) |
||||
return data; // right operand never gets evaluated
|
||||
DefiniteAssignmentStatus afterLeft = binaryOperatorExpression.Left.AcceptVisitor(this, data); |
||||
DefiniteAssignmentStatus beforeRight; |
||||
if (afterLeft == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
beforeRight = DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
else if (afterLeft == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
beforeRight = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else |
||||
beforeRight = afterLeft; |
||||
DefiniteAssignmentStatus afterRight = binaryOperatorExpression.Right.AcceptVisitor(this, beforeRight); |
||||
if (afterLeft == DefiniteAssignmentStatus.DefinitelyAssigned) |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else if (afterRight == DefiniteAssignmentStatus.DefinitelyAssigned && afterLeft == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
return DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
else if (afterRight == DefiniteAssignmentStatus.DefinitelyAssigned || afterRight == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterFalseExpression; |
||||
else if (afterLeft == DefiniteAssignmentStatus.AssignedAfterTrueExpression && afterRight == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterTrueExpression; |
||||
else |
||||
return DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
} else if (binaryOperatorExpression.Operator == BinaryOperatorType.NullCoalescing) { |
||||
// C# 4.0 spec: §5.3.3.27 Definite assignment for ?? expressions
|
||||
ResolveResult crr = analysis.EvaluateConstant(binaryOperatorExpression.Left); |
||||
if (crr != null && crr.IsCompileTimeConstant && crr.ConstantValue == null) |
||||
return binaryOperatorExpression.Right.AcceptVisitor(this, data); |
||||
DefiniteAssignmentStatus status = CleanSpecialValues(binaryOperatorExpression.Left.AcceptVisitor(this, data)); |
||||
binaryOperatorExpression.Right.AcceptVisitor(this, status); |
||||
return status; |
||||
} else { |
||||
// use default logic for other operators
|
||||
return VisitChildren(binaryOperatorExpression, data); |
||||
} |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (unaryOperatorExpression.Operator == UnaryOperatorType.Not) { |
||||
// C# 4.0 spec: §5.3.3.26 Definite assignment for ! expressions
|
||||
DefiniteAssignmentStatus status = unaryOperatorExpression.Expression.AcceptVisitor(this, data); |
||||
if (status == DefiniteAssignmentStatus.AssignedAfterFalseExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterTrueExpression; |
||||
else if (status == DefiniteAssignmentStatus.AssignedAfterTrueExpression) |
||||
return DefiniteAssignmentStatus.AssignedAfterFalseExpression; |
||||
else |
||||
return status; |
||||
} else { |
||||
// use default logic for other operators
|
||||
return VisitChildren(unaryOperatorExpression, data); |
||||
} |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitConditionalExpression(ConditionalExpression conditionalExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
// C# 4.0 spec: §5.3.3.28 Definite assignment for ?: expressions
|
||||
bool? cond = analysis.EvaluateCondition(conditionalExpression.Condition); |
||||
if (cond == true) { |
||||
return conditionalExpression.TrueExpression.AcceptVisitor(this, data); |
||||
} else if (cond == false) { |
||||
return conditionalExpression.FalseExpression.AcceptVisitor(this, data); |
||||
} else { |
||||
DefiniteAssignmentStatus afterCondition = conditionalExpression.Condition.AcceptVisitor(this, data); |
||||
|
||||
DefiniteAssignmentStatus beforeTrue, beforeFalse; |
||||
if (afterCondition == DefiniteAssignmentStatus.AssignedAfterTrueExpression) { |
||||
beforeTrue = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
beforeFalse = DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
} else if (afterCondition == DefiniteAssignmentStatus.AssignedAfterFalseExpression) { |
||||
beforeTrue = DefiniteAssignmentStatus.PotentiallyAssigned; |
||||
beforeFalse = DefiniteAssignmentStatus.DefinitelyAssigned; |
||||
} else { |
||||
beforeTrue = afterCondition; |
||||
beforeFalse = afterCondition; |
||||
} |
||||
|
||||
DefiniteAssignmentStatus afterTrue = conditionalExpression.TrueExpression.AcceptVisitor(this, beforeTrue); |
||||
DefiniteAssignmentStatus afterFalse = conditionalExpression.FalseExpression.AcceptVisitor(this, beforeFalse); |
||||
return MergeStatus(CleanSpecialValues(afterTrue), CleanSpecialValues(afterFalse)); |
||||
} |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
BlockStatement body = anonymousMethodExpression.Body; |
||||
analysis.ChangeNodeStatus(analysis.beginNodeDict[body], data); |
||||
return data; |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitLambdaExpression(LambdaExpression lambdaExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
Statement body = lambdaExpression.Body as Statement; |
||||
if (body != null) { |
||||
analysis.ChangeNodeStatus(analysis.beginNodeDict[body], data); |
||||
} else { |
||||
lambdaExpression.Body.AcceptVisitor(this, data); |
||||
} |
||||
return data; |
||||
} |
||||
|
||||
public override DefiniteAssignmentStatus VisitIdentifierExpression(IdentifierExpression identifierExpression, DefiniteAssignmentStatus data) |
||||
{ |
||||
if (data != DefiniteAssignmentStatus.DefinitelyAssigned |
||||
&& identifierExpression.Identifier == analysis.variableName && identifierExpression.TypeArguments.Count == 0) |
||||
{ |
||||
analysis.unassignedVariableUses.Add(identifierExpression); |
||||
} |
||||
return data; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,231 @@
@@ -0,0 +1,231 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the children of an AstNode that have a specific role.
|
||||
/// </summary>
|
||||
public class AstNodeCollection<T> : ICollection<T> |
||||
#if NET_4_5
|
||||
, IReadOnlyCollection<T> |
||||
#endif
|
||||
where T : AstNode |
||||
{ |
||||
readonly AstNode node; |
||||
readonly Role<T> role; |
||||
|
||||
public AstNodeCollection(AstNode node, Role<T> role) |
||||
{ |
||||
if (node == null) |
||||
throw new ArgumentNullException("node"); |
||||
if (role == null) |
||||
throw new ArgumentNullException("role"); |
||||
this.node = node; |
||||
this.role = role; |
||||
} |
||||
|
||||
public int Count { |
||||
get { |
||||
int count = 0; |
||||
uint roleIndex = role.Index; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = cur.NextSibling) { |
||||
if (cur.RoleIndex == roleIndex) |
||||
count++; |
||||
} |
||||
return count; |
||||
} |
||||
} |
||||
|
||||
public void Add(T element) |
||||
{ |
||||
node.AddChild(element, role); |
||||
} |
||||
|
||||
public void AddRange(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we add the new children
|
||||
// Example: collection.AddRange(collection);
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes.ToList()) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void AddRange(T[] nodes) |
||||
{ |
||||
// Fast overload for arrays - we don't need to create a copy
|
||||
if (nodes != null) { |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void ReplaceWith(IEnumerable<T> nodes) |
||||
{ |
||||
// Evaluate 'nodes' first, since it might change when we call Clear()
|
||||
// Example: collection.ReplaceWith(collection);
|
||||
if (nodes != null) |
||||
nodes = nodes.ToList(); |
||||
Clear(); |
||||
if (nodes != null) { |
||||
foreach (T node in nodes) |
||||
Add(node); |
||||
} |
||||
} |
||||
|
||||
public void MoveTo(ICollection<T> targetCollection) |
||||
{ |
||||
if (targetCollection == null) |
||||
throw new ArgumentNullException("targetCollection"); |
||||
foreach (T node in this) { |
||||
node.Remove(); |
||||
targetCollection.Add(node); |
||||
} |
||||
} |
||||
|
||||
public bool Contains(T element) |
||||
{ |
||||
return element != null && element.Parent == node && element.RoleIndex == role.Index; |
||||
} |
||||
|
||||
public bool Remove(T element) |
||||
{ |
||||
if (Contains(element)) { |
||||
element.Remove(); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public void CopyTo(T[] array, int arrayIndex) |
||||
{ |
||||
foreach (T item in this) |
||||
array[arrayIndex++] = item; |
||||
} |
||||
|
||||
public void Clear() |
||||
{ |
||||
foreach (T item in this) |
||||
item.Remove(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the first element for which the predicate returns true,
|
||||
/// or the null node (AstNode with IsNull=true) if no such object is found.
|
||||
/// </summary>
|
||||
public T FirstOrNullObject(Func<T, bool> predicate = null) |
||||
{ |
||||
foreach (T item in this) |
||||
if (predicate == null || predicate(item)) |
||||
return item; |
||||
return role.NullObject; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the last element for which the predicate returns true,
|
||||
/// or the null node (AstNode with IsNull=true) if no such object is found.
|
||||
/// </summary>
|
||||
public T LastOrNullObject(Func<T, bool> predicate = null) |
||||
{ |
||||
T result = role.NullObject; |
||||
foreach (T item in this) |
||||
if (predicate == null || predicate(item)) |
||||
result = item; |
||||
return result; |
||||
} |
||||
|
||||
bool ICollection<T>.IsReadOnly { |
||||
get { return false; } |
||||
} |
||||
|
||||
public IEnumerator<T> GetEnumerator() |
||||
{ |
||||
uint roleIndex = role.Index; |
||||
AstNode next; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.Parent == node); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.NextSibling; |
||||
if (cur.RoleIndex == roleIndex) |
||||
yield return (T)cur; |
||||
} |
||||
} |
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() |
||||
{ |
||||
return GetEnumerator(); |
||||
} |
||||
|
||||
#region Equals and GetHashCode implementation
|
||||
public override int GetHashCode() |
||||
{ |
||||
return node.GetHashCode() ^ role.GetHashCode(); |
||||
} |
||||
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
AstNodeCollection<T> other = obj as AstNodeCollection<T>; |
||||
if (other == null) |
||||
return false; |
||||
return this.node == other.node && this.role == other.role; |
||||
} |
||||
#endregion
|
||||
|
||||
internal bool DoMatch(AstNodeCollection<T> other, Match match) |
||||
{ |
||||
return Pattern.DoMatchCollection(role, node.FirstChild, other.node.FirstChild, match); |
||||
} |
||||
|
||||
public void InsertAfter(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildAfter(existingItem, newItem, role); |
||||
} |
||||
|
||||
public void InsertBefore(T existingItem, T newItem) |
||||
{ |
||||
node.InsertChildBefore(existingItem, newItem, role); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Applies the <paramref name="visitor"/> to all nodes in this collection.
|
||||
/// </summary>
|
||||
public void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
uint roleIndex = role.Index; |
||||
AstNode next; |
||||
for (AstNode cur = node.FirstChild; cur != null; cur = next) { |
||||
Debug.Assert(cur.Parent == node); |
||||
// Remember next before yielding cur.
|
||||
// This allows removing/replacing nodes while iterating through the list.
|
||||
next = cur.NextSibling; |
||||
if (cur.RoleIndex == roleIndex) |
||||
cur.AcceptVisitor(visitor); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,288 @@
@@ -0,0 +1,288 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// A type reference in the C# AST.
|
||||
/// </summary>
|
||||
public abstract class AstType : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly AstType Null = new NullAstType (); |
||||
|
||||
sealed class NullAstType : AstType |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
|
||||
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) |
||||
{ |
||||
return SpecialType.UnknownType; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator AstType(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AstType, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder (this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder (this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder (this, child, data); |
||||
} |
||||
|
||||
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.TypeReference; } |
||||
} |
||||
|
||||
public new AstType Clone() |
||||
{ |
||||
return (AstType)base.Clone(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets whether this type is a SimpleType "var".
|
||||
/// </summary>
|
||||
public bool IsVar() |
||||
{ |
||||
SimpleType st = this as SimpleType; |
||||
return st != null && st.Identifier == "var" && st.TypeArguments.Count == 0; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Create an ITypeReference for this AstType.
|
||||
/// Uses the context (ancestors of this node) to determine the correct <see cref="NameLookupMode"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The resulting type reference will read the context information from the
|
||||
/// <see cref="ITypeResolveContext"/>:
|
||||
/// For resolving type parameters, the CurrentTypeDefinition/CurrentMember is used.
|
||||
/// For resolving simple names, the current namespace and usings from the CurrentUsingScope
|
||||
/// (on CSharpTypeResolveContext only) is used.
|
||||
/// </remarks>
|
||||
public ITypeReference ToTypeReference(InterningProvider interningProvider = null) |
||||
{ |
||||
return ToTypeReference(GetNameLookupMode(), interningProvider); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Create an ITypeReference for this AstType.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The resulting type reference will read the context information from the
|
||||
/// <see cref="ITypeResolveContext"/>:
|
||||
/// For resolving type parameters, the CurrentTypeDefinition/CurrentMember is used.
|
||||
/// For resolving simple names, the current namespace and usings from the CurrentUsingScope
|
||||
/// (on CSharpTypeResolveContext only) is used.
|
||||
/// </remarks>
|
||||
public abstract ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null); |
||||
|
||||
/// <summary>
|
||||
/// Gets the name lookup mode from the context (looking at the ancestors of this <see cref="AstType"/>).
|
||||
/// </summary>
|
||||
public NameLookupMode GetNameLookupMode() |
||||
{ |
||||
AstType outermostType = this; |
||||
while (outermostType.Parent is AstType) |
||||
outermostType = (AstType)outermostType.Parent; |
||||
|
||||
if (outermostType.Parent is UsingDeclaration || outermostType.Parent is UsingAliasDeclaration) { |
||||
return NameLookupMode.TypeInUsingDeclaration; |
||||
} else if (outermostType.Role == Roles.BaseType) { |
||||
// Use BaseTypeReference for a type's base type, and for a constraint on a type.
|
||||
// Do not use it for a constraint on a method.
|
||||
if (outermostType.Parent is TypeDeclaration || (outermostType.Parent is Constraint && outermostType.Parent.Parent is TypeDeclaration)) |
||||
return NameLookupMode.BaseTypeReference; |
||||
} |
||||
return NameLookupMode.Type; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a pointer type from this type by nesting it in a <see cref="ComposedType"/>.
|
||||
/// If this type already is a pointer type, this method just increases the PointerRank of the existing pointer type.
|
||||
/// </summary>
|
||||
public virtual AstType MakePointerType() |
||||
{ |
||||
return new ComposedType { BaseType = this }.MakePointerType(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates an array type from this type by nesting it in a <see cref="ComposedType"/>.
|
||||
/// If this type already is an array type, the additional rank is prepended to the existing array specifier list.
|
||||
/// Thus, <c>new SimpleType("T").MakeArrayType(1).MakeArrayType(2)</c> will result in "T[,][]".
|
||||
/// </summary>
|
||||
public virtual AstType MakeArrayType(int rank = 1) |
||||
{ |
||||
return new ComposedType { BaseType = this }.MakeArrayType(rank); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a nullable type from this type by nesting it in a <see cref="ComposedType"/>.
|
||||
/// </summary>
|
||||
public AstType MakeNullableType() |
||||
{ |
||||
return new ComposedType { BaseType = this, HasNullableSpecifier = true }; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a C# 7 ref type from this type by nesting it in a <see cref="ComposedType"/>.
|
||||
/// </summary>
|
||||
public virtual AstType MakeRefType() |
||||
{ |
||||
return new ComposedType { BaseType = this, HasRefSpecifier = true }; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an expression that can be used to access a static member on this type.
|
||||
/// </summary>
|
||||
public MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new TypeReferenceExpression { Type = this }.Member(memberName); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an expression that can be used to access a static member on this type.
|
||||
/// </summary>
|
||||
public MemberType MemberType(string memberName, params AstType[] typeArguments) |
||||
{ |
||||
var memberType = new MemberType(this, memberName); |
||||
memberType.TypeArguments.AddRange(typeArguments); |
||||
return memberType; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an expression that can be used to access a static member on this type.
|
||||
/// </summary>
|
||||
public MemberType MemberType(string memberName, IEnumerable<AstType> typeArguments) |
||||
{ |
||||
var memberType = new MemberType(this, memberName); |
||||
memberType.TypeArguments.AddRange(typeArguments); |
||||
return memberType; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this type as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments) |
||||
{ |
||||
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this type as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, params Expression[] arguments) |
||||
{ |
||||
return new TypeReferenceExpression { Type = this }.Invoke(methodName, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this type as target.
|
||||
/// </summary>
|
||||
public InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
return new TypeReferenceExpression { Type = this }.Invoke(methodName, typeArguments, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a simple AstType from a dotted name.
|
||||
/// Does not support generics, arrays, etc. - just simple dotted names,
|
||||
/// e.g. namespace names.
|
||||
/// </summary>
|
||||
public static AstType Create(string dottedName) |
||||
{ |
||||
string[] parts = dottedName.Split('.'); |
||||
AstType type = new SimpleType(parts[0]); |
||||
for (int i = 1; i < parts.Length; i++) { |
||||
type = new MemberType(type, parts[i]); |
||||
} |
||||
return type; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,218 @@
@@ -0,0 +1,218 @@
|
||||
//
|
||||
// CSharpModifierToken.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class CSharpModifierToken : CSharpTokenNode |
||||
{ |
||||
Modifiers modifier; |
||||
|
||||
public Modifiers Modifier { |
||||
get { return modifier; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
this.modifier = value; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (StartLocation.Line, StartLocation.Column + GetModifierLength (Modifier)); |
||||
} |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return GetModifierName (Modifier); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CSharpModifierToken o = other as CSharpModifierToken; |
||||
return o != null && this.modifier == o.modifier; |
||||
} |
||||
|
||||
// Not worth using a dictionary for such few elements.
|
||||
// This table is sorted in the order that modifiers should be output when generating code.
|
||||
static readonly Modifiers[] allModifiers = { |
||||
Modifiers.Public, Modifiers.Protected, Modifiers.Private, Modifiers.Internal, |
||||
Modifiers.New, |
||||
Modifiers.Unsafe, |
||||
Modifiers.Abstract, Modifiers.Virtual, Modifiers.Sealed, Modifiers.Static, Modifiers.Override, |
||||
Modifiers.Readonly, Modifiers.Volatile, |
||||
Modifiers.Extern, Modifiers.Partial, Modifiers.Const, |
||||
Modifiers.Async, |
||||
Modifiers.Any |
||||
}; |
||||
|
||||
public static IEnumerable<Modifiers> AllModifiers { |
||||
get { return allModifiers; } |
||||
} |
||||
|
||||
public CSharpModifierToken (TextLocation location, Modifiers modifier) : base (location, null) |
||||
{ |
||||
this.Modifier = modifier; |
||||
} |
||||
|
||||
public static string GetModifierName(Modifiers modifier) |
||||
{ |
||||
switch (modifier) { |
||||
case Modifiers.Private: |
||||
return "private"; |
||||
case Modifiers.Internal: |
||||
return "internal"; |
||||
case Modifiers.Protected: |
||||
return "protected"; |
||||
case Modifiers.Public: |
||||
return "public"; |
||||
case Modifiers.Abstract: |
||||
return "abstract"; |
||||
case Modifiers.Virtual: |
||||
return "virtual"; |
||||
case Modifiers.Sealed: |
||||
return "sealed"; |
||||
case Modifiers.Static: |
||||
return "static"; |
||||
case Modifiers.Override: |
||||
return "override"; |
||||
case Modifiers.Readonly: |
||||
return "readonly"; |
||||
case Modifiers.Const: |
||||
return "const"; |
||||
case Modifiers.New: |
||||
return "new"; |
||||
case Modifiers.Partial: |
||||
return "partial"; |
||||
case Modifiers.Extern: |
||||
return "extern"; |
||||
case Modifiers.Volatile: |
||||
return "volatile"; |
||||
case Modifiers.Unsafe: |
||||
return "unsafe"; |
||||
case Modifiers.Async: |
||||
return "async"; |
||||
case Modifiers.Any: |
||||
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
|
||||
return "any"; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for Modifiers"); |
||||
} |
||||
} |
||||
|
||||
public static int GetModifierLength(Modifiers modifier) |
||||
{ |
||||
switch (modifier) { |
||||
case Modifiers.Private: |
||||
return "private".Length; |
||||
case Modifiers.Internal: |
||||
return "internal".Length; |
||||
case Modifiers.Protected: |
||||
return "protected".Length; |
||||
case Modifiers.Public: |
||||
return "public".Length; |
||||
case Modifiers.Abstract: |
||||
return "abstract".Length; |
||||
case Modifiers.Virtual: |
||||
return "virtual".Length; |
||||
case Modifiers.Sealed: |
||||
return "sealed".Length; |
||||
case Modifiers.Static: |
||||
return "static".Length; |
||||
case Modifiers.Override: |
||||
return "override".Length; |
||||
case Modifiers.Readonly: |
||||
return "readonly".Length; |
||||
case Modifiers.Const: |
||||
return "const".Length; |
||||
case Modifiers.New: |
||||
return "new".Length; |
||||
case Modifiers.Partial: |
||||
return "partial".Length; |
||||
case Modifiers.Extern: |
||||
return "extern".Length; |
||||
case Modifiers.Volatile: |
||||
return "volatile".Length; |
||||
case Modifiers.Unsafe: |
||||
return "unsafe".Length; |
||||
case Modifiers.Async: |
||||
return "async".Length; |
||||
case Modifiers.Any: |
||||
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
|
||||
return "any".Length; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for Modifiers"); |
||||
} |
||||
} |
||||
|
||||
public static Modifiers GetModifierValue(string modifier) |
||||
{ |
||||
switch (modifier) { |
||||
case "private": |
||||
return Modifiers.Private; |
||||
case "internal": |
||||
return Modifiers.Internal; |
||||
case "protected": |
||||
return Modifiers.Protected; |
||||
case "public": |
||||
return Modifiers.Public; |
||||
case "abstract": |
||||
return Modifiers.Abstract; |
||||
case "virtual": |
||||
return Modifiers.Virtual; |
||||
case "sealed": |
||||
return Modifiers.Sealed; |
||||
case "static": |
||||
return Modifiers.Static; |
||||
case "override": |
||||
return Modifiers.Override; |
||||
case "readonly": |
||||
return Modifiers.Readonly; |
||||
case "const": |
||||
return Modifiers.Const; |
||||
case "new": |
||||
return Modifiers.New; |
||||
case "partial": |
||||
return Modifiers.Partial; |
||||
case "extern": |
||||
return Modifiers.Extern; |
||||
case "volatile": |
||||
return Modifiers.Volatile; |
||||
case "unsafe": |
||||
return Modifiers.Unsafe; |
||||
case "async": |
||||
return Modifiers.Async; |
||||
case "any": |
||||
// even though it's used for pattern matching only, 'any' needs to be in this list to be usable in the AST
|
||||
return Modifiers.Any; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for Modifiers"); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// TokenNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a token in C#. Note that the type of the token is defined through the TokenRole.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// In all non null c# token nodes the Role of a CSharpToken must be a TokenRole.
|
||||
/// </remarks>
|
||||
public class CSharpTokenNode : AstNode |
||||
{ |
||||
public static new readonly CSharpTokenNode Null = new NullCSharpTokenNode (); |
||||
class NullCSharpTokenNode : CSharpTokenNode |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public NullCSharpTokenNode () : base (TextLocation.Empty, null) |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Token; |
||||
} |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
int TokenLength { |
||||
get { |
||||
return TokenRole.TokenLengths [(int)(this.flags >> AstNodeFlagsUsedBits)]; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (StartLocation.Line, StartLocation.Column + TokenLength); |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode (TextLocation location, TokenRole role) |
||||
{ |
||||
this.startLocation = location; |
||||
if (role != null) |
||||
this.flags |= role.TokenIndex << AstNodeFlagsUsedBits; |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return TokenRole.Tokens [(int)(this.flags >> AstNodeFlagsUsedBits)]; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitCSharpTokenNode (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitCSharpTokenNode (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCSharpTokenNode (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CSharpTokenNode o = other as CSharpTokenNode; |
||||
return o != null && !o.IsNull && !(o is CSharpModifierToken); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,180 @@
@@ -0,0 +1,180 @@
|
||||
//
|
||||
// CSharpUtil.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public static class CSharpUtil |
||||
{ |
||||
/// <summary>
|
||||
/// Inverts a boolean condition. Note: The condition object can be frozen (from AST) it's cloned internally.
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to invert.</param>
|
||||
public static Expression InvertCondition(Expression condition) |
||||
{ |
||||
return InvertConditionInternal(condition); |
||||
} |
||||
|
||||
static Expression InvertConditionInternal(Expression condition) |
||||
{ |
||||
if (condition is ParenthesizedExpression) { |
||||
return new ParenthesizedExpression(InvertCondition(((ParenthesizedExpression)condition).Expression)); |
||||
} |
||||
|
||||
if (condition is UnaryOperatorExpression) { |
||||
var uOp = (UnaryOperatorExpression)condition; |
||||
if (uOp.Operator == UnaryOperatorType.Not) { |
||||
if (!(uOp.Parent is Expression)) |
||||
return GetInnerMostExpression(uOp.Expression).Clone(); |
||||
return uOp.Expression.Clone(); |
||||
} |
||||
return new UnaryOperatorExpression(UnaryOperatorType.Not, uOp.Clone()); |
||||
} |
||||
|
||||
if (condition is BinaryOperatorExpression) { |
||||
var bOp = (BinaryOperatorExpression)condition; |
||||
|
||||
if ((bOp.Operator == BinaryOperatorType.ConditionalAnd) || (bOp.Operator == BinaryOperatorType.ConditionalOr)) { |
||||
return new BinaryOperatorExpression(InvertCondition(bOp.Left), NegateConditionOperator(bOp.Operator), InvertCondition(bOp.Right)); |
||||
} else if ((bOp.Operator == BinaryOperatorType.Equality) || (bOp.Operator == BinaryOperatorType.InEquality) || (bOp.Operator == BinaryOperatorType.GreaterThan) |
||||
|| (bOp.Operator == BinaryOperatorType.GreaterThanOrEqual) || (bOp.Operator == BinaryOperatorType.LessThan) || |
||||
(bOp.Operator == BinaryOperatorType.LessThanOrEqual)) { |
||||
return new BinaryOperatorExpression(bOp.Left.Clone(), NegateRelationalOperator(bOp.Operator), bOp.Right.Clone()); |
||||
} else { |
||||
var negatedOp = NegateRelationalOperator(bOp.Operator); |
||||
if (negatedOp == BinaryOperatorType.Any) |
||||
return new UnaryOperatorExpression(UnaryOperatorType.Not, new ParenthesizedExpression(condition.Clone())); |
||||
bOp = (BinaryOperatorExpression)bOp.Clone(); |
||||
bOp.Operator = negatedOp; |
||||
return bOp; |
||||
} |
||||
} |
||||
if (condition is ConditionalExpression) { |
||||
var cEx = condition.Clone() as ConditionalExpression; |
||||
cEx.Condition = InvertCondition(cEx.Condition); |
||||
return cEx; |
||||
} |
||||
if (condition is PrimitiveExpression) { |
||||
var pex = condition as PrimitiveExpression; |
||||
if (pex.Value is bool) { |
||||
return new PrimitiveExpression(!((bool)pex.Value)); |
||||
} |
||||
} |
||||
|
||||
return new UnaryOperatorExpression(UnaryOperatorType.Not, AddParensForUnaryExpressionIfRequired(condition.Clone())); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// When negating an expression this is required, otherwise you would end up with
|
||||
/// a or b -> !a or b
|
||||
/// </summary>
|
||||
internal static Expression AddParensForUnaryExpressionIfRequired(Expression expression) |
||||
{ |
||||
if ((expression is BinaryOperatorExpression) || |
||||
(expression is AssignmentExpression) || |
||||
(expression is CastExpression) || |
||||
(expression is AsExpression) || |
||||
(expression is IsExpression) || |
||||
(expression is LambdaExpression) || |
||||
(expression is ConditionalExpression)) { |
||||
return new ParenthesizedExpression(expression); |
||||
} |
||||
|
||||
return expression; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get negation of the specified relational operator
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// negation of the specified relational operator, or BinaryOperatorType.Any if it's not a relational operator
|
||||
/// </returns>
|
||||
public static BinaryOperatorType NegateRelationalOperator(BinaryOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case BinaryOperatorType.GreaterThan: |
||||
return BinaryOperatorType.LessThanOrEqual; |
||||
case BinaryOperatorType.GreaterThanOrEqual: |
||||
return BinaryOperatorType.LessThan; |
||||
case BinaryOperatorType.Equality: |
||||
return BinaryOperatorType.InEquality; |
||||
case BinaryOperatorType.InEquality: |
||||
return BinaryOperatorType.Equality; |
||||
case BinaryOperatorType.LessThan: |
||||
return BinaryOperatorType.GreaterThanOrEqual; |
||||
case BinaryOperatorType.LessThanOrEqual: |
||||
return BinaryOperatorType.GreaterThan; |
||||
case BinaryOperatorType.ConditionalOr: |
||||
return BinaryOperatorType.ConditionalAnd; |
||||
case BinaryOperatorType.ConditionalAnd: |
||||
return BinaryOperatorType.ConditionalOr; |
||||
} |
||||
return BinaryOperatorType.Any; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true, if the specified operator is a relational operator
|
||||
/// </summary>
|
||||
public static bool IsRelationalOperator(BinaryOperatorType op) |
||||
{ |
||||
return NegateRelationalOperator(op) != BinaryOperatorType.Any; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Get negation of the condition operator
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// negation of the specified condition operator, or BinaryOperatorType.Any if it's not a condition operator
|
||||
/// </returns>
|
||||
public static BinaryOperatorType NegateConditionOperator(BinaryOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case BinaryOperatorType.ConditionalOr: |
||||
return BinaryOperatorType.ConditionalAnd; |
||||
case BinaryOperatorType.ConditionalAnd: |
||||
return BinaryOperatorType.ConditionalOr; |
||||
} |
||||
return BinaryOperatorType.Any; |
||||
} |
||||
|
||||
public static bool AreConditionsEqual(Expression cond1, Expression cond2) |
||||
{ |
||||
if (cond1 == null || cond2 == null) |
||||
return false; |
||||
return GetInnerMostExpression(cond1).IsMatch(GetInnerMostExpression(cond2)); |
||||
} |
||||
|
||||
public static Expression GetInnerMostExpression(Expression target) |
||||
{ |
||||
while (target is ParenthesizedExpression) |
||||
target = ((ParenthesizedExpression)target).Expression; |
||||
return target; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,259 @@
@@ -0,0 +1,259 @@
|
||||
//
|
||||
// ComposedType.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class ComposedType : AstType |
||||
{ |
||||
public static readonly TokenRole RefRole = new TokenRole("ref"); |
||||
public static readonly TokenRole NullableRole = new TokenRole("?"); |
||||
public static readonly TokenRole PointerRole = new TokenRole("*"); |
||||
public static readonly Role<ArraySpecifier> ArraySpecifierRole = new Role<ArraySpecifier>("ArraySpecifier"); |
||||
|
||||
/// <summary>
|
||||
/// Gets/sets whether this type has a 'ref' specifier.
|
||||
/// This is used for C# 7 ref locals/ref return.
|
||||
/// Parameters use ParameterDeclaration.ParameterModifier instead.
|
||||
/// </summary>
|
||||
public bool HasRefSpecifier { |
||||
get { |
||||
return !GetChildByRole(RefRole).IsNull; |
||||
} |
||||
set { |
||||
SetChildByRole(RefRole, value ? new CSharpTokenNode(TextLocation.Empty, null) : null); |
||||
} |
||||
} |
||||
|
||||
public AstType BaseType { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public bool HasNullableSpecifier { |
||||
get { |
||||
return !GetChildByRole(NullableRole).IsNull; |
||||
} |
||||
set { |
||||
SetChildByRole(NullableRole, value ? new CSharpTokenNode(TextLocation.Empty, null) : null); |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode NullableSpecifierToken { |
||||
get { |
||||
return GetChildByRole(NullableRole); |
||||
} |
||||
} |
||||
|
||||
public int PointerRank { |
||||
get { |
||||
return GetChildrenByRole(PointerRole).Count; |
||||
} |
||||
set { |
||||
if (value < 0) |
||||
throw new ArgumentOutOfRangeException(); |
||||
int d = this.PointerRank; |
||||
while (d > value) { |
||||
GetChildByRole(PointerRole).Remove(); |
||||
d--; |
||||
} |
||||
while (d < value) { |
||||
InsertChildBefore(GetChildByRole(PointerRole), new CSharpTokenNode(TextLocation.Empty, PointerRole), PointerRole); |
||||
d++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<ArraySpecifier> ArraySpecifiers { |
||||
get { return GetChildrenByRole (ArraySpecifierRole); } |
||||
} |
||||
|
||||
public AstNodeCollection<CSharpTokenNode> PointerTokens { |
||||
get { return GetChildrenByRole (PointerRole); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitComposedType (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitComposedType (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitComposedType (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ComposedType o = other as ComposedType; |
||||
return o != null |
||||
&& this.HasNullableSpecifier == o.HasNullableSpecifier |
||||
&& this.PointerRank == o.PointerRank |
||||
&& this.HasRefSpecifier == o.HasRefSpecifier |
||||
&& this.BaseType.DoMatch(o.BaseType, match) |
||||
&& this.ArraySpecifiers.DoMatch(o.ArraySpecifiers, match); |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
StringBuilder b = new StringBuilder(); |
||||
if (this.HasRefSpecifier) |
||||
b.Append("ref "); |
||||
b.Append(this.BaseType.ToString()); |
||||
if (this.HasNullableSpecifier) |
||||
b.Append('?'); |
||||
b.Append('*', this.PointerRank); |
||||
foreach (var arraySpecifier in this.ArraySpecifiers) { |
||||
b.Append('['); |
||||
b.Append(',', arraySpecifier.Dimensions - 1); |
||||
b.Append(']'); |
||||
} |
||||
return b.ToString(); |
||||
} |
||||
|
||||
public override AstType MakePointerType() |
||||
{ |
||||
if (ArraySpecifiers.Any()) { |
||||
return base.MakePointerType(); |
||||
} else { |
||||
this.PointerRank++; |
||||
return this; |
||||
} |
||||
} |
||||
|
||||
public override AstType MakeArrayType(int dimensions) |
||||
{ |
||||
InsertChildBefore(this.ArraySpecifiers.FirstOrDefault(), new ArraySpecifier(dimensions), ArraySpecifierRole); |
||||
return this; |
||||
} |
||||
|
||||
public override AstType MakeRefType() |
||||
{ |
||||
this.HasRefSpecifier = true; |
||||
return this; |
||||
} |
||||
|
||||
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) |
||||
{ |
||||
if (interningProvider == null) |
||||
interningProvider = InterningProvider.Dummy; |
||||
ITypeReference t = this.BaseType.ToTypeReference(lookupMode, interningProvider); |
||||
if (this.HasNullableSpecifier) { |
||||
t = interningProvider.Intern(NullableType.Create(t)); |
||||
} |
||||
int pointerRank = this.PointerRank; |
||||
for (int i = 0; i < pointerRank; i++) { |
||||
t = interningProvider.Intern(new PointerTypeReference(t)); |
||||
} |
||||
foreach (var a in this.ArraySpecifiers.Reverse()) { |
||||
t = interningProvider.Intern(new ArrayTypeReference(t, a.Dimensions)); |
||||
} |
||||
if (this.HasRefSpecifier) { |
||||
t = interningProvider.Intern(new ByReferenceTypeReference(t)); |
||||
} |
||||
return t; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// [,,,]
|
||||
/// </summary>
|
||||
public class ArraySpecifier : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public ArraySpecifier() |
||||
{ |
||||
} |
||||
|
||||
public ArraySpecifier(int dimensions) |
||||
{ |
||||
this.Dimensions = dimensions; |
||||
} |
||||
|
||||
public CSharpTokenNode LBracketToken { |
||||
get { return GetChildByRole (Roles.LBracket); } |
||||
} |
||||
|
||||
public int Dimensions { |
||||
get { return 1 + GetChildrenByRole(Roles.Comma).Count; } |
||||
set { |
||||
int d = this.Dimensions; |
||||
while (d > value) { |
||||
GetChildByRole(Roles.Comma).Remove(); |
||||
d--; |
||||
} |
||||
while (d < value) { |
||||
InsertChildBefore(GetChildByRole(Roles.Comma), new CSharpTokenNode(TextLocation.Empty, Roles.Comma), Roles.Comma); |
||||
d++; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode RBracketToken { |
||||
get { return GetChildByRole (Roles.RBracket); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitArraySpecifier (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitArraySpecifier (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArraySpecifier(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArraySpecifier o = other as ArraySpecifier; |
||||
return o != null && this.Dimensions == o.Dimensions; |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return "[" + new string(',', this.Dimensions - 1) + "]"; |
||||
} |
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a 'cref' reference in XML documentation.
|
||||
/// </summary>
|
||||
public class DocumentationReference : AstNode |
||||
{ |
||||
public static readonly Role<AstType> DeclaringTypeRole = new Role<AstType>("DeclaringType", AstType.Null); |
||||
public static readonly Role<AstType> ConversionOperatorReturnTypeRole = new Role<AstType>("ConversionOperatorReturnType", AstType.Null); |
||||
|
||||
SymbolKind symbolKind; |
||||
OperatorType operatorType; |
||||
bool hasParameterList; |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the entity type.
|
||||
/// Possible values are:
|
||||
/// <c>SymbolKind.Operator</c> for operators,
|
||||
/// <c>SymbolKind.Indexer</c> for indexers,
|
||||
/// <c>SymbolKind.TypeDefinition</c> for references to primitive types,
|
||||
/// and <c>SymbolKind.None</c> for everything else.
|
||||
/// </summary>
|
||||
public SymbolKind SymbolKind { |
||||
get { return symbolKind; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
symbolKind = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the operator type.
|
||||
/// This property is only used when SymbolKind==Operator.
|
||||
/// </summary>
|
||||
public OperatorType OperatorType { |
||||
get { return operatorType; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
operatorType = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets whether a parameter list was provided.
|
||||
/// </summary>
|
||||
public bool HasParameterList { |
||||
get { return hasParameterList; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
hasParameterList = value; |
||||
} |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Unknown; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the declaring type.
|
||||
/// </summary>
|
||||
public AstType DeclaringType { |
||||
get { return GetChildByRole(DeclaringTypeRole); } |
||||
set { SetChildByRole(DeclaringTypeRole, value); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the member name.
|
||||
/// This property is only used when SymbolKind==None.
|
||||
/// </summary>
|
||||
public string MemberName { |
||||
get { return GetChildByRole(Roles.Identifier).Name; } |
||||
set { SetChildByRole(Roles.Identifier, Identifier.Create(value)); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the return type of conversion operators.
|
||||
/// This property is only used when SymbolKind==Operator and OperatorType is explicit or implicit.
|
||||
/// </summary>
|
||||
public AstType ConversionOperatorReturnType { |
||||
get { return GetChildByRole(ConversionOperatorReturnTypeRole); } |
||||
set { SetChildByRole(ConversionOperatorReturnTypeRole, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole (Roles.Parameter); } |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
DocumentationReference o = other as DocumentationReference; |
||||
if (!(o != null && this.SymbolKind == o.SymbolKind && this.HasParameterList == o.HasParameterList)) |
||||
return false; |
||||
if (this.SymbolKind == SymbolKind.Operator) { |
||||
if (this.OperatorType != o.OperatorType) |
||||
return false; |
||||
if (this.OperatorType == OperatorType.Implicit || this.OperatorType == OperatorType.Explicit) { |
||||
if (!this.ConversionOperatorReturnType.DoMatch(o.ConversionOperatorReturnType, match)) |
||||
return false; |
||||
} |
||||
} else if (this.SymbolKind == SymbolKind.None) { |
||||
if (!MatchString(this.MemberName, o.MemberName)) |
||||
return false; |
||||
if (!this.TypeArguments.DoMatch(o.TypeArguments, match)) |
||||
return false; |
||||
} |
||||
return this.Parameters.DoMatch(o.Parameters, match); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitDocumentationReference (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitDocumentationReference (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDocumentationReference (this, data); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,88 @@
@@ -0,0 +1,88 @@
|
||||
//
|
||||
// ErrorNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin (http://www.xamarin.com);
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a parsing error in the ast. At the moment it only represents missing closing bracket.
|
||||
/// This closing bracket is replaced by a node at the highest possible position.
|
||||
/// (To make GetAstNodeAt (line, col) working).
|
||||
/// </summary>
|
||||
public class ErrorNode : AstNode |
||||
{ |
||||
static TextLocation maxLoc = new TextLocation (int.MaxValue, int.MaxValue); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return maxLoc; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return maxLoc; |
||||
} |
||||
} |
||||
|
||||
public ErrorNode () |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitErrorNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitErrorNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitErrorNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as ErrorNode; |
||||
return o != null; |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return "[ErrorNode]"; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// AnonymousMethodExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// [async] delegate(Parameters) {Body}
|
||||
/// </summary>
|
||||
public class AnonymousMethodExpression : Expression |
||||
{ |
||||
public readonly static TokenRole DelegateKeywordRole = new TokenRole ("delegate"); |
||||
public readonly static TokenRole AsyncModifierRole = LambdaExpression.AsyncModifierRole; |
||||
|
||||
bool isAsync; |
||||
|
||||
public bool IsAsync { |
||||
get { return isAsync; } |
||||
set { ThrowIfFrozen(); isAsync = value; } |
||||
} |
||||
|
||||
// used to tell the difference between delegate {} and delegate () {}
|
||||
bool hasParameterList; |
||||
|
||||
public bool HasParameterList { |
||||
get { return hasParameterList || Parameters.Any(); } |
||||
set { ThrowIfFrozen(); hasParameterList = value; } |
||||
} |
||||
|
||||
public CSharpTokenNode DelegateToken { |
||||
get { return GetChildByRole (DelegateKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole (Roles.Parameter); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public BlockStatement Body { |
||||
get { return GetChildByRole (Roles.Body); } |
||||
set { SetChildByRole (Roles.Body, value); } |
||||
} |
||||
|
||||
public AnonymousMethodExpression () |
||||
{ |
||||
} |
||||
|
||||
public AnonymousMethodExpression (BlockStatement body, IEnumerable<ParameterDeclaration> parameters = null) |
||||
{ |
||||
if (parameters != null) { |
||||
hasParameterList = true; |
||||
foreach (var parameter in parameters) { |
||||
AddChild (parameter, Roles.Parameter); |
||||
} |
||||
} |
||||
AddChild (body, Roles.Body); |
||||
} |
||||
|
||||
public AnonymousMethodExpression (BlockStatement body, params ParameterDeclaration[] parameters) : this (body, (IEnumerable<ParameterDeclaration>)parameters) |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAnonymousMethodExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAnonymousMethodExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAnonymousMethodExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
AnonymousMethodExpression o = other as AnonymousMethodExpression; |
||||
return o != null && this.IsAsync == o.IsAsync && this.HasParameterList == o.HasParameterList |
||||
&& this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// AnonymousTypeCreateExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// new { [ExpressionList] }
|
||||
/// </summary>
|
||||
public class AnonymousTypeCreateExpression : Expression |
||||
{ |
||||
public readonly static TokenRole NewKeywordRole = new TokenRole ("new"); |
||||
|
||||
public CSharpTokenNode NewToken { |
||||
get { return GetChildByRole (NewKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Initializers { |
||||
get { return GetChildrenByRole (Roles.Expression); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public AnonymousTypeCreateExpression () |
||||
{ |
||||
} |
||||
|
||||
public AnonymousTypeCreateExpression (IEnumerable<Expression> initializers) |
||||
{ |
||||
foreach (var ini in initializers) { |
||||
AddChild (ini, Roles.Expression); |
||||
} |
||||
} |
||||
|
||||
public AnonymousTypeCreateExpression (params Expression[] initializer) : this ((IEnumerable<Expression>)initializer) |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAnonymousTypeCreateExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAnonymousTypeCreateExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAnonymousTypeCreateExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as AnonymousTypeCreateExpression; |
||||
return o != null && this.Initializers.DoMatch(o.Initializers, match); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// new Type[Dimensions]
|
||||
/// </summary>
|
||||
public class ArrayCreateExpression : Expression |
||||
{ |
||||
public readonly static TokenRole NewKeywordRole = new TokenRole ("new"); |
||||
public readonly static Role<ArraySpecifier> AdditionalArraySpecifierRole = new Role<ArraySpecifier>("AdditionalArraySpecifier"); |
||||
public readonly static Role<ArrayInitializerExpression> InitializerRole = new Role<ArrayInitializerExpression>("Initializer", ArrayInitializerExpression.Null); |
||||
|
||||
public CSharpTokenNode NewToken { |
||||
get { return GetChildByRole (NewKeywordRole); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole (Roles.Argument); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets additional array ranks (those without size info).
|
||||
/// Empty for "new int[5,1]"; will contain a single element for "new int[5][]".
|
||||
/// </summary>
|
||||
public AstNodeCollection<ArraySpecifier> AdditionalArraySpecifiers { |
||||
get { return GetChildrenByRole(AdditionalArraySpecifierRole); } |
||||
} |
||||
|
||||
public ArrayInitializerExpression Initializer { |
||||
get { return GetChildByRole (InitializerRole); } |
||||
set { SetChildByRole (InitializerRole, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitArrayCreateExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitArrayCreateExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArrayCreateExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArrayCreateExpression o = other as ArrayCreateExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.AdditionalArraySpecifiers.DoMatch(o.AdditionalArraySpecifiers, match) && this.Initializer.DoMatch(o.Initializer, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,192 @@
@@ -0,0 +1,192 @@
|
||||
//
|
||||
// ArrayInitializerExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// { Elements }
|
||||
/// </summary>
|
||||
public class ArrayInitializerExpression : Expression |
||||
{ |
||||
/// <summary>
|
||||
/// For ease of use purposes in the resolver the ast representation
|
||||
/// of { a, b, c } is { {a}, {b}, {c} }.
|
||||
/// If IsSingleElement is true then this array initializer expression is a generated one.
|
||||
/// That has no meaning in the source code (and contains no brace tokens).
|
||||
/// </summary>
|
||||
public virtual bool IsSingleElement { |
||||
get { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public ArrayInitializerExpression() |
||||
{ |
||||
} |
||||
|
||||
public ArrayInitializerExpression(IEnumerable<Expression> elements) |
||||
{ |
||||
this.Elements.AddRange(elements); |
||||
} |
||||
|
||||
public ArrayInitializerExpression(params Expression[] elements) |
||||
{ |
||||
this.Elements.AddRange(elements); |
||||
} |
||||
|
||||
#region Null
|
||||
public new static readonly ArrayInitializerExpression Null = new NullArrayInitializerExpression (); |
||||
|
||||
sealed class NullArrayInitializerExpression : ArrayInitializerExpression |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public CSharpTokenNode LBraceToken { |
||||
get { return GetChildByRole (Roles.LBrace); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Elements { |
||||
get { return GetChildrenByRole(Roles.Expression); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBraceToken { |
||||
get { return GetChildByRole (Roles.RBrace); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitArrayInitializerExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitArrayInitializerExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitArrayInitializerExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ArrayInitializerExpression o = other as ArrayInitializerExpression; |
||||
return o != null && this.Elements.DoMatch(o.Elements, match); |
||||
} |
||||
|
||||
public static ArrayInitializerExpression CreateSingleElementInitializer () |
||||
{ |
||||
return new SingleArrayInitializerExpression(); |
||||
} |
||||
/// <summary>
|
||||
/// Single elements in array initializers are represented with this special class.
|
||||
/// </summary>
|
||||
class SingleArrayInitializerExpression : ArrayInitializerExpression |
||||
{ |
||||
public override bool IsSingleElement { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator ArrayInitializerExpression(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : ArrayInitializerExpression, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// AsExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Expression as TypeReference
|
||||
/// </summary>
|
||||
public class AsExpression : Expression |
||||
{ |
||||
public readonly static TokenRole AsKeywordRole = new TokenRole ("as"); |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode AsToken { |
||||
get { return GetChildByRole (AsKeywordRole); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public AsExpression () |
||||
{ |
||||
} |
||||
|
||||
public AsExpression (Expression expression, AstType type) |
||||
{ |
||||
AddChild (expression, Roles.Expression); |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAsExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAsExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAsExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
AsExpression o = other as AsExpression; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,304 @@
@@ -0,0 +1,304 @@
|
||||
//
|
||||
// AssignmentExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq.Expressions; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Left Operator= Right
|
||||
/// </summary>
|
||||
public class AssignmentExpression : Expression |
||||
{ |
||||
// reuse roles from BinaryOperatorExpression
|
||||
public readonly static Role<Expression> LeftRole = BinaryOperatorExpression.LeftRole; |
||||
public readonly static Role<Expression> RightRole = BinaryOperatorExpression.RightRole; |
||||
|
||||
public readonly static TokenRole AssignRole = new TokenRole ("="); |
||||
public readonly static TokenRole AddRole = new TokenRole ("+="); |
||||
public readonly static TokenRole SubtractRole = new TokenRole ("-="); |
||||
public readonly static TokenRole MultiplyRole = new TokenRole ("*="); |
||||
public readonly static TokenRole DivideRole = new TokenRole ("/="); |
||||
public readonly static TokenRole ModulusRole = new TokenRole ("%="); |
||||
public readonly static TokenRole ShiftLeftRole = new TokenRole ("<<="); |
||||
public readonly static TokenRole ShiftRightRole = new TokenRole (">>="); |
||||
public readonly static TokenRole BitwiseAndRole = new TokenRole ("&="); |
||||
public readonly static TokenRole BitwiseOrRole = new TokenRole ("|="); |
||||
public readonly static TokenRole ExclusiveOrRole = new TokenRole ("^="); |
||||
|
||||
public AssignmentExpression() |
||||
{ |
||||
} |
||||
|
||||
public AssignmentExpression(Expression left, Expression right) |
||||
{ |
||||
this.Left = left; |
||||
this.Right = right; |
||||
} |
||||
|
||||
public AssignmentExpression(Expression left, AssignmentOperatorType op, Expression right) |
||||
{ |
||||
this.Left = left; |
||||
this.Operator = op; |
||||
this.Right = right; |
||||
} |
||||
|
||||
public AssignmentOperatorType Operator { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Expression Left { |
||||
get { return GetChildByRole (LeftRole); } |
||||
set { SetChildByRole(LeftRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode OperatorToken { |
||||
get { return GetChildByRole (GetOperatorRole(Operator)); } |
||||
} |
||||
|
||||
public Expression Right { |
||||
get { return GetChildByRole (RightRole); } |
||||
set { SetChildByRole(RightRole, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAssignmentExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAssignmentExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAssignmentExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
AssignmentExpression o = other as AssignmentExpression; |
||||
return o != null && (this.Operator == AssignmentOperatorType.Any || this.Operator == o.Operator) |
||||
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match); |
||||
} |
||||
|
||||
public static TokenRole GetOperatorRole(AssignmentOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case AssignmentOperatorType.Assign: |
||||
return AssignRole; |
||||
case AssignmentOperatorType.Add: |
||||
return AddRole; |
||||
case AssignmentOperatorType.Subtract: |
||||
return SubtractRole; |
||||
case AssignmentOperatorType.Multiply: |
||||
return MultiplyRole; |
||||
case AssignmentOperatorType.Divide: |
||||
return DivideRole; |
||||
case AssignmentOperatorType.Modulus: |
||||
return ModulusRole; |
||||
case AssignmentOperatorType.ShiftLeft: |
||||
return ShiftLeftRole; |
||||
case AssignmentOperatorType.ShiftRight: |
||||
return ShiftRightRole; |
||||
case AssignmentOperatorType.BitwiseAnd: |
||||
return BitwiseAndRole; |
||||
case AssignmentOperatorType.BitwiseOr: |
||||
return BitwiseOrRole; |
||||
case AssignmentOperatorType.ExclusiveOr: |
||||
return ExclusiveOrRole; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for AssignmentOperatorType"); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the binary operator for the specified compound assignment operator.
|
||||
/// Returns null if 'op' is not a compound assignment.
|
||||
/// </summary>
|
||||
public static BinaryOperatorType? GetCorrespondingBinaryOperator(AssignmentOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case AssignmentOperatorType.Assign: |
||||
return null; |
||||
case AssignmentOperatorType.Add: |
||||
return BinaryOperatorType.Add; |
||||
case AssignmentOperatorType.Subtract: |
||||
return BinaryOperatorType.Subtract; |
||||
case AssignmentOperatorType.Multiply: |
||||
return BinaryOperatorType.Multiply; |
||||
case AssignmentOperatorType.Divide: |
||||
return BinaryOperatorType.Divide; |
||||
case AssignmentOperatorType.Modulus: |
||||
return BinaryOperatorType.Modulus; |
||||
case AssignmentOperatorType.ShiftLeft: |
||||
return BinaryOperatorType.ShiftLeft; |
||||
case AssignmentOperatorType.ShiftRight: |
||||
return BinaryOperatorType.ShiftRight; |
||||
case AssignmentOperatorType.BitwiseAnd: |
||||
return BinaryOperatorType.BitwiseAnd; |
||||
case AssignmentOperatorType.BitwiseOr: |
||||
return BinaryOperatorType.BitwiseOr; |
||||
case AssignmentOperatorType.ExclusiveOr: |
||||
return BinaryOperatorType.ExclusiveOr; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for AssignmentOperatorType"); |
||||
} |
||||
} |
||||
|
||||
public static ExpressionType GetLinqNodeType(AssignmentOperatorType op, bool checkForOverflow) |
||||
{ |
||||
switch (op) { |
||||
case AssignmentOperatorType.Assign: |
||||
return ExpressionType.Assign; |
||||
case AssignmentOperatorType.Add: |
||||
return checkForOverflow ? ExpressionType.AddAssignChecked : ExpressionType.AddAssign; |
||||
case AssignmentOperatorType.Subtract: |
||||
return checkForOverflow ? ExpressionType.SubtractAssignChecked : ExpressionType.SubtractAssign; |
||||
case AssignmentOperatorType.Multiply: |
||||
return checkForOverflow ? ExpressionType.MultiplyAssignChecked : ExpressionType.MultiplyAssign; |
||||
case AssignmentOperatorType.Divide: |
||||
return ExpressionType.DivideAssign; |
||||
case AssignmentOperatorType.Modulus: |
||||
return ExpressionType.ModuloAssign; |
||||
case AssignmentOperatorType.ShiftLeft: |
||||
return ExpressionType.LeftShiftAssign; |
||||
case AssignmentOperatorType.ShiftRight: |
||||
return ExpressionType.RightShiftAssign; |
||||
case AssignmentOperatorType.BitwiseAnd: |
||||
return ExpressionType.AndAssign; |
||||
case AssignmentOperatorType.BitwiseOr: |
||||
return ExpressionType.OrAssign; |
||||
case AssignmentOperatorType.ExclusiveOr: |
||||
return ExpressionType.ExclusiveOrAssign; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for AssignmentOperatorType"); |
||||
} |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
|
||||
public enum AssignmentOperatorType |
||||
{ |
||||
/// <summary>left = right</summary>
|
||||
Assign, |
||||
|
||||
/// <summary>left += right</summary>
|
||||
Add, |
||||
/// <summary>left -= right</summary>
|
||||
Subtract, |
||||
/// <summary>left *= right</summary>
|
||||
Multiply, |
||||
/// <summary>left /= right</summary>
|
||||
Divide, |
||||
/// <summary>left %= right</summary>
|
||||
Modulus, |
||||
|
||||
/// <summary>left <<= right</summary>
|
||||
ShiftLeft, |
||||
/// <summary>left >>= right</summary>
|
||||
ShiftRight, |
||||
|
||||
/// <summary>left &= right</summary>
|
||||
BitwiseAnd, |
||||
/// <summary>left |= right</summary>
|
||||
BitwiseOr, |
||||
/// <summary>left ^= right</summary>
|
||||
ExclusiveOr, |
||||
|
||||
/// <summary>Any operator (for pattern matching)</summary>
|
||||
Any |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// BaseReferenceExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// base
|
||||
/// </summary>
|
||||
public class BaseReferenceExpression : Expression |
||||
{ |
||||
public TextLocation Location { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return Location; |
||||
} |
||||
} |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (Location.Line, Location.Column + "base".Length); |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitBaseReferenceExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitBaseReferenceExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBaseReferenceExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
BaseReferenceExpression o = other as BaseReferenceExpression; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,325 @@
@@ -0,0 +1,325 @@
|
||||
//
|
||||
// BinaryOperatorExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq.Expressions; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Left Operator Right
|
||||
/// </summary>
|
||||
public class BinaryOperatorExpression : Expression |
||||
{ |
||||
public readonly static TokenRole BitwiseAndRole = new TokenRole ("&"); |
||||
public readonly static TokenRole BitwiseOrRole = new TokenRole ("|"); |
||||
public readonly static TokenRole ConditionalAndRole = new TokenRole ("&&"); |
||||
public readonly static TokenRole ConditionalOrRole = new TokenRole ("||"); |
||||
public readonly static TokenRole ExclusiveOrRole = new TokenRole ("^"); |
||||
public readonly static TokenRole GreaterThanRole = new TokenRole (">"); |
||||
public readonly static TokenRole GreaterThanOrEqualRole = new TokenRole (">="); |
||||
public readonly static TokenRole EqualityRole = new TokenRole ("=="); |
||||
public readonly static TokenRole InEqualityRole = new TokenRole ("!="); |
||||
public readonly static TokenRole LessThanRole = new TokenRole ("<"); |
||||
public readonly static TokenRole LessThanOrEqualRole = new TokenRole ("<="); |
||||
public readonly static TokenRole AddRole = new TokenRole ("+"); |
||||
public readonly static TokenRole SubtractRole = new TokenRole ("-"); |
||||
public readonly static TokenRole MultiplyRole = new TokenRole ("*"); |
||||
public readonly static TokenRole DivideRole = new TokenRole ("/"); |
||||
public readonly static TokenRole ModulusRole = new TokenRole ("%"); |
||||
public readonly static TokenRole ShiftLeftRole = new TokenRole ("<<"); |
||||
public readonly static TokenRole ShiftRightRole = new TokenRole (">>"); |
||||
public readonly static TokenRole NullCoalescingRole = new TokenRole ("??"); |
||||
|
||||
public readonly static Role<Expression> LeftRole = new Role<Expression>("Left", Expression.Null); |
||||
public readonly static Role<Expression> RightRole = new Role<Expression>("Right", Expression.Null); |
||||
|
||||
public BinaryOperatorExpression() |
||||
{ |
||||
} |
||||
|
||||
public BinaryOperatorExpression(Expression left, BinaryOperatorType op, Expression right) |
||||
{ |
||||
this.Left = left; |
||||
this.Operator = op; |
||||
this.Right = right; |
||||
} |
||||
|
||||
public BinaryOperatorType Operator { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public Expression Left { |
||||
get { return GetChildByRole (LeftRole); } |
||||
set { SetChildByRole(LeftRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode OperatorToken { |
||||
get { return GetChildByRole (GetOperatorRole (Operator)); } |
||||
} |
||||
|
||||
public Expression Right { |
||||
get { return GetChildByRole (RightRole); } |
||||
set { SetChildByRole (RightRole, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitBinaryOperatorExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitBinaryOperatorExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBinaryOperatorExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
BinaryOperatorExpression o = other as BinaryOperatorExpression; |
||||
return o != null && (this.Operator == BinaryOperatorType.Any || this.Operator == o.Operator) |
||||
&& this.Left.DoMatch(o.Left, match) && this.Right.DoMatch(o.Right, match); |
||||
} |
||||
|
||||
public static TokenRole GetOperatorRole (BinaryOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case BinaryOperatorType.BitwiseAnd: |
||||
return BitwiseAndRole; |
||||
case BinaryOperatorType.BitwiseOr: |
||||
return BitwiseOrRole; |
||||
case BinaryOperatorType.ConditionalAnd: |
||||
return ConditionalAndRole; |
||||
case BinaryOperatorType.ConditionalOr: |
||||
return ConditionalOrRole; |
||||
case BinaryOperatorType.ExclusiveOr: |
||||
return ExclusiveOrRole; |
||||
case BinaryOperatorType.GreaterThan: |
||||
return GreaterThanRole; |
||||
case BinaryOperatorType.GreaterThanOrEqual: |
||||
return GreaterThanOrEqualRole; |
||||
case BinaryOperatorType.Equality: |
||||
return EqualityRole; |
||||
case BinaryOperatorType.InEquality: |
||||
return InEqualityRole; |
||||
case BinaryOperatorType.LessThan: |
||||
return LessThanRole; |
||||
case BinaryOperatorType.LessThanOrEqual: |
||||
return LessThanOrEqualRole; |
||||
case BinaryOperatorType.Add: |
||||
return AddRole; |
||||
case BinaryOperatorType.Subtract: |
||||
return SubtractRole; |
||||
case BinaryOperatorType.Multiply: |
||||
return MultiplyRole; |
||||
case BinaryOperatorType.Divide: |
||||
return DivideRole; |
||||
case BinaryOperatorType.Modulus: |
||||
return ModulusRole; |
||||
case BinaryOperatorType.ShiftLeft: |
||||
return ShiftLeftRole; |
||||
case BinaryOperatorType.ShiftRight: |
||||
return ShiftRightRole; |
||||
case BinaryOperatorType.NullCoalescing: |
||||
return NullCoalescingRole; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for BinaryOperatorType"); |
||||
} |
||||
} |
||||
|
||||
public static ExpressionType GetLinqNodeType(BinaryOperatorType op, bool checkForOverflow) |
||||
{ |
||||
switch (op) { |
||||
case BinaryOperatorType.BitwiseAnd: |
||||
return ExpressionType.And; |
||||
case BinaryOperatorType.BitwiseOr: |
||||
return ExpressionType.Or; |
||||
case BinaryOperatorType.ConditionalAnd: |
||||
return ExpressionType.AndAlso; |
||||
case BinaryOperatorType.ConditionalOr: |
||||
return ExpressionType.OrElse; |
||||
case BinaryOperatorType.ExclusiveOr: |
||||
return ExpressionType.ExclusiveOr; |
||||
case BinaryOperatorType.GreaterThan: |
||||
return ExpressionType.GreaterThan; |
||||
case BinaryOperatorType.GreaterThanOrEqual: |
||||
return ExpressionType.GreaterThanOrEqual; |
||||
case BinaryOperatorType.Equality: |
||||
return ExpressionType.Equal; |
||||
case BinaryOperatorType.InEquality: |
||||
return ExpressionType.NotEqual; |
||||
case BinaryOperatorType.LessThan: |
||||
return ExpressionType.LessThan; |
||||
case BinaryOperatorType.LessThanOrEqual: |
||||
return ExpressionType.LessThanOrEqual; |
||||
case BinaryOperatorType.Add: |
||||
return checkForOverflow ? ExpressionType.AddChecked : ExpressionType.Add; |
||||
case BinaryOperatorType.Subtract: |
||||
return checkForOverflow ? ExpressionType.SubtractChecked : ExpressionType.Subtract; |
||||
case BinaryOperatorType.Multiply: |
||||
return checkForOverflow ? ExpressionType.MultiplyChecked : ExpressionType.Multiply; |
||||
case BinaryOperatorType.Divide: |
||||
return ExpressionType.Divide; |
||||
case BinaryOperatorType.Modulus: |
||||
return ExpressionType.Modulo; |
||||
case BinaryOperatorType.ShiftLeft: |
||||
return ExpressionType.LeftShift; |
||||
case BinaryOperatorType.ShiftRight: |
||||
return ExpressionType.RightShift; |
||||
case BinaryOperatorType.NullCoalescing: |
||||
return ExpressionType.Coalesce; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for BinaryOperatorType"); |
||||
} |
||||
} |
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
|
||||
public enum BinaryOperatorType |
||||
{ |
||||
/// <summary>
|
||||
/// Any binary operator (used in pattern matching)
|
||||
/// </summary>
|
||||
Any, |
||||
|
||||
// We avoid 'logical or' on purpose, because it's not clear if that refers to the bitwise
|
||||
// or to the short-circuiting (conditional) operator:
|
||||
// MCS and old NRefactory used bitwise='|', logical='||'
|
||||
// but the C# spec uses logical='|', conditional='||'
|
||||
/// <summary>left & right</summary>
|
||||
BitwiseAnd, |
||||
/// <summary>left | right</summary>
|
||||
BitwiseOr, |
||||
/// <summary>left && right</summary>
|
||||
ConditionalAnd, |
||||
/// <summary>left || right</summary>
|
||||
ConditionalOr, |
||||
/// <summary>left ^ right</summary>
|
||||
ExclusiveOr, |
||||
|
||||
/// <summary>left > right</summary>
|
||||
GreaterThan, |
||||
/// <summary>left >= right</summary>
|
||||
GreaterThanOrEqual, |
||||
/// <summary>left == right</summary>
|
||||
Equality, |
||||
/// <summary>left != right</summary>
|
||||
InEquality, |
||||
/// <summary>left < right</summary>
|
||||
LessThan, |
||||
/// <summary>left <= right</summary>
|
||||
LessThanOrEqual, |
||||
|
||||
/// <summary>left + right</summary>
|
||||
Add, |
||||
/// <summary>left - right</summary>
|
||||
Subtract, |
||||
/// <summary>left * right</summary>
|
||||
Multiply, |
||||
/// <summary>left / right</summary>
|
||||
Divide, |
||||
/// <summary>left % right</summary>
|
||||
Modulus, |
||||
|
||||
/// <summary>left << right</summary>
|
||||
ShiftLeft, |
||||
/// <summary>left >> right</summary>
|
||||
ShiftRight, |
||||
|
||||
/// <summary>left ?? right</summary>
|
||||
NullCoalescing |
||||
} |
||||
} |
@ -0,0 +1,152 @@
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// CastExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// (CastTo)Expression
|
||||
/// </summary>
|
||||
public class CastExpression : Expression |
||||
{ |
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CastExpression () |
||||
{ |
||||
} |
||||
|
||||
public CastExpression (AstType castToType, Expression expression) |
||||
{ |
||||
AddChild (castToType, Roles.Type); |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitCastExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitCastExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCastExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CastExpression o = other as CastExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// CheckedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// checked(Expression)
|
||||
/// </summary>
|
||||
public class CheckedExpression : Expression |
||||
{ |
||||
public readonly static TokenRole CheckedKeywordRole = new TokenRole ("checked"); |
||||
|
||||
public CSharpTokenNode CheckedToken { |
||||
get { return GetChildByRole (CheckedKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public CheckedExpression () |
||||
{ |
||||
} |
||||
|
||||
public CheckedExpression (Expression expression) |
||||
{ |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitCheckedExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitCheckedExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCheckedExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CheckedExpression o = other as CheckedExpression; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// ConditionalExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Condition ? TrueExpression : FalseExpression
|
||||
/// </summary>
|
||||
public class ConditionalExpression : Expression |
||||
{ |
||||
public readonly static Role<Expression> ConditionRole = Roles.Condition; |
||||
public readonly static TokenRole QuestionMarkRole = new TokenRole("?"); |
||||
public readonly static Role<Expression> TrueRole = new Role<Expression>("True", Expression.Null); |
||||
public readonly static TokenRole ColonRole = Roles.Colon; |
||||
public readonly static Role<Expression> FalseRole = new Role<Expression>("False", Expression.Null); |
||||
|
||||
public Expression Condition { |
||||
get { return GetChildByRole(ConditionRole); } |
||||
set { SetChildByRole(ConditionRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode QuestionMarkToken { |
||||
get { return GetChildByRole (QuestionMarkRole); } |
||||
} |
||||
|
||||
public Expression TrueExpression { |
||||
get { return GetChildByRole(TrueRole); } |
||||
set { SetChildByRole(TrueRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode ColonToken { |
||||
get { return GetChildByRole (ColonRole); } |
||||
} |
||||
|
||||
public Expression FalseExpression { |
||||
get { return GetChildByRole(FalseRole); } |
||||
set { SetChildByRole(FalseRole, value); } |
||||
} |
||||
|
||||
public ConditionalExpression () |
||||
{ |
||||
} |
||||
|
||||
public ConditionalExpression (Expression condition, Expression trueExpression, Expression falseExpression) |
||||
{ |
||||
AddChild (condition, ConditionRole); |
||||
AddChild (trueExpression, TrueRole); |
||||
AddChild (falseExpression, FalseRole); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitConditionalExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitConditionalExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitConditionalExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ConditionalExpression o = other as ConditionalExpression; |
||||
return o != null && this.Condition.DoMatch(o.Condition, match) && this.TrueExpression.DoMatch(o.TrueExpression, match) && this.FalseExpression.DoMatch(o.FalseExpression, match); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// DefaultValueExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// default(Type)
|
||||
/// </summary>
|
||||
public class DefaultValueExpression : Expression |
||||
{ |
||||
public readonly static TokenRole DefaultKeywordRole = new TokenRole ("default"); |
||||
|
||||
public CSharpTokenNode DefaultToken { |
||||
get { return GetChildByRole (DefaultKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public DefaultValueExpression () |
||||
{ |
||||
} |
||||
|
||||
public DefaultValueExpression (AstType type) |
||||
{ |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitDefaultValueExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitDefaultValueExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDefaultValueExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
DefaultValueExpression o = other as DefaultValueExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// DirectionExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum FieldDirection |
||||
{ |
||||
None, |
||||
Out, |
||||
Ref |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// ref Expression
|
||||
/// </summary>
|
||||
public class DirectionExpression : Expression |
||||
{ |
||||
public readonly static TokenRole RefKeywordRole = new TokenRole ("ref"); |
||||
public readonly static TokenRole OutKeywordRole = new TokenRole ("out"); |
||||
|
||||
public FieldDirection FieldDirection { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public CSharpTokenNode FieldDirectionToken { |
||||
get { return FieldDirection == ICSharpCode.NRefactory.CSharp.FieldDirection.Ref ? GetChildByRole (RefKeywordRole) : GetChildByRole (OutKeywordRole); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public DirectionExpression () |
||||
{ |
||||
} |
||||
|
||||
public DirectionExpression (FieldDirection direction, Expression expression) |
||||
{ |
||||
this.FieldDirection = direction; |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitDirectionExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitDirectionExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDirectionExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
DirectionExpression o = other as DirectionExpression; |
||||
return o != null && this.FieldDirection == o.FieldDirection && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,129 @@
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// ErrorExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
[Obsolete("This class is obsolete. Remove all referencing code.")] |
||||
public class EmptyExpression : AstNode |
||||
{ |
||||
#region implemented abstract members of AstNode
|
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
|
||||
} |
||||
|
||||
public class ErrorExpression : Expression |
||||
{ |
||||
TextLocation location; |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
public string Error { |
||||
get; |
||||
private set; |
||||
} |
||||
|
||||
public ErrorExpression () |
||||
{ |
||||
} |
||||
|
||||
public ErrorExpression (TextLocation location) |
||||
{ |
||||
this.location = location; |
||||
} |
||||
|
||||
public ErrorExpression (string error) |
||||
{ |
||||
this.Error = error; |
||||
} |
||||
|
||||
public ErrorExpression (string error, TextLocation location) |
||||
{ |
||||
this.location = location; |
||||
this.Error = error; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitErrorNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitErrorNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitErrorNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch (AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as ErrorExpression; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,230 @@
@@ -0,0 +1,230 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for expressions.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is useful even though it doesn't provide any additional functionality:
|
||||
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be an expression"
|
||||
/// </remarks>
|
||||
public abstract class Expression : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly Expression Null = new NullExpression (); |
||||
|
||||
sealed class NullExpression : Expression |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator Expression(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : Expression, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Expression; |
||||
} |
||||
} |
||||
|
||||
public new Expression Clone() |
||||
{ |
||||
return (Expression)base.Clone(); |
||||
} |
||||
|
||||
public Expression ReplaceWith(Func<Expression, Expression> replaceFunction) |
||||
{ |
||||
if (replaceFunction == null) |
||||
throw new ArgumentNullException("replaceFunction"); |
||||
return (Expression)base.ReplaceWith(node => replaceFunction((Expression)node)); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
/// <summary>
|
||||
/// Builds an member reference expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an indexer expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = this; |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an indexer expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = this; |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual InvocationExpression Invoke(string methodName, IEnumerable<Expression> arguments) |
||||
{ |
||||
return Invoke(methodName, null, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual InvocationExpression Invoke(string methodName, params Expression[] arguments) |
||||
{ |
||||
return Invoke(methodName, null, arguments); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = this; |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = this; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Builds an invocation expression using this expression as target.
|
||||
/// </summary>
|
||||
public virtual InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = this; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public virtual CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = this }; |
||||
} |
||||
|
||||
public virtual AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = this }; |
||||
} |
||||
|
||||
public virtual IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = this }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// IdentifierExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class IdentifierExpression : Expression |
||||
{ |
||||
public IdentifierExpression() |
||||
{ |
||||
} |
||||
|
||||
public IdentifierExpression(string identifier) |
||||
{ |
||||
this.Identifier = identifier; |
||||
} |
||||
|
||||
public IdentifierExpression(string identifier, TextLocation location) |
||||
{ |
||||
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (identifier, location)); |
||||
} |
||||
|
||||
// public Identifier IdentifierToken {
|
||||
// get { return GetChildByRole (Roles.Identifier); }
|
||||
// }
|
||||
|
||||
public string Identifier { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value)); |
||||
} |
||||
} |
||||
|
||||
public Identifier IdentifierToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitIdentifierExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitIdentifierExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIdentifierExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
IdentifierExpression o = other as IdentifierExpression; |
||||
return o != null && MatchString(this.Identifier, o.Identifier) && this.TypeArguments.DoMatch(o.TypeArguments, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// IndexerExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Target[Arguments]
|
||||
/// </summary>
|
||||
public class IndexerExpression : Expression |
||||
{ |
||||
public Expression Target { |
||||
get { return GetChildByRole (Roles.TargetExpression); } |
||||
set { SetChildByRole(Roles.TargetExpression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode LBracketToken { |
||||
get { return GetChildByRole (Roles.LBracket); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole<Expression>(Roles.Argument); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBracketToken { |
||||
get { return GetChildByRole (Roles.RBracket); } |
||||
} |
||||
|
||||
public IndexerExpression () |
||||
{ |
||||
} |
||||
|
||||
public IndexerExpression (Expression target, IEnumerable<Expression> arguments) |
||||
{ |
||||
AddChild (target, Roles.TargetExpression); |
||||
if (arguments != null) { |
||||
foreach (var arg in arguments) { |
||||
AddChild (arg, Roles.Argument); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public IndexerExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments) |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitIndexerExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitIndexerExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIndexerExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
IndexerExpression o = other as IndexerExpression; |
||||
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// InvocationExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Target(Arguments)
|
||||
/// </summary>
|
||||
public class InvocationExpression : Expression |
||||
{ |
||||
public Expression Target { |
||||
get { return GetChildByRole (Roles.TargetExpression); } |
||||
set { SetChildByRole(Roles.TargetExpression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole<Expression>(Roles.Argument); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitInvocationExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitInvocationExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitInvocationExpression (this, data); |
||||
} |
||||
|
||||
public InvocationExpression () |
||||
{ |
||||
} |
||||
|
||||
public InvocationExpression (Expression target, IEnumerable<Expression> arguments) |
||||
{ |
||||
AddChild (target, Roles.TargetExpression); |
||||
if (arguments != null) { |
||||
foreach (var arg in arguments) { |
||||
AddChild (arg, Roles.Argument); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public InvocationExpression (Expression target, params Expression[] arguments) : this (target, (IEnumerable<Expression>)arguments) |
||||
{ |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
InvocationExpression o = other as InvocationExpression; |
||||
return o != null && this.Target.DoMatch(o.Target, match) && this.Arguments.DoMatch(o.Arguments, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,150 @@
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// TypeOfIsExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Expression is Type
|
||||
/// </summary>
|
||||
public class IsExpression : Expression |
||||
{ |
||||
public readonly static TokenRole IsKeywordRole = new TokenRole ("is"); |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole(Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode IsToken { |
||||
get { return GetChildByRole (IsKeywordRole); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public IsExpression() |
||||
{ |
||||
} |
||||
|
||||
public IsExpression (Expression expression, AstType type) |
||||
{ |
||||
AddChild (expression, Roles.Expression); |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitIsExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitIsExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIsExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
IsExpression o = other as IsExpression; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match) && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
|
||||
#region Builder methods
|
||||
public override MemberReferenceExpression Member(string memberName) |
||||
{ |
||||
return new MemberReferenceExpression { Target = this, MemberName = memberName }; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(IEnumerable<Expression> arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override IndexerExpression Indexer(params Expression[] arguments) |
||||
{ |
||||
IndexerExpression expr = new IndexerExpression(); |
||||
expr.Target = new ParenthesizedExpression(this); |
||||
expr.Arguments.AddRange(arguments); |
||||
return expr; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(string methodName, IEnumerable<AstType> typeArguments, IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
MemberReferenceExpression mre = new MemberReferenceExpression(); |
||||
mre.Target = new ParenthesizedExpression(this); |
||||
mre.MemberName = methodName; |
||||
mre.TypeArguments.AddRange(typeArguments); |
||||
ie.Target = mre; |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(IEnumerable<Expression> arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override InvocationExpression Invoke(params Expression[] arguments) |
||||
{ |
||||
InvocationExpression ie = new InvocationExpression(); |
||||
ie.Target = new ParenthesizedExpression(this); |
||||
ie.Arguments.AddRange(arguments); |
||||
return ie; |
||||
} |
||||
|
||||
public override CastExpression CastTo(AstType type) |
||||
{ |
||||
return new CastExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override AsExpression CastAs(AstType type) |
||||
{ |
||||
return new AsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
|
||||
public override IsExpression IsType(AstType type) |
||||
{ |
||||
return new IsExpression { Type = type, Expression = new ParenthesizedExpression(this) }; |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// LambdaExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// [async] Parameters => Body
|
||||
/// </summary>
|
||||
public class LambdaExpression : Expression |
||||
{ |
||||
public readonly static TokenRole AsyncModifierRole = new TokenRole ("async"); |
||||
public readonly static TokenRole ArrowRole = new TokenRole ("=>"); |
||||
public static readonly Role<AstNode> BodyRole = new Role<AstNode>("Body", AstNode.Null); |
||||
|
||||
bool isAsync; |
||||
|
||||
public bool IsAsync { |
||||
get { return isAsync; } |
||||
set { ThrowIfFrozen(); isAsync = value; } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole (Roles.Parameter); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public CSharpTokenNode ArrowToken { |
||||
get { return GetChildByRole (ArrowRole); } |
||||
} |
||||
|
||||
public AstNode Body { |
||||
get { return GetChildByRole (BodyRole); } |
||||
set { SetChildByRole (BodyRole, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitLambdaExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitLambdaExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitLambdaExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
LambdaExpression o = other as LambdaExpression; |
||||
return o != null && this.IsAsync == o.IsAsync && this.Parameters.DoMatch(o.Parameters, match) && this.Body.DoMatch(o.Body, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// NamedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// name = expression
|
||||
/// This isn't the same as 'assign' even though it has the same syntax.
|
||||
/// This expression is used in object initializers and for named attribute arguments [Attr(FieldName = value)].
|
||||
/// </summary>
|
||||
public class NamedExpression : Expression |
||||
{ |
||||
public NamedExpression() |
||||
{ |
||||
} |
||||
|
||||
public NamedExpression (string name, Expression expression) |
||||
{ |
||||
this.Name = name; |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, CSharp.Identifier.Create (value)); |
||||
} |
||||
} |
||||
|
||||
public Identifier NameToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode AssignToken { |
||||
get { return GetChildByRole (Roles.Assign); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNamedExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNamedExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNamedExpression(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as NamedExpression; |
||||
return o != null && MatchString(this.Name, o.Name) && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// NullReferenceExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// null
|
||||
/// </summary>
|
||||
public class NullReferenceExpression : Expression |
||||
{ |
||||
TextLocation location; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
internal void SetStartLocation(TextLocation value) |
||||
{ |
||||
ThrowIfFrozen(); |
||||
this.location = value; |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (location.Line, location.Column + "null".Length); |
||||
} |
||||
} |
||||
|
||||
public NullReferenceExpression () |
||||
{ |
||||
} |
||||
|
||||
public NullReferenceExpression (TextLocation location) |
||||
{ |
||||
this.location = location; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullReferenceExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullReferenceExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullReferenceExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
NullReferenceExpression o = other as NullReferenceExpression; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,104 @@
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ObjectCreateExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// new Type(Arguments) { Initializer }
|
||||
/// </summary>
|
||||
public class ObjectCreateExpression : Expression |
||||
{ |
||||
public readonly static TokenRole NewKeywordRole = new TokenRole ("new"); |
||||
public readonly static Role<ArrayInitializerExpression> InitializerRole = ArrayCreateExpression.InitializerRole; |
||||
|
||||
public CSharpTokenNode NewToken { |
||||
get { return GetChildByRole (NewKeywordRole); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole (Roles.Argument); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public ArrayInitializerExpression Initializer { |
||||
get { return GetChildByRole (InitializerRole); } |
||||
set { SetChildByRole (InitializerRole, value); } |
||||
} |
||||
|
||||
public ObjectCreateExpression () |
||||
{ |
||||
} |
||||
|
||||
public ObjectCreateExpression (AstType type, IEnumerable<Expression> arguments = null) |
||||
{ |
||||
AddChild (type, Roles.Type); |
||||
if (arguments != null) { |
||||
foreach (var arg in arguments) { |
||||
AddChild (arg, Roles.Argument); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public ObjectCreateExpression (AstType type, params Expression[] arguments) : this (type, (IEnumerable<Expression>)arguments) |
||||
{ |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitObjectCreateExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitObjectCreateExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitObjectCreateExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ObjectCreateExpression o = other as ObjectCreateExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.Arguments.DoMatch(o.Arguments, match) && this.Initializer.DoMatch(o.Initializer, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,98 @@
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// ParenthesizedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// ( Expression )
|
||||
/// </summary>
|
||||
public class ParenthesizedExpression : Expression |
||||
{ |
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public ParenthesizedExpression() |
||||
{ |
||||
} |
||||
|
||||
public ParenthesizedExpression(Expression expr) |
||||
{ |
||||
Expression = expr; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitParenthesizedExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitParenthesizedExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitParenthesizedExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ParenthesizedExpression o = other as ParenthesizedExpression; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets whether the expression acts like a parenthesized expression,
|
||||
/// i.e. whether information about the expected type (for lambda type inference) flows
|
||||
/// into the inner expression.
|
||||
/// </summary>
|
||||
/// <returns>Returns true for ParenthesizedExpression, CheckedExpression or UncheckedExpression; false otherwise.</returns>
|
||||
public static bool ActsAsParenthesizedExpression(AstNode expression) |
||||
{ |
||||
return expression is ParenthesizedExpression || expression is CheckedExpression || expression is UncheckedExpression; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Unpacks the given expression if it is a ParenthesizedExpression, CheckedExpression or UncheckedExpression.
|
||||
/// </summary>
|
||||
public static Expression UnpackParenthesizedExpression(Expression expr) |
||||
{ |
||||
while (ActsAsParenthesizedExpression(expr)) |
||||
expr = expr.GetChildByRole(Roles.Expression); |
||||
return expr; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// PointerReferenceExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Target->MemberName
|
||||
/// </summary>
|
||||
public class PointerReferenceExpression : Expression |
||||
{ |
||||
public readonly static TokenRole ArrowRole = new TokenRole ("->"); |
||||
|
||||
public Expression Target { |
||||
get { return GetChildByRole (Roles.TargetExpression); } |
||||
set { SetChildByRole(Roles.TargetExpression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode ArrowToken { |
||||
get { return GetChildByRole (ArrowRole); } |
||||
} |
||||
|
||||
public string MemberName { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, Identifier.Create (value)); |
||||
} |
||||
} |
||||
|
||||
public Identifier MemberNameToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> TypeArguments { |
||||
get { return GetChildrenByRole (Roles.TypeArgument); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPointerReferenceExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPointerReferenceExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPointerReferenceExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PointerReferenceExpression o = other as PointerReferenceExpression; |
||||
return o != null && MatchString(this.MemberName, o.MemberName) && this.TypeArguments.DoMatch(o.TypeArguments, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,162 @@
@@ -0,0 +1,162 @@
|
||||
//
|
||||
// PrimitiveExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a literal value.
|
||||
/// </summary>
|
||||
public class PrimitiveExpression : Expression |
||||
{ |
||||
public static readonly object AnyValue = new object(); |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
internal void SetStartLocation(TextLocation value) |
||||
{ |
||||
ThrowIfFrozen(); |
||||
this.startLocation = value; |
||||
this.endLocation = null; |
||||
} |
||||
|
||||
string literalValue; |
||||
TextLocation? endLocation; |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
if (!endLocation.HasValue) { |
||||
endLocation = value is string ? AdvanceLocation (StartLocation, literalValue ?? "") : |
||||
new TextLocation (StartLocation.Line, StartLocation.Column + (literalValue ?? "").Length); |
||||
} |
||||
return endLocation.Value; |
||||
} |
||||
} |
||||
|
||||
object value; |
||||
|
||||
public object Value { |
||||
get { return this.value; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
this.value = value; |
||||
literalValue = null; |
||||
} |
||||
} |
||||
|
||||
/// <remarks>Never returns null.</remarks>
|
||||
public string LiteralValue { |
||||
get { return literalValue ?? ""; } |
||||
} |
||||
|
||||
/// <remarks>Can be null.</remarks>
|
||||
public string UnsafeLiteralValue { |
||||
get { return literalValue; } |
||||
} |
||||
|
||||
public void SetValue(object value, string literalValue) |
||||
{ |
||||
if (value == null) |
||||
throw new ArgumentNullException(); |
||||
ThrowIfFrozen(); |
||||
this.value = value; |
||||
this.literalValue = literalValue; |
||||
} |
||||
|
||||
public PrimitiveExpression (object value) |
||||
{ |
||||
this.Value = value; |
||||
this.literalValue = null; |
||||
} |
||||
|
||||
public PrimitiveExpression (object value, string literalValue) |
||||
{ |
||||
this.Value = value; |
||||
this.literalValue = literalValue; |
||||
} |
||||
|
||||
public PrimitiveExpression (object value, TextLocation startLocation, string literalValue) |
||||
{ |
||||
this.Value = value; |
||||
this.startLocation = startLocation; |
||||
this.literalValue = literalValue; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPrimitiveExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPrimitiveExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPrimitiveExpression (this, data); |
||||
} |
||||
|
||||
unsafe static TextLocation AdvanceLocation(TextLocation startLocation, string str) |
||||
{ |
||||
int line = startLocation.Line; |
||||
int col = startLocation.Column; |
||||
fixed (char* start = str) { |
||||
char* p = start; |
||||
char* endPtr = start + str.Length; |
||||
while (p < endPtr) { |
||||
var nl = NewLine.GetDelimiterLength(*p, () => { |
||||
char* nextp = p + 1; |
||||
if (nextp < endPtr) |
||||
return *nextp; |
||||
return '\0'; |
||||
}); |
||||
if (nl > 0) { |
||||
line++; |
||||
col = 1; |
||||
if (nl == 2) |
||||
p++; |
||||
} else { |
||||
col++; |
||||
} |
||||
p++; |
||||
} |
||||
} |
||||
return new TextLocation (line, col); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PrimitiveExpression o = other as PrimitiveExpression; |
||||
return o != null && (this.Value == AnyValue || object.Equals(this.Value, o.Value)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// SizeOfExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// sizeof(Type)
|
||||
/// </summary>
|
||||
public class SizeOfExpression : Expression |
||||
{ |
||||
public readonly static TokenRole SizeofKeywordRole = new TokenRole ("sizeof"); |
||||
|
||||
public CSharpTokenNode SizeOfToken { |
||||
get { return GetChildByRole (SizeofKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public SizeOfExpression () |
||||
{ |
||||
} |
||||
|
||||
public SizeOfExpression (AstType type) |
||||
{ |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitSizeOfExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitSizeOfExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitSizeOfExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
SizeOfExpression o = other as SizeOfExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// StackAllocExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// stackalloc Type[Count]
|
||||
/// </summary>
|
||||
public class StackAllocExpression : Expression |
||||
{ |
||||
public readonly static TokenRole StackallocKeywordRole = new TokenRole ("stackalloc"); |
||||
|
||||
public CSharpTokenNode StackAllocToken { |
||||
get { return GetChildByRole (StackallocKeywordRole); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode LBracketToken { |
||||
get { return GetChildByRole (Roles.LBracket); } |
||||
} |
||||
|
||||
public Expression CountExpression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBracketToken { |
||||
get { return GetChildByRole (Roles.RBracket); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitStackAllocExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitStackAllocExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitStackAllocExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
StackAllocExpression o = other as StackAllocExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.CountExpression.DoMatch(o.CountExpression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
//
|
||||
// ThisReferenceExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// this
|
||||
/// </summary>
|
||||
public class ThisReferenceExpression : Expression |
||||
{ |
||||
public TextLocation Location { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return Location; |
||||
} |
||||
} |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (Location.Line, Location.Column + "this".Length); |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitThisReferenceExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitThisReferenceExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitThisReferenceExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ThisReferenceExpression o = other as ThisReferenceExpression; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// TypeOfExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// typeof(Type)
|
||||
/// </summary>
|
||||
public class TypeOfExpression : Expression |
||||
{ |
||||
public readonly static TokenRole TypeofKeywordRole = new TokenRole ("typeof"); |
||||
|
||||
public CSharpTokenNode TypeOfToken { |
||||
get { return GetChildByRole (TypeofKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public TypeOfExpression () |
||||
{ |
||||
} |
||||
|
||||
public TypeOfExpression (AstType type) |
||||
{ |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitTypeOfExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitTypeOfExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitTypeOfExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
TypeOfExpression o = other as TypeOfExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents an AstType as an expression.
|
||||
/// This is used when calling a method on a primitive type: "int.Parse()"
|
||||
/// </summary>
|
||||
public class TypeReferenceExpression : Expression |
||||
{ |
||||
public AstType Type { |
||||
get { return GetChildByRole(Roles.Type); } |
||||
set { SetChildByRole(Roles.Type, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitTypeReferenceExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitTypeReferenceExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitTypeReferenceExpression(this, data); |
||||
} |
||||
|
||||
public TypeReferenceExpression () |
||||
{ |
||||
} |
||||
|
||||
public TypeReferenceExpression (AstType type) |
||||
{ |
||||
AddChild (type, Roles.Type); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
TypeReferenceExpression o = other as TypeReferenceExpression; |
||||
return o != null && this.Type.DoMatch(o.Type, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,181 @@
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// UnaryOperatorExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq.Expressions; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Operator Expression
|
||||
/// </summary>
|
||||
public class UnaryOperatorExpression : Expression |
||||
{ |
||||
public readonly static TokenRole NotRole = new TokenRole ("!"); |
||||
public readonly static TokenRole BitNotRole = new TokenRole ("~"); |
||||
public readonly static TokenRole MinusRole = new TokenRole ("-"); |
||||
public readonly static TokenRole PlusRole = new TokenRole ("+"); |
||||
public readonly static TokenRole IncrementRole = new TokenRole ("++"); |
||||
public readonly static TokenRole DecrementRole = new TokenRole ("--"); |
||||
public readonly static TokenRole DereferenceRole = new TokenRole ("*"); |
||||
public readonly static TokenRole AddressOfRole = new TokenRole ("&"); |
||||
public readonly static TokenRole AwaitRole = new TokenRole ("await"); |
||||
|
||||
public UnaryOperatorExpression() |
||||
{ |
||||
} |
||||
|
||||
public UnaryOperatorExpression(UnaryOperatorType op, Expression expression) |
||||
{ |
||||
this.Operator = op; |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
public UnaryOperatorType Operator { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public CSharpTokenNode OperatorToken { |
||||
get { return GetChildByRole (GetOperatorRole (Operator)); } |
||||
} |
||||
|
||||
static Expression NoUnaryExpressionError = new ErrorExpression ("No unary expression"); |
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression) ?? NoUnaryExpressionError; } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUnaryOperatorExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUnaryOperatorExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUnaryOperatorExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UnaryOperatorExpression o = other as UnaryOperatorExpression; |
||||
return o != null && (this.Operator == UnaryOperatorType.Any || this.Operator == o.Operator) |
||||
&& this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
|
||||
public static TokenRole GetOperatorRole(UnaryOperatorType op) |
||||
{ |
||||
switch (op) { |
||||
case UnaryOperatorType.Not: |
||||
return NotRole; |
||||
case UnaryOperatorType.BitNot: |
||||
return BitNotRole; |
||||
case UnaryOperatorType.Minus: |
||||
return MinusRole; |
||||
case UnaryOperatorType.Plus: |
||||
return PlusRole; |
||||
case UnaryOperatorType.Increment: |
||||
case UnaryOperatorType.PostIncrement: |
||||
return IncrementRole; |
||||
case UnaryOperatorType.PostDecrement: |
||||
case UnaryOperatorType.Decrement: |
||||
return DecrementRole; |
||||
case UnaryOperatorType.Dereference: |
||||
return DereferenceRole; |
||||
case UnaryOperatorType.AddressOf: |
||||
return AddressOfRole; |
||||
case UnaryOperatorType.Await: |
||||
return AwaitRole; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for UnaryOperatorType"); |
||||
} |
||||
} |
||||
|
||||
public static ExpressionType GetLinqNodeType(UnaryOperatorType op, bool checkForOverflow) |
||||
{ |
||||
switch (op) { |
||||
case UnaryOperatorType.Not: |
||||
return ExpressionType.Not; |
||||
case UnaryOperatorType.BitNot: |
||||
return ExpressionType.OnesComplement; |
||||
case UnaryOperatorType.Minus: |
||||
return checkForOverflow ? ExpressionType.NegateChecked : ExpressionType.Negate; |
||||
case UnaryOperatorType.Plus: |
||||
return ExpressionType.UnaryPlus; |
||||
case UnaryOperatorType.Increment: |
||||
return ExpressionType.PreIncrementAssign; |
||||
case UnaryOperatorType.Decrement: |
||||
return ExpressionType.PreDecrementAssign; |
||||
case UnaryOperatorType.PostIncrement: |
||||
return ExpressionType.PostIncrementAssign; |
||||
case UnaryOperatorType.PostDecrement: |
||||
return ExpressionType.PostDecrementAssign; |
||||
case UnaryOperatorType.Dereference: |
||||
case UnaryOperatorType.AddressOf: |
||||
case UnaryOperatorType.Await: |
||||
return ExpressionType.Extension; |
||||
default: |
||||
throw new NotSupportedException("Invalid value for UnaryOperatorType"); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public enum UnaryOperatorType |
||||
{ |
||||
/// <summary>
|
||||
/// Any unary operator (used in pattern matching)
|
||||
/// </summary>
|
||||
Any, |
||||
|
||||
/// <summary>Logical not (!a)</summary>
|
||||
Not, |
||||
/// <summary>Bitwise not (~a)</summary>
|
||||
BitNot, |
||||
/// <summary>Unary minus (-a)</summary>
|
||||
Minus, |
||||
/// <summary>Unary plus (+a)</summary>
|
||||
Plus, |
||||
/// <summary>Pre increment (++a)</summary>
|
||||
Increment, |
||||
/// <summary>Pre decrement (--a)</summary>
|
||||
Decrement, |
||||
/// <summary>Post increment (a++)</summary>
|
||||
PostIncrement, |
||||
/// <summary>Post decrement (a--)</summary>
|
||||
PostDecrement, |
||||
/// <summary>Dereferencing (*a)</summary>
|
||||
Dereference, |
||||
/// <summary>Get address (&a)</summary>
|
||||
AddressOf, |
||||
/// <summary>C# 5.0 await</summary>
|
||||
Await |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// UncheckedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// unchecked(Expression)
|
||||
/// </summary>
|
||||
public class UncheckedExpression : Expression |
||||
{ |
||||
public readonly static TokenRole UncheckedKeywordRole = new TokenRole ("unchecked"); |
||||
|
||||
public CSharpTokenNode UncheckedToken { |
||||
get { return GetChildByRole (UncheckedKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole(Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public UncheckedExpression () |
||||
{ |
||||
} |
||||
|
||||
public UncheckedExpression (Expression expression) |
||||
{ |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUncheckedExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUncheckedExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUncheckedExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UncheckedExpression o = other as UncheckedExpression; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,105 @@
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// UndocumentedExpression.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum UndocumentedExpressionType |
||||
{ |
||||
ArgListAccess, // __arglist
|
||||
ArgList, // __arglist (a1, a2, ..., an)
|
||||
RefValue, // __refvalue (expr , type)
|
||||
RefType, // __reftype (expr)
|
||||
MakeRef // __makeref (expr)
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents undocumented expressions.
|
||||
/// </summary>
|
||||
public class UndocumentedExpression : Expression |
||||
{ |
||||
public readonly static TokenRole ArglistKeywordRole = new TokenRole ("__arglist"); |
||||
public readonly static TokenRole RefvalueKeywordRole = new TokenRole ("__refvalue"); |
||||
public readonly static TokenRole ReftypeKeywordRole = new TokenRole ("__reftype"); |
||||
public readonly static TokenRole MakerefKeywordRole = new TokenRole ("__makeref"); |
||||
|
||||
public UndocumentedExpressionType UndocumentedExpressionType { |
||||
get; set; |
||||
} |
||||
|
||||
public CSharpTokenNode UndocumentedToken { |
||||
get { |
||||
switch (UndocumentedExpressionType) { |
||||
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.ArgListAccess: |
||||
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.ArgList: |
||||
return GetChildByRole (ArglistKeywordRole); |
||||
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.RefValue: |
||||
return GetChildByRole (RefvalueKeywordRole); |
||||
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.RefType: |
||||
return GetChildByRole (ReftypeKeywordRole); |
||||
case ICSharpCode.NRefactory.CSharp.UndocumentedExpressionType.MakeRef: |
||||
return GetChildByRole (MakerefKeywordRole); |
||||
} |
||||
return CSharpTokenNode.Null; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return GetChildrenByRole(Roles.Argument); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUndocumentedExpression (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUndocumentedExpression (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUndocumentedExpression (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UndocumentedExpression o = other as UndocumentedExpression; |
||||
return o != null && this.UndocumentedExpressionType == o.UndocumentedExpressionType && this.Arguments.DoMatch(o.Arguments, match); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
//
|
||||
// Attribute.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Attribute(Arguments)
|
||||
/// </summary>
|
||||
public class Attribute : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Expression> Arguments { |
||||
get { return base.GetChildrenByRole (Roles.Argument); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
// HasArgumentList == false: [Empty]
|
||||
public bool HasArgumentList { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAttribute (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAttribute (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAttribute (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch (AstNode other, PatternMatching.Match match) |
||||
{ |
||||
Attribute o = other as Attribute; |
||||
return o != null && this.Type.DoMatch (o.Type, match) && this.Arguments.DoMatch (o.Arguments, match); |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
if (IsNull) |
||||
return "Null"; |
||||
return base.ToString(formattingOptions); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,174 @@
@@ -0,0 +1,174 @@
|
||||
//
|
||||
// AttributeSection.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// [AttributeTarget: Attributes]
|
||||
/// </summary>
|
||||
public class AttributeSection : AstNode |
||||
{ |
||||
#region PatternPlaceholder
|
||||
public static implicit operator AttributeSection(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : AttributeSection, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder (this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder (this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode LBracketToken { |
||||
get { return GetChildByRole (Roles.LBracket); } |
||||
} |
||||
|
||||
public string AttributeTarget { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, CSharp.Identifier.Create (value)); |
||||
} |
||||
} |
||||
|
||||
public Identifier AttributeTargetToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole (Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<Attribute> Attributes { |
||||
get { return base.GetChildrenByRole (Roles.Attribute); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBracketToken { |
||||
get { return GetChildByRole (Roles.RBracket); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitAttributeSection (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitAttributeSection (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitAttributeSection (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
AttributeSection o = other as AttributeSection; |
||||
return o != null && MatchString(this.AttributeTarget, o.AttributeTarget) && this.Attributes.DoMatch(o.Attributes, match); |
||||
} |
||||
|
||||
public AttributeSection() |
||||
{ |
||||
} |
||||
|
||||
public AttributeSection(Attribute attr) |
||||
{ |
||||
this.Attributes.Add(attr); |
||||
} |
||||
|
||||
// public static string GetAttributeTargetName(AttributeTarget attributeTarget)
|
||||
// {
|
||||
// switch (attributeTarget) {
|
||||
// case AttributeTarget.None:
|
||||
// return null;
|
||||
// case AttributeTarget.Assembly:
|
||||
// return "assembly";
|
||||
// case AttributeTarget.Module:
|
||||
// return "module";
|
||||
// case AttributeTarget.Type:
|
||||
// return "type";
|
||||
// case AttributeTarget.Param:
|
||||
// return "param";
|
||||
// case AttributeTarget.Field:
|
||||
// return "field";
|
||||
// case AttributeTarget.Return:
|
||||
// return "return";
|
||||
// case AttributeTarget.Method:
|
||||
// return "method";
|
||||
// default:
|
||||
// throw new NotSupportedException("Invalid value for AttributeTarget");
|
||||
// }
|
||||
// }
|
||||
} |
||||
} |
@ -0,0 +1,140 @@
@@ -0,0 +1,140 @@
|
||||
//
|
||||
// Comment.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum CommentType |
||||
{ |
||||
/// <summary>
|
||||
/// "//" comment
|
||||
/// </summary>
|
||||
SingleLine, |
||||
/// <summary>
|
||||
/// "/* */" comment
|
||||
/// </summary>
|
||||
MultiLine, |
||||
/// <summary>
|
||||
/// "///" comment
|
||||
/// </summary>
|
||||
Documentation, |
||||
/// <summary>
|
||||
/// Inactive code (code in non-taken "#if")
|
||||
/// </summary>
|
||||
InactiveCode, |
||||
/// <summary>
|
||||
/// "/** */" comment
|
||||
/// </summary>
|
||||
MultiLineDocumentation |
||||
} |
||||
|
||||
public class Comment : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Whitespace; |
||||
} |
||||
} |
||||
|
||||
CommentType commentType; |
||||
|
||||
public CommentType CommentType { |
||||
get { return commentType; } |
||||
set { ThrowIfFrozen(); commentType = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns true if the <see cref="CommentType"/> is Documentation or MultiLineDocumentation.
|
||||
/// </summary>
|
||||
public bool IsDocumentation { |
||||
get { |
||||
return commentType == CommentType.Documentation || commentType == CommentType.MultiLineDocumentation; |
||||
} |
||||
} |
||||
|
||||
bool startsLine; |
||||
|
||||
public bool StartsLine { |
||||
get { return startsLine; } |
||||
set { ThrowIfFrozen(); startsLine = value; } |
||||
} |
||||
|
||||
string content; |
||||
|
||||
public string Content { |
||||
get { return content; } |
||||
set { ThrowIfFrozen(); content = value; } |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
TextLocation endLocation; |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return endLocation; |
||||
} |
||||
} |
||||
|
||||
public Comment (string content, CommentType type = CommentType.SingleLine) |
||||
{ |
||||
this.CommentType = type; |
||||
this.Content = content; |
||||
} |
||||
|
||||
public Comment (CommentType commentType, TextLocation startLocation, TextLocation endLocation) |
||||
{ |
||||
this.CommentType = commentType; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitComment (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitComment (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitComment (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
Comment o = other as Comment; |
||||
return o != null && this.CommentType == o.CommentType && MatchString(this.Content, o.Content); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// Constraint.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// where TypeParameter : BaseTypes
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// new(), struct and class constraints are represented using a PrimitiveType "new", "struct" or "class"
|
||||
/// </remarks>
|
||||
public class Constraint : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode WhereKeyword { |
||||
get { return GetChildByRole (Roles.WhereKeyword); } |
||||
} |
||||
|
||||
public SimpleType TypeParameter { |
||||
get { |
||||
return GetChildByRole (Roles.ConstraintTypeParameter); |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.ConstraintTypeParameter, value); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> BaseTypes { |
||||
get { |
||||
return GetChildrenByRole(Roles.BaseType); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitConstraint (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitConstraint (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitConstraint (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
Constraint o = other as Constraint; |
||||
return o != null && this.TypeParameter.DoMatch (o.TypeParameter, match) && this.BaseTypes.DoMatch(o.BaseTypes, match); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,92 @@
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// DelegateDeclaration.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// delegate ReturnType Name<TypeParameters>(Parameters) where Constraints;
|
||||
/// </summary>
|
||||
public class DelegateDeclaration : EntityDeclaration |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { return NodeType.TypeDeclaration; } |
||||
} |
||||
|
||||
public override SymbolKind SymbolKind { |
||||
get { return SymbolKind.TypeDefinition; } |
||||
} |
||||
|
||||
public CSharpTokenNode DelegateToken { |
||||
get { return GetChildByRole(Roles.DelegateKeyword); } |
||||
} |
||||
|
||||
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { |
||||
get { return GetChildrenByRole (Roles.TypeParameter); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<ParameterDeclaration> Parameters { |
||||
get { return GetChildrenByRole (Roles.Parameter); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public AstNodeCollection<Constraint> Constraints { |
||||
get { return GetChildrenByRole (Roles.Constraint); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitDelegateDeclaration (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitDelegateDeclaration (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDelegateDeclaration (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
DelegateDeclaration o = other as DelegateDeclaration; |
||||
return o != null && MatchString(this.Name, o.Name) |
||||
&& this.MatchAttributesAndModifiers(o, match) && this.ReturnType.DoMatch(o.ReturnType, match) |
||||
&& this.TypeParameters.DoMatch(o.TypeParameters, match) && this.Parameters.DoMatch(o.Parameters, match) |
||||
&& this.Constraints.DoMatch(o.Constraints, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,158 @@
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// NamespaceDeclaration.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// namespace Name { Members }
|
||||
/// </summary>
|
||||
public class NamespaceDeclaration : AstNode |
||||
{ |
||||
public static readonly Role<AstNode> MemberRole = SyntaxTree.MemberRole; |
||||
public static readonly Role<AstType> NamespaceNameRole = new Role<AstType>("NamespaceName", AstType.Null); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode NamespaceToken { |
||||
get { return GetChildByRole(Roles.NamespaceKeyword); } |
||||
} |
||||
|
||||
public AstType NamespaceName { |
||||
get { return GetChildByRole(NamespaceNameRole) ?? AstType.Null; } |
||||
set { SetChildByRole(NamespaceNameRole, value); } |
||||
} |
||||
|
||||
public string Name { |
||||
get { |
||||
return UsingDeclaration.ConstructNamespace(NamespaceName); |
||||
} |
||||
set { |
||||
var arr = value.Split('.'); |
||||
NamespaceName = ConstructType(arr, arr.Length - 1); |
||||
} |
||||
} |
||||
|
||||
static AstType ConstructType(string[] arr, int i) |
||||
{ |
||||
if (i < 0 || i >= arr.Length) |
||||
throw new ArgumentOutOfRangeException("i"); |
||||
if (i == 0) |
||||
return new SimpleType(arr[i]); |
||||
return new MemberType(ConstructType(arr, i - 1), arr[i]); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the full namespace name (including any parent namespaces)
|
||||
/// </summary>
|
||||
public string FullName { |
||||
get { |
||||
NamespaceDeclaration parentNamespace = Parent as NamespaceDeclaration; |
||||
if (parentNamespace != null) |
||||
return BuildQualifiedName(parentNamespace.FullName, Name); |
||||
return Name; |
||||
} |
||||
} |
||||
|
||||
public IEnumerable<string> Identifiers { |
||||
get { |
||||
var result = new Stack<string>(); |
||||
AstType type = NamespaceName; |
||||
while (type is MemberType) { |
||||
var mt = (MemberType)type; |
||||
result.Push(mt.MemberName); |
||||
type = mt.Target; |
||||
} |
||||
if (type is SimpleType) |
||||
result.Push(((SimpleType)type).Identifier); |
||||
return result; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode LBraceToken { |
||||
get { return GetChildByRole(Roles.LBrace); } |
||||
} |
||||
|
||||
public AstNodeCollection<AstNode> Members { |
||||
get { return GetChildrenByRole(MemberRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBraceToken { |
||||
get { return GetChildByRole(Roles.RBrace); } |
||||
} |
||||
|
||||
public NamespaceDeclaration() |
||||
{ |
||||
} |
||||
|
||||
public NamespaceDeclaration(string name) |
||||
{ |
||||
this.Name = name; |
||||
} |
||||
|
||||
public static string BuildQualifiedName(string name1, string name2) |
||||
{ |
||||
if (string.IsNullOrEmpty(name1)) |
||||
return name2; |
||||
if (string.IsNullOrEmpty(name2)) |
||||
return name1; |
||||
return name1 + "." + name2; |
||||
} |
||||
|
||||
public void AddMember(AstNode child) |
||||
{ |
||||
AddChild(child, MemberRole); |
||||
} |
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNamespaceDeclaration(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNamespaceDeclaration(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNamespaceDeclaration(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
NamespaceDeclaration o = other as NamespaceDeclaration; |
||||
return o != null && MatchString(this.Name, o.Name) && this.Members.DoMatch(o.Members, match); |
||||
} |
||||
} |
||||
} ; |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
using System; |
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
|
||||
/// <summary>
|
||||
/// A New line node represents a line break in the text.
|
||||
/// </summary>
|
||||
public sealed class NewLineNode : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Whitespace; |
||||
} |
||||
} |
||||
|
||||
const uint newLineMask = 0xfu << AstNodeFlagsUsedBits; |
||||
static readonly UnicodeNewline[] newLineTypes = { |
||||
UnicodeNewline.Unknown, |
||||
UnicodeNewline.LF, |
||||
UnicodeNewline.CRLF, |
||||
UnicodeNewline.CR, |
||||
UnicodeNewline.NEL, |
||||
UnicodeNewline.VT, |
||||
UnicodeNewline.FF, |
||||
UnicodeNewline.LS, |
||||
UnicodeNewline.PS |
||||
}; |
||||
|
||||
public UnicodeNewline NewLineType { |
||||
get { |
||||
return newLineTypes[(flags & newLineMask) >> AstNodeFlagsUsedBits]; |
||||
} |
||||
set { |
||||
ThrowIfFrozen(); |
||||
int pos = Array.IndexOf(newLineTypes, value); |
||||
if (pos < 0) |
||||
pos = 0; |
||||
flags &= ~newLineMask; // clear old newline type
|
||||
flags |= (uint)pos << AstNodeFlagsUsedBits; |
||||
} |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (startLocation.Line + 1, 1); |
||||
} |
||||
} |
||||
|
||||
public NewLineNode() : this (TextLocation.Empty) |
||||
{ |
||||
} |
||||
|
||||
public NewLineNode(TextLocation startLocation) |
||||
{ |
||||
this.startLocation = startLocation; |
||||
} |
||||
|
||||
public sealed override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return NewLine.GetString (NewLineType); |
||||
} |
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNewLine (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNewLine (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNewLine (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, ICSharpCode.NRefactory.PatternMatching.Match match) |
||||
{ |
||||
return other is NewLineNode; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,205 @@
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// PreProcessorDirective.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin Inc.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum PreProcessorDirectiveType : byte |
||||
{ |
||||
Invalid = 0, |
||||
Region = 1, |
||||
Endregion = 2, |
||||
|
||||
If = 3, |
||||
Endif = 4, |
||||
Elif = 5, |
||||
Else = 6, |
||||
|
||||
Define = 7, |
||||
Undef = 8, |
||||
Error = 9, |
||||
Warning = 10, |
||||
Pragma = 11, |
||||
Line = 12 |
||||
} |
||||
|
||||
public class LinePreprocessorDirective : PreProcessorDirective |
||||
{ |
||||
public int LineNumber { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public string FileName { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public LinePreprocessorDirective(TextLocation startLocation, TextLocation endLocation) : base (PreProcessorDirectiveType.Line, startLocation, endLocation) |
||||
{ |
||||
} |
||||
|
||||
public LinePreprocessorDirective(string argument = null) : base (PreProcessorDirectiveType.Line, argument) |
||||
{ |
||||
} |
||||
} |
||||
|
||||
public class PragmaWarningPreprocessorDirective : PreProcessorDirective |
||||
{ |
||||
public static readonly Role<PrimitiveExpression> WarningRole = new Role<PrimitiveExpression> ("Warning"); |
||||
|
||||
public static readonly TokenRole PragmaKeywordRole = new TokenRole ("#pragma"); |
||||
public static readonly TokenRole WarningKeywordRole = new TokenRole ("warning"); |
||||
public static readonly TokenRole DisableKeywordRole = new TokenRole ("disable"); |
||||
public static readonly TokenRole RestoreKeywordRole = new TokenRole ("restore"); |
||||
|
||||
public bool Disable { |
||||
get { |
||||
return !DisableToken.IsNull; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode PragmaToken { |
||||
get { return GetChildByRole (PragmaKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode WarningToken { |
||||
get { return GetChildByRole (WarningKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode DisableToken { |
||||
get { return GetChildByRole (DisableKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RestoreToken { |
||||
get { return GetChildByRole (RestoreKeywordRole); } |
||||
} |
||||
|
||||
public AstNodeCollection<PrimitiveExpression> Warnings { |
||||
get { return GetChildrenByRole(WarningRole); } |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
var child = LastChild; |
||||
if (child == null) |
||||
return base.EndLocation; |
||||
return child.EndLocation; |
||||
} |
||||
} |
||||
|
||||
public PragmaWarningPreprocessorDirective(TextLocation startLocation, TextLocation endLocation) : base (PreProcessorDirectiveType.Pragma, startLocation, endLocation) |
||||
{ |
||||
} |
||||
|
||||
public PragmaWarningPreprocessorDirective(string argument = null) : base (PreProcessorDirectiveType.Pragma, argument) |
||||
{ |
||||
} |
||||
|
||||
public bool IsDefined(int pragmaWarning) |
||||
{ |
||||
return Warnings.Select(w => (int)w.Value).Any(n => n == pragmaWarning); |
||||
} |
||||
} |
||||
|
||||
public class PreProcessorDirective : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Whitespace; |
||||
} |
||||
} |
||||
|
||||
public PreProcessorDirectiveType Type { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public string Argument { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// For an '#if' directive, specifies whether the condition evaluated to true.
|
||||
/// </summary>
|
||||
public bool Take { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
TextLocation endLocation; |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return endLocation; |
||||
} |
||||
} |
||||
|
||||
public PreProcessorDirective(PreProcessorDirectiveType type, TextLocation startLocation, TextLocation endLocation) |
||||
{ |
||||
this.Type = type; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
public PreProcessorDirective(PreProcessorDirectiveType type, string argument = null) |
||||
{ |
||||
this.Type = type; |
||||
this.Argument = argument; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPreProcessorDirective (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPreProcessorDirective (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPreProcessorDirective (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PreProcessorDirective o = other as PreProcessorDirective; |
||||
return o != null && Type == o.Type && MatchString(Argument, o.Argument); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,94 @@
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// TextNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// A text node contains text without syntactic or semantic information.
|
||||
/// (non parseable part of a text)
|
||||
/// </summary>
|
||||
public class TextNode : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Whitespace; |
||||
} |
||||
} |
||||
|
||||
public string Text { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
TextLocation endLocation; |
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return endLocation; |
||||
} |
||||
} |
||||
|
||||
public TextNode(string text) : this (text, TextLocation.Empty, TextLocation.Empty) |
||||
{ |
||||
} |
||||
|
||||
public TextNode(string text, TextLocation startLocation, TextLocation endLocation) |
||||
{ |
||||
this.Text = text; |
||||
this.startLocation = startLocation; |
||||
this.endLocation = endLocation; |
||||
} |
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitText (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitText (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitText (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as TextNode; |
||||
return o != null && o.Text == Text; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,145 @@
@@ -0,0 +1,145 @@
|
||||
//
|
||||
// TypeDeclaration.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum ClassType |
||||
{ |
||||
Class, |
||||
Struct, |
||||
Interface, |
||||
Enum |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// class Name<TypeParameters> : BaseTypes where Constraints;
|
||||
/// </summary>
|
||||
public class TypeDeclaration : EntityDeclaration |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { return NodeType.TypeDeclaration; } |
||||
} |
||||
|
||||
public override SymbolKind SymbolKind { |
||||
get { return SymbolKind.TypeDefinition; } |
||||
} |
||||
|
||||
ClassType classType; |
||||
|
||||
public CSharpTokenNode TypeKeyword { |
||||
get { |
||||
switch (classType) { |
||||
case ClassType.Class: |
||||
return GetChildByRole(Roles.ClassKeyword); |
||||
case ClassType.Struct: |
||||
return GetChildByRole(Roles.StructKeyword); |
||||
case ClassType.Interface: |
||||
return GetChildByRole(Roles.InterfaceKeyword); |
||||
case ClassType.Enum: |
||||
return GetChildByRole(Roles.EnumKeyword); |
||||
default: |
||||
return CSharpTokenNode.Null; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public ClassType ClassType { |
||||
get { return classType; } |
||||
set { |
||||
ThrowIfFrozen(); |
||||
classType = value; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode LChevronToken { |
||||
get { return GetChildByRole (Roles.LChevron); } |
||||
} |
||||
|
||||
public AstNodeCollection<TypeParameterDeclaration> TypeParameters { |
||||
get { return GetChildrenByRole (Roles.TypeParameter); } |
||||
} |
||||
|
||||
public CSharpTokenNode RChevronToken { |
||||
get { return GetChildByRole (Roles.RChevron); } |
||||
} |
||||
|
||||
|
||||
|
||||
public CSharpTokenNode ColonToken { |
||||
get { |
||||
return GetChildByRole(Roles.Colon); |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<AstType> BaseTypes { |
||||
get { return GetChildrenByRole(Roles.BaseType); } |
||||
} |
||||
|
||||
public AstNodeCollection<Constraint> Constraints { |
||||
get { return GetChildrenByRole(Roles.Constraint); } |
||||
} |
||||
|
||||
public CSharpTokenNode LBraceToken { |
||||
get { return GetChildByRole (Roles.LBrace); } |
||||
} |
||||
|
||||
public AstNodeCollection<EntityDeclaration> Members { |
||||
get { return GetChildrenByRole (Roles.TypeMemberRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBraceToken { |
||||
get { return GetChildByRole (Roles.RBrace); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitTypeDeclaration (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitTypeDeclaration (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitTypeDeclaration (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
TypeDeclaration o = other as TypeDeclaration; |
||||
return o != null && this.ClassType == o.ClassType && MatchString(this.Name, o.Name) |
||||
&& this.MatchAttributesAndModifiers(o, match) && this.TypeParameters.DoMatch(o.TypeParameters, match) |
||||
&& this.BaseTypes.DoMatch(o.BaseTypes, match) && this.Constraints.DoMatch(o.Constraints, match) |
||||
&& this.Members.DoMatch(o.Members, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,122 @@
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// UsingDeclaration.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using System.Text; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// using Import;
|
||||
/// </summary>
|
||||
public class UsingDeclaration : AstNode |
||||
{ |
||||
public static readonly TokenRole UsingKeywordRole = new TokenRole ("using"); |
||||
public static readonly Role<AstType> ImportRole = new Role<AstType>("Import", AstType.Null); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode UsingToken { |
||||
get { return GetChildByRole (UsingKeywordRole); } |
||||
} |
||||
|
||||
public AstType Import { |
||||
get { return GetChildByRole (ImportRole); } |
||||
set { SetChildByRole (ImportRole, value); } |
||||
} |
||||
|
||||
public string Namespace { |
||||
get { return ConstructNamespace (Import); } |
||||
} |
||||
|
||||
internal static string ConstructNamespace (AstType type) |
||||
{ |
||||
var stack = new Stack<string>(); |
||||
while (type is MemberType) { |
||||
var mt = (MemberType)type; |
||||
stack.Push(mt.MemberName); |
||||
type = mt.Target; |
||||
if (mt.IsDoubleColon) { |
||||
stack.Push("::"); |
||||
} else { |
||||
stack.Push("."); |
||||
} |
||||
} |
||||
if (type is SimpleType) |
||||
stack.Push(((SimpleType)type).Identifier); |
||||
|
||||
var result = new StringBuilder(); |
||||
while (stack.Count > 0) |
||||
result.Append(stack.Pop()); |
||||
return result.ToString(); |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public UsingDeclaration () |
||||
{ |
||||
} |
||||
|
||||
public UsingDeclaration (string nameSpace) |
||||
{ |
||||
AddChild (AstType.Create (nameSpace), ImportRole); |
||||
} |
||||
|
||||
public UsingDeclaration (AstType import) |
||||
{ |
||||
AddChild (import, ImportRole); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUsingDeclaration (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUsingDeclaration (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUsingDeclaration (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UsingDeclaration o = other as UsingDeclaration; |
||||
return o != null && this.Import.DoMatch(o.Import, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
//
|
||||
// WhitespaceNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// A Whitespace node contains only whitespaces.
|
||||
/// </summary>
|
||||
public class WhitespaceNode : AstNode |
||||
{ |
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Whitespace; |
||||
} |
||||
} |
||||
|
||||
public string WhiteSpaceText { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (startLocation.Line, startLocation.Column + WhiteSpaceText.Length); |
||||
} |
||||
} |
||||
|
||||
public WhitespaceNode(string whiteSpaceText) : this (whiteSpaceText, TextLocation.Empty) |
||||
{ |
||||
} |
||||
|
||||
public WhitespaceNode(string whiteSpaceText, TextLocation startLocation) |
||||
{ |
||||
this.WhiteSpaceText = whiteSpaceText; |
||||
this.startLocation = startLocation; |
||||
} |
||||
|
||||
public override void AcceptVisitor(IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitWhitespace (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T>(IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitWhitespace (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitWhitespace (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as WhitespaceNode; |
||||
return o != null && o.WhiteSpaceText == WhiteSpaceText; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,418 @@
@@ -0,0 +1,418 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// AST visitor.
|
||||
/// </summary>
|
||||
public interface IAstVisitor |
||||
{ |
||||
void VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression); |
||||
void VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression); |
||||
void VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression); |
||||
void VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression); |
||||
void VisitAsExpression(AsExpression asExpression); |
||||
void VisitAssignmentExpression(AssignmentExpression assignmentExpression); |
||||
void VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression); |
||||
void VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression); |
||||
void VisitCastExpression(CastExpression castExpression); |
||||
void VisitCheckedExpression(CheckedExpression checkedExpression); |
||||
void VisitConditionalExpression(ConditionalExpression conditionalExpression); |
||||
void VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression); |
||||
void VisitDirectionExpression(DirectionExpression directionExpression); |
||||
void VisitIdentifierExpression(IdentifierExpression identifierExpression); |
||||
void VisitIndexerExpression(IndexerExpression indexerExpression); |
||||
void VisitInvocationExpression(InvocationExpression invocationExpression); |
||||
void VisitIsExpression(IsExpression isExpression); |
||||
void VisitLambdaExpression(LambdaExpression lambdaExpression); |
||||
void VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression); |
||||
void VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression); |
||||
void VisitNamedExpression(NamedExpression namedExpression); |
||||
void VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression); |
||||
void VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression); |
||||
void VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression); |
||||
void VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression); |
||||
void VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression); |
||||
void VisitPrimitiveExpression(PrimitiveExpression primitiveExpression); |
||||
void VisitSizeOfExpression(SizeOfExpression sizeOfExpression); |
||||
void VisitStackAllocExpression(StackAllocExpression stackAllocExpression); |
||||
void VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression); |
||||
void VisitTypeOfExpression(TypeOfExpression typeOfExpression); |
||||
void VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression); |
||||
void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression); |
||||
void VisitUncheckedExpression(UncheckedExpression uncheckedExpression); |
||||
|
||||
void VisitQueryExpression(QueryExpression queryExpression); |
||||
void VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause); |
||||
void VisitQueryFromClause(QueryFromClause queryFromClause); |
||||
void VisitQueryLetClause(QueryLetClause queryLetClause); |
||||
void VisitQueryWhereClause(QueryWhereClause queryWhereClause); |
||||
void VisitQueryJoinClause(QueryJoinClause queryJoinClause); |
||||
void VisitQueryOrderClause(QueryOrderClause queryOrderClause); |
||||
void VisitQueryOrdering(QueryOrdering queryOrdering); |
||||
void VisitQuerySelectClause(QuerySelectClause querySelectClause); |
||||
void VisitQueryGroupClause(QueryGroupClause queryGroupClause); |
||||
|
||||
void VisitAttribute(Attribute attribute); |
||||
void VisitAttributeSection(AttributeSection attributeSection); |
||||
void VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration); |
||||
void VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration); |
||||
void VisitTypeDeclaration(TypeDeclaration typeDeclaration); |
||||
void VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration); |
||||
void VisitUsingDeclaration(UsingDeclaration usingDeclaration); |
||||
void VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration); |
||||
|
||||
void VisitBlockStatement(BlockStatement blockStatement); |
||||
void VisitBreakStatement(BreakStatement breakStatement); |
||||
void VisitCheckedStatement(CheckedStatement checkedStatement); |
||||
void VisitContinueStatement(ContinueStatement continueStatement); |
||||
void VisitDoWhileStatement(DoWhileStatement doWhileStatement); |
||||
void VisitEmptyStatement(EmptyStatement emptyStatement); |
||||
void VisitExpressionStatement(ExpressionStatement expressionStatement); |
||||
void VisitFixedStatement(FixedStatement fixedStatement); |
||||
void VisitForeachStatement(ForeachStatement foreachStatement); |
||||
void VisitForStatement(ForStatement forStatement); |
||||
void VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement); |
||||
void VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement); |
||||
void VisitGotoStatement(GotoStatement gotoStatement); |
||||
void VisitIfElseStatement(IfElseStatement ifElseStatement); |
||||
void VisitLabelStatement(LabelStatement labelStatement); |
||||
void VisitLockStatement(LockStatement lockStatement); |
||||
void VisitReturnStatement(ReturnStatement returnStatement); |
||||
void VisitSwitchStatement(SwitchStatement switchStatement); |
||||
void VisitSwitchSection(SwitchSection switchSection); |
||||
void VisitCaseLabel(CaseLabel caseLabel); |
||||
void VisitThrowStatement(ThrowStatement throwStatement); |
||||
void VisitTryCatchStatement(TryCatchStatement tryCatchStatement); |
||||
void VisitCatchClause(CatchClause catchClause); |
||||
void VisitUncheckedStatement(UncheckedStatement uncheckedStatement); |
||||
void VisitUnsafeStatement(UnsafeStatement unsafeStatement); |
||||
void VisitUsingStatement(UsingStatement usingStatement); |
||||
void VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement); |
||||
void VisitWhileStatement(WhileStatement whileStatement); |
||||
void VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement); |
||||
void VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement); |
||||
|
||||
void VisitAccessor(Accessor accessor); |
||||
void VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration); |
||||
void VisitConstructorInitializer(ConstructorInitializer constructorInitializer); |
||||
void VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration); |
||||
void VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration); |
||||
void VisitEventDeclaration(EventDeclaration eventDeclaration); |
||||
void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration); |
||||
void VisitFieldDeclaration(FieldDeclaration fieldDeclaration); |
||||
void VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration); |
||||
void VisitMethodDeclaration(MethodDeclaration methodDeclaration); |
||||
void VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration); |
||||
void VisitParameterDeclaration(ParameterDeclaration parameterDeclaration); |
||||
void VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration); |
||||
void VisitVariableInitializer(VariableInitializer variableInitializer); |
||||
void VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration); |
||||
void VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer); |
||||
|
||||
void VisitSyntaxTree(SyntaxTree syntaxTree); |
||||
void VisitSimpleType(SimpleType simpleType); |
||||
void VisitMemberType(MemberType memberType); |
||||
void VisitComposedType(ComposedType composedType); |
||||
void VisitArraySpecifier(ArraySpecifier arraySpecifier); |
||||
void VisitPrimitiveType(PrimitiveType primitiveType); |
||||
|
||||
void VisitComment(Comment comment); |
||||
void VisitNewLine(NewLineNode newLineNode); |
||||
void VisitWhitespace(WhitespaceNode whitespaceNode); |
||||
void VisitText(TextNode textNode); |
||||
void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective); |
||||
void VisitDocumentationReference(DocumentationReference documentationReference); |
||||
|
||||
void VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration); |
||||
void VisitConstraint(Constraint constraint); |
||||
void VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode); |
||||
void VisitIdentifier(Identifier identifier); |
||||
|
||||
void VisitNullNode(AstNode nullNode); |
||||
void VisitErrorNode(AstNode errorNode); |
||||
void VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// AST visitor.
|
||||
/// </summary>
|
||||
public interface IAstVisitor<out S> |
||||
{ |
||||
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression); |
||||
S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression); |
||||
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression); |
||||
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression); |
||||
S VisitAsExpression(AsExpression asExpression); |
||||
S VisitAssignmentExpression(AssignmentExpression assignmentExpression); |
||||
S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression); |
||||
S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression); |
||||
S VisitCastExpression(CastExpression castExpression); |
||||
S VisitCheckedExpression(CheckedExpression checkedExpression); |
||||
S VisitConditionalExpression(ConditionalExpression conditionalExpression); |
||||
S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression); |
||||
S VisitDirectionExpression(DirectionExpression directionExpression); |
||||
S VisitIdentifierExpression(IdentifierExpression identifierExpression); |
||||
S VisitIndexerExpression(IndexerExpression indexerExpression); |
||||
S VisitInvocationExpression(InvocationExpression invocationExpression); |
||||
S VisitIsExpression(IsExpression isExpression); |
||||
S VisitLambdaExpression(LambdaExpression lambdaExpression); |
||||
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression); |
||||
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression); |
||||
S VisitNamedExpression(NamedExpression namedExpression); |
||||
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression); |
||||
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression); |
||||
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression); |
||||
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression); |
||||
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression); |
||||
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression); |
||||
S VisitSizeOfExpression(SizeOfExpression sizeOfExpression); |
||||
S VisitStackAllocExpression(StackAllocExpression stackAllocExpression); |
||||
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression); |
||||
S VisitTypeOfExpression(TypeOfExpression typeOfExpression); |
||||
S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression); |
||||
S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression); |
||||
S VisitUncheckedExpression(UncheckedExpression uncheckedExpression); |
||||
|
||||
S VisitQueryExpression(QueryExpression queryExpression); |
||||
S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause); |
||||
S VisitQueryFromClause(QueryFromClause queryFromClause); |
||||
S VisitQueryLetClause(QueryLetClause queryLetClause); |
||||
S VisitQueryWhereClause(QueryWhereClause queryWhereClause); |
||||
S VisitQueryJoinClause(QueryJoinClause queryJoinClause); |
||||
S VisitQueryOrderClause(QueryOrderClause queryOrderClause); |
||||
S VisitQueryOrdering(QueryOrdering queryOrdering); |
||||
S VisitQuerySelectClause(QuerySelectClause querySelectClause); |
||||
S VisitQueryGroupClause(QueryGroupClause queryGroupClause); |
||||
|
||||
S VisitAttribute(Attribute attribute); |
||||
S VisitAttributeSection(AttributeSection attributeSection); |
||||
S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration); |
||||
S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration); |
||||
S VisitTypeDeclaration(TypeDeclaration typeDeclaration); |
||||
S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration); |
||||
S VisitUsingDeclaration(UsingDeclaration usingDeclaration); |
||||
S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration); |
||||
|
||||
S VisitBlockStatement(BlockStatement blockStatement); |
||||
S VisitBreakStatement(BreakStatement breakStatement); |
||||
S VisitCheckedStatement(CheckedStatement checkedStatement); |
||||
S VisitContinueStatement(ContinueStatement continueStatement); |
||||
S VisitDoWhileStatement(DoWhileStatement doWhileStatement); |
||||
S VisitEmptyStatement(EmptyStatement emptyStatement); |
||||
S VisitExpressionStatement(ExpressionStatement expressionStatement); |
||||
S VisitFixedStatement(FixedStatement fixedStatement); |
||||
S VisitForeachStatement(ForeachStatement foreachStatement); |
||||
S VisitForStatement(ForStatement forStatement); |
||||
S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement); |
||||
S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement); |
||||
S VisitGotoStatement(GotoStatement gotoStatement); |
||||
S VisitIfElseStatement(IfElseStatement ifElseStatement); |
||||
S VisitLabelStatement(LabelStatement labelStatement); |
||||
S VisitLockStatement(LockStatement lockStatement); |
||||
S VisitReturnStatement(ReturnStatement returnStatement); |
||||
S VisitSwitchStatement(SwitchStatement switchStatement); |
||||
S VisitSwitchSection(SwitchSection switchSection); |
||||
S VisitCaseLabel(CaseLabel caseLabel); |
||||
S VisitThrowStatement(ThrowStatement throwStatement); |
||||
S VisitTryCatchStatement(TryCatchStatement tryCatchStatement); |
||||
S VisitCatchClause(CatchClause catchClause); |
||||
S VisitUncheckedStatement(UncheckedStatement uncheckedStatement); |
||||
S VisitUnsafeStatement(UnsafeStatement unsafeStatement); |
||||
S VisitUsingStatement(UsingStatement usingStatement); |
||||
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement); |
||||
S VisitWhileStatement(WhileStatement whileStatement); |
||||
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement); |
||||
S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement); |
||||
|
||||
S VisitAccessor(Accessor accessor); |
||||
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration); |
||||
S VisitConstructorInitializer(ConstructorInitializer constructorInitializer); |
||||
S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration); |
||||
S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration); |
||||
S VisitEventDeclaration(EventDeclaration eventDeclaration); |
||||
S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration); |
||||
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration); |
||||
S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration); |
||||
S VisitMethodDeclaration(MethodDeclaration methodDeclaration); |
||||
S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration); |
||||
S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration); |
||||
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration); |
||||
S VisitVariableInitializer(VariableInitializer variableInitializer); |
||||
S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration); |
||||
S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer); |
||||
|
||||
S VisitSyntaxTree(SyntaxTree syntaxTree); |
||||
S VisitSimpleType(SimpleType simpleType); |
||||
S VisitMemberType(MemberType memberType); |
||||
S VisitComposedType(ComposedType composedType); |
||||
S VisitArraySpecifier(ArraySpecifier arraySpecifier); |
||||
S VisitPrimitiveType(PrimitiveType primitiveType); |
||||
|
||||
S VisitComment(Comment comment); |
||||
S VisitWhitespace(WhitespaceNode whitespaceNode); |
||||
S VisitText(TextNode textNode); |
||||
S VisitNewLine(NewLineNode newLineNode); |
||||
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective); |
||||
S VisitDocumentationReference(DocumentationReference documentationReference); |
||||
|
||||
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration); |
||||
S VisitConstraint(Constraint constraint); |
||||
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode); |
||||
S VisitIdentifier(Identifier identifier); |
||||
|
||||
S VisitNullNode(AstNode nullNode); |
||||
S VisitErrorNode(AstNode errorNode); |
||||
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// AST visitor.
|
||||
/// </summary>
|
||||
public interface IAstVisitor<in T, out S> |
||||
{ |
||||
S VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression, T data); |
||||
S VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression, T data); |
||||
S VisitArrayCreateExpression(ArrayCreateExpression arrayCreateExpression, T data); |
||||
S VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression, T data); |
||||
S VisitAsExpression(AsExpression asExpression, T data); |
||||
S VisitAssignmentExpression(AssignmentExpression assignmentExpression, T data); |
||||
S VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression, T data); |
||||
S VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, T data); |
||||
S VisitCastExpression(CastExpression castExpression, T data); |
||||
S VisitCheckedExpression(CheckedExpression checkedExpression, T data); |
||||
S VisitConditionalExpression(ConditionalExpression conditionalExpression, T data); |
||||
S VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression, T data); |
||||
S VisitDirectionExpression(DirectionExpression directionExpression, T data); |
||||
S VisitIdentifierExpression(IdentifierExpression identifierExpression, T data); |
||||
S VisitIndexerExpression(IndexerExpression indexerExpression, T data); |
||||
S VisitInvocationExpression(InvocationExpression invocationExpression, T data); |
||||
S VisitIsExpression(IsExpression isExpression, T data); |
||||
S VisitLambdaExpression(LambdaExpression lambdaExpression, T data); |
||||
S VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, T data); |
||||
S VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression, T data); |
||||
S VisitNamedExpression(NamedExpression namedExpression, T data); |
||||
S VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression, T data); |
||||
S VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression, T data); |
||||
S VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression, T data); |
||||
S VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, T data); |
||||
S VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression, T data); |
||||
S VisitPrimitiveExpression(PrimitiveExpression primitiveExpression, T data); |
||||
S VisitSizeOfExpression(SizeOfExpression sizeOfExpression, T data); |
||||
S VisitStackAllocExpression(StackAllocExpression stackAllocExpression, T data); |
||||
S VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression, T data); |
||||
S VisitTypeOfExpression(TypeOfExpression typeOfExpression, T data); |
||||
S VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression, T data); |
||||
S VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, T data); |
||||
S VisitUncheckedExpression(UncheckedExpression uncheckedExpression, T data); |
||||
|
||||
S VisitQueryExpression(QueryExpression queryExpression, T data); |
||||
S VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause, T data); |
||||
S VisitQueryFromClause(QueryFromClause queryFromClause, T data); |
||||
S VisitQueryLetClause(QueryLetClause queryLetClause, T data); |
||||
S VisitQueryWhereClause(QueryWhereClause queryWhereClause, T data); |
||||
S VisitQueryJoinClause(QueryJoinClause queryJoinClause, T data); |
||||
S VisitQueryOrderClause(QueryOrderClause queryOrderClause, T data); |
||||
S VisitQueryOrdering(QueryOrdering queryOrdering, T data); |
||||
S VisitQuerySelectClause(QuerySelectClause querySelectClause, T data); |
||||
S VisitQueryGroupClause(QueryGroupClause queryGroupClause, T data); |
||||
|
||||
S VisitAttribute(Attribute attribute, T data); |
||||
S VisitAttributeSection(AttributeSection attributeSection, T data); |
||||
S VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration, T data); |
||||
S VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration, T data); |
||||
S VisitTypeDeclaration(TypeDeclaration typeDeclaration, T data); |
||||
S VisitUsingAliasDeclaration(UsingAliasDeclaration usingAliasDeclaration, T data); |
||||
S VisitUsingDeclaration(UsingDeclaration usingDeclaration, T data); |
||||
S VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration, T data); |
||||
|
||||
S VisitBlockStatement(BlockStatement blockStatement, T data); |
||||
S VisitBreakStatement(BreakStatement breakStatement, T data); |
||||
S VisitCheckedStatement(CheckedStatement checkedStatement, T data); |
||||
S VisitContinueStatement(ContinueStatement continueStatement, T data); |
||||
S VisitDoWhileStatement(DoWhileStatement doWhileStatement, T data); |
||||
S VisitEmptyStatement(EmptyStatement emptyStatement, T data); |
||||
S VisitExpressionStatement(ExpressionStatement expressionStatement, T data); |
||||
S VisitFixedStatement(FixedStatement fixedStatement, T data); |
||||
S VisitForeachStatement(ForeachStatement foreachStatement, T data); |
||||
S VisitForStatement(ForStatement forStatement, T data); |
||||
S VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement, T data); |
||||
S VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement, T data); |
||||
S VisitGotoStatement(GotoStatement gotoStatement, T data); |
||||
S VisitIfElseStatement(IfElseStatement ifElseStatement, T data); |
||||
S VisitLabelStatement(LabelStatement labelStatement, T data); |
||||
S VisitLockStatement(LockStatement lockStatement, T data); |
||||
S VisitReturnStatement(ReturnStatement returnStatement, T data); |
||||
S VisitSwitchStatement(SwitchStatement switchStatement, T data); |
||||
S VisitSwitchSection(SwitchSection switchSection, T data); |
||||
S VisitCaseLabel(CaseLabel caseLabel, T data); |
||||
S VisitThrowStatement(ThrowStatement throwStatement, T data); |
||||
S VisitTryCatchStatement(TryCatchStatement tryCatchStatement, T data); |
||||
S VisitCatchClause(CatchClause catchClause, T data); |
||||
S VisitUncheckedStatement(UncheckedStatement uncheckedStatement, T data); |
||||
S VisitUnsafeStatement(UnsafeStatement unsafeStatement, T data); |
||||
S VisitUsingStatement(UsingStatement usingStatement, T data); |
||||
S VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement, T data); |
||||
S VisitWhileStatement(WhileStatement whileStatement, T data); |
||||
S VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement, T data); |
||||
S VisitYieldReturnStatement(YieldReturnStatement yieldReturnStatement, T data); |
||||
|
||||
S VisitAccessor(Accessor accessor, T data); |
||||
S VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration, T data); |
||||
S VisitConstructorInitializer(ConstructorInitializer constructorInitializer, T data); |
||||
S VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration, T data); |
||||
S VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration, T data); |
||||
S VisitEventDeclaration(EventDeclaration eventDeclaration, T data); |
||||
S VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration, T data); |
||||
S VisitFieldDeclaration(FieldDeclaration fieldDeclaration, T data); |
||||
S VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration, T data); |
||||
S VisitMethodDeclaration(MethodDeclaration methodDeclaration, T data); |
||||
S VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration, T data); |
||||
S VisitParameterDeclaration(ParameterDeclaration parameterDeclaration, T data); |
||||
S VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration, T data); |
||||
S VisitVariableInitializer(VariableInitializer variableInitializer, T data); |
||||
S VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration, T data); |
||||
S VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer, T data); |
||||
|
||||
S VisitSyntaxTree(SyntaxTree syntaxTree, T data); |
||||
S VisitSimpleType(SimpleType simpleType, T data); |
||||
S VisitMemberType(MemberType memberType, T data); |
||||
S VisitComposedType(ComposedType composedType, T data); |
||||
S VisitArraySpecifier(ArraySpecifier arraySpecifier, T data); |
||||
S VisitPrimitiveType(PrimitiveType primitiveType, T data); |
||||
|
||||
S VisitComment(Comment comment, T data); |
||||
S VisitNewLine(NewLineNode newLineNode, T data); |
||||
S VisitWhitespace(WhitespaceNode whitespaceNode, T data); |
||||
S VisitText(TextNode textNode, T data); |
||||
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data); |
||||
S VisitDocumentationReference(DocumentationReference documentationReference, T data); |
||||
|
||||
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data); |
||||
S VisitConstraint(Constraint constraint, T data); |
||||
S VisitCSharpTokenNode(CSharpTokenNode cSharpTokenNode, T data); |
||||
S VisitIdentifier(Identifier identifier, T data); |
||||
|
||||
S VisitNullNode(AstNode nullNode, T data); |
||||
S VisitErrorNode(AstNode errorNode, T data); |
||||
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data); |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
//
|
||||
// Identifier.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class Identifier : AstNode |
||||
{ |
||||
public new static readonly Identifier Null = new NullIdentifier (); |
||||
sealed class NullIdentifier : Identifier |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Token; |
||||
} |
||||
} |
||||
|
||||
string name; |
||||
public string Name { |
||||
get { return this.name; } |
||||
set { |
||||
if (value == null) |
||||
throw new ArgumentNullException("value"); |
||||
ThrowIfFrozen(); |
||||
this.name = value; |
||||
} |
||||
} |
||||
|
||||
TextLocation startLocation; |
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return startLocation; |
||||
} |
||||
} |
||||
|
||||
internal void SetStartLocation(TextLocation value) |
||||
{ |
||||
ThrowIfFrozen(); |
||||
this.startLocation = value; |
||||
} |
||||
|
||||
const uint verbatimBit = 1u << AstNodeFlagsUsedBits; |
||||
|
||||
public bool IsVerbatim { |
||||
get { |
||||
return (flags & verbatimBit) != 0; |
||||
} |
||||
set { |
||||
ThrowIfFrozen(); |
||||
if (value) |
||||
flags |= verbatimBit; |
||||
else |
||||
flags &= ~verbatimBit; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (StartLocation.Line, StartLocation.Column + (Name ?? "").Length + (IsVerbatim ? 1 : 0)); |
||||
} |
||||
} |
||||
|
||||
Identifier () |
||||
{ |
||||
this.name = string.Empty; |
||||
} |
||||
|
||||
protected Identifier (string name, TextLocation location) |
||||
{ |
||||
if (name == null) |
||||
throw new ArgumentNullException("name"); |
||||
this.Name = name; |
||||
this.startLocation = location; |
||||
} |
||||
|
||||
public static Identifier Create (string name) |
||||
{ |
||||
return Create (name, TextLocation.Empty); |
||||
} |
||||
|
||||
public static Identifier Create (string name, TextLocation location) |
||||
{ |
||||
if (string.IsNullOrEmpty(name)) |
||||
return Identifier.Null; |
||||
if (name[0] == '@') |
||||
return new Identifier (name.Substring (1), new TextLocation (location.Line, location.Column + 1)) { IsVerbatim = true }; |
||||
else |
||||
return new Identifier (name, location); |
||||
} |
||||
|
||||
public static Identifier Create (string name, TextLocation location, bool isVerbatim) |
||||
{ |
||||
if (string.IsNullOrEmpty (name)) |
||||
return Identifier.Null; |
||||
|
||||
if (isVerbatim) |
||||
return new Identifier (name, location) { IsVerbatim = true }; |
||||
return new Identifier (name, location); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitIdentifier (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitIdentifier (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIdentifier (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
Identifier o = other as Identifier; |
||||
return o != null && !o.IsNull && MatchString(this.Name, o.Name); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,54 @@
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.PatternMatching; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Matches identifier expressions that have the same identifier as the referenced variable/type definition/method definition.
|
||||
/// </summary>
|
||||
public class IdentifierExpressionBackreference : Pattern |
||||
{ |
||||
readonly string referencedGroupName; |
||||
|
||||
public string ReferencedGroupName { |
||||
get { return referencedGroupName; } |
||||
} |
||||
|
||||
public IdentifierExpressionBackreference(string referencedGroupName) |
||||
{ |
||||
if (referencedGroupName == null) |
||||
throw new ArgumentNullException("referencedGroupName"); |
||||
this.referencedGroupName = referencedGroupName; |
||||
} |
||||
|
||||
public override bool DoMatch(INode other, Match match) |
||||
{ |
||||
CSharp.IdentifierExpression ident = other as CSharp.IdentifierExpression; |
||||
if (ident == null || ident.TypeArguments.Any()) |
||||
return false; |
||||
CSharp.AstNode referenced = (CSharp.AstNode)match.Get(referencedGroupName).Last(); |
||||
if (referenced == null) |
||||
return false; |
||||
return ident.Identifier == referenced.GetChildByRole(CSharp.Roles.Identifier).Name; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// Modifiers.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
[Flags] |
||||
public enum Modifiers |
||||
{ |
||||
None = 0, |
||||
|
||||
Private = 0x0001, |
||||
Internal = 0x0002, |
||||
Protected = 0x0004, |
||||
Public = 0x0008, |
||||
|
||||
Abstract = 0x0010, |
||||
Virtual = 0x0020, |
||||
Sealed = 0x0040, |
||||
Static = 0x0080, |
||||
Override = 0x0100, |
||||
Readonly = 0x0200, |
||||
Const = 0x0400, |
||||
New = 0x0800, |
||||
Partial = 0x1000, |
||||
|
||||
Extern = 0x2000, |
||||
Volatile = 0x4000, |
||||
Unsafe = 0x8000, |
||||
Async = 0x10000, |
||||
|
||||
VisibilityMask = Private | Internal | Protected | Public, |
||||
|
||||
/// <summary>
|
||||
/// Special value used to match any modifiers during pattern matching.
|
||||
/// </summary>
|
||||
Any = unchecked((int)0x80000000) |
||||
} |
||||
} |
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// NodeType.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public enum NodeType |
||||
{ |
||||
Unknown, |
||||
/// <summary>
|
||||
/// AstType
|
||||
/// </summary>
|
||||
TypeReference, |
||||
/// <summary>
|
||||
/// Type or delegate declaration
|
||||
/// </summary>
|
||||
TypeDeclaration, |
||||
Member, |
||||
Statement, |
||||
Expression, |
||||
Token, |
||||
QueryClause, |
||||
/// <summary>
|
||||
/// Comment or whitespace or pre-processor directive
|
||||
/// </summary>
|
||||
Whitespace, |
||||
/// <summary>
|
||||
/// Placeholder for a pattern
|
||||
/// </summary>
|
||||
Pattern |
||||
} |
||||
} |
@ -0,0 +1,857 @@
@@ -0,0 +1,857 @@
|
||||
//
|
||||
// ObservableAstVisitor.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class ObservableAstVisitor : IAstVisitor |
||||
{ |
||||
void Visit<T>(Action<T> enter, Action<T> leave, T node) where T : AstNode |
||||
{ |
||||
if (enter != null) |
||||
enter(node); |
||||
AstNode next; |
||||
for (var child = node.FirstChild; child != null; child = next) { |
||||
// Store next to allow the loop to continue
|
||||
// if the visitor removes/replaces children.
|
||||
next = child.NextSibling; |
||||
child.AcceptVisitor (this); |
||||
} |
||||
if (leave != null) |
||||
leave(node); |
||||
} |
||||
|
||||
void IAstVisitor.VisitNullNode(AstNode nullNode) |
||||
{ |
||||
} |
||||
|
||||
void IAstVisitor.VisitErrorNode(AstNode nullNode) |
||||
{ |
||||
} |
||||
|
||||
public event Action<SyntaxTree> EnterSyntaxTree, LeaveSyntaxTree; |
||||
|
||||
void IAstVisitor.VisitSyntaxTree(SyntaxTree unit) |
||||
{ |
||||
Visit(EnterSyntaxTree, LeaveSyntaxTree, unit); |
||||
} |
||||
|
||||
public event Action<Comment> EnterComment, LeaveComment; |
||||
|
||||
void IAstVisitor.VisitComment(Comment comment) |
||||
{ |
||||
Visit(EnterComment, LeaveComment, comment); |
||||
} |
||||
|
||||
public event Action<NewLineNode> EnterNewLine, LeaveNewLine; |
||||
|
||||
void IAstVisitor.VisitNewLine(NewLineNode newLineNode) |
||||
{ |
||||
Visit(EnterNewLine, LeaveNewLine, newLineNode); |
||||
} |
||||
|
||||
public event Action<WhitespaceNode> EnterWhitespace, LeaveWhitespace; |
||||
|
||||
void IAstVisitor.VisitWhitespace(WhitespaceNode whitespace) |
||||
{ |
||||
Visit(EnterWhitespace, LeaveWhitespace, whitespace); |
||||
} |
||||
|
||||
public event Action<TextNode> EnterText, LeaveText; |
||||
|
||||
void IAstVisitor.VisitText(TextNode textNode) |
||||
{ |
||||
Visit(EnterText, LeaveText, textNode); |
||||
} |
||||
|
||||
public event Action<PreProcessorDirective> EnterPreProcessorDirective, LeavePreProcessorDirective; |
||||
void IAstVisitor.VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective) |
||||
{ |
||||
Visit(EnterPreProcessorDirective, LeavePreProcessorDirective, preProcessorDirective); |
||||
} |
||||
|
||||
public event Action<DocumentationReference> EnterDocumentationReference, LeaveDocumentationReference; |
||||
|
||||
void IAstVisitor.VisitDocumentationReference(DocumentationReference documentationReference) |
||||
{ |
||||
Visit(EnterDocumentationReference, LeaveDocumentationReference, documentationReference); |
||||
} |
||||
|
||||
public event Action<Identifier> EnterIdentifier, LeaveIdentifier; |
||||
|
||||
void IAstVisitor.VisitIdentifier(Identifier identifier) |
||||
{ |
||||
Visit(EnterIdentifier, LeaveIdentifier, identifier); |
||||
} |
||||
|
||||
public event Action<CSharpTokenNode> EnterCSharpTokenNode, LeaveCSharpTokenNode; |
||||
|
||||
void IAstVisitor.VisitCSharpTokenNode(CSharpTokenNode token) |
||||
{ |
||||
Visit(EnterCSharpTokenNode, LeaveCSharpTokenNode, token); |
||||
} |
||||
|
||||
public event Action<PrimitiveType> EnterPrimitiveType, LeavePrimitiveType; |
||||
|
||||
void IAstVisitor.VisitPrimitiveType(PrimitiveType primitiveType) |
||||
{ |
||||
Visit(EnterPrimitiveType, LeavePrimitiveType, primitiveType); |
||||
} |
||||
|
||||
public event Action<ComposedType> EnterComposedType, LeaveComposedType; |
||||
|
||||
void IAstVisitor.VisitComposedType(ComposedType composedType) |
||||
{ |
||||
Visit(EnterComposedType, LeaveComposedType, composedType); |
||||
} |
||||
|
||||
public event Action<SimpleType> EnterSimpleType, LeaveSimpleType; |
||||
|
||||
void IAstVisitor.VisitSimpleType(SimpleType simpleType) |
||||
{ |
||||
Visit(EnterSimpleType, LeaveSimpleType, simpleType); |
||||
} |
||||
|
||||
public event Action<MemberType> EnterMemberType, LeaveMemberType; |
||||
|
||||
void IAstVisitor.VisitMemberType(MemberType memberType) |
||||
{ |
||||
Visit(EnterMemberType, LeaveMemberType, memberType); |
||||
} |
||||
|
||||
public event Action<Attribute> EnterAttribute, LeaveAttribute; |
||||
|
||||
void IAstVisitor.VisitAttribute(Attribute attribute) |
||||
{ |
||||
Visit(EnterAttribute, LeaveAttribute, attribute); |
||||
} |
||||
|
||||
public event Action<AttributeSection> EnterAttributeSection, LeaveAttributeSection; |
||||
|
||||
void IAstVisitor.VisitAttributeSection(AttributeSection attributeSection) |
||||
{ |
||||
Visit(EnterAttributeSection, LeaveAttributeSection, attributeSection); |
||||
} |
||||
|
||||
public event Action<DelegateDeclaration> EnterDelegateDeclaration, LeaveDelegateDeclaration; |
||||
|
||||
void IAstVisitor.VisitDelegateDeclaration(DelegateDeclaration delegateDeclaration) |
||||
{ |
||||
Visit(EnterDelegateDeclaration, LeaveDelegateDeclaration, delegateDeclaration); |
||||
} |
||||
|
||||
public event Action<NamespaceDeclaration> EnterNamespaceDeclaration, LeaveNamespaceDeclaration; |
||||
|
||||
void IAstVisitor.VisitNamespaceDeclaration(NamespaceDeclaration namespaceDeclaration) |
||||
{ |
||||
Visit(EnterNamespaceDeclaration, LeaveNamespaceDeclaration, namespaceDeclaration); |
||||
} |
||||
|
||||
public event Action<TypeDeclaration> EnterTypeDeclaration, LeaveTypeDeclaration; |
||||
|
||||
void IAstVisitor.VisitTypeDeclaration(TypeDeclaration typeDeclaration) |
||||
{ |
||||
Visit(EnterTypeDeclaration, LeaveTypeDeclaration, typeDeclaration); |
||||
} |
||||
|
||||
public event Action<TypeParameterDeclaration> EnterTypeParameterDeclaration, LeaveTypeParameterDeclaration; |
||||
|
||||
void IAstVisitor.VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration) |
||||
{ |
||||
Visit(EnterTypeParameterDeclaration, LeaveTypeParameterDeclaration, typeParameterDeclaration); |
||||
} |
||||
|
||||
public event Action<EnumMemberDeclaration> EnterEnumMemberDeclaration, LeaveEnumMemberDeclaration; |
||||
|
||||
void IAstVisitor.VisitEnumMemberDeclaration(EnumMemberDeclaration enumMemberDeclaration) |
||||
{ |
||||
Visit(EnterEnumMemberDeclaration, LeaveEnumMemberDeclaration, enumMemberDeclaration); |
||||
} |
||||
|
||||
public event Action<UsingDeclaration> EnterUsingDeclaration, LeaveUsingDeclaration; |
||||
|
||||
void IAstVisitor.VisitUsingDeclaration(UsingDeclaration usingDeclaration) |
||||
{ |
||||
Visit(EnterUsingDeclaration, LeaveUsingDeclaration, usingDeclaration); |
||||
} |
||||
|
||||
public event Action<UsingAliasDeclaration> EnterUsingAliasDeclaration, LeaveUsingAliasDeclaration; |
||||
|
||||
void IAstVisitor.VisitUsingAliasDeclaration(UsingAliasDeclaration usingDeclaration) |
||||
{ |
||||
Visit(EnterUsingAliasDeclaration, LeaveUsingAliasDeclaration, usingDeclaration); |
||||
} |
||||
|
||||
public event Action<ExternAliasDeclaration> EnterExternAliasDeclaration, LeaveExternAliasDeclaration; |
||||
|
||||
void IAstVisitor.VisitExternAliasDeclaration(ExternAliasDeclaration externAliasDeclaration) |
||||
{ |
||||
Visit(EnterExternAliasDeclaration, LeaveExternAliasDeclaration, externAliasDeclaration); |
||||
} |
||||
|
||||
public event Action<ConstructorDeclaration> EnterConstructorDeclaration, LeaveConstructorDeclaration; |
||||
|
||||
void IAstVisitor.VisitConstructorDeclaration(ConstructorDeclaration constructorDeclaration) |
||||
{ |
||||
Visit(EnterConstructorDeclaration, LeaveConstructorDeclaration, constructorDeclaration); |
||||
} |
||||
|
||||
public event Action<ConstructorInitializer> EnterConstructorInitializer, LeaveConstructorInitializer; |
||||
|
||||
void IAstVisitor.VisitConstructorInitializer(ConstructorInitializer constructorInitializer) |
||||
{ |
||||
Visit(EnterConstructorInitializer, LeaveConstructorInitializer, constructorInitializer); |
||||
} |
||||
|
||||
public event Action<DestructorDeclaration> EnterDestructorDeclaration, LeaveDestructorDeclaration; |
||||
|
||||
void IAstVisitor.VisitDestructorDeclaration(DestructorDeclaration destructorDeclaration) |
||||
{ |
||||
Visit(EnterDestructorDeclaration, LeaveDestructorDeclaration, destructorDeclaration); |
||||
} |
||||
|
||||
public event Action<EventDeclaration> EnterEventDeclaration, LeaveEventDeclaration; |
||||
|
||||
void IAstVisitor.VisitEventDeclaration(EventDeclaration eventDeclaration) |
||||
{ |
||||
Visit(EnterEventDeclaration, LeaveEventDeclaration, eventDeclaration); |
||||
} |
||||
|
||||
public event Action<CustomEventDeclaration> EnterCustomEventDeclaration, LeaveCustomEventDeclaration; |
||||
|
||||
void IAstVisitor.VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration) |
||||
{ |
||||
Visit(EnterCustomEventDeclaration, LeaveCustomEventDeclaration, eventDeclaration); |
||||
} |
||||
|
||||
public event Action<FieldDeclaration> EnterFieldDeclaration, LeaveFieldDeclaration; |
||||
|
||||
void IAstVisitor.VisitFieldDeclaration(FieldDeclaration fieldDeclaration) |
||||
{ |
||||
Visit(EnterFieldDeclaration, LeaveFieldDeclaration, fieldDeclaration); |
||||
} |
||||
|
||||
public event Action<FixedFieldDeclaration> EnterFixedFieldDeclaration, LeaveFixedFieldDeclaration; |
||||
|
||||
void IAstVisitor.VisitFixedFieldDeclaration(FixedFieldDeclaration fixedFieldDeclaration) |
||||
{ |
||||
Visit(EnterFixedFieldDeclaration, LeaveFixedFieldDeclaration, fixedFieldDeclaration); |
||||
} |
||||
|
||||
public event Action<FixedVariableInitializer> EnterFixedVariableInitializer, LeaveFixedVariableInitializer; |
||||
|
||||
void IAstVisitor.VisitFixedVariableInitializer(FixedVariableInitializer fixedVariableInitializer) |
||||
{ |
||||
Visit(EnterFixedVariableInitializer, LeaveFixedVariableInitializer, fixedVariableInitializer); |
||||
} |
||||
|
||||
public event Action<IndexerDeclaration> EnterIndexerDeclaration, LeaveIndexerDeclaration; |
||||
|
||||
void IAstVisitor.VisitIndexerDeclaration(IndexerDeclaration indexerDeclaration) |
||||
{ |
||||
Visit(EnterIndexerDeclaration, LeaveIndexerDeclaration, indexerDeclaration); |
||||
} |
||||
|
||||
public event Action<MethodDeclaration> EnterMethodDeclaration, LeaveMethodDeclaration; |
||||
|
||||
void IAstVisitor.VisitMethodDeclaration(MethodDeclaration methodDeclaration) |
||||
{ |
||||
Visit(EnterMethodDeclaration, LeaveMethodDeclaration, methodDeclaration); |
||||
} |
||||
|
||||
public event Action<OperatorDeclaration> EnterOperatorDeclaration, LeaveOperatorDeclaration; |
||||
|
||||
void IAstVisitor.VisitOperatorDeclaration(OperatorDeclaration operatorDeclaration) |
||||
{ |
||||
Visit(EnterOperatorDeclaration, LeaveOperatorDeclaration, operatorDeclaration); |
||||
} |
||||
|
||||
public event Action<PropertyDeclaration> EnterPropertyDeclaration, LeavePropertyDeclaration; |
||||
|
||||
void IAstVisitor.VisitPropertyDeclaration(PropertyDeclaration propertyDeclaration) |
||||
{ |
||||
Visit(EnterPropertyDeclaration, LeavePropertyDeclaration, propertyDeclaration); |
||||
} |
||||
|
||||
public event Action<Accessor> EnterAccessor, LeaveAccessor; |
||||
|
||||
void IAstVisitor.VisitAccessor(Accessor accessor) |
||||
{ |
||||
Visit(EnterAccessor, LeaveAccessor, accessor); |
||||
} |
||||
|
||||
public event Action<VariableInitializer> EnterVariableInitializer, LeaveVariableInitializer; |
||||
|
||||
void IAstVisitor.VisitVariableInitializer(VariableInitializer variableInitializer) |
||||
{ |
||||
Visit(EnterVariableInitializer, LeaveVariableInitializer, variableInitializer); |
||||
} |
||||
|
||||
public event Action<ParameterDeclaration> EnterParameterDeclaration, LeaveParameterDeclaration; |
||||
|
||||
void IAstVisitor.VisitParameterDeclaration(ParameterDeclaration parameterDeclaration) |
||||
{ |
||||
Visit(EnterParameterDeclaration, LeaveParameterDeclaration, parameterDeclaration); |
||||
} |
||||
|
||||
public event Action<Constraint> EnterConstraint, LeaveConstraint; |
||||
|
||||
void IAstVisitor.VisitConstraint(Constraint constraint) |
||||
{ |
||||
Visit(EnterConstraint, LeaveConstraint, constraint); |
||||
} |
||||
|
||||
public event Action<BlockStatement> EnterBlockStatement, LeaveBlockStatement; |
||||
|
||||
void IAstVisitor.VisitBlockStatement(BlockStatement blockStatement) |
||||
{ |
||||
Visit(EnterBlockStatement, LeaveBlockStatement, blockStatement); |
||||
} |
||||
|
||||
public event Action<ExpressionStatement> EnterExpressionStatement, LeaveExpressionStatement; |
||||
|
||||
void IAstVisitor.VisitExpressionStatement(ExpressionStatement expressionStatement) |
||||
{ |
||||
Visit(EnterExpressionStatement, LeaveExpressionStatement, expressionStatement); |
||||
} |
||||
|
||||
public event Action<BreakStatement> EnterBreakStatement, LeaveBreakStatement; |
||||
|
||||
void IAstVisitor.VisitBreakStatement(BreakStatement breakStatement) |
||||
{ |
||||
Visit(EnterBreakStatement, LeaveBreakStatement, breakStatement); |
||||
} |
||||
|
||||
public event Action<CheckedStatement> EnterCheckedStatement, LeaveCheckedStatement; |
||||
|
||||
void IAstVisitor.VisitCheckedStatement(CheckedStatement checkedStatement) |
||||
{ |
||||
Visit(EnterCheckedStatement, LeaveCheckedStatement, checkedStatement); |
||||
} |
||||
|
||||
public event Action<ContinueStatement> EnterContinueStatement, LeaveContinueStatement; |
||||
|
||||
void IAstVisitor.VisitContinueStatement(ContinueStatement continueStatement) |
||||
{ |
||||
Visit(EnterContinueStatement, LeaveContinueStatement, continueStatement); |
||||
} |
||||
|
||||
public event Action<DoWhileStatement> EnterDoWhileStatement, LeaveDoWhileStatement; |
||||
|
||||
void IAstVisitor.VisitDoWhileStatement(DoWhileStatement doWhileStatement) |
||||
{ |
||||
Visit(EnterDoWhileStatement, LeaveDoWhileStatement, doWhileStatement); |
||||
} |
||||
|
||||
public event Action<EmptyStatement> EnterEmptyStatement, LeaveEmptyStatement; |
||||
|
||||
void IAstVisitor.VisitEmptyStatement(EmptyStatement emptyStatement) |
||||
{ |
||||
Visit(EnterEmptyStatement, LeaveEmptyStatement, emptyStatement); |
||||
} |
||||
|
||||
public event Action<FixedStatement> EnterFixedStatement, LeaveFixedStatement; |
||||
|
||||
void IAstVisitor.VisitFixedStatement(FixedStatement fixedStatement) |
||||
{ |
||||
Visit(EnterFixedStatement, LeaveFixedStatement, fixedStatement); |
||||
} |
||||
|
||||
public event Action<ForeachStatement> EnterForeachStatement, LeaveForeachStatement; |
||||
|
||||
void IAstVisitor.VisitForeachStatement(ForeachStatement foreachStatement) |
||||
{ |
||||
Visit(EnterForeachStatement, LeaveForeachStatement, foreachStatement); |
||||
} |
||||
|
||||
public event Action<ForStatement> EnterForStatement, LeaveForStatement; |
||||
|
||||
void IAstVisitor.VisitForStatement(ForStatement forStatement) |
||||
{ |
||||
Visit(EnterForStatement, LeaveForStatement, forStatement); |
||||
} |
||||
|
||||
public event Action<GotoCaseStatement> EnterGotoCaseStatement, LeaveGotoCaseStatement; |
||||
|
||||
void IAstVisitor.VisitGotoCaseStatement(GotoCaseStatement gotoCaseStatement) |
||||
{ |
||||
Visit(EnterGotoCaseStatement, LeaveGotoCaseStatement, gotoCaseStatement); |
||||
} |
||||
|
||||
public event Action<GotoDefaultStatement> EnterGotoDefaultStatement, LeaveGotoDefaultStatement; |
||||
|
||||
void IAstVisitor.VisitGotoDefaultStatement(GotoDefaultStatement gotoDefaultStatement) |
||||
{ |
||||
Visit(EnterGotoDefaultStatement, LeaveGotoDefaultStatement, gotoDefaultStatement); |
||||
} |
||||
|
||||
public event Action<GotoStatement> EnterGotoStatement, LeaveGotoStatement; |
||||
|
||||
void IAstVisitor.VisitGotoStatement(GotoStatement gotoStatement) |
||||
{ |
||||
Visit(EnterGotoStatement, LeaveGotoStatement, gotoStatement); |
||||
} |
||||
|
||||
public event Action<IfElseStatement> EnterIfElseStatement, LeaveIfElseStatement; |
||||
|
||||
void IAstVisitor.VisitIfElseStatement(IfElseStatement ifElseStatement) |
||||
{ |
||||
Visit(EnterIfElseStatement, LeaveIfElseStatement, ifElseStatement); |
||||
} |
||||
|
||||
public event Action<LabelStatement> EnterLabelStatement, LeaveLabelStatement; |
||||
|
||||
void IAstVisitor.VisitLabelStatement(LabelStatement labelStatement) |
||||
{ |
||||
Visit(EnterLabelStatement, LeaveLabelStatement, labelStatement); |
||||
} |
||||
|
||||
public event Action<LockStatement> EnterLockStatement, LeaveLockStatement; |
||||
|
||||
void IAstVisitor.VisitLockStatement(LockStatement lockStatement) |
||||
{ |
||||
Visit(EnterLockStatement, LeaveLockStatement, lockStatement); |
||||
} |
||||
|
||||
public event Action<ReturnStatement> EnterReturnStatement, LeaveReturnStatement; |
||||
|
||||
void IAstVisitor.VisitReturnStatement(ReturnStatement returnStatement) |
||||
{ |
||||
Visit(EnterReturnStatement, LeaveReturnStatement, returnStatement); |
||||
} |
||||
|
||||
public event Action<SwitchStatement> EnterSwitchStatement, LeaveSwitchStatement; |
||||
|
||||
void IAstVisitor.VisitSwitchStatement(SwitchStatement switchStatement) |
||||
{ |
||||
Visit(EnterSwitchStatement, LeaveSwitchStatement, switchStatement); |
||||
} |
||||
|
||||
public event Action<SwitchSection> EnterSwitchSection, LeaveSwitchSection; |
||||
|
||||
void IAstVisitor.VisitSwitchSection(SwitchSection switchSection) |
||||
{ |
||||
Visit(EnterSwitchSection, LeaveSwitchSection, switchSection); |
||||
} |
||||
|
||||
public event Action<CaseLabel> EnterCaseLabel, LeaveCaseLabel; |
||||
|
||||
void IAstVisitor.VisitCaseLabel(CaseLabel caseLabel) |
||||
{ |
||||
Visit(EnterCaseLabel, LeaveCaseLabel, caseLabel); |
||||
} |
||||
|
||||
public event Action<ThrowStatement> EnterThrowStatement, LeaveThrowStatement; |
||||
|
||||
void IAstVisitor.VisitThrowStatement(ThrowStatement throwStatement) |
||||
{ |
||||
Visit(EnterThrowStatement, LeaveThrowStatement, throwStatement); |
||||
} |
||||
|
||||
public event Action<TryCatchStatement> EnterTryCatchStatement, LeaveTryCatchStatement; |
||||
|
||||
void IAstVisitor.VisitTryCatchStatement(TryCatchStatement tryCatchStatement) |
||||
{ |
||||
Visit(EnterTryCatchStatement, LeaveTryCatchStatement, tryCatchStatement); |
||||
} |
||||
|
||||
public event Action<CatchClause> EnterCatchClause, LeaveCatchClause; |
||||
|
||||
void IAstVisitor.VisitCatchClause(CatchClause catchClause) |
||||
{ |
||||
Visit(EnterCatchClause, LeaveCatchClause, catchClause); |
||||
} |
||||
|
||||
public event Action<UncheckedStatement> EnterUncheckedStatement, LeaveUncheckedStatement; |
||||
|
||||
void IAstVisitor.VisitUncheckedStatement(UncheckedStatement uncheckedStatement) |
||||
{ |
||||
Visit(EnterUncheckedStatement, LeaveUncheckedStatement, uncheckedStatement); |
||||
} |
||||
|
||||
public event Action<UnsafeStatement> EnterUnsafeStatement, LeaveUnsafeStatement; |
||||
|
||||
void IAstVisitor.VisitUnsafeStatement(UnsafeStatement unsafeStatement) |
||||
{ |
||||
Visit(EnterUnsafeStatement, LeaveUnsafeStatement, unsafeStatement); |
||||
} |
||||
|
||||
public event Action<UsingStatement> EnterUsingStatement, LeaveUsingStatement; |
||||
|
||||
void IAstVisitor.VisitUsingStatement(UsingStatement usingStatement) |
||||
{ |
||||
Visit(EnterUsingStatement, LeaveUsingStatement, usingStatement); |
||||
} |
||||
|
||||
public event Action<VariableDeclarationStatement> EnterVariableDeclarationStatement, LeaveVariableDeclarationStatement; |
||||
|
||||
void IAstVisitor.VisitVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement) |
||||
{ |
||||
Visit(EnterVariableDeclarationStatement, LeaveVariableDeclarationStatement, variableDeclarationStatement); |
||||
} |
||||
|
||||
public event Action<WhileStatement> EnterWhileStatement, LeaveWhileStatement; |
||||
|
||||
void IAstVisitor.VisitWhileStatement(WhileStatement whileStatement) |
||||
{ |
||||
Visit(EnterWhileStatement, LeaveWhileStatement, whileStatement); |
||||
} |
||||
|
||||
public event Action<YieldBreakStatement> EnterYieldBreakStatement, LeaveYieldBreakStatement; |
||||
|
||||
void IAstVisitor.VisitYieldBreakStatement(YieldBreakStatement yieldBreakStatement) |
||||
{ |
||||
Visit(EnterYieldBreakStatement, LeaveYieldBreakStatement, yieldBreakStatement); |
||||
} |
||||
|
||||
public event Action<YieldReturnStatement> EnterYieldReturnStatement, LeaveYieldReturnStatement; |
||||
|
||||
void IAstVisitor.VisitYieldReturnStatement(YieldReturnStatement yieldStatement) |
||||
{ |
||||
Visit(EnterYieldReturnStatement, LeaveYieldReturnStatement, yieldStatement); |
||||
} |
||||
|
||||
public event Action<AnonymousMethodExpression> EnterAnonymousMethodExpression, LeaveAnonymousMethodExpression; |
||||
|
||||
void IAstVisitor.VisitAnonymousMethodExpression(AnonymousMethodExpression anonymousMethodExpression) |
||||
{ |
||||
Visit(EnterAnonymousMethodExpression, LeaveAnonymousMethodExpression, anonymousMethodExpression); |
||||
} |
||||
|
||||
public event Action<LambdaExpression> EnterLambdaExpression, LeaveLambdaExpression; |
||||
|
||||
void IAstVisitor.VisitLambdaExpression(LambdaExpression lambdaExpression) |
||||
{ |
||||
Visit(EnterLambdaExpression, LeaveLambdaExpression, lambdaExpression); |
||||
} |
||||
|
||||
public event Action<AssignmentExpression> EnterAssignmentExpression, LeaveAssignmentExpression; |
||||
|
||||
void IAstVisitor.VisitAssignmentExpression(AssignmentExpression assignmentExpression) |
||||
{ |
||||
Visit(EnterAssignmentExpression, LeaveAssignmentExpression, assignmentExpression); |
||||
} |
||||
|
||||
public event Action<BaseReferenceExpression> EnterBaseReferenceExpression, LeaveBaseReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitBaseReferenceExpression(BaseReferenceExpression baseReferenceExpression) |
||||
{ |
||||
Visit(EnterBaseReferenceExpression, LeaveBaseReferenceExpression, baseReferenceExpression); |
||||
} |
||||
|
||||
public event Action<BinaryOperatorExpression> EnterBinaryOperatorExpression, LeaveBinaryOperatorExpression; |
||||
|
||||
void IAstVisitor.VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression) |
||||
{ |
||||
Visit(EnterBinaryOperatorExpression, LeaveBinaryOperatorExpression, binaryOperatorExpression); |
||||
} |
||||
|
||||
public event Action<CastExpression> EnterCastExpression, LeaveCastExpression; |
||||
|
||||
void IAstVisitor.VisitCastExpression(CastExpression castExpression) |
||||
{ |
||||
Visit(EnterCastExpression, LeaveCastExpression, castExpression); |
||||
} |
||||
|
||||
public event Action<CheckedExpression> EnterCheckedExpression, LeaveCheckedExpression; |
||||
|
||||
void IAstVisitor.VisitCheckedExpression(CheckedExpression checkedExpression) |
||||
{ |
||||
Visit(EnterCheckedExpression, LeaveCheckedExpression, checkedExpression); |
||||
} |
||||
|
||||
public event Action<ConditionalExpression> EnterConditionalExpression, LeaveConditionalExpression; |
||||
|
||||
void IAstVisitor.VisitConditionalExpression(ConditionalExpression conditionalExpression) |
||||
{ |
||||
Visit(EnterConditionalExpression, LeaveConditionalExpression, conditionalExpression); |
||||
} |
||||
|
||||
public event Action<IdentifierExpression> EnterIdentifierExpression, LeaveIdentifierExpression; |
||||
|
||||
void IAstVisitor.VisitIdentifierExpression(IdentifierExpression identifierExpression) |
||||
{ |
||||
Visit(EnterIdentifierExpression, LeaveIdentifierExpression, identifierExpression); |
||||
} |
||||
|
||||
public event Action<IndexerExpression> EnterIndexerExpression, LeaveIndexerExpression; |
||||
|
||||
void IAstVisitor.VisitIndexerExpression(IndexerExpression indexerExpression) |
||||
{ |
||||
Visit(EnterIndexerExpression, LeaveIndexerExpression, indexerExpression); |
||||
} |
||||
|
||||
public event Action<InvocationExpression> EnterInvocationExpression, LeaveInvocationExpression; |
||||
|
||||
void IAstVisitor.VisitInvocationExpression(InvocationExpression invocationExpression) |
||||
{ |
||||
Visit(EnterInvocationExpression, LeaveInvocationExpression, invocationExpression); |
||||
} |
||||
|
||||
public event Action<DirectionExpression> EnterDirectionExpression, LeaveDirectionExpression; |
||||
|
||||
void IAstVisitor.VisitDirectionExpression(DirectionExpression directionExpression) |
||||
{ |
||||
Visit(EnterDirectionExpression, LeaveDirectionExpression, directionExpression); |
||||
} |
||||
|
||||
public event Action<MemberReferenceExpression> EnterMemberReferenceExpression, LeaveMemberReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression) |
||||
{ |
||||
Visit(EnterMemberReferenceExpression, LeaveMemberReferenceExpression, memberReferenceExpression); |
||||
} |
||||
|
||||
public event Action<NullReferenceExpression> EnterNullReferenceExpression, LeaveNullReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitNullReferenceExpression(NullReferenceExpression nullReferenceExpression) |
||||
{ |
||||
Visit(EnterNullReferenceExpression, LeaveNullReferenceExpression, nullReferenceExpression); |
||||
} |
||||
|
||||
public event Action<ObjectCreateExpression> EnterObjectCreateExpression, LeaveObjectCreateExpression; |
||||
|
||||
void IAstVisitor.VisitObjectCreateExpression(ObjectCreateExpression objectCreateExpression) |
||||
{ |
||||
Visit(EnterObjectCreateExpression, LeaveObjectCreateExpression, objectCreateExpression); |
||||
} |
||||
|
||||
public event Action<AnonymousTypeCreateExpression> EnterAnonymousTypeCreateExpression, LeaveAnonymousTypeCreateExpression; |
||||
|
||||
void IAstVisitor.VisitAnonymousTypeCreateExpression(AnonymousTypeCreateExpression anonymousTypeCreateExpression) |
||||
{ |
||||
Visit(EnterAnonymousTypeCreateExpression, LeaveAnonymousTypeCreateExpression, anonymousTypeCreateExpression); |
||||
} |
||||
|
||||
public event Action<ArrayCreateExpression> EnterArrayCreateExpression, LeaveArrayCreateExpression; |
||||
|
||||
void IAstVisitor.VisitArrayCreateExpression(ArrayCreateExpression arraySCreateExpression) |
||||
{ |
||||
Visit(EnterArrayCreateExpression, LeaveArrayCreateExpression, arraySCreateExpression); |
||||
} |
||||
|
||||
public event Action<ParenthesizedExpression> EnterParenthesizedExpression, LeaveParenthesizedExpression; |
||||
|
||||
void IAstVisitor.VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression) |
||||
{ |
||||
Visit(EnterParenthesizedExpression, LeaveParenthesizedExpression, parenthesizedExpression); |
||||
} |
||||
|
||||
public event Action<PointerReferenceExpression> EnterPointerReferenceExpression, LeavePointerReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitPointerReferenceExpression(PointerReferenceExpression pointerReferenceExpression) |
||||
{ |
||||
Visit(EnterPointerReferenceExpression, LeavePointerReferenceExpression, pointerReferenceExpression); |
||||
} |
||||
|
||||
public event Action<PrimitiveExpression> EnterPrimitiveExpression, LeavePrimitiveExpression; |
||||
|
||||
void IAstVisitor.VisitPrimitiveExpression(PrimitiveExpression primitiveExpression) |
||||
{ |
||||
Visit(EnterPrimitiveExpression, LeavePrimitiveExpression, primitiveExpression); |
||||
} |
||||
|
||||
public event Action<SizeOfExpression> EnterSizeOfExpression, LeaveSizeOfExpression; |
||||
|
||||
void IAstVisitor.VisitSizeOfExpression(SizeOfExpression sizeOfExpression) |
||||
{ |
||||
Visit(EnterSizeOfExpression, LeaveSizeOfExpression, sizeOfExpression); |
||||
} |
||||
|
||||
public event Action<StackAllocExpression> EnterStackAllocExpression, LeaveStackAllocExpression; |
||||
|
||||
void IAstVisitor.VisitStackAllocExpression(StackAllocExpression stackAllocExpression) |
||||
{ |
||||
Visit(EnterStackAllocExpression, LeaveStackAllocExpression, stackAllocExpression); |
||||
} |
||||
|
||||
public event Action<ThisReferenceExpression> EnterThisReferenceExpression, LeaveThisReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitThisReferenceExpression(ThisReferenceExpression thisReferenceExpression) |
||||
{ |
||||
Visit(EnterThisReferenceExpression, LeaveThisReferenceExpression, thisReferenceExpression); |
||||
} |
||||
|
||||
public event Action<TypeOfExpression> EnterTypeOfExpression, LeaveTypeOfExpression; |
||||
|
||||
void IAstVisitor.VisitTypeOfExpression(TypeOfExpression typeOfExpression) |
||||
{ |
||||
Visit(EnterTypeOfExpression, LeaveTypeOfExpression, typeOfExpression); |
||||
} |
||||
|
||||
public event Action<TypeReferenceExpression> EnterTypeReferenceExpression, LeaveTypeReferenceExpression; |
||||
|
||||
void IAstVisitor.VisitTypeReferenceExpression(TypeReferenceExpression typeReferenceExpression) |
||||
{ |
||||
Visit(EnterTypeReferenceExpression, LeaveTypeReferenceExpression, typeReferenceExpression); |
||||
} |
||||
|
||||
public event Action<UnaryOperatorExpression> EnterUnaryOperatorExpression, LeaveUnaryOperatorExpression; |
||||
|
||||
void IAstVisitor.VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression) |
||||
{ |
||||
Visit(EnterUnaryOperatorExpression, LeaveUnaryOperatorExpression, unaryOperatorExpression); |
||||
} |
||||
|
||||
public event Action<UncheckedExpression> EnterUncheckedExpression, LeaveUncheckedExpression; |
||||
|
||||
void IAstVisitor.VisitUncheckedExpression(UncheckedExpression uncheckedExpression) |
||||
{ |
||||
Visit(EnterUncheckedExpression, LeaveUncheckedExpression, uncheckedExpression); |
||||
} |
||||
|
||||
public event Action<QueryExpression> EnterQueryExpression, LeaveQueryExpression; |
||||
|
||||
void IAstVisitor.VisitQueryExpression(QueryExpression queryExpression) |
||||
{ |
||||
Visit(EnterQueryExpression, LeaveQueryExpression, queryExpression); |
||||
} |
||||
|
||||
public event Action<QueryContinuationClause> EnterQueryContinuationClause, LeaveQueryContinuationClause; |
||||
|
||||
void IAstVisitor.VisitQueryContinuationClause(QueryContinuationClause queryContinuationClause) |
||||
{ |
||||
Visit(EnterQueryContinuationClause, LeaveQueryContinuationClause, queryContinuationClause); |
||||
} |
||||
|
||||
public event Action<QueryFromClause> EnterQueryFromClause, LeaveQueryFromClause; |
||||
|
||||
void IAstVisitor.VisitQueryFromClause(QueryFromClause queryFromClause) |
||||
{ |
||||
Visit(EnterQueryFromClause, LeaveQueryFromClause, queryFromClause); |
||||
} |
||||
|
||||
public event Action<QueryLetClause> EnterQueryLetClause, LeaveQueryLetClause; |
||||
|
||||
void IAstVisitor.VisitQueryLetClause(QueryLetClause queryLetClause) |
||||
{ |
||||
Visit(EnterQueryLetClause, LeaveQueryLetClause, queryLetClause); |
||||
} |
||||
|
||||
public event Action<QueryWhereClause> EnterQueryWhereClause, LeaveQueryWhereClause; |
||||
|
||||
void IAstVisitor.VisitQueryWhereClause(QueryWhereClause queryWhereClause) |
||||
{ |
||||
Visit(EnterQueryWhereClause, LeaveQueryWhereClause, queryWhereClause); |
||||
} |
||||
|
||||
public event Action<QueryJoinClause> EnterQueryJoinClause, LeaveQueryJoinClause; |
||||
|
||||
void IAstVisitor.VisitQueryJoinClause(QueryJoinClause queryJoinClause) |
||||
{ |
||||
Visit(EnterQueryJoinClause, LeaveQueryJoinClause, queryJoinClause); |
||||
} |
||||
|
||||
public event Action<QueryOrderClause> EnterQueryOrderClause, LeaveQueryOrderClause; |
||||
|
||||
void IAstVisitor.VisitQueryOrderClause(QueryOrderClause queryOrderClause) |
||||
{ |
||||
Visit(EnterQueryOrderClause, LeaveQueryOrderClause, queryOrderClause); |
||||
} |
||||
|
||||
public event Action<QueryOrdering> EnterQueryOrdering, LeaveQueryOrdering; |
||||
|
||||
void IAstVisitor.VisitQueryOrdering(QueryOrdering queryOrdering) |
||||
{ |
||||
Visit(EnterQueryOrdering, LeaveQueryOrdering, queryOrdering); |
||||
} |
||||
|
||||
public event Action<QuerySelectClause> EnterQuerySelectClause, LeaveQuerySelectClause; |
||||
|
||||
void IAstVisitor.VisitQuerySelectClause(QuerySelectClause querySelectClause) |
||||
{ |
||||
Visit(EnterQuerySelectClause, LeaveQuerySelectClause, querySelectClause); |
||||
} |
||||
|
||||
public event Action<QueryGroupClause> EnterQueryGroupClause, LeaveQueryGroupClause; |
||||
|
||||
void IAstVisitor.VisitQueryGroupClause(QueryGroupClause queryGroupClause) |
||||
{ |
||||
Visit(EnterQueryGroupClause, LeaveQueryGroupClause, queryGroupClause); |
||||
} |
||||
|
||||
public event Action<AsExpression> EnterAsExpression, LeaveAsExpression; |
||||
|
||||
void IAstVisitor.VisitAsExpression(AsExpression asExpression) |
||||
{ |
||||
Visit(EnterAsExpression, LeaveAsExpression, asExpression); |
||||
} |
||||
|
||||
public event Action<IsExpression> EnterIsExpression, LeaveIsExpression; |
||||
|
||||
void IAstVisitor.VisitIsExpression(IsExpression isExpression) |
||||
{ |
||||
Visit(EnterIsExpression, LeaveIsExpression, isExpression); |
||||
} |
||||
|
||||
public event Action<DefaultValueExpression> EnterDefaultValueExpression, LeaveDefaultValueExpression; |
||||
|
||||
void IAstVisitor.VisitDefaultValueExpression(DefaultValueExpression defaultValueExpression) |
||||
{ |
||||
Visit(EnterDefaultValueExpression, LeaveDefaultValueExpression, defaultValueExpression); |
||||
} |
||||
|
||||
public event Action<UndocumentedExpression> EnterUndocumentedExpression, LeaveUndocumentedExpression; |
||||
|
||||
void IAstVisitor.VisitUndocumentedExpression(UndocumentedExpression undocumentedExpression) |
||||
{ |
||||
Visit(EnterUndocumentedExpression, LeaveUndocumentedExpression, undocumentedExpression); |
||||
} |
||||
|
||||
public event Action<ArrayInitializerExpression> EnterArrayInitializerExpression, LeaveArrayInitializerExpression; |
||||
|
||||
void IAstVisitor.VisitArrayInitializerExpression(ArrayInitializerExpression arrayInitializerExpression) |
||||
{ |
||||
Visit(EnterArrayInitializerExpression, LeaveArrayInitializerExpression, arrayInitializerExpression); |
||||
} |
||||
|
||||
public event Action<ArraySpecifier> EnterArraySpecifier, LeaveArraySpecifier; |
||||
|
||||
void IAstVisitor.VisitArraySpecifier(ArraySpecifier arraySpecifier) |
||||
{ |
||||
Visit(EnterArraySpecifier, LeaveArraySpecifier, arraySpecifier); |
||||
} |
||||
|
||||
public event Action<NamedArgumentExpression> EnterNamedArgumentExpression, LeaveNamedArgumentExpression; |
||||
|
||||
void IAstVisitor.VisitNamedArgumentExpression(NamedArgumentExpression namedArgumentExpression) |
||||
{ |
||||
Visit(EnterNamedArgumentExpression, LeaveNamedArgumentExpression, namedArgumentExpression); |
||||
} |
||||
|
||||
public event Action<NamedExpression> EnterNamedExpression, LeaveNamedExpression; |
||||
|
||||
void IAstVisitor.VisitNamedExpression(NamedExpression namedExpression) |
||||
{ |
||||
Visit(EnterNamedExpression, LeaveNamedExpression, namedExpression); |
||||
} |
||||
|
||||
void IAstVisitor.VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern) |
||||
{ |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,166 @@
@@ -0,0 +1,166 @@
|
||||
//
|
||||
// FullTypeName.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.NRefactory.CSharp.Resolver; |
||||
using ICSharpCode.NRefactory.TypeSystem; |
||||
using ICSharpCode.NRefactory.TypeSystem.Implementation; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class PrimitiveType : AstType |
||||
{ |
||||
TextLocation location; |
||||
string keyword = string.Empty; |
||||
|
||||
public string Keyword { |
||||
get { return keyword; } |
||||
set { |
||||
if (value == null) |
||||
throw new ArgumentNullException(); |
||||
ThrowIfFrozen(); |
||||
keyword = value; |
||||
} |
||||
} |
||||
|
||||
public KnownTypeCode KnownTypeCode { |
||||
get { return GetTypeCodeForPrimitiveType(this.Keyword); } |
||||
} |
||||
|
||||
public PrimitiveType() |
||||
{ |
||||
} |
||||
|
||||
public PrimitiveType(string keyword) |
||||
{ |
||||
this.Keyword = keyword; |
||||
} |
||||
|
||||
public PrimitiveType(string keyword, TextLocation location) |
||||
{ |
||||
this.Keyword = keyword; |
||||
this.location = location; |
||||
} |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return location; |
||||
} |
||||
} |
||||
|
||||
internal void SetStartLocation(TextLocation value) |
||||
{ |
||||
ThrowIfFrozen(); |
||||
this.location = value; |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (location.Line, location.Column + keyword.Length); |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPrimitiveType (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPrimitiveType (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPrimitiveType (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
PrimitiveType o = other as PrimitiveType; |
||||
return o != null && MatchString(this.Keyword, o.Keyword); |
||||
} |
||||
|
||||
public override string ToString(CSharpFormattingOptions formattingOptions) |
||||
{ |
||||
return Keyword; |
||||
} |
||||
|
||||
public override ITypeReference ToTypeReference(NameLookupMode lookupMode, InterningProvider interningProvider = null) |
||||
{ |
||||
KnownTypeCode typeCode = GetTypeCodeForPrimitiveType(this.Keyword); |
||||
if (typeCode == KnownTypeCode.None) { |
||||
if (this.Keyword == "__arglist") |
||||
return SpecialType.ArgList; |
||||
return new UnknownType(null, this.Keyword); |
||||
} else { |
||||
return KnownTypeReference.Get(typeCode); |
||||
} |
||||
} |
||||
|
||||
public static KnownTypeCode GetTypeCodeForPrimitiveType(string keyword) |
||||
{ |
||||
switch (keyword) { |
||||
case "string": |
||||
return KnownTypeCode.String; |
||||
case "int": |
||||
return KnownTypeCode.Int32; |
||||
case "uint": |
||||
return KnownTypeCode.UInt32; |
||||
case "object": |
||||
return KnownTypeCode.Object; |
||||
case "bool": |
||||
return KnownTypeCode.Boolean; |
||||
case "sbyte": |
||||
return KnownTypeCode.SByte; |
||||
case "byte": |
||||
return KnownTypeCode.Byte; |
||||
case "short": |
||||
return KnownTypeCode.Int16; |
||||
case "ushort": |
||||
return KnownTypeCode.UInt16; |
||||
case "long": |
||||
return KnownTypeCode.Int64; |
||||
case "ulong": |
||||
return KnownTypeCode.UInt64; |
||||
case "float": |
||||
return KnownTypeCode.Single; |
||||
case "double": |
||||
return KnownTypeCode.Double; |
||||
case "decimal": |
||||
return KnownTypeCode.Decimal; |
||||
case "char": |
||||
return KnownTypeCode.Char; |
||||
case "void": |
||||
return KnownTypeCode.Void; |
||||
default: |
||||
return KnownTypeCode.None; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,96 @@
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Roles.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@xamarin.com>
|
||||
//
|
||||
// Copyright (c) 2012 Xamarin <http://xamarin.com>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public static class Roles |
||||
{ |
||||
public static readonly Role<AstNode> Root = AstNode.RootRole; |
||||
|
||||
// some pre defined constants for common roles
|
||||
public static readonly Role<Identifier> Identifier = new Role<Identifier> ("Identifier", CSharp.Identifier.Null); |
||||
public static readonly Role<BlockStatement> Body = new Role<BlockStatement> ("Body", CSharp.BlockStatement.Null); |
||||
public static readonly Role<ParameterDeclaration> Parameter = new Role<ParameterDeclaration> ("Parameter"); |
||||
public static readonly Role<Expression> Argument = new Role<Expression> ("Argument", CSharp.Expression.Null); |
||||
public static readonly Role<AstType> Type = new Role<AstType> ("Type", CSharp.AstType.Null); |
||||
public static readonly Role<Expression> Expression = new Role<Expression> ("Expression", CSharp.Expression.Null); |
||||
public static readonly Role<Expression> TargetExpression = new Role<Expression> ("Target", CSharp.Expression.Null); |
||||
public readonly static Role<Expression> Condition = new Role<Expression> ("Condition", CSharp.Expression.Null); |
||||
public static readonly Role<TypeParameterDeclaration> TypeParameter = new Role<TypeParameterDeclaration> ("TypeParameter"); |
||||
public static readonly Role<AstType> TypeArgument = new Role<AstType> ("TypeArgument", CSharp.AstType.Null); |
||||
public readonly static Role<Constraint> Constraint = new Role<Constraint> ("Constraint"); |
||||
public static readonly Role<VariableInitializer> Variable = new Role<VariableInitializer> ("Variable", VariableInitializer.Null); |
||||
public static readonly Role<Statement> EmbeddedStatement = new Role<Statement> ("EmbeddedStatement", CSharp.Statement.Null); |
||||
public readonly static Role<EntityDeclaration> TypeMemberRole = new Role<EntityDeclaration> ("TypeMember"); |
||||
|
||||
|
||||
// public static readonly TokenRole Keyword = new TokenRole ("Keyword", CSharpTokenNode.Null);
|
||||
// public static readonly TokenRole InKeyword = new TokenRole ("InKeyword", CSharpTokenNode.Null);
|
||||
|
||||
// some pre defined constants for most used punctuation
|
||||
public static readonly TokenRole LPar = new TokenRole ("("); |
||||
public static readonly TokenRole RPar = new TokenRole (")"); |
||||
public static readonly TokenRole LBracket = new TokenRole ("["); |
||||
public static readonly TokenRole RBracket = new TokenRole ("]"); |
||||
public static readonly TokenRole LBrace = new TokenRole ("{"); |
||||
public static readonly TokenRole RBrace = new TokenRole ("}"); |
||||
public static readonly TokenRole LChevron = new TokenRole ("<"); |
||||
public static readonly TokenRole RChevron = new TokenRole (">"); |
||||
public static readonly TokenRole Comma = new TokenRole (","); |
||||
public static readonly TokenRole Dot = new TokenRole ("."); |
||||
public static readonly TokenRole Semicolon = new TokenRole (";"); |
||||
public static readonly TokenRole Assign = new TokenRole ("="); |
||||
public static readonly TokenRole Colon = new TokenRole (":"); |
||||
public static readonly TokenRole DoubleColon = new TokenRole ("::"); |
||||
public static readonly Role<Comment> Comment = new Role<Comment> ("Comment"); |
||||
public static readonly Role<NewLineNode> NewLine = new Role<NewLineNode> ("NewLine"); |
||||
public static readonly Role<WhitespaceNode> Whitespace = new Role<WhitespaceNode> ("Whitespace"); |
||||
public static readonly Role<TextNode> Text = new Role<TextNode> ("Text"); |
||||
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective"); |
||||
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error"); |
||||
|
||||
public readonly static Role<AstType> BaseType = new Role<AstType> ("BaseType", AstType.Null); |
||||
|
||||
public static readonly Role<Attribute> Attribute = new Role<Attribute> ("Attribute"); |
||||
public static readonly Role<CSharpTokenNode> AttributeTargetRole = new Role<CSharpTokenNode> ("AttributeTarget", CSharpTokenNode.Null); |
||||
|
||||
public readonly static TokenRole WhereKeyword = new TokenRole ("where"); |
||||
public readonly static Role<SimpleType> ConstraintTypeParameter = new Role<SimpleType> ("TypeParameter", SimpleType.Null); |
||||
public readonly static TokenRole DelegateKeyword = new TokenRole ("delegate"); |
||||
public static readonly TokenRole ExternKeyword = new TokenRole ("extern"); |
||||
public static readonly TokenRole AliasKeyword = new TokenRole ("alias"); |
||||
public static readonly TokenRole NamespaceKeyword = new TokenRole ("namespace"); |
||||
|
||||
public static readonly TokenRole EnumKeyword = new TokenRole ("enum"); |
||||
public static readonly TokenRole InterfaceKeyword = new TokenRole ("interface"); |
||||
public static readonly TokenRole StructKeyword = new TokenRole ("struct"); |
||||
public static readonly TokenRole ClassKeyword = new TokenRole ("class"); |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,164 @@
@@ -0,0 +1,164 @@
|
||||
//
|
||||
// BlockStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// { Statements }
|
||||
/// </summary>
|
||||
public class BlockStatement : Statement, IEnumerable<Statement> |
||||
{ |
||||
public static readonly Role<Statement> StatementRole = new Role<Statement>("Statement", Statement.Null); |
||||
|
||||
#region Null
|
||||
public static readonly new BlockStatement Null = new NullBlockStatement (); |
||||
sealed class NullBlockStatement : BlockStatement |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator BlockStatement(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : BlockStatement, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public CSharpTokenNode LBraceToken { |
||||
get { return GetChildByRole (Roles.LBrace); } |
||||
} |
||||
|
||||
public AstNodeCollection<Statement> Statements { |
||||
get { return GetChildrenByRole (StatementRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBraceToken { |
||||
get { return GetChildByRole (Roles.RBrace); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitBlockStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitBlockStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBlockStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
BlockStatement o = other as BlockStatement; |
||||
return o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match); |
||||
} |
||||
|
||||
public void Add(Statement statement) |
||||
{ |
||||
AddChild(statement, StatementRole); |
||||
} |
||||
|
||||
IEnumerator<Statement> IEnumerable<Statement>.GetEnumerator() |
||||
{ |
||||
return this.Statements.GetEnumerator(); |
||||
} |
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() |
||||
{ |
||||
return this.Statements.GetEnumerator(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// BreakStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// break;
|
||||
/// </summary>
|
||||
public class BreakStatement : Statement |
||||
{ |
||||
public static readonly TokenRole BreakKeywordRole = new TokenRole ("break"); |
||||
|
||||
public CSharpTokenNode BreakToken { |
||||
get { return GetChildByRole (BreakKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitBreakStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitBreakStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitBreakStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
BreakStatement o = other as BreakStatement; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// CheckedStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// checked BodyBlock
|
||||
/// </summary>
|
||||
public class CheckedStatement : Statement |
||||
{ |
||||
public static readonly TokenRole CheckedKeywordRole = new TokenRole ("checked"); |
||||
|
||||
public CSharpTokenNode CheckedToken { |
||||
get { return GetChildByRole (CheckedKeywordRole); } |
||||
} |
||||
|
||||
public BlockStatement Body { |
||||
get { return GetChildByRole (Roles.Body); } |
||||
set { SetChildByRole (Roles.Body, value); } |
||||
} |
||||
|
||||
public CheckedStatement () |
||||
{ |
||||
} |
||||
|
||||
public CheckedStatement (BlockStatement body) |
||||
{ |
||||
AddChild (body, Roles.Body); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitCheckedStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitCheckedStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCheckedStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CheckedStatement o = other as CheckedStatement; |
||||
return o != null && this.Body.DoMatch(o.Body, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// ContinueStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// continue;
|
||||
/// </summary>
|
||||
public class ContinueStatement : Statement |
||||
{ |
||||
public static readonly TokenRole ContinueKeywordRole = new TokenRole ("continue"); |
||||
|
||||
public CSharpTokenNode ContinueToken { |
||||
get { return GetChildByRole (ContinueKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitContinueStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitContinueStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitContinueStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ContinueStatement o = other as ContinueStatement; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,99 @@
@@ -0,0 +1,99 @@
|
||||
//
|
||||
// DoWhileStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.using System;
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// "do EmbeddedStatement while(Condition);"
|
||||
/// </summary>
|
||||
public class DoWhileStatement : Statement |
||||
{ |
||||
public static readonly TokenRole DoKeywordRole = new TokenRole ("do"); |
||||
public static readonly TokenRole WhileKeywordRole = new TokenRole ("while"); |
||||
|
||||
public CSharpTokenNode DoToken { |
||||
get { return GetChildByRole (DoKeywordRole); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode WhileToken { |
||||
get { return GetChildByRole (WhileKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Condition { |
||||
get { return GetChildByRole (Roles.Condition); } |
||||
set { SetChildByRole (Roles.Condition, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitDoWhileStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitDoWhileStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitDoWhileStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
DoWhileStatement o = other as DoWhileStatement; |
||||
return o != null && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match) && this.Condition.DoMatch(o.Condition, match); |
||||
} |
||||
|
||||
public DoWhileStatement() |
||||
{ |
||||
} |
||||
|
||||
public DoWhileStatement(Expression condition, Statement embeddedStatement) |
||||
{ |
||||
this.Condition = condition; |
||||
this.EmbeddedStatement = embeddedStatement; |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// EmptyStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// ;
|
||||
/// </summary>
|
||||
public class EmptyStatement : Statement |
||||
{ |
||||
public TextLocation Location { |
||||
get; |
||||
set; |
||||
} |
||||
|
||||
public override TextLocation StartLocation { |
||||
get { |
||||
return Location; |
||||
} |
||||
} |
||||
|
||||
public override TextLocation EndLocation { |
||||
get { |
||||
return new TextLocation (Location.Line, Location.Column + 1); |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitEmptyStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitEmptyStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitEmptyStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
EmptyStatement o = other as EmptyStatement; |
||||
return o != null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
//
|
||||
// ExpressionStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2010 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Expression;
|
||||
/// </summary>
|
||||
public class ExpressionStatement : Statement |
||||
{ |
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitExpressionStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitExpressionStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitExpressionStatement (this, data); |
||||
} |
||||
|
||||
public ExpressionStatement() |
||||
{ |
||||
} |
||||
|
||||
public ExpressionStatement(Expression expression) |
||||
{ |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ExpressionStatement o = other as ExpressionStatement; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
//
|
||||
// FixedStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// fixed (Type Variables) EmbeddedStatement
|
||||
/// </summary>
|
||||
public class FixedStatement : Statement |
||||
{ |
||||
public static readonly TokenRole FixedKeywordRole = new TokenRole ("fixed"); |
||||
|
||||
public CSharpTokenNode FixedToken { |
||||
get { return GetChildByRole (FixedKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<VariableInitializer> Variables { |
||||
get { return GetChildrenByRole (Roles.Variable); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitFixedStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitFixedStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitFixedStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
FixedStatement o = other as FixedStatement; |
||||
return o != null && this.Type.DoMatch(o.Type, match) && this.Variables.DoMatch(o.Variables, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,97 @@
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// ForStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// for (Initializers; Condition; Iterators) EmbeddedStatement
|
||||
/// </summary>
|
||||
public class ForStatement : Statement |
||||
{ |
||||
public static readonly TokenRole ForKeywordRole = new TokenRole ("for"); |
||||
public readonly static Role<Statement> InitializerRole = new Role<Statement>("Initializer", Statement.Null); |
||||
public readonly static Role<Statement> IteratorRole = new Role<Statement>("Iterator", Statement.Null); |
||||
|
||||
public CSharpTokenNode ForToken { |
||||
get { return GetChildByRole (ForKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the list of initializer statements.
|
||||
/// Note: this contains multiple statements for "for (a = 2, b = 1; a > b; a--)", but contains
|
||||
/// only a single statement for "for (int a = 2, b = 1; a > b; a--)" (a single VariableDeclarationStatement with two variables)
|
||||
/// </summary>
|
||||
public AstNodeCollection<Statement> Initializers { |
||||
get { return GetChildrenByRole (InitializerRole); } |
||||
} |
||||
|
||||
public Expression Condition { |
||||
get { return GetChildByRole (Roles.Condition); } |
||||
set { SetChildByRole (Roles.Condition, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<Statement> Iterators { |
||||
get { return GetChildrenByRole (IteratorRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitForStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitForStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitForStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ForStatement o = other as ForStatement; |
||||
return o != null && this.Initializers.DoMatch(o.Initializers, match) && this.Condition.DoMatch(o.Condition, match) |
||||
&& this.Iterators.DoMatch(o.Iterators, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,108 @@
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// ForeachStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// foreach (Type VariableName in InExpression) EmbeddedStatement
|
||||
/// </summary>
|
||||
public class ForeachStatement : Statement |
||||
{ |
||||
public static readonly TokenRole ForeachKeywordRole = new TokenRole ("foreach"); |
||||
public static readonly TokenRole InKeywordRole = new TokenRole ("in"); |
||||
|
||||
public CSharpTokenNode ForeachToken { |
||||
get { return GetChildByRole (ForeachKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public AstType VariableType { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public string VariableName { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier).Name; |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, Identifier.Create (value)); |
||||
} |
||||
} |
||||
|
||||
public Identifier VariableNameToken { |
||||
get { |
||||
return GetChildByRole (Roles.Identifier); |
||||
} |
||||
set { |
||||
SetChildByRole(Roles.Identifier, value); |
||||
} |
||||
} |
||||
|
||||
public CSharpTokenNode InToken { |
||||
get { return GetChildByRole (InKeywordRole); } |
||||
} |
||||
|
||||
public Expression InExpression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitForeachStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitForeachStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitForeachStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ForeachStatement o = other as ForeachStatement; |
||||
return o != null && this.VariableType.DoMatch(o.VariableType, match) && MatchString(this.VariableName, o.VariableName) |
||||
&& this.InExpression.DoMatch(o.InExpression, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
//
|
||||
// IfElseStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// if (Condition) TrueStatement else FalseStatement
|
||||
/// </summary>
|
||||
public class IfElseStatement : Statement |
||||
{ |
||||
public readonly static TokenRole IfKeywordRole = new TokenRole ("if"); |
||||
public readonly static Role<Expression> ConditionRole = Roles.Condition; |
||||
public readonly static Role<Statement> TrueRole = new Role<Statement>("True", Statement.Null); |
||||
public readonly static TokenRole ElseKeywordRole = new TokenRole ("else"); |
||||
public readonly static Role<Statement> FalseRole = new Role<Statement>("False", Statement.Null); |
||||
|
||||
public CSharpTokenNode IfToken { |
||||
get { return GetChildByRole (IfKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Condition { |
||||
get { return GetChildByRole (ConditionRole); } |
||||
set { SetChildByRole (ConditionRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement TrueStatement { |
||||
get { return GetChildByRole (TrueRole); } |
||||
set { SetChildByRole (TrueRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode ElseToken { |
||||
get { return GetChildByRole (ElseKeywordRole); } |
||||
} |
||||
|
||||
public Statement FalseStatement { |
||||
get { return GetChildByRole (FalseRole); } |
||||
set { SetChildByRole (FalseRole, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitIfElseStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitIfElseStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitIfElseStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
IfElseStatement o = other as IfElseStatement; |
||||
return o != null && this.Condition.DoMatch(o.Condition, match) && this.TrueStatement.DoMatch(o.TrueStatement, match) && this.FalseStatement.DoMatch(o.FalseStatement, match); |
||||
} |
||||
|
||||
public IfElseStatement() |
||||
{ |
||||
} |
||||
|
||||
public IfElseStatement(Expression condition, Statement trueStatement, Statement falseStatement = null) |
||||
{ |
||||
this.Condition = condition; |
||||
this.TrueStatement = trueStatement; |
||||
this.FalseStatement = falseStatement; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// LockStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// lock (Expression) EmbeddedStatement;
|
||||
/// </summary>
|
||||
public class LockStatement : Statement |
||||
{ |
||||
public static readonly TokenRole LockKeywordRole = new TokenRole ("lock"); |
||||
|
||||
public CSharpTokenNode LockToken { |
||||
get { return GetChildByRole (LockKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitLockStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitLockStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitLockStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
LockStatement o = other as LockStatement; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// ReturnStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// return Expression;
|
||||
/// </summary>
|
||||
public class ReturnStatement : Statement |
||||
{ |
||||
public static readonly TokenRole ReturnKeywordRole = new TokenRole ("return"); |
||||
|
||||
public CSharpTokenNode ReturnToken { |
||||
get { return GetChildByRole (ReturnKeywordRole); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public ReturnStatement () |
||||
{ |
||||
} |
||||
|
||||
public ReturnStatement (Expression returnExpression) |
||||
{ |
||||
AddChild (returnExpression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitReturnStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitReturnStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitReturnStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ReturnStatement o = other as ReturnStatement; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,132 @@
@@ -0,0 +1,132 @@
|
||||
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
|
||||
// software and associated documentation files (the "Software"), to deal in the Software
|
||||
// without restriction, including without limitation the rights to use, copy, modify, merge,
|
||||
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
|
||||
// to whom the Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all copies or
|
||||
// substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for statements.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This class is useful even though it doesn't provide any additional functionality:
|
||||
/// It can be used to communicate more information in APIs, e.g. "this subnode will always be a statement"
|
||||
/// </remarks>
|
||||
public abstract class Statement : AstNode |
||||
{ |
||||
#region Null
|
||||
public new static readonly Statement Null = new NullStatement (); |
||||
|
||||
sealed class NullStatement : Statement |
||||
{ |
||||
public override bool IsNull { |
||||
get { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitNullNode(this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitNullNode(this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return other == null || other.IsNull; |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
#region PatternPlaceholder
|
||||
public static implicit operator Statement(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : Statement, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public new Statement Clone() |
||||
{ |
||||
return (Statement)base.Clone(); |
||||
} |
||||
|
||||
public Statement ReplaceWith(Func<Statement, Statement> replaceFunction) |
||||
{ |
||||
if (replaceFunction == null) |
||||
throw new ArgumentNullException("replaceFunction"); |
||||
return (Statement)base.ReplaceWith(node => replaceFunction((Statement)node)); |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Statement; } |
||||
} |
||||
|
||||
public static implicit operator Statement (Expression type) |
||||
{ |
||||
return new ExpressionStatement(type); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,230 @@
@@ -0,0 +1,230 @@
|
||||
//
|
||||
// SwitchStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// switch (Expression) { SwitchSections }
|
||||
/// </summary>
|
||||
public class SwitchStatement : Statement |
||||
{ |
||||
public static readonly TokenRole SwitchKeywordRole = new TokenRole ("switch"); |
||||
public static readonly Role<SwitchSection> SwitchSectionRole = new Role<SwitchSection>("SwitchSection"); |
||||
|
||||
public CSharpTokenNode SwitchToken { |
||||
get { return GetChildByRole (SwitchKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public CSharpTokenNode LBraceToken { |
||||
get { return GetChildByRole (Roles.LBrace); } |
||||
} |
||||
|
||||
public AstNodeCollection<SwitchSection> SwitchSections { |
||||
get { return GetChildrenByRole (SwitchSectionRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode RBraceToken { |
||||
get { return GetChildByRole (Roles.RBrace); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitSwitchStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitSwitchStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitSwitchStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
SwitchStatement o = other as SwitchStatement; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match) && this.SwitchSections.DoMatch(o.SwitchSections, match); |
||||
} |
||||
} |
||||
|
||||
public class SwitchSection : AstNode |
||||
{ |
||||
#region PatternPlaceholder
|
||||
public static implicit operator SwitchSection(PatternMatching.Pattern pattern) |
||||
{ |
||||
return pattern != null ? new PatternPlaceholder(pattern) : null; |
||||
} |
||||
|
||||
sealed class PatternPlaceholder : SwitchSection, PatternMatching.INode |
||||
{ |
||||
readonly PatternMatching.Pattern child; |
||||
|
||||
public PatternPlaceholder(PatternMatching.Pattern child) |
||||
{ |
||||
this.child = child; |
||||
} |
||||
|
||||
public override NodeType NodeType { |
||||
get { return NodeType.Pattern; } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitPatternPlaceholder(this, child, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
return child.DoMatch(other, match); |
||||
} |
||||
|
||||
bool PatternMatching.INode.DoMatchCollection(Role role, PatternMatching.INode pos, PatternMatching.Match match, PatternMatching.BacktrackingInfo backtrackingInfo) |
||||
{ |
||||
return child.DoMatchCollection(role, pos, match, backtrackingInfo); |
||||
} |
||||
} |
||||
#endregion
|
||||
|
||||
public static readonly Role<CaseLabel> CaseLabelRole = new Role<CaseLabel>("CaseLabel"); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public AstNodeCollection<CaseLabel> CaseLabels { |
||||
get { return GetChildrenByRole (CaseLabelRole); } |
||||
} |
||||
|
||||
public AstNodeCollection<Statement> Statements { |
||||
get { return GetChildrenByRole (Roles.EmbeddedStatement); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitSwitchSection (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitSwitchSection (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitSwitchSection (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
SwitchSection o = other as SwitchSection; |
||||
return o != null && this.CaseLabels.DoMatch(o.CaseLabels, match) && this.Statements.DoMatch(o.Statements, match); |
||||
} |
||||
} |
||||
|
||||
public class CaseLabel : AstNode |
||||
{ |
||||
public static readonly TokenRole CaseKeywordRole = new TokenRole ("case"); |
||||
public static readonly TokenRole DefaultKeywordRole = new TokenRole ("default"); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the expression. The expression can be null - if the expression is null, it's the default switch section.
|
||||
/// </summary>
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode ColonToken { |
||||
get { return GetChildByRole (Roles.Colon); } |
||||
} |
||||
|
||||
public CaseLabel () |
||||
{ |
||||
} |
||||
|
||||
public CaseLabel (Expression expression) |
||||
{ |
||||
this.Expression = expression; |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitCaseLabel (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitCaseLabel (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitCaseLabel (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
CaseLabel o = other as CaseLabel; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// ThrowStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// throw Expression;
|
||||
/// </summary>
|
||||
public class ThrowStatement : Statement |
||||
{ |
||||
public static readonly TokenRole ThrowKeywordRole = new TokenRole ("throw"); |
||||
|
||||
public CSharpTokenNode ThrowToken { |
||||
get { return GetChildByRole (ThrowKeywordRole); } |
||||
} |
||||
|
||||
public Expression Expression { |
||||
get { return GetChildByRole (Roles.Expression); } |
||||
set { SetChildByRole (Roles.Expression, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public ThrowStatement () |
||||
{ |
||||
} |
||||
|
||||
public ThrowStatement (Expression expression) |
||||
{ |
||||
AddChild (expression, Roles.Expression); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitThrowStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitThrowStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitThrowStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
ThrowStatement o = other as ThrowStatement; |
||||
return o != null && this.Expression.DoMatch(o.Expression, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// UncheckedStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// unchecked BodyBlock
|
||||
/// </summary>
|
||||
public class UncheckedStatement : Statement |
||||
{ |
||||
public static readonly TokenRole UncheckedKeywordRole = new TokenRole ("unchecked"); |
||||
|
||||
public CSharpTokenNode UncheckedToken { |
||||
get { return GetChildByRole (UncheckedKeywordRole); } |
||||
} |
||||
|
||||
public BlockStatement Body { |
||||
get { return GetChildByRole (Roles.Body); } |
||||
set { SetChildByRole (Roles.Body, value); } |
||||
} |
||||
|
||||
public UncheckedStatement () |
||||
{ |
||||
} |
||||
|
||||
public UncheckedStatement (BlockStatement body) |
||||
{ |
||||
AddChild (body, Roles.Body); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUncheckedStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUncheckedStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUncheckedStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UncheckedStatement o = other as UncheckedStatement; |
||||
return o != null && this.Body.DoMatch(o.Body, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
//
|
||||
// UnsafeStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// unsafe { Body }
|
||||
/// </summary>
|
||||
public class UnsafeStatement : Statement |
||||
{ |
||||
public static readonly TokenRole UnsafeKeywordRole = new TokenRole ("unsafe"); |
||||
|
||||
public CSharpTokenNode UnsafeToken { |
||||
get { return GetChildByRole (UnsafeKeywordRole); } |
||||
} |
||||
|
||||
public BlockStatement Body { |
||||
get { return GetChildByRole (Roles.Body); } |
||||
set { SetChildByRole (Roles.Body, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUnsafeStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUnsafeStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUnsafeStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UnsafeStatement o = other as UnsafeStatement; |
||||
return o != null && this.Body.DoMatch(o.Body, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,83 @@
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// UsingStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// using (ResourceAcquisition) EmbeddedStatement
|
||||
/// </summary>
|
||||
public class UsingStatement : Statement |
||||
{ |
||||
public static readonly TokenRole UsingKeywordRole = new TokenRole ("using"); |
||||
public static readonly Role<AstNode> ResourceAcquisitionRole = new Role<AstNode>("ResourceAcquisition", AstNode.Null); |
||||
|
||||
public CSharpTokenNode UsingToken { |
||||
get { return GetChildByRole (UsingKeywordRole); } |
||||
} |
||||
|
||||
public CSharpTokenNode LParToken { |
||||
get { return GetChildByRole (Roles.LPar); } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Either a VariableDeclarationStatement, or an Expression.
|
||||
/// </summary>
|
||||
public AstNode ResourceAcquisition { |
||||
get { return GetChildByRole (ResourceAcquisitionRole); } |
||||
set { SetChildByRole (ResourceAcquisitionRole, value); } |
||||
} |
||||
|
||||
public CSharpTokenNode RParToken { |
||||
get { return GetChildByRole (Roles.RPar); } |
||||
} |
||||
|
||||
public Statement EmbeddedStatement { |
||||
get { return GetChildByRole (Roles.EmbeddedStatement); } |
||||
set { SetChildByRole (Roles.EmbeddedStatement, value); } |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitUsingStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitUsingStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitUsingStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
UsingStatement o = other as UsingStatement; |
||||
return o != null && this.ResourceAcquisition.DoMatch(o.ResourceAcquisition, match) && this.EmbeddedStatement.DoMatch(o.EmbeddedStatement, match); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// VariableDeclarationStatement.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public class VariableDeclarationStatement : Statement |
||||
{ |
||||
public static readonly Role<CSharpModifierToken> ModifierRole = EntityDeclaration.ModifierRole; |
||||
|
||||
public VariableDeclarationStatement() |
||||
{ |
||||
} |
||||
|
||||
public VariableDeclarationStatement(AstType type, string name, Expression initializer = null) |
||||
{ |
||||
this.Type = type; |
||||
this.Variables.Add(new VariableInitializer(name, initializer)); |
||||
} |
||||
|
||||
public Modifiers Modifiers { |
||||
get { return EntityDeclaration.GetModifiers(this); } |
||||
set { EntityDeclaration.SetModifiers(this, value); } |
||||
} |
||||
|
||||
public AstType Type { |
||||
get { return GetChildByRole (Roles.Type); } |
||||
set { SetChildByRole (Roles.Type, value); } |
||||
} |
||||
|
||||
public AstNodeCollection<VariableInitializer> Variables { |
||||
get { return GetChildrenByRole (Roles.Variable); } |
||||
} |
||||
|
||||
public CSharpTokenNode SemicolonToken { |
||||
get { return GetChildByRole (Roles.Semicolon); } |
||||
} |
||||
|
||||
public VariableInitializer GetVariable (string name) |
||||
{ |
||||
return Variables.FirstOrNullObject (vi => vi.Name == name); |
||||
} |
||||
|
||||
public override void AcceptVisitor (IAstVisitor visitor) |
||||
{ |
||||
visitor.VisitVariableDeclarationStatement (this); |
||||
} |
||||
|
||||
public override T AcceptVisitor<T> (IAstVisitor<T> visitor) |
||||
{ |
||||
return visitor.VisitVariableDeclarationStatement (this); |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
return visitor.VisitVariableDeclarationStatement (this, data); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
VariableDeclarationStatement o = other as VariableDeclarationStatement; |
||||
return o != null && this.Modifiers == o.Modifiers && this.Type.DoMatch(o.Type, match) && this.Variables.DoMatch(o.Variables, match); |
||||
} |
||||
} |
||||
} |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue