Пример #1
0
 public override Expression VisitIndexer(Indexer indexer)
 {
     Expression indexerExpr = Templates.GetExpressionTemplate("IndexerAccess");
     Replacer.Replace(indexerExpr, "_arrayType", indexer.Object.Type.Name);
     Replacer.Replace(indexerExpr, "_ptrExpr", this.VisitExpression(indexer.Object));
     Expression intTypeRestore = Templates.GetExpressionTemplate("IntTypeRestoration");
     Replacer.Replace(intTypeRestore, "_enumValue", this.VisitExpression(indexer.Operands[0]));
     Replacer.Replace(indexerExpr, "_indexExpr", intTypeRestore);
     return indexerExpr;
 }
Пример #2
0
 public override Expression VisitIndexer(Indexer indexer)
 {
     this.VisitExpression(indexer.Object);
     Write("[");
     this.VisitExpressionList(indexer.Operands);
     Write("]");
     return indexer;
 }
Пример #3
0
    public override Expression VisitIndexer(Indexer indexer) {
      if (indexer == null) return null;
      // saving outermost binding sub-expression (in order to reset state when leaving it)
      if (st.OuterMostBinding == null) st.OuterMostBinding = indexer;
      IndexerAccess = true;
      // BASE CALL on array-object
      this.VisitExpression(indexer.Object);

      byte elementLevel = st.ElementLevel;
      if (st.OutsideOwnedCone)
        this.HandleError(st.OuterMostBinding, Error.NotAdmissibleBoundCollArrayNotOwned, st.LastAccessedName);
      else if (elementLevel == 0 || (elementLevel == 1 && st.ContextDepth < 2))
        st.OutsideOwnedCone = true;
      else if (elementLevel == 1)
        st.ContextDepth--;
      // NOTE: with elementsLevel==2 we just stay at same level

      st.LastAccessedName = "on element of " + st.LastAccessedName;

      // visiting index-expressions
      PushState();
      foreach (Expression param in indexer.Operands) {
        ResetCurrentState();
        this.VisitExpression(param);
      }
      PopState();

      if (st.OuterMostBinding == indexer) ResetCurrentState();
      return indexer;
    }
Пример #4
0
 public virtual Expression VisitIndexer(Indexer indexer)
 {
     if (indexer == null) return null;
     indexer.Object = this.VisitExpression(indexer.Object);
     indexer.Operands = this.VisitExpressionList(indexer.Operands);
     return indexer;
 }
Пример #5
0
 public override Expression VisitIndexer(Indexer indexer)
 {
     if (indexer == null) return null;
     indexer = (Indexer)base.VisitIndexer((Indexer)indexer.Clone());
     if (indexer == null) return null;
     indexer.ElementType = this.VisitTypeReference(indexer.ElementType);
     return indexer;
 }
Пример #6
0
 private Expression ParseIndexerCallOrSelector(Expression expression, TokenSet followers){
   TokenSet followersOrContinuers = followers|Token.LeftBracket|Token.LeftParenthesis|Token.Dot;
   for(;;){
     switch (this.currentToken){
       case Token.LeftBracket:
         SourceContext lbCtx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         if (this.insideModifiesClause && this.currentToken == Token.Multiply){
           // Handle code such as
           //
           //     modifies myArray[*];
           //
           // which means that the method may modify all elements of myArray.
           int savedStartPos = this.scanner.startPos;
           int savedEndPos = this.scanner.endPos;
           this.GetNextToken();
           if (this.currentToken == Token.RightBracket){
             SourceContext sctxt = this.scanner.CurrentSourceContext;
             sctxt.StartPos = lbCtx.StartPos;
             this.GetNextToken();
             return new ModifiesArrayClause(expression, sctxt);
           }
           this.scanner.startPos = savedStartPos;
           this.scanner.endPos = savedEndPos;
         }
         int endCol;
         ExpressionList indices = this.ParseIndexList(followersOrContinuers, lbCtx, out endCol);
         Indexer indexer = new Indexer(expression, indices);
         indexer.SourceContext = expression.SourceContext;
         indexer.SourceContext.EndPos = endCol;
         indexer.ArgumentListIsIncomplete = this.scanner.GetChar(endCol-1) != ']';
         expression = indexer;
         break;
       case Token.LessThan:
         SourceContext ltCtx = this.scanner.CurrentSourceContext;
         ScannerState ss = this.scanner.state;
         int arity;
         TypeNodeList typeArguments = this.ParseTypeArguments(true, false, followers|Token.LeftParenthesis, out endCol, out arity);
         if (typeArguments == null || (typeArguments.Count > 1 && Parser.TypeArgumentListNonFollower[this.currentToken])) {
           this.scanner.endPos = ltCtx.StartPos;
           this.scanner.state = ss;
           this.currentToken = Token.None;
           this.GetNextToken();
           return expression;
         }
         TemplateInstance instance = new TemplateInstance(expression, typeArguments);
         instance.TypeArgumentExpressions = typeArguments == null ? null : typeArguments.Clone();
         instance.SourceContext = expression.SourceContext;
         instance.SourceContext.EndPos = endCol;
         expression = instance;
         break;
       case Token.LeftParenthesis:
         SourceContext lpCtx = this.scanner.CurrentSourceContext;
         this.GetNextToken();
         ExpressionList arguments = this.ParseArgumentList(followersOrContinuers, lpCtx, out endCol);
         if (expression == null) return null;
         if (expression is Identifier && arguments.Count == 1 && ((Identifier)expression).Name == "old" && InEnsuresContext){
           OldExpression old = new OldExpression(arguments[0]);
           typeArguments = null;
           old.SourceContext = expression.SourceContext;
           old.SourceContext.EndPos = endCol;
           expression = old;
           break;
         }
         if (expression is TemplateInstance)
           ((TemplateInstance)expression).IsMethodTemplate = true;
         MethodCall mcall = new MethodCall(expression, arguments);
         typeArguments = null;
         mcall.GiveErrorIfSpecialNameMethod = true;
         mcall.SourceContext = expression.SourceContext;
         mcall.SourceContext.EndPos = endCol;
         mcall.ArgumentListIsIncomplete = this.scanner.GetChar(endCol-1) != ')';
         expression = mcall;
         break;
       case Token.LeftBrace:
         if (this.compatibilityOn || this.scanner.TokenIsFirstAfterLineBreak) goto default;
         Expression quant = this.ParseComprehension(followers);
         if (quant == null) { break; }
         Block argBlock = new Block(new StatementList(new ExpressionStatement(quant)),quant.SourceContext,
           this.insideCheckedBlock, this.insideUncheckedBlock, this.inUnsafeCode);
         argBlock.IsUnsafe = this.inUnsafeCode;
         argBlock.SourceContext = quant.SourceContext;
         ExpressionList arguments2 = new ExpressionList(new AnonymousNestedFunction(new ParameterList(0), argBlock, quant.SourceContext));
         MethodCall mcall2 = new MethodCall(expression, arguments2);
         typeArguments = null;
         mcall2.GiveErrorIfSpecialNameMethod = true;
         mcall2.SourceContext = expression.SourceContext;
         mcall2.SourceContext.EndPos = this.scanner.endPos;
         expression = mcall2;
         break;
       case Token.Dot:
         expression = this.ParseQualifiedIdentifier(expression, followersOrContinuers);
         break;
       case Token.RealLiteral:
         string tokStr = this.scanner.GetTokenSource();
         if (this.insideModifiesClause && tokStr == ".0") {
           // this case is here only for parsing ".0" while parsing a modifies clause
           // e.g., "modifies this.0;"
           this.GetNextToken(); // eat the ".0"
           return new ModifiesNothingClause(expression, this.scanner.CurrentSourceContext);
         } else {
           return expression;
         }
       case Token.Arrow:
         if (!this.allowUnsafeCode){
           this.HandleError(Error.IllegalUnsafe);
           this.allowUnsafeCode = true;
         }
         this.currentToken = Token.Dot;
         AddressDereference ad = new AddressDereference();
         ad.Address = expression;
         ad.ExplicitOperator = AddressDereference.ExplicitOp.Arrow;
         ad.SourceContext = expression.SourceContext;
         expression = this.ParseQualifiedIdentifier(ad, followersOrContinuers);
         break;
       default:
         return expression;
     }
   }
 }
Пример #7
0
    /// <summary>
    /// </summary>
    /// <param name="indexer">Cloned</param>
    /// <returns></returns>
		public override Expression VisitIndexer(Indexer indexer)
		{
      // copy indexer, since CCI shares them in post increments
      indexer = (Indexer)indexer.Clone();
      indexer.Operands = (ExpressionList)indexer.Operands.Clone();

			indexer.Object   = simplify(indexer.Object);
			ExpressionList ops = this.VisitExpressionList(indexer.Operands);
			System.Diagnostics.Debug.Assert(ops != null, "VisitExpressionList must return non-null if arg is non-null");
			indexer.Operands = ops;
			return indexer;
		}
Пример #8
0
            /// <summary>
            ///     Determines whether the specified indexer refers to an array
            ///     created in the currently validated contract.
            /// </summary>
            /// <param name="indexer">
            ///     An indexer which references object origin shall be determined.
            /// </param>
            /// <returns>
            ///     <see langword="true"/> if the specified indexer refers to an array
            ///     created in the currently validated contract;
            ///     <see langword="false"/>, otherwise.
            /// </returns>
            private bool IsConstructedArrayIndexer(Indexer indexer)
            {
                if (!seenConstructArray || !seenDup)
                {
                    return false;
                }

                Node obj = indexer.Object;
                if (obj == null)
                {
                    return false;
                }

                return obj.NodeType == NodeType.Pop;
            }
Пример #9
0
 public EventingVisitor(Action<Indexer> visitIndexer) { VisitedIndexer += visitIndexer; } public event Action<Indexer> VisitedIndexer; public override Expression VisitIndexer(Indexer indexer) { if (VisitedIndexer != null) VisitedIndexer(indexer); return base.VisitIndexer(indexer); }