public object VisitMethodDeclAST([NotNull] MethodDeclASTContext context) { string type = "void"; if (context.type() != null) { type = (string)Visit(context.type()); } IdentASTContext ident = (IdentASTContext)Visit(context.ident()); if (ident != null) { if (!ExistIdent(ident.IDENT().Symbol.Text, true)) { MethodIdentifier identifier = new MethodIdentifier(ident.IDENT().Symbol.Text, ident.IDENT().Symbol, identificationTable.getLevel(), type, context, (FormParsASTContext)context.formPars()); identificationTable.Insert(identifier); identificationTable.OpenLevel(); // Para los parámetros ya existe un scope nuevo if (context.formPars() != null) { Visit(context.formPars()); //Cuando se visitan los parámetros y se encuentra un error, ellos lo reportan } if (context.varDecl() != null) { context.varDecl().ToList().ForEach(varDecl => Visit(varDecl)); } if (context.block() != null) { List <Pair <string, IToken> > returnedTypes = Visit(context.block()) as List <Pair <string, IToken> >; returnedTypes.ForEach(returned => { if (returned.a != null && (!returned.a.Equals(type) && (type == "void" || returned.a != "none"))) { InsertError(returned.b, $"El tipo de retorno del método {identifier.Id} es {type}, pero se retorna {(returned.a == "none" ? "null" : returned.a)}"); } }); } identificationTable.CloseLevel(); } else { InsertError(ident.IDENT().Symbol, "El identificador " + ident.IDENT().Symbol.Text + " ya fue declarado en este scope"); } } return(null); }
public object VisitMethodDeclAST([NotNull] MethodDeclASTContext context) { if (context.ident().GetText() != "Main") { AddLine($"DEF {context.ident().GetText()}"); if (context.formPars() != null) { Visit(context.formPars()); } Visit(context.block()); AddLine("RETURN"); WhiteLine(); WhiteLine(); } else { AddLine("DEF Main"); Visit(context.block()); AddLine("END"); WhiteLine(); } return(null); }