Пример #1
0
 public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration){
   if (localDeclaration == null) return null;
   this.CheckForShadowDeclaration(localDeclaration);
   return base.VisitLocalDeclaration(localDeclaration);
 }
Пример #2
0
 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;
   }
 }
Пример #3
0
 public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration)
 {
     if (localDeclaration == null) return null;
     return base.VisitLocalDeclaration((LocalDeclaration)localDeclaration.Clone());
 }
Пример #4
0
 public virtual LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration)
 {
     if (localDeclaration == null) return null;
     localDeclaration.InitialValue = this.VisitExpression(localDeclaration.InitialValue);
     return localDeclaration;
 }
Пример #5
0
 private Statement ParseLocalDeclarations(TypeNode t, SourceContext ctx, bool constant, bool initOnly, bool preferExpressionToDeclaration, bool skipSemicolon, TokenSet followers){
   TypeNode firstT = t;
   LocalDeclarationsStatement result = new LocalDeclarationsStatement();
   result.SourceContext = ctx;
   result.Constant = constant;
   result.InitOnly = initOnly;
   ScannerState oss = this.scanner.state;
   LocalDeclarationList locList = result.Declarations = new LocalDeclarationList();
   result.Type = result.TypeExpression = t;
   for(;;){
     LocalDeclaration loc = new LocalDeclaration();
     loc.SourceContext = this.scanner.CurrentSourceContext;
     locList.Add(loc);
     loc.Name = this.scanner.GetIdentifier();
     this.SkipIdentifierOrNonReservedKeyword();
     if (this.currentToken == Token.LeftBracket){
       this.HandleError(Error.CStyleArray);
       int endPos = this.scanner.endPos;
       int rank = this.ParseRankSpecifier(true, followers|Token.RightBracket|Parser.IdentifierOrNonReservedKeyword|Token.Assign|Token.Semicolon|Token.Comma);
       if (rank > 0)
         t = result.Type = result.TypeExpression =
           this.ParseArrayType(rank, t, followers|Token.RightBracket|Parser.IdentifierOrNonReservedKeyword|Token.Assign|Token.Semicolon|Token.Comma);
       else{
         this.currentToken = Token.LeftBracket;
         this.scanner.endPos = endPos;
         this.GetNextToken();
         while (!this.scanner.TokenIsFirstAfterLineBreak &&
           this.currentToken != Token.RightBracket && this.currentToken != Token.Assign && this.currentToken != Token.Semicolon)
           this.GetNextToken();
         if (this.currentToken == Token.RightBracket) this.GetNextToken();
       }
     }
     if (this.currentToken == Token.LeftParenthesis){
       this.HandleError(Error.BadVarDecl);
       int dummy;
       SourceContext lpCtx = this.scanner.CurrentSourceContext;
       this.GetNextToken();
       this.ParseArgumentList(followers|Token.LeftBrace|Token.Semicolon|Token.Comma, lpCtx, out dummy);
     }else if (this.currentToken == Token.Assign || constant){
       this.Skip(Token.Assign);
       if (this.currentToken == Token.LeftBrace)
         loc.InitialValue = this.ParseArrayInitializer(t, followers|Token.Semicolon|Token.Comma);
       else
         loc.InitialValue = this.ParseExpression(followers|Token.Semicolon|Token.Comma);
     }
     if (loc.InitialValue != null)
       loc.SourceContext.EndPos = loc.InitialValue.SourceContext.EndPos;
     else
       loc.SourceContext.EndPos = this.scanner.endPos;
     if (this.currentToken != Token.Comma) break;
     this.GetNextToken();
     SourceContext sctx = this.scanner.CurrentSourceContext;
     ScannerState ss = this.scanner.state;
     TypeNode ty = this.ParseTypeExpression(null, followers|Token.Identifier|Token.Comma|Token.Semicolon, true);
     if (ty == null || this.currentToken != Token.Identifier){
       this.scanner.endPos = sctx.StartPos;
       this.scanner.state = ss;
       this.currentToken = Token.None;
       this.GetNextToken();
     }else
       this.HandleError(sctx, Error.MultiTypeInDeclaration);
   }
   if (Parser.IsVoidType(firstT)){
     this.HandleError(ctx, Error.NoVoidHere);
     result.Type = this.TypeExpressionFor(Token.Object);
     result.Type.SourceContext = firstT.SourceContext;
   }
   if (preferExpressionToDeclaration && this.currentToken != Token.Semicolon && locList.Count == 1 && locList[0].InitialValue == null){
     //The parse as a declaration is going to fail. Since an expression is preferred, restore the state and reparse as an expression
     this.scanner.endPos = ctx.StartPos;
     this.scanner.state = oss;
     this.currentToken = Token.None;
     this.GetNextToken();
     ExpressionStatement eStat = new ExpressionStatement(this.ParseExpression(followers));
     if (eStat.Expression != null) eStat.SourceContext = eStat.Expression.SourceContext;
     return eStat;
   }
   if (skipSemicolon) this.SkipSemiColon(followers);
   this.SkipTo(followers);
   return result;
 }
Пример #6
0
 public LocalDeclarationsStatement(LocalDeclaration ldecl, TypeNode type)
     : base(NodeType.LocalDeclarationsStatement)
 {
     Declarations = new LocalDeclarationList();
     Declarations.Add(ldecl);
     this.Type = type;
 }
Пример #7
0
 public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration)
 {
     if (localDeclaration == null) return null;
     localDeclaration.InitialValue = this.VisitExpression(localDeclaration.InitialValue);
     localDeclaration.Name = (Identifier)this.VisitIdentifier(localDeclaration.Name);
     return localDeclaration;
 }
Пример #8
0
        public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDecl)
        {
            this.VisitIdentifier(localDecl.Name);

            if (localDecl.InitialValue != null)
            {
                Write(" = ");
                this.VisitExpression(localDecl.InitialValue);
            }
            return localDecl;
        }
Пример #9
0
 public EventingVisitor(Action<LocalDeclaration> visitLocalDeclaration) { VisitedLocalDeclaration += visitLocalDeclaration; } public event Action<LocalDeclaration> VisitedLocalDeclaration; public override LocalDeclaration VisitLocalDeclaration(LocalDeclaration localDeclaration) { if (VisitedLocalDeclaration != null) VisitedLocalDeclaration(localDeclaration); return base.VisitLocalDeclaration(localDeclaration); }