public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     foreach (VariableDeclaration var in localVariableDeclaration.Variables) {
         CodeTypeReference type = new CodeTypeReference(Convert(var.Type));
         if (var.Initializer != null) {
             currentMethod.Statements.Add(new CodeVariableDeclarationStatement(type,
                                                                               var.Name,
                                                                               (CodeExpression)((INode)var.Initializer).AcceptVisitor(this, data)));
         } else {
             currentMethod.Statements.Add(new CodeVariableDeclarationStatement(type,
                                                                               var.Name));
         }
     }
     return null;
 }
 public override object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     foreach (VariableDeclaration varDecl in localVariableDeclaration.Variables) {
         AddVariable(varDecl.Type,
                     varDecl.Name,
                     localVariableDeclaration.StartLocation,
                     CurrentBlock == null ? new Point(-1, -1) : CurrentBlock.EndLocation);
     }
     return data;
 }
        public object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
        {
            DebugOutput(localVariableDeclaration);
            for (int i = 0; i < localVariableDeclaration.Variables.Count; ++i) {
                VariableDeclaration localVar = (VariableDeclaration)localVariableDeclaration.Variables[i];
                AppendIndentation();
                sourceText.Append(GetModifier(localVariableDeclaration.Modifier));
                ArrayCreateExpression ace = localVar.Initializer as ArrayCreateExpression;
                if (ace != null && (ace.ArrayInitializer == null || ace.ArrayInitializer.CreateExpressions == null)) {
                    sourceText.Append(ConvertTypeString(ace.CreateType.Type));
                    sourceText.Append(" ");
                    sourceText.Append(localVar.Name);
                    sourceText.Append("[");
                    sourceText.Append(GetExpressionList(ace.Parameters));
                    sourceText.Append("]");

                } else {
                    if (localVar.Type == null) {
                        bool foundType = false;
                        for (int j = i + 1; j < localVariableDeclaration.Variables.Count; ++j) {
                            VariableDeclaration nextLocalVar = (VariableDeclaration)localVariableDeclaration.Variables[j];
                            if (nextLocalVar.Type != null) {
                                sourceText.Append(GetTypeString(nextLocalVar.Type));
                                foundType = true;
                                break;
                            }
                        }
                        if (!foundType) {
                            sourceText.Append("object");
                        }
                    } else {
                        sourceText.Append(GetTypeString(localVar.Type));
                    }
                    sourceText.Append(" ");
                    sourceText.Append(localVar.Name);
                    if (localVar.Initializer != null) {
                        sourceText.Append(" = ");
                        sourceText.Append(localVar.Initializer.AcceptVisitor(this, data).ToString());
                    } else {
                        if (localVar.Type != null && localVar.Type.Dimension != null) {
                            sourceText.Append(" = new ");
                            sourceText.Append(ConvertTypeString(localVar.Type.Type));
                            sourceText.Append("[");
                            sourceText.Append(GetExpressionList(localVar.Type.Dimension));
                            sourceText.Append("]");
                        }
                    }
                }
                sourceText.Append(";");
                AppendNewLine();
            }
            return null;
        }
Ejemplo n.º 4
0
	void LocalDeclarationStatement(
#line  2038 "VBNET.ATG" 
out Statement statement) {

#line  2040 "VBNET.ATG" 
		Modifiers m = new Modifiers(this);
		ArrayList vars = new ArrayList();
		LocalVariableDeclaration localVariableDeclaration;
		bool dimfound = false;
		
		while (la.kind == 72 || la.kind == 82 || la.kind == 163) {
			if (la.kind == 72) {
				lexer.NextToken();

#line  2047 "VBNET.ATG" 
				m.Add(Modifier.Constant); 
			} else if (la.kind == 163) {
				lexer.NextToken();

#line  2048 "VBNET.ATG" 
				m.Add(Modifier.Static); 
			} else {
				lexer.NextToken();

#line  2049 "VBNET.ATG" 
				dimfound = true; 
			}
		}

#line  2052 "VBNET.ATG" 
		if(dimfound && (m.Modifier & Modifier.Constant) != 0) {
		Error("Dim is not allowed on constants.");
		}
		
		if(m.isNone && dimfound == false) {
			Error("Const, Dim or Static expected");
		}
		
		localVariableDeclaration = new LocalVariableDeclaration(m.Modifier);
		localVariableDeclaration.StartLocation = t.Location;
		
		VariableDeclarator(
#line  2063 "VBNET.ATG" 
vars);
		while (la.kind == 12) {
			lexer.NextToken();
			VariableDeclarator(
#line  2064 "VBNET.ATG" 
vars);
		}

#line  2066 "VBNET.ATG" 
		localVariableDeclaration.Variables = vars;
		statement = localVariableDeclaration;
		
	}
 public virtual object Visit(LocalVariableDeclaration localVariableDeclaration, object data)
 {
     object ret = data;
     if (localVariableDeclaration.Variables != null) {
         foreach (VariableDeclaration v in localVariableDeclaration.Variables) {
             ret = v.AcceptVisitor(this, data);
         }
     }
     return ret;
 }