public override void VisitDeclaration(DeclarationStatement decl)
{
Argument arg = currentRoutine.GetArgument(decl.Name);
if (arg != null) {
report.Error(decl.Location,
"this local variable declaration is " +
"in the scope of {0}:{1} which has the same name",
arg.Name, arg.NodeType.FullName);
return;
}
LocalVariable local = localVariableStack.GetLocal(decl.Name);
if (local != null) {
report.Error(decl.Location,
"this local variable declaration is " +
"in the scope of {0}:{1} which has the same name",
local.Name, local.LocalType.FullName);
return;
}
TypeData type;
if (!decl.TypeSpecifier.IsNull) {
decl.TypeSpecifier.Accept(this);
type = decl.TypeSpecifier.NodeType;
}
else {
if (!(decl.Next is AssignStatement)) {
report.Error(decl.Location, "type not specified");
return;
}
AssignStatement assign = (AssignStatement) decl.Next;
if (assign.Value is VoidExpression) {
report.Error(decl.Location,
"right hand side of `::=' may not be `void'");
return;
}
assign.Value.Accept(this);
type = assign.Value.NodeType;
}
localVariableStack.AddLocal(decl.Name, type);
}