Example #1
0
 public void declareLocals(LocalDeclarationStatementNode statement)
 {
     foreach (var decl in statement.Declarators)
     {
         localInfos.add(decl.getUserData(typeof(MemberInfo)));
     }
 }
Example #2
0
            protected override Void handleLocalDeclaration(LocalDeclarationStatementNode localDeclaration, Set <TypeInfo> dependencies)
            {
                var info = localDeclaration.getUserData(typeof(ExpressionInfo));

                addDependencies(info.Type, dependencies);
                foreach (var decl in localDeclaration.Declarators)
                {
                    if (decl.Value != null)
                    {
                        expressionHandler.handleExpression(decl.Value, dependencies, true);
                    }
                }
                return(null);
            }
 protected override Boolean handleLocalDeclaration(LocalDeclarationStatementNode localDeclaration, HashSet <StatementNode> visited)
 {
     foreach (var decl in localDeclaration.Declarators)
     {
         if (decl.Value != null)
         {
             if (expressionChecker.handleExpression(decl.Value, visited, true) == AssignmentState.Assigned)
             {
                 return(Boolean.FALSE);
             }
         }
     }
     return(Boolean.TRUE);
 }
 protected override Void handleLocalDeclaration(LocalDeclarationStatementNode localDeclaration, Void source)
 {
     if (localDeclaration.Type == null)
     {
         if (localDeclaration.Declarators.size() > 1)
         {
             context.addError(CompileErrorId.MultipleImplicitVariableDeclarators, localDeclaration);
         }
         var decl = localDeclaration.Declarators[0];
         if (decl.Value == null)
         {
             throw context.error(CompileErrorId.MissingImplicitVariableInitializer, localDeclaration);
         }
         if (decl.Value.ExpressionKind == ExpressionKind.ArrayInitializer)
         {
             throw context.error(CompileErrorId.ImplicitVariableWithArrayInitializer, localDeclaration);
         }
         this.ExpressionValidator.handleExpression(decl.Value, null, true);
         var info = decl.Value.getUserData(typeof(ExpressionInfo));
         if (info == null)
         {
             throw context.error(CompileErrorId.NullImplicitVariableInitializer, localDeclaration);
         }
         localDeclaration.addOrReplaceUserData(new ExpressionInfo(ValidationHelper.getType(context, decl.Value)));
         var name = context.getIdentifier(decl.NameOffset, decl.NameLength);
         if (context.MemberResolver.hasLocal(name))
         {
             context.addError(CompileErrorId.VariableRedefinition, decl, name);
         }
         var local = context.MemberResolver.defineLocal(name, ValidationHelper.getVariableType(context, info.Type),
                                                        context.CodeValidationContext.CurrentMethod);
         decl.addOrReplaceUserData(local);
     }
     else
     {
         var type = CompilerHelper.resolveTypeReference(context, context.CurrentType.PackageName, localDeclaration.Type);
         localDeclaration.addOrReplaceUserData(new ExpressionInfo(type));
         foreach (var decl in localDeclaration.Declarators)
         {
             var name = context.getIdentifier(decl.NameOffset, decl.NameLength);
             if (decl.Value != null)
             {
                 var isArrayInit = decl.Value.ExpressionKind == ExpressionKind.ArrayInitializer;
                 if (isArrayInit && !type.IsArray)
                 {
                     throw context.error(CompileErrorId.ArrayTypeExpected, decl);
                 }
                 this.ExpressionValidator.handleExpression(decl.Value, type, true);
                 ValidationHelper.setBoxing(context, type, decl.Value);
                 if (!ValidationHelper.isAssignable(context, type, decl.Value))
                 {
                     var vinfo = decl.Value.getUserData(typeof(ExpressionInfo));
                     var vtype = (vinfo == null) ? null : vinfo.Type;
                     context.addError(CompileErrorId.NoImplicitConversion, decl.Value,
                                      BytecodeHelper.getDisplayName(vtype),
                                      BytecodeHelper.getDisplayName(type));
                 }
                 if (isArrayInit)
                 {
                     ValidationHelper.setArrayInitializerTypes((ArrayInitializerExpressionNode)decl.Value, type);
                 }
             }
             if (context.MemberResolver.hasLocal(name))
             {
                 context.addError(CompileErrorId.VariableRedefinition, decl, name);
             }
             var local = context.MemberResolver.defineLocal(name, ValidationHelper.getVariableType(context, type),
                                                            context.CodeValidationContext.CurrentMethod);
             decl.addOrReplaceUserData(local);
         }
     }
     return(null);
 }