Пример #1
0
 public void writeStruct(StructDef sd){
     Console.WriteLine(";Struct : " + sd.name + "  size: " + sd.sizeRequired + "  {");
     foreach(Field f in sd.fields){
         Console.WriteLine(";" + f.type.name + ' ' + f.name + "|\tOffset : " + f.offset 
             + " \tSize : " + f.type.sizeRequired);
     }
     Console.WriteLine(";}\n");
 }
Пример #2
0
 public StructDef newStructDef(String name, List<Tuple<Type, String>> fields){
     if(structDefs.ContainsKey(name))
         parser.SemErr("Struct with name :" + name  + " already exists in current context");
     int id = nextTypeId++;
     StructDef sd = new StructDef(name, fields, id);
     structDefs.Add(name, sd);
     types.Add(id, new Type(name, sd.sizeRequired, id));
     topScope.defs.Add(name);
     writeStruct(sd);
     return sd;
 }
Пример #3
0
        // create new object node in current scope
        public Obj NewObj (string name, int kind, int type, int adr) {
            Obj p, last;
            Obj obj = new Obj ();
            obj.name = name;
            obj.kind = kind;
            if(!types.TryGetValue(type,out obj.type)) //will set obj.type if exists
                parser.SemErr("Could not find associated type id :" + type);
            obj.dimensions = null;
            obj.compileTimeValue = -1;
            obj.scopeEndLabel = -1;
            obj.level = curLevel;
            obj.next = null;
            p = topScope.locals;
            last = null;
            while (p != null) {
                if (p.name == name)
                    parser.SemErr ("name declared twice");
                last = p;
                p = p.next;
            }
            if (last == null)
                topScope.locals = obj;
            else last.next = obj;

            if (kind == var || kind == constant){
                obj.adr = adr;
                if(typeIsStruct(type)){ //What a bad way to tell if its a struct but...timeee
                    StructDef sd = getStructDef(getType(type).name);
                    foreach(Field f in sd.fields){
                        NewObj(name + '.' + f.name, var, f.type.id, obj.adr + f.offset);
                    }
                }else{
                    topScope.nextAdr += obj.type.sizeRequired;
                }
            
            
            }else if(kind == proc){
            }else if(kind == scope){
            }else{
                parser.SemErr("Is not of kind var, constant,scope or proc");                
            }
            return obj;
        }