Пример #1
0
        public bool Visit(AST_ClassDef node)
        {
            bool solve = true;

            if (!All_Types.ContainsKey(node.Id.Id))
            {
                return(false);
            }

            CurrType = All_Types[node.Id.Id];

            CurrContext = CurrContext.CreateChild();

            SemanticType father = All_Types[node.Id.Id].Father;

            while (true)
            {
                var my_atributes = father.GetAllAttr();
                foreach (var attr in my_atributes)
                {
                    //if (attr.Type.Name == "int")
                    //    attr.Type.Name = "Int";
                    //if (attr.Type.Name == "string")
                    //    attr.Type.Name = "String";
                    //if (attr.Type.Name == "bool")
                    //    attr.Type.Name = "Bool";
                    if (!All_Types.ContainsKey(attr.Type.Name))
                    {
                        CurrErrorLoger.LogError(node.row, node.col, "El tipo de la declaracion del atributo no existe");
                        if (!CurrContext.NullFather())
                        {
                            CurrContext = CurrContext.GetParent();
                        }
                        return(false);
                    }
                    CurrContext.SetType(attr.Id, attr.Type);
                }
                father = father.Father;
                if (father == null)
                {
                    break;
                }
            }

            bool visit_result = node.Property_list.Visit(this) &&
                                node.Method_list.Visit(this);

            if (!CurrContext.NullFather())
            {
                CurrContext = CurrContext.GetParent();
            }

            CurrType = null;

            return(visit_result);
        }
        public bool Visit(AST_ClassDef node)
        {
            bool solve = true;

            CurrContext = CurrContext.CreateChild();
            SemanticType father = All_Types[node.Id.Id].Father;

            while (true)
            {
                var my_atributes = father.GetAllAttr();
                foreach (var attr in my_atributes)
                {
                    if (CurrContext.IsDefine(attr.Id))
                    {
                        solve = false;
                        CurrErrorLoger.LogError(node.row, node.col, "Propiedad " + attr.Id + " previamente definida");
                    }
                    CurrContext.Define(attr.Id);
                }
                father = father.Father;
                if (father == null)
                {
                    break;
                }
            }

            foreach (var prop in node.Property_list.Propertys)
            {
                if (CurrContext.IsDefine(prop.decl.id.Id))
                {
                    solve = false;
                    CurrErrorLoger.LogError(prop.decl.row, prop.decl.col, "Propiedad " + node.Id + " previamente definida");
                }
                else
                {
                    CurrContext.Define(prop.decl.id.Id);
                }
            }

            solve = node.Method_list.Visit(this);
            if (!CurrContext.NullFather())
            {
                CurrContext = CurrContext.GetParent();
            }
            return(solve);
        }