public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) { if (localDeclarations == null) { return(null); } FieldFlags flags = FieldFlags.CompilerControlled | FieldFlags.NotSerialized; //NotSerialized "poisons" the field until Checker clears it if (localDeclarations.Constant) { flags |= FieldFlags.Literal; } else if (localDeclarations.InitOnly) { flags = FieldFlags.Public | FieldFlags.InitOnly; } TypeNode type = localDeclarations.Type; LocalDeclarationList decls = localDeclarations.Declarations; for (int i = 0, n = decls.Count; i < n; i++) { LocalDeclaration decl = decls[i]; Field f = new Field(this.scope, null, flags, decl.Name, type, null); f.Initializer = this.VisitExpression(decl.InitialValue); this.scope.Members.Add(f); decl.Field = f; } return(localDeclarations); }
public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration) { if (localDeclaration == null) { return(null); } this.CheckForShadowDeclaration(localDeclaration); return(base.VisitLocalDeclaration(localDeclaration)); }
public void CheckForShadowDeclaration(LocalDeclaration decl) { Field f = decl.Field; if (f == null) { return; } Scope scope = f.DeclaringType as BlockScope; if (scope == null) { return; } scope = scope.OuterScope; // Start search in previous scope while (scope != null) { if (scope is TypeScope) { break; } if (scope is NamespaceScope) { break; } if (scope == null) { return; } MemberList members = scope.GetMembersNamed(f.Name); for (int i = 0, n = members == null ? 0 : members.Count; i < n; i++) { Field outer = members[i] as Field; if (outer == null) { continue; } this.HandleError(decl, Error.LocalShadowsOuterDeclaration, f.Name.Name); return; } scope = scope.OuterScope; } }
public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) { if (localDeclarations == null) { return(null); } TypeNode type = localDeclarations.Type = this.VisitTypeReference(localDeclarations.Type); if (!localDeclarations.Constant) { return(localDeclarations); } LocalDeclarationList decls = localDeclarations.Declarations; for (int i = 0, n = decls.Count; i < n; i++) { LocalDeclaration decl = decls[i]; Field f = decl.Field; f.Type = type; f.Initializer = this.VisitExpression(f.Initializer); } return(localDeclarations); }
public override Statement VisitLocalDeclarationsStatement(LocalDeclarationsStatement localDeclarations) { if (localDeclarations == null) { return(null); } Statement result = base.VisitLocalDeclarationsStatement(localDeclarations); if (localDeclarations.Type == null && localDeclarations.TypeExpression is TypeExpression) { Identifier id = ((TypeExpression)localDeclarations.TypeExpression).Expression as Identifier; if (id != null && id.UniqueIdKey == StandardIds.Var.UniqueIdKey) { //Use the inferred type of the initializer of the first declaration as the variable type TypeNode t = null; LocalDeclarationList decls = localDeclarations.Declarations; for (int i = 0, n = decls == null ? 0 : decls.Count; i < n; i++) { LocalDeclaration decl = decls[i]; if (decl == null || decl.Field == null) { continue; } if (t == null) { if (decl.InitialValue != null) { t = decl.InitialValue.Type; } } decl.Field.Type = t; localDeclarations.Type = t; } } } return(result); }
public virtual Differences VisitLocalDeclaration(LocalDeclaration localDeclaration1, LocalDeclaration localDeclaration2){ Differences differences = new Differences(localDeclaration1, localDeclaration2); if (localDeclaration1 == null || localDeclaration2 == null){ if (localDeclaration1 != localDeclaration2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } LocalDeclaration changes = (LocalDeclaration)localDeclaration2.Clone(); LocalDeclaration deletions = (LocalDeclaration)localDeclaration2.Clone(); LocalDeclaration insertions = (LocalDeclaration)localDeclaration2.Clone(); Differences diff = this.VisitExpression(localDeclaration1.InitialValue, localDeclaration2.InitialValue); if (diff == null){Debug.Assert(false); return differences;} changes.InitialValue = diff.Changes as Expression; deletions.InitialValue = diff.Deletions as Expression; insertions.InitialValue = diff.Insertions as Expression; Debug.Assert(diff.Changes == changes.InitialValue && diff.Deletions == deletions.InitialValue && diff.Insertions == insertions.InitialValue); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitIdentifier(localDeclaration1.Name, localDeclaration2.Name); if (diff == null){Debug.Assert(false); return differences;} changes.Name = diff.Changes as Identifier; deletions.Name = diff.Deletions as Identifier; insertions.Name = diff.Insertions as Identifier; Debug.Assert(diff.Changes == changes.Name && diff.Deletions == deletions.Name && diff.Insertions == insertions.Name); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public virtual LocalDeclaration GetClosestMatch(LocalDeclaration/*!*/ nd1, LocalDeclarationList/*!*/ list1, LocalDeclarationList list2, int list1pos, ref int list2start, TrivialHashtable/*!*/ matchedNodes, out Differences closestDifferences, out int list2pos) { closestDifferences = null; list2pos = -1; if (list2 == null) return null; if (nd1 == null || list1 == null || matchedNodes == null || list1pos < 0 || list1pos >= list1.Count || list2start < 0 || list2start >= list2.Count) { Debug.Assert(false); return null; } LocalDeclaration closest = null; Differences winnerSoFar = null; for (int j = list2start, m = list2.Count; j < m; j++){ LocalDeclaration nd2 = list2[j]; if (list2start == j) list2start++; if (nd2 == null) continue; if (matchedNodes[nd2.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1, nd2); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= 0.5){ //Not a good enough match if (list2start == j+1) list2start--; //The next call to GetClosestMatch will start looking at list2start, so this node will be considered then continue; //ignore it for the rest of this call } if (winnerSoFar != null && winnerSoFar.Similarity >= diff.Similarity) continue; winnerSoFar = closestDifferences = diff; closest = nd2; list2pos = j; if (diff.NumberOfDifferences == 0) return closest; //Perfect match, no need to look for other matches } if (closest != null){ //^ assert winnerSoFar != null; //closest is closer to nd1 than any other node in list2, but this is no good if some other node in list1 has a better claim on closest for (int i = list1pos+1, n = list1.Count; i < n; i++){ LocalDeclaration nd1alt = list1[i]; if (nd1alt == null) continue; if (matchedNodes[nd1alt.UniqueKey] != null) continue; Differences diff = this.GetDifferences(nd1alt, closest); if (diff == null){Debug.Assert(false); continue;} if (diff.Similarity <= winnerSoFar.Similarity) continue; //nd1alt has a better claim on closest. See if it wants closest. Differences diff2; int j, k = list2start; LocalDeclaration nd2alt = this.GetClosestMatch(nd1alt, list1, list2, i, ref k, matchedNodes, out diff2, out j); if (nd2alt != closest){ Debug.Assert(nd2alt != null && diff2 != null && diff2.Similarity >= diff.Similarity); continue; //nd1alt prefers nd2alt to closest, so closest is still available } //nd1alt wants closest, take it out of the running matchedNodes[closest.UniqueKey] = nd1alt; //Now that closest is out of the running, try again k = list2start; LocalDeclaration newClosest = this.GetClosestMatch(nd1, list1, list2, i, ref k, matchedNodes, out winnerSoFar, out list2pos); //put closest back in the running so that the next call to this routine will pick it up matchedNodes[closest.UniqueKey] = closest; closest = newClosest; break; } } closestDifferences = winnerSoFar; return closest; }
public virtual LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration){ if (localDeclaration == null) return null; localDeclaration.InitialValue = this.VisitExpression(localDeclaration.InitialValue); return localDeclaration; }
public static Method GetArrayInitializationMethod(String name, bool isPublic, TypeNode declaringType, ARRAY_TYPE type, SourceContext sourceContext) { //Array NewTypeName() //{ // Array Res; // Res = new Array[A.GetLength(0), A.GetLength(1)]; // for (int i1 = 0; i1 < A.GetLength(0); i1++) // Res[i1] = new Array[]; // return Res; //} TypeNode returnType = (TypeNode)type.convertAndGetType(); Method method = new Method(); method.Name = Identifier.For("New" + name); method.DeclaringType = declaringType; method.Flags = MethodFlags.Static; if (isPublic) { method.Flags |= MethodFlags.Public; } else { method.Flags |= MethodFlags.Private; } method.InitLocals = true; method.SourceContext = sourceContext; method.Body = new Block(); method.Body.Checked = false; //??? method.Body.HasLocals = true; method.Body.Statements = new StatementList(); method.ReturnType = returnType; method.Parameters = new ParameterList(); int count = 0; // Add parameters List <Expression> parameterAccess = new List <Expression>(); ARRAY_TYPE arrayType = type; while (arrayType != null) { for (int i = 0; i < arrayType.dimensions.Length; i++) { if (arrayType.dimensions[i] == null || arrayType.dimensions[i].calculate() == null) { Identifier paramName = Identifier.For("n" + count.ToString()); Parameter parameter = new Parameter(paramName, SystemTypes.Int32); method.Parameters.Add(parameter); parameterAccess.Add(paramName); count++; } } if (arrayType.base_type is ARRAY_TYPE) { arrayType = (ARRAY_TYPE)arrayType.base_type; } else { arrayType = null; } } Identifier resultName = Identifier.For("res"); LocalDeclarationsStatement loc_stmt = new LocalDeclarationsStatement(); loc_stmt.Constant = false; loc_stmt.Declarations = new LocalDeclarationList(1); loc_stmt.InitOnly = false; loc_stmt.SourceContext = sourceContext; loc_stmt.Type = returnType; LocalDeclaration local = new LocalDeclaration(); local.Name = resultName; local.SourceContext = sourceContext; loc_stmt.Declarations.Add(local); method.Body.Statements.Add(loc_stmt); method.Body.Statements.Add(createElementInitializerInternal(type, resultName, 0, parameterAccess, false, sourceContext)); Return ret = new Return(); ret.Expression = resultName; method.Body.Statements.Add(ret); return(method); }
public virtual void VisitLocalDeclaration(LocalDeclaration localDeclaration) { if (localDeclaration == null) return; this.VisitExpression(localDeclaration.InitialValue); }
protected virtual LocalDefinition CreateLocalTempForProjection(List<Statement> statements) { IName dummyName = this.ContainingBlock.Helper.NameTable.GetNameFor("__temp" + this.SourceLocation.StartIndex); NameDeclaration tempName = new NameDeclaration(dummyName, this.SourceLocation); LocalDeclaration temp = new LocalDeclaration(false, false, tempName, null, this.SourceLocation); List<LocalDeclaration> declarations = new List<LocalDeclaration>(1) {temp}; LocalDeclarationsStatement statement = new LocalDeclarationsStatement(false, false, false, TypeExpression.For(this.structureTypeExpression.ResolvedType), declarations, this.SourceLocation); statements.Add(statement); statement.SetContainingBlock(this.ContainingBlock); temp.SetContainingLocalDeclarationsStatement(statement); return temp.LocalVariable; }
public virtual LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration1, LocalDeclaration localDeclaration2) { if (localDeclaration1 == null) return null; if (localDeclaration2 == null) localDeclaration1.InitialValue = this.VisitExpression(localDeclaration1.InitialValue, null); else localDeclaration1.InitialValue = this.VisitExpression(localDeclaration1.InitialValue, localDeclaration2.InitialValue); return localDeclaration1; }
public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration decl) { return decl; }
public SingleLocalDeclarationStement(LocalDeclaration local) { Local = local; Column = local.Column; Line = local.Line; }
public static void report(Node node, int shift) { if (node == null) { indent(shift); Console.WriteLine("NULL ENTITY"); return; } switch (node.NodeType) { case NodeType.AliasDefinition: { AliasDefinition alias = node as AliasDefinition; indent(shift); Console.WriteLine("using {0} = {1};", alias.Alias.Name, alias.AliasedUri.Name); break; } case NodeType.CompilationUnit: case NodeType.CompilationUnitSnippet: { CompilationUnit cu = node as CompilationUnit; for (int i = 0, n = cu.Nodes.Length; i < n; i++) { report(cu.Nodes[i], 0); } break; } case NodeType.Namespace: { Namespace ns = node as Namespace; if (ns.UsedNamespaces != null && ns.UsedNamespaces.Length != 0) { indent(shift); Console.WriteLine("using "); for (int i = 0, n = ns.UsedNamespaces.Length; i < n; i++) { Console.Write("{0}", ns.UsedNamespaces[i].Namespace.Name); if (i < n - 1) { Console.Write(", "); } } Console.WriteLine(); } indent(shift); Console.WriteLine("namespace {0}", ns.FullNameId.Name); indent(shift); Console.WriteLine("{"); if (ns.AliasDefinitions != null && ns.AliasDefinitions.Length != 0) { for (int i = 0, n = ns.AliasDefinitions.Length; i < n; i++) { report(ns.AliasDefinitions[i], shift + ind); } } if (ns.NestedNamespaces != null && ns.NestedNamespaces.Length != 0) { for (int i = 0, n = ns.NestedNamespaces.Length; i < n; i++) { report(ns.NestedNamespaces[i], shift + ind); } } if (ns.Types != null && ns.Types.Length != 0) { for (int i = 0, n = ns.Types.Length; i < n; i++) { report(ns.Types[i], shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Class: { Class cls = node as Class; if (cls == SystemTypes.Object) { Console.Write(cls.Name); break; } indent(shift); if (cls.IsAbstract) { Console.Write("abstract "); } if (cls.IsPrivate) { Console.Write("private "); } else if (cls.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ?????????????? } if (cls.IsSealed) { Console.Write("sealed "); } Console.Write("class "); if (cls.DeclaringType != null) { Console.Write("{0}::", cls.DeclaringType.Name.Name); } Console.Write("{0}", cls.Name != null?cls.Name.Name:"<NONAME>"); if (cls.BaseClass != null) { Console.Write(" : {0}", cls.BaseClass.Name.Name); } if (cls.Interfaces != null && cls.Interfaces.Length != 0) { if (cls.BaseClass != null) { Console.Write(","); } else { Console.Write(" :"); } for (int i = 0, n = cls.Interfaces.Length; i < n; i++) { Interface interfac = cls.Interfaces[i]; if (interfac != null) { Console.Write(" {0}", interfac.Name.Name); } if (i < n - 1) { Console.Write(","); } } } Console.WriteLine(); indent(shift); Console.WriteLine("{"); if (cls.Members != null && cls.Members.Length != 0) { for (int i = 0, n = cls.Members.Length; i < n; i++) { Member member = cls.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Struct: { Struct struc = node as Struct; indent(shift); if (struc.IsAbstract) { Console.Write("abstract "); } if (struc.IsPrivate) { Console.Write("private "); } else if (struc.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ?????????????? } if (struc.IsSealed) { Console.Write("sealed "); } Console.Write("struct "); if (struc.DeclaringType != null) { Console.Write("{0}::", struc.DeclaringType.Name.Name); } Console.Write("{0}", struc.Name != null?struc.Name.Name:"<NONAME>"); if (struc.Interfaces != null && struc.Interfaces.Length != 0) { Console.Write(" :"); for (int i = 0, n = struc.Interfaces.Length; i < n; i++) { Interface interfac = struc.Interfaces[i]; if (interfac != null) { Console.Write(" {0}", interfac.Name.Name); } if (i < n - 1) { Console.Write(","); } } } Console.WriteLine(); indent(shift); Console.WriteLine("{"); if (struc.Members != null && struc.Members.Length != 0) { for (int i = 0, n = struc.Members.Length; i < n; i++) { Member member = struc.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.EnumNode: { EnumNode enume = node as EnumNode; indent(shift); if (enume.Name != null && enume.Name.Name != null) { Console.Write("enum {0} = ", enume.Name.Name); } else { Console.Write("enum <NONAME> = "); } Console.Write("{"); for (int i = 0, n = enume.Members.Length; i < n; i++) { Field enumerator = (Field)enume.Members[i]; Console.Write("{0}", enumerator.Name.Name); if (enumerator.DefaultValue != null) { Console.Write(" = {0}", enumerator.DefaultValue.ToString()); } if (i < n - 1) { Console.Write(", "); } } Console.WriteLine("};"); break; } case NodeType.Interface: { Interface interfac = node as Interface; indent(shift); if (interfac.IsAbstract) { Console.Write("abstract "); } if (interfac.IsPrivate) { Console.Write("private "); } else if (interfac.IsPublic) { Console.Write("public "); } else { Console.Write("internal "); // ??????????? } Console.WriteLine("interface {0}", interfac.Name.Name); indent(shift); Console.WriteLine("{"); if (interfac.Members != null && interfac.Members.Length != 0) { for (int i = 0, n = interfac.Members.Length; i < n; i++) { Member member = interfac.Members[i]; if (member == null) { indent(shift + ind); Console.WriteLine("<UNRESOLVED MEMBER>"); continue; } report(member, shift + ind); } } indent(shift); Console.WriteLine("}"); break; } case NodeType.Method: case NodeType.InstanceInitializer: { Method method = node as Method; indent(shift); if (method.IsAbstract) { Console.Write("abstract "); } if (method.IsPublic) { Console.Write("public "); } if (method.IsStatic) { Console.Write("static "); } if (method.IsVirtual) { Console.Write("virtual "); } if (method.IsPrivate) { Console.Write("private "); } if (method.OverriddenMethod != null) { Console.Write("override "); } if (method.ReturnType != null && method.ReturnType.Name != null) { Console.Write("{0} ", method.ReturnType.Name.Name); } if (method.Name != null) { if (method.ImplementedInterfaceMethods != null && method.ImplementedInterfaceMethods.Length != 0) { Method interf = method.ImplementedInterfaceMethods[0]; if (interf != null) { string name = interf.DeclaringType.Name.Name; Console.Write("{0}.", name); } } Console.Write("{0}", method.Name.Name); } Console.Write(" ("); if (method.Parameters != null && method.Parameters.Length != 0) { for (int i = 0, n = method.Parameters.Length; i < n; i++) { Parameter par = method.Parameters[i]; if (par == null) { continue; } if ((par.Flags & ParameterFlags.In) != 0) { Console.Write("in "); } if ((par.Flags & ParameterFlags.Out) != 0) { Console.Write("out "); } if (par.Type != null && par.Type.Name != null) { Console.Write("{0}", par.Type.Name.Name); } else { report(par.Type, 0); } Console.Write(" {0}", par.Name.Name); if (i < n - 1) { Console.Write(", "); } } } Console.Write(" )"); // method body if (method.Body != null) { Console.WriteLine(); report(method.Body, shift); } else { Console.WriteLine(";"); } break; } case NodeType.DelegateNode: { DelegateNode dn = node as DelegateNode; indent(shift); Console.Write("delegate "); if (dn.ReturnType != null && dn.ReturnType.Name != null) { Console.Write("{0} ", dn.ReturnType.Name.Name); } if (dn.Name != null) { Console.Write("{0}", dn.Name.Name); } Console.Write(" ("); if (dn.Parameters != null && dn.Parameters.Length != 0) { for (int i = 0, n = dn.Parameters.Length; i < n; i++) { Parameter par = dn.Parameters[i]; if (par == null) { continue; } if ((par.Flags & ParameterFlags.In) != 0) { Console.Write("in "); } if ((par.Flags & ParameterFlags.Out) != 0) { Console.Write("out "); } if (par.Type != null && par.Type.Name != null) { Console.Write("{0}", par.Type.Name.Name); } else { report(par.Type, 0); } Console.Write(" {0}", par.Name.Name); if (i < n - 1) { Console.Write(", "); } } } Console.WriteLine(" );"); break; } case NodeType.StaticInitializer: { StaticInitializer si = node as StaticInitializer; indent(shift); Console.WriteLine("static {0} ( )", si.Name.Name); // body if (si.Body != null) { report(si.Body, shift); } else { Console.WriteLine("NO BODY"); } break; } case NodeType.FieldInitializerBlock: { FieldInitializerBlock initializers = node as FieldInitializerBlock; indent(shift); if (initializers.IsStatic) { Console.Write("static "); } Console.WriteLine("init {"); for (int i = 0, n = initializers.Statements.Length; i < n; i++) { report(initializers.Statements[i], shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Base: { Console.Write("base"); break; } case NodeType.Field: { Field field = node as Field; indent(shift); if (field.IsPrivate) { Console.Write("private "); } else if (field.IsPublic) { Console.Write("public "); } if (field.IsStatic) { Console.Write("static "); } if (field.IsInitOnly) { Console.Write("readonly "); } if (field.Type != null) { if (field.Type.Name != null) { Console.Write("{0}", field.Type.Name.Name); } else { report(field.Type, 0); } } Console.Write(" {0}", field.Name.Name); if (field.Initializer != null) { Console.Write(" = "); report(field.Initializer, 0); } Console.WriteLine(";"); break; } case NodeType.VariableDeclaration: { VariableDeclaration variable = node as VariableDeclaration; indent(shift); if (variable.Type != null && variable.Type.Name != null) { Console.Write("{0}", variable.Type.Name.Name); } else { report(variable.Type, 0); } Console.Write(" {0}", variable.Name.Name); if (variable.Initializer != null) { Console.Write(" = "); report(variable.Initializer, 0); } Console.WriteLine(";"); break; } case NodeType.LocalDeclarationsStatement: { LocalDeclarationsStatement stmt = node as LocalDeclarationsStatement; indent(shift); TypeNode type = stmt.Type; if (type != null && type.Name != null) { Console.Write("{0}", type.Name.Name); } else { report(type, 0); } Console.Write(" "); LocalDeclarationList list = stmt.Declarations; for (int i = 0, n = list.Length; i < n; i++) { LocalDeclaration local = list[i]; Console.Write("{0}", local.Name.Name); if (local.InitialValue != null) { Console.Write(" = "); report(local.InitialValue, 0); } if (i < n - 1) { Console.Write(", "); } } Console.WriteLine(";"); break; } case NodeType.Property: { Property property = node as Property; indent(shift); if (property.IsPrivate) { Console.Write("private "); } else if (property.IsPublic) { Console.Write("public "); } if (property.IsStatic) { Console.Write("static "); } if (property != null) { if (property.Type != null && property.Type.Name != null) { Console.Write("{0} ", property.Type.Name.Name); } if (property.ImplementedTypes != null) { TypeNode typ = property.ImplementedTypes[0]; Console.Write("{0}.", typ.Name.Name); } if (property.Name != null) { Console.WriteLine("{0}", property.Name.Name); } } indent(shift); Console.WriteLine("{"); if (property.Getter != null) { report(property.Getter, shift + ind); } if (property.Setter != null) { report(property.Setter, shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Lock: { Lock _lock = node as Lock; indent(shift); Console.Write("lock("); report(_lock.Guard, shift); Console.WriteLine(")"); report(_lock.Body, shift + ind); indent(shift); Console.WriteLine("}"); break; } case NodeType.Block: { Block block = node as Block; if (block == null || block.Statements == null) { break; } indent(shift); Console.WriteLine("{"); for (int i = 0, n = block.Statements.Length; i < n; i++) { report(block.Statements[i], shift + ind); Console.WriteLine(); } indent(shift); Console.WriteLine("}"); break; } case NodeType.MemberBinding: { MemberBinding mb = node as MemberBinding; if (mb.TargetObject != null) { report(mb.TargetObject, 0); } else if (mb.BoundMember != null && mb.BoundMember.DeclaringType != null) { Console.Write(mb.BoundMember.DeclaringType.Name); } Console.Write("."); if (mb.BoundMember.Name != null) { Console.Write(mb.BoundMember.Name.Name); } else { report(mb.BoundMember, 0); } break; } case NodeType.AssignmentStatement: { AssignmentStatement assignment = node as AssignmentStatement; indent(shift); report(assignment.Target, 0); switch (assignment.Operator) { case NodeType.Nop: Console.Write(" = "); break; case NodeType.Add: Console.Write(" += "); break; case NodeType.Add_Ovf: Console.Write(" += "); break; case NodeType.Add_Ovf_Un: Console.Write(" += "); break; case NodeType.Sub: Console.Write(" -= "); break; case NodeType.Sub_Ovf: Console.Write(" -= "); break; case NodeType.Sub_Ovf_Un: Console.Write(" -= "); break; case NodeType.Mul: Console.Write(" *= "); break; case NodeType.Mul_Ovf: Console.Write(" *= "); break; case NodeType.Mul_Ovf_Un: Console.Write(" *= "); break; } report(assignment.Source, 0); Console.Write(";"); break; } case NodeType.ExpressionStatement: { ExpressionStatement exprStatement = node as ExpressionStatement; indent(shift); report(exprStatement.Expression, 0); Console.Write(";"); break; } case NodeType.Return: { Return return_stmt = node as Return; indent(shift); Console.Write("return"); if (return_stmt.Expression != null) { Console.Write(" "); report(return_stmt.Expression, 0); } Console.Write(";"); break; } case NodeType.Branch: { Branch branch = node as Branch; indent(shift); Console.WriteLine("break; (???)"); break; } case NodeType.For: { For for_stmt = node as For; indent(shift); Console.Write("for ( "); for (int i = 0, n = for_stmt.Initializer.Length; i < n; i++) { report(for_stmt.Initializer[i], 0); } report(for_stmt.Condition, 0); Console.Write("; "); for (int i = 0, n = for_stmt.Incrementer.Length; i < n; i++) { report(for_stmt.Incrementer[i], 0); } Console.WriteLine(")"); indent(shift); Console.WriteLine("{"); report(for_stmt.Body, shift + ind); indent(shift); Console.WriteLine("}"); break; } case NodeType.While: { While while_loop = node as While; indent(shift); Console.Write("while ( "); report(while_loop.Condition, 0); Console.WriteLine(" )"); report(while_loop.Body, shift); break; } case NodeType.DoWhile: { DoWhile repeat = node as DoWhile; indent(shift); Console.WriteLine("do"); report(repeat.Body, shift); indent(shift); Console.Write("while ("); report(repeat.Condition, 0); Console.WriteLine(" );"); break; } case NodeType.If: { If if_stmt = node as If; indent(shift); Console.Write("if ( "); report(if_stmt.Condition, 0); Console.WriteLine(" )"); report(if_stmt.TrueBlock, shift); if (if_stmt.FalseBlock == null || if_stmt.FalseBlock.Statements == null || if_stmt.FalseBlock.Statements.Length == 0) { break; } indent(shift); Console.WriteLine("else"); report(if_stmt.FalseBlock, shift); break; } case NodeType.Switch: { Switch swtch = node as Switch; indent(shift); Console.Write("switch ( "); report(swtch.Expression, 0); Console.WriteLine(" )"); indent(shift); Console.WriteLine("{"); for (int i = 0, n = swtch.Cases.Length; i < n; i++) { indent(shift + ind); if (swtch.Cases[i].Label != null) { Console.Write("case "); report(swtch.Cases[i].Label, 0); Console.WriteLine(":"); } else { Console.WriteLine("default:"); } report(swtch.Cases[i].Body, shift + ind); } indent(shift); Console.WriteLine("}"); break; } case NodeType.Throw: { Throw thro = node as Throw; indent(shift); Console.Write("throw ("); report(thro.Expression, 0); Console.Write(");"); break; } case NodeType.Exit: { indent(shift); Console.WriteLine("exit;"); break; } case NodeType.Continue: { indent(shift); Console.WriteLine("continue;"); break; } case NodeType.Try: { Try trys = node as Try; indent(shift); Console.WriteLine("try {"); report(trys.TryBlock, shift + ind); indent(shift); Console.WriteLine("}"); if (trys.Catchers != null) { for (int i = 0, n = trys.Catchers.Length; i < n; i++) { indent(shift); if (trys.Catchers[i].Type != null) { Console.Write("catch ( {0} ", trys.Catchers[i].Type.FullName); } else { Console.Write("catch ( "); } if (trys.Catchers[i].Variable != null) { report(trys.Catchers[i].Variable, 0); } Console.WriteLine(" ) {"); report(trys.Catchers[i].Block, shift + ind); indent(shift); Console.WriteLine("}"); } } if (trys.Finally != null && trys.Finally.Block != null) { indent(shift); Console.WriteLine("finally"); report(trys.Finally.Block, shift); } break; } case NodeType.BlockExpression: { BlockExpression be = node as BlockExpression; Console.WriteLine("("); StatementList sl = be.Block.Statements; for (int i = 0, n = sl.Length; i < n; i++) { report(sl[i], shift + ind); } indent(shift); Console.Write(")"); break; } case NodeType.ArrayTypeExpression: { ArrayTypeExpression array = node as ArrayTypeExpression; indent(shift); if (array.ElementType != null && array.ElementType.Name != null && array.ElementType.Name.Name != null) { Console.Write(array.ElementType.Name.Name); } else { report(array.ElementType, 0); } Console.Write("["); for (int i = 0, n = array.Rank; i < n; i++) { if (array.Sizes != null) { Console.Write(array.Sizes[i]); } if (i < n - 1) { Console.Write(","); } } Console.Write("]"); break; } case NodeType.Construct: { Construct construct = node as Construct; indent(shift); Console.Write("new "); report(construct.Constructor, 0); Console.Write("("); if (construct.Operands != null) { for (int i = 0, n = construct.Operands.Length; i < n; i++) { report(construct.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } } Console.Write(")"); break; } case NodeType.ConstructArray: { ConstructArray initializer = node as ConstructArray; Console.Write("new "); if (initializer.ElementType != null && initializer.ElementType.Name != null && initializer.ElementType.Name.Name != null) { Console.Write(initializer.ElementType.Name.Name); } else { report(initializer.ElementType, 0); } Console.Write("["); for (int i = 0, n = initializer.Operands.Length; i < n; i++) { report(initializer.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } Console.Write("]"); break; } case NodeType.ConstructDelegate: { ConstructDelegate cd = node as ConstructDelegate; // Console.Write("new {0}({1})",cd.DelegateType.Name.Name,cd.MethodName.Name); Console.Write("new {0}(", cd.DelegateType.Name.Name); report(cd.TargetObject, 0); Console.Write(".{0})", cd.MethodName.Name); // cd.Type; break; } default: { if (node is ZonnonCompilation) { ZonnonCompilation zc = node as ZonnonCompilation; report(zc.CompilationUnits[0], shift); } // Expression? else if (node is MethodCall) { MethodCall call = node as MethodCall; report(call.Callee, 0); Console.Write("("); if (call.Operands != null && call.Operands.Length != 0) { for (int i = 0, n = call.Operands.Length; i < n; i++) { report(call.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } } Console.Write(")"); } else if (node is Variable) { Variable variable = node as Variable; Console.Write("{0}", variable.Name.Name); } else if (node is Identifier) { Identifier identifier = node as Identifier; Console.Write("{0}", identifier.Name); } else if (node is QualifiedIdentifier) { QualifiedIdentifier qualid = node as QualifiedIdentifier; report(qualid.Qualifier, 0); Console.Write(".{0}", qualid.Identifier == null?"<UNRESOLVED>":qualid.Identifier.Name); } else if (node is Literal) { Literal literal = node as Literal; if (literal.Value == null) { Console.Write("null"); } else { if (literal.Value is string) { Console.Write("\""); } else if (literal.Value is char) { Console.Write("'"); } Console.Write("{0}", literal.Value.ToString()); if (literal.Value is string) { Console.Write("\""); } else if (literal.Value is char) { Console.Write("'"); } } } else if (node is Indexer) { Indexer indexer = node as Indexer; report(indexer.Object, 0); Console.Write("["); for (int i = 0, n = indexer.Operands.Length; i < n; i++) { report(indexer.Operands[i], 0); if (i < n - 1) { Console.Write(","); } } Console.Write("]"); } else if (node is UnaryExpression) { UnaryExpression unexpr = node as UnaryExpression; bool add_pars = unexpr.Operand is BinaryExpression || unexpr.Operand is UnaryExpression; switch (unexpr.NodeType) { case NodeType.Add: Console.Write("+"); break; case NodeType.Sub: Console.Write("-"); break; case NodeType.Neg: Console.Write("-"); break; case NodeType.Not: Console.Write("~"); break; case NodeType.UnaryPlus: Console.Write("+"); break; case NodeType.LogicalNot: Console.Write("!"); break; case NodeType.Conv_U2: Console.Write("(UInt16)"); break; case NodeType.RefAddress: Console.Write("ref "); break; case NodeType.Ckfinite: Console.Write("(Ckfinite)"); break; default: Console.Write("???"); break; } if (add_pars) { Console.Write("("); } report(unexpr.Operand, 0); if (add_pars) { Console.Write(")"); } } else if (node is BinaryExpression) { BinaryExpression binexpr = node as BinaryExpression; bool add_pars = binexpr.Operand1 is BinaryExpression || binexpr.Operand1 is UnaryExpression; if (binexpr.NodeType == NodeType.Castclass) { Console.Write("("); report(binexpr.Operand2, 0); Console.Write(")"); if (add_pars) { Console.Write("("); } report(binexpr.Operand1, 0); if (add_pars) { Console.Write(")"); } break; } if (add_pars) { Console.Write("("); } report(binexpr.Operand1, 0); if (add_pars) { Console.Write(")"); } switch (binexpr.NodeType) { case NodeType.Add: Console.Write(" + "); break; case NodeType.Add_Ovf: Console.Write(" + "); break; case NodeType.Add_Ovf_Un: Console.Write(" + "); break; case NodeType.Sub: Console.Write(" - "); break; case NodeType.Sub_Ovf: Console.Write(" - "); break; case NodeType.Sub_Ovf_Un: Console.Write(" - "); break; case NodeType.Mul: Console.Write(" * "); break; case NodeType.Mul_Ovf: Console.Write(" * "); break; case NodeType.Mul_Ovf_Un: Console.Write(" * "); break; case NodeType.Div: Console.Write(" / "); break; // case NodeType.Div : Console.Write(" DIV "); break; // "DIV" ????? case NodeType.Rem: Console.Write(" % "); break; // "MOD" ????? case NodeType.Or: Console.Write(" | "); break; case NodeType.And: Console.Write(" & "); break; case NodeType.Eq: Console.Write(" == "); break; case NodeType.Ne: Console.Write(" != "); break; case NodeType.Lt: Console.Write(" < "); break; case NodeType.Le: Console.Write(" <= "); break; case NodeType.Gt: Console.Write(" > "); break; case NodeType.Ge: Console.Write(" >= "); break; case NodeType.LogicalOr: Console.Write(" || "); break; case NodeType.LogicalAnd: Console.Write(" && "); break; case NodeType.Is: Console.Write(" is "); break; case NodeType.Comma: Console.Write(","); break; // case OPERATORS.In : expression.NodeType = NodeType // "IN" break; // case OPERATORS.Implements : expression.NodeType = NodeType // "IMPLEMENTS" break; default: Console.Write(" !! "); break; } add_pars = binexpr.Operand2 is BinaryExpression || binexpr.Operand2 is UnaryExpression; if (add_pars) { Console.Write("("); } report(binexpr.Operand2, 0); if (add_pars) { Console.Write(")"); } } else if (node is TernaryExpression) { TernaryExpression ter = node as TernaryExpression; if (ter.NodeType == NodeType.Conditional) { report(ter.Operand1, 0); Console.Write(" ? "); report(ter.Operand2, 0); Console.Write(" : "); report(ter.Operand3, 0); } } else if (node is PostfixExpression) { PostfixExpression postfixExpr = node as PostfixExpression; report(postfixExpr.Expression, 0); switch (postfixExpr.Operator) { case NodeType.Increment: Console.Write("++"); break; case NodeType.Decrement: Console.Write("--"); break; default: Console.Write("???"); break; } } else if (node is LabeledStatement) { LabeledStatement lbst = node as LabeledStatement; indent(shift); report(lbst.Label, 0); Console.Write(" : "); report(lbst.Statement, 0); } else if (node is Goto) { Goto gt = node as Goto; indent(shift); Console.Write("goto "); report(gt.TargetLabel, 0); } else { indent(shift); Console.WriteLine("No code for reporting {0}:{1}", node.UniqueKey, node.ToString()); } break; } } }
public virtual LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration, LocalDeclaration changes, LocalDeclaration deletions, LocalDeclaration insertions){ this.UpdateSourceContext(localDeclaration, changes); if (localDeclaration == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ } }else if (deletions != null) return null; return localDeclaration; }
public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration) { if (localDeclaration == null) return null; return base.VisitLocalDeclaration((LocalDeclaration)localDeclaration.Clone()); }