Esempio n. 1
0
        public IType Visit(Class_Def node)
        {
            Context.ActualType = Context.GetType(node.type.s);
            Context.DefineSymbol("self", Context.ActualType);

            foreach (var attr in Context.GetType(node.inherit_type.s).AllAttributes())
            {
                Context.DefineSymbol(attr.Name, attr.Type);
            }

            foreach (var cldr in node.attr.list_Node)
            {
                IType t = this.Visit(cldr);
                Context.DefineSymbol(cldr.name.name, t);
            }
            foreach (var cldr in node.method.list_Node)
            {
                this.Visit(cldr);
            }

            foreach (var cldr in node.attr.list_Node)
            {
                Context.UndefineSymbol();
            }

            Context.UndefineSymbol();
            return(null);
        }
        public bool Visit(Class_Def node)
        {
            bool solve = true;

            if (Types_built_in.Contains(node.inherit_type.s))
            {
                Logger += "En la expresion " + node.ToString() + "-> error de definicion (clase '" + node.type.s + "' no puede heredar de tipos built-in) \n";
                solve   = false;
            }

            if (!Types.Contains(node.inherit_type.s))
            {
                Logger += "En la expresion " + node.ToString() + "-> error de definicion (el tipo padre de la clase '" + node.type.s + "' no esta definido ) \n";
                solve   = false;
            }

            foreach (var item in node.attr.list_Node)
            {
                solve &= this.Visit(item);
            }

            foreach (var item in node.method.list_Node)
            {
                solve &= this.Visit(item);
            }

            return(solve);
        }
Esempio n. 3
0
 public string Visit(Class_Def node)
 {
     current_type = Types_Cool[node.type.s];
     foreach (Method_Def item in node.method.list_Node)
     {
         Visit(item);
     }
     return("");
 }
Esempio n. 4
0
        public string Visit(Class_Def node)
        {
            current_type = Types_Cool[node.type.s];

            // Formando el metodo init
            method = new Current_Method();
            string father = Types_Cool[node.type.s].Father.Name;

            if (father != "IO" && father != "Object")
            {
                string f = method.Add_local("father", true);
                method.Add_Instruction(new CIL_Allocate(f, father));
                method.Add_Instruction(new CIL_VCall(f, father, "__init", new List <string> {
                    f
                }));
                foreach (string attr in Types[father].Attributes)
                {
                    string a = method.Add_local("attr", true);
                    method.Add_Instruction(new CIL_GetAttr(a, new CIL_MyVar(f, father), attr));
                    method.Add_Instruction(new CIL_SetAttr(new CIL_MyVar("this", node.type.s), attr, a));
                }
            }
            foreach (var attr in node.attr.list_Node)
            {
                attr.Visit(this);
            }

            method.Add_Instruction(new CIL_Return("this"));
            string mtdName = "__init_" + node.type.s;

            Code.Add(mtdName, new CIL_Function(mtdName, new List <string>(), new List <string>(method.locals.Values), method.body));

            foreach (Method_Def item in node.method.list_Node)
            {
                Visit(item);
            }
            return("");
        }
        public bool Visit(Class_Def node)
        {
            bool solve = true;

            Context.ActualType = Context.GetType(node.type.s);
            Context.DefineSymbol("self", Context.ActualType);
            List <string> id_defines = new List <string>();

            // Definiendo atributos del padre
            foreach (var attr in Context.GetType(node.inherit_type.s).AllAttributes())
            {
                Context.DefineSymbol(attr.Name, attr.Type);
            }

            // Definiendo los atributos del hijo
            foreach (var attr in node.attr.list_Node)
            {
                if (id_defines.Contains(attr.name.name) || Context.ActualType.Father.GetAttribute(attr.name.name) != null)
                {
                    solve   = false;
                    Logger += "En la expresion " + node.ToString() + "-> error de identificador ('" + attr.name.name + "' ya esta definido) \n";
                }
                else
                {
                    id_defines.Add(attr.name.name);
                    Context.DefineSymbol(attr.name.name, Context.GetType(attr.type.s));
                }
            }
            foreach (var mtd in node.method.list_Node)
            {
                if (Context.ThereAreMethod(mtd.name.name))
                {
                    solve   = false;
                    Logger += "En la expresion " + node.ToString() + "-> error de identificador (metodo '" + mtd.name.name + "' ya esta definido) \n";
                }
                else
                {
                    Context.DefineMethod(mtd.name.name, Context.GetType(node.type.s));
                }
                Method mtd_father = Context.ActualType.Father.GetMethod(mtd.name.name);
                if (mtd_father != null && !Method.Equal_Def(mtd, mtd_father))
                {
                    solve   = false;
                    Logger += "En la expresion " + node.ToString() + "-> error de identificador (metodo '" + mtd.name.name + "' esta definido con elementos diferentes en un tipo mayor) \n";
                }
            }
            foreach (var cld in node.attr.list_Node)
            {
                if (!this.Visit(cld))
                {
                    solve = false;
                }
            }

            foreach (var cld in node.method.list_Node)
            {
                if (!this.Visit(cld))
                {
                    solve = false;
                }
            }

            Context.UndefineSymbol(id_defines.Count);

            Context.UndefineMethods();

            return(solve);
        }
Esempio n. 6
0
 public bool Visit(Class_Def node)
 {
     throw new System.NotImplementedException();
 }