public void Visit(ReturnStatementNode node) { bool returnsSomething = node.Count() != 0; string procedureName = currentScope; Type returnType = procedureTable[procedureName].type; if (returnsSomething) { Visit((dynamic)node[0]); } else { string defaultValue = GetTypeDefaultCilValue(returnType); builder.AppendLine($"\t\t{defaultValue}"); } builder.AppendLine("\t\tret"); }
public Type Visit(ReturnStatementNode node) { if (currentScope == "") { throw new SemanticError("Unexpected return statement", node.AnchorToken); } Type type = node.Count() == 0 ? Type.VOID : Visit((dynamic)node[0]); var procedureType = procedureTable[currentScope].type; if (!procedureType.CompatibleWith(type)) { throw new SemanticError($"Invalid return type {type} for procedure of type {procedureType}", node.AnchorToken); } return(type); }