示例#1
0
 public virtual Statement VisitTypeswitch(Typeswitch Typeswitch, Typeswitch changes, Typeswitch deletions, Typeswitch insertions){
   this.UpdateSourceContext(Typeswitch, changes);
   if (Typeswitch == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return Typeswitch;
 }
示例#2
0
 public virtual Statement VisitTypeswitch(Typeswitch Typeswitch){
   if (Typeswitch == null) return null;
   Typeswitch.Expression = this.VisitExpression(Typeswitch.Expression);
   Typeswitch.Cases = this.VisitTypeswitchCaseList(Typeswitch.Cases);
   return Typeswitch;
 }
    public virtual Differences VisitTypeswitch(Typeswitch typeswitch1, Typeswitch typeswitch2){
      Differences differences = new Differences(typeswitch1, typeswitch2);
      if (typeswitch1 == null || typeswitch2 == null){
        if (typeswitch1 != typeswitch2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      Typeswitch changes = (Typeswitch)typeswitch2.Clone();
      Typeswitch deletions = (Typeswitch)typeswitch2.Clone();
      Typeswitch insertions = (Typeswitch)typeswitch2.Clone();

      TypeswitchCaseList caseChanges, caseDeletions, caseInsertions;
      Differences diff = this.VisitTypeswitchCaseList(typeswitch1.Cases, typeswitch2.Cases, out caseChanges, out caseDeletions, out caseInsertions);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Cases = caseChanges;
      deletions.Cases = caseDeletions;
      insertions.Cases = caseInsertions;
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(typeswitch1.Expression, typeswitch2.Expression);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Expression = diff.Changes as Expression;
      deletions.Expression = diff.Deletions as Expression;
      insertions.Expression = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Expression && diff.Deletions == deletions.Expression && diff.Insertions == insertions.Expression);
      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;
    }
示例#4
0
 public virtual void VisitTypeswitch(Typeswitch Typeswitch)
 {
   if (Typeswitch == null) return;
   this.VisitExpression(Typeswitch.Expression);
   this.VisitTypeswitchCaseList(Typeswitch.Cases);
 }
示例#5
0
 public override Statement VisitTypeswitch(Typeswitch Typeswitch) {
   if (Typeswitch == null) return null;
   Expression e = this.VisitExpression(Typeswitch.Expression);
   if (e == null) return null;
   TypeNode t = e.Type; //HACK
   while (t is TypeAlias) {
     t = ((TypeAlias)t).AliasedType;
     e = this.typeSystem.ExplicitCoercion(e, t, this.TypeViewer);
   }
   TypeUnion tUnion = t as TypeUnion;
   if (tUnion == null) {
     this.HandleError(Typeswitch.Expression, Error.TypeSwitchExpressionMustBeUnion);
     return null;
   }
   TypeNodeList types = tUnion.Types;
   if (types == null) return null; //TODO: give an error
   TypeswitchCaseList oldCases = Typeswitch.Cases;
   if (oldCases == null) return null;
   int n = types.Count;
   TypeswitchCaseList newCases = Typeswitch.Cases = new TypeswitchCaseList(n);
   for (int i = 0; i < n; i++) newCases.Add(null);
   this.VisitTypeswitchCaseList(oldCases, newCases, tUnion);
   Typeswitch.Expression = e;
   return Typeswitch;
 }
 public override Statement VisitTypeswitch(Typeswitch Typeswitch)
 {
   throw new ApplicationException("unimplemented");
 }
示例#7
0
 public override Statement VisitTypeswitch(Typeswitch Typeswitch)
 {
     if (Typeswitch == null) return null;
     return base.VisitTypeswitch((Typeswitch)Typeswitch.Clone());
 }
示例#8
0
 public virtual Statement VisitTypeswitch(Typeswitch Typeswitch1, Typeswitch Typeswitch2)
 {
     if (Typeswitch1 == null) return null;
     if (Typeswitch2 == null)
     {
         Typeswitch1.Expression = this.VisitExpression(Typeswitch1.Expression, null);
         Typeswitch1.Cases = this.VisitTypeswitchCaseList(Typeswitch1.Cases, null);
     }
     else
     {
         Typeswitch1.Expression = this.VisitExpression(Typeswitch1.Expression, Typeswitch2.Expression);
         Typeswitch1.Cases = this.VisitTypeswitchCaseList(Typeswitch1.Cases, Typeswitch2.Cases);
     }
     return Typeswitch1;
 }
示例#9
0
 public override Statement VisitTypeswitch(Typeswitch Typeswitch){
   if (Typeswitch == null) return null;
   Expression e = Typeswitch.Expression = this.VisitExpression(Typeswitch.Expression);
   if (e == null || e.Type == null) return null;
   Method getTag = this.GetTypeView(e.Type).GetMethod(StandardIds.GetTag);
   if (getTag == null) return null;
   Method getValue = this.GetTypeView(e.Type).GetMethod(StandardIds.GetValue);
   if (getValue == null) return null;
   TypeswitchCaseList oldCases = Typeswitch.Cases;
   if (oldCases == null) return null;
   int n = oldCases.Count;
   BlockList targets = new BlockList(n);
   StatementList statements = new StatementList(n+3);
   Block result = new Block(statements);
   Local unionTemp = e as Local;
   if (unionTemp == null){
     unionTemp = new Local(Identifier.Empty, e.Type);
     statements.Add(new AssignmentStatement(unionTemp, e, e.SourceContext));
   }
   Local objectTemp = new Local(Identifier.Empty, SystemTypes.Object);
   SwitchInstruction switchInstruction = new SwitchInstruction(new MethodCall(new MemberBinding(new UnaryExpression(unionTemp, NodeType.AddressOf, unionTemp.Type.GetReferenceType()), getTag), null), targets);
   switchInstruction.SourceContext = Typeswitch.SourceContext;
   Block nextStatement = new Block();
   this.exitTargets.Add(nextStatement);
   statements.Add(new AssignmentStatement(objectTemp, new MethodCall(new MemberBinding(new UnaryExpression(unionTemp, NodeType.AddressOf, unionTemp.Type.GetReferenceType()), getValue), null)));
   statements.Add(switchInstruction);
   this.VisitTypeswitchCaseList(oldCases, targets, statements, nextStatement, objectTemp);
   statements.Add(nextStatement);
   this.exitTargets.Count--;
   return result;
 }
示例#10
0
 public override Statement VisitTypeswitch(Typeswitch Typeswitch)
 {
     throw new ApplicationException("unimplemented");
 }