public bool Visit(AST_ClassProperty node) { if (ReservedWords.Contains(node.decl.id.Id)) { CurrErrorLoger.LogError(node.decl.row, node.decl.col, "El id de la variable es una palabra reservada"); return(false); } if (Types.Contains(node.decl.id.Id)) { CurrErrorLoger.LogError(node.decl.row, node.decl.col, "El id de la variable es una tipo definido"); return(false); } if (!Types.Contains(node.decl.type.Type)) { CurrErrorLoger.LogError(node.decl.row, node.decl.col, "El tipo de la variable no esta definido"); return(false); } if (node.exp != null) { if (!node.exp.Visit(this)) { return(false); } } return(true); }
public string Visit(AST_ClassProperty node) { string id = methodcontext.GenLocal(node.decl.id.Id, false); if (node.exp != null) { var s = node.exp.Visit(this); methodcontext.Staments.Add(new CIL_Asig(id, s, "var")); } return(""); }
public bool Visit(AST_ClassProperty node) { bool solve = true; var type = CurrContext.GetType(node.decl.id.Id); bool visit_tuple = true; if (node.exp != null) { visit_tuple = node.exp.Visit(this); } if (!visit_tuple || type != null) { CurrErrorLoger.LogError(node.row, node.col, "El tipo " + node.decl.id.Id + " ya posee un tipo"); return(false); } if (type == null) { if (!All_Types.ContainsKey(node.decl.type.Type)) { CurrErrorLoger.LogError(node.row, node.col, "Tipo no definido"); return(false); } else { //if (node.decl.type.Type == "int") // node.decl.type.Type = "Int"; //if (node.decl.type.Type == "string") // node.decl.type.Type = "String"; //if (node.decl.type.Type == "bool") // node.decl.type.Type = "Bool"; node.decl.id.MyType = All_Types[node.decl.type.Type]; CurrContext.SetType(node.decl.id.Id, All_Types[node.decl.type.Type]); } } if (node.decl.id.MyType != null && node.exp != null) { SemanticType lca = SemanticType.LCA(All_Types[node.decl.type.Type], node.exp.MyType); if (lca.Name != node.decl.id.MyType.Name) { CurrErrorLoger.LogError(node.row, node.col, "El tipo " + node.exp.MyType.Name + " no se conforma a " + node.decl.type.Type); return(false); } } return(solve); }
public override AST_Node VisitCaseof([NotNull] CoolParser.CaseofContext context) { var exp = (AST_Expresion)Visit(context.expr()); List <AST_ClassProperty> props = new List <AST_ClassProperty>(); foreach (var item in context.branch()) { var s = new AST_FormalDec(item.formal(), new AST_Id(item.formal().ID(), item.formal().ID().GetText()), new AST_Type_Node(item.formal().TYPE(), item.formal().TYPE().GetText())); AST_ClassProperty x = new AST_ClassProperty(item, s, (AST_Expresion)Visit(item.expr())); props.Add(x); } return(new AST_CaseOf(context, new AST_ListProp(context, props), exp)); }
public bool Visit(AST_ClassProperty node) { bool solve = true; if (CurrContext.IsDefineInMe(node.decl.id.Id)) { solve = false; CurrErrorLoger.LogError(node.decl.row, node.decl.col, "La propiedad " + node.decl.id.Id + " ya pertenece a la clase"); } if (node.exp != null && !node.exp.Visit(this)) { solve = false; } CurrContext.Define(node.decl.id.Id); return(solve); }
public override AST_Node VisitMethod([NotNull] CoolParser.MethodContext context) { AST_Id id = new AST_Id(context.ID(), context.ID().GetText()); AST_Type_Node type = new AST_Type_Node(context.TYPE(), context.TYPE().GetText()); List <AST_ClassProperty> param = new List <AST_ClassProperty>(); AST_Expresion corpus = (AST_Expresion)Visit(context.expr()); foreach (var item in context.formal()) { var iid = new AST_Id(item.ID(), item.ID().GetText()); var ity = new AST_Type_Node(item.TYPE(), item.TYPE().GetText()); var formald = new AST_FormalDec(item, iid, ity); AST_ClassProperty i = new AST_ClassProperty(item, formald, null); param.Add(i); } return(new AST_MethodDef(context, id, type, new AST_ListProp(context, param), corpus)); }
public override AST_Node VisitLet([NotNull] CoolParser.LetContext context) { List <AST_ClassProperty> param = new List <AST_ClassProperty>(); AST_Expresion corpus = (AST_Expresion)Visit(context.expr()); foreach (var item in context.property()) { var iid = new AST_Id(item.formal().ID(), item.formal().ID().GetText()); var ity = new AST_Type_Node(item.formal().TYPE(), item.formal().TYPE().GetText()); var formald = new AST_FormalDec(item, iid, ity); AST_Expresion subexp = null; if (item.expr() != null) { subexp = (AST_Expresion)Visit(item.expr()); } AST_ClassProperty i = new AST_ClassProperty(item, formald, subexp); param.Add(i); } return(new AST_Let(context, new AST_ListProp(context, param), corpus)); }
public bool Visit(AST_ClassProperty node) { throw new NotImplementedException(); }
public Base_Object_Value Visit(AST_ClassProperty node) { throw new NotImplementedException(); }