Exemplo n.º 1
0
 public virtual Expression VisitStackAlloc(StackAlloc alloc, StackAlloc changes, StackAlloc deletions, StackAlloc insertions){
   this.UpdateSourceContext(alloc, changes);
   if (alloc == null) return changes;
   if (changes != null){
     if (deletions == null || insertions == null)
       Debug.Assert(false);
     else{
     }
   }else if (deletions != null)
     return null;
   return alloc;
 }
Exemplo n.º 2
0
    public virtual Differences VisitStackAlloc(StackAlloc alloc1, StackAlloc alloc2){
      Differences differences = new Differences(alloc1, alloc2);
      if (alloc1 == null || alloc2 == null){
        if (alloc1 != alloc2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      StackAlloc changes = (StackAlloc)alloc2.Clone();
      StackAlloc deletions = (StackAlloc)alloc2.Clone();
      StackAlloc insertions = (StackAlloc)alloc2.Clone();


      Differences diff = this.VisitTypeNode(alloc1.ElementType, alloc2.ElementType);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.ElementType = diff.Changes as TypeNode;
      deletions.ElementType = diff.Deletions as TypeNode;
      insertions.ElementType = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.ElementType && diff.Deletions == deletions.ElementType && diff.Insertions == insertions.ElementType);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;
      
      diff = this.VisitExpression(alloc1.NumberOfElements, alloc2.NumberOfElements);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.NumberOfElements = diff.Changes as Expression;
      deletions.NumberOfElements = diff.Deletions as Expression;
      insertions.NumberOfElements = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.NumberOfElements && diff.Deletions == deletions.NumberOfElements && diff.Insertions == insertions.NumberOfElements);
      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 override object Visit (StackAlloc stackAllocExpression)
			{
				var result = new StackAllocExpression ();
				
				var location = LocationsBag.GetLocations (stackAllocExpression);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location [0]), StackAllocExpression.StackallocKeywordRole), StackAllocExpression.StackallocKeywordRole);
				if (stackAllocExpression.TypeExpression != null)
					result.AddChild (ConvertToType (stackAllocExpression.TypeExpression), Roles.Type);
				if (location != null && location.Count > 1)
					result.AddChild (new CSharpTokenNode (Convert (location [1]), Roles.LBracket), Roles.LBracket);
				if (stackAllocExpression.CountExpression != null)
					result.AddChild ((Expression)stackAllocExpression.CountExpression.Accept (this), Roles.Expression);
				if (location != null && location.Count > 2)
					result.AddChild (new CSharpTokenNode (Convert (location [2]), Roles.RBracket), Roles.RBracket);
				return result;
			}
Exemplo n.º 4
0
void case_899()
#line 6017 "cs-parser.jay"
{
		report.Error (1575, GetLocation (yyVals[-1+yyTop]), "A stackalloc expression requires [] after type");
		yyVal = new StackAlloc ((Expression) yyVals[0+yyTop], null, GetLocation (yyVals[-1+yyTop]));		
	  }
Exemplo n.º 5
0
 public virtual Expression VisitStackAlloc(StackAlloc alloc){
   if (alloc == null) return null;
   alloc.ElementType = this.VisitTypeReference(alloc.ElementType);
   alloc.NumberOfElements = this.VisitExpression(alloc.NumberOfElements);
   return alloc;
 }
Exemplo n.º 6
0
 public override Expression VisitStackAlloc(StackAlloc alloc) {
   if (alloc == null) return null;
   if (this.insideCatchClause || this.currentFinallyClause != null) {
     this.HandleError(alloc, Error.StackallocInCatchFinally);
     return null;
   }
   return base.VisitStackAlloc(alloc);
 }
Exemplo n.º 7
0
void case_898()
#line 6012 "cs-parser.jay"
{
		yyVal = new StackAlloc ((Expression) yyVals[-3+yyTop], (Expression) yyVals[-1+yyTop], GetLocation (yyVals[-4+yyTop]));
		lbag.AddLocation (yyVal, GetLocation (yyVals[-2+yyTop]), GetLocation (yyVals[0+yyTop]));
	  }
Exemplo n.º 8
0
 public override Expression VisitStackAlloc(StackAlloc alloc){
   if (alloc == null) return null;
   if (alloc.ElementType == null) return null;
   if (!alloc.ElementType.IsUnmanaged){
     this.HandleError(alloc.ElementTypeExpression, Error.ManagedAddr, this.GetTypeName(alloc.ElementType));
     return null;
   }
   alloc.Type = alloc.ElementType.GetPointerType();
   Expression numElements = this.VisitExpression(alloc.NumberOfElements);
   if (numElements == null) return null;
   numElements = this.typeSystem.CoerceToIndex(numElements, this.TypeViewer);
   if (numElements == null) return null;
   Expression elemSize = this.VisitUnaryExpression(new UnaryExpression(new Literal(alloc.ElementType, SystemTypes.Type), NodeType.Sizeof));
   if (numElements.Type != SystemTypes.Int32) elemSize = this.typeSystem.ExplicitCoercion(elemSize, numElements.Type, this.TypeViewer);
   BinaryExpression index = new BinaryExpression(numElements, elemSize, NodeType.Mul, numElements.Type, numElements.SourceContext);
   alloc.NumberOfElements = index;
   if (numElements is Literal && elemSize is Literal){ 
     alloc.NumberOfElements = this.VisitBinaryExpression(index); //Constant folding 
     Literal lit = alloc.NumberOfElements as Literal;
     if (lit != null && this.typeSystem.ImplicitCoercionFromTo(lit, lit.Type, SystemTypes.Int64, this.TypeViewer) && ((IConvertible)lit.Value).ToInt64(null) < 0){
       this.HandleError(lit, Error.NegativeStackAllocSize);
       return null;
     }
   }
   return alloc;
 }
Exemplo n.º 9
0
 public virtual void VisitStackAlloc(StackAlloc alloc)
 {
   if (alloc == null) return;
   this.VisitTypeReference(alloc.ElementType);
   this.VisitExpression(alloc.NumberOfElements);
 }
Exemplo n.º 10
0
		public virtual object Visit (StackAlloc stackAllocExpression)
		{
			return null;
		}
Exemplo n.º 11
0
 public virtual Expression VisitStackAlloc(StackAlloc alloc1, StackAlloc alloc2)
 {
     if (alloc1 == null) return null;
     if (alloc2 == null)
     {
         alloc1.ElementType = this.VisitTypeReference(alloc1.ElementType, null);
         alloc1.NumberOfElements = this.VisitExpression(alloc1.NumberOfElements, null);
     }
     else
     {
         alloc1.ElementType = this.VisitTypeReference(alloc1.ElementType, alloc2.ElementType);
         alloc1.NumberOfElements = this.VisitExpression(alloc1.NumberOfElements, alloc2.NumberOfElements);
     }
     return alloc1;
 }
Exemplo n.º 12
0
 public override Expression VisitStackAlloc(StackAlloc alloc){
   if (alloc == null) return null;
   return new UnaryExpression(this.VisitExpression(alloc.NumberOfElements), NodeType.Localloc, alloc.Type, alloc.SourceContext);
 }