Beispiel #1
0
    void VarNameDecl(model2mbed.TypeDecl type)
    {
        string name; model2mbed.Expression arg1 = null, arg2 = null;

        Ident(out name);
        model2mbed.VarDecl vardecl = new model2mbed.VarDecl(name, type); decls.Add(vardecl);
        if (la.kind == 11)
        {
            Get();
            Expression(out arg1);
            Expect(12);
            int low = 0, length = 0;
            if (!decls.getArrSizeValue(arg1, out low, out length))
            {
                throw new FatalError("Could not calculate array size!");
            }
            vardecl.IsArray   = true;
            vardecl.ArrLow    = low;
            vardecl.ArrLength = length;
        }
        if (la.kind == 13)
        {
            Get();
            Expression(out arg2);
            vardecl.Expr = arg2; vardecl.HasExpr = true;
        }
    }
Beispiel #2
0
 public VarDecl(string name, TypeDecl type)
 {
     Name      = name;
     Type      = type;
     IsArray   = false;
     ArrLow    = 0;
     ArrLength = 0;
     HasExpr   = false;
     Expr      = null;
 }
        public TypeDecl normalizeType(TypeDecl decl, string name)
        {
            TypedefDecl exists = getTypeDef(name);

            if (exists == null)
            {
                throw new ParseException("Invalid type " + name);
            }

            decl.merge(exists.Type);

            return(decl);
        }
Beispiel #4
0
        public void merge(TypeDecl typedef)
        {
            Type = typedef.Type;
            if (typedef.Const)
            {
                Const = true;
            }
            if (typedef.Urgent)
            {
                Urgent = true;
            }
            if (typedef.Broadcast)
            {
                Broadcast = true;
            }

            sanitizeFlags();
        }
Beispiel #5
0
 void TypeDecl(out model2mbed.TypeDecl data)
 {
     data = new model2mbed.TypeDecl(); string tname; model2mbed.Expression arg1 = null, arg2 = null;
     while (StartOf(4))
     {
         if (la.kind == 14)
         {
             Get();
             data.Const = true;
         }
         else if (la.kind == 15)
         {
             Get();
             data.Urgent = true;
         }
         else if (la.kind == 16)
         {
             Get();
             data.Broadcast = true;
         }
         else
         {
             Get();
         }
     }
     if (la.kind == 18)
     {
         Get();
         data.Type = model2mbed.VarType.Int;
     }
     else if (la.kind == 19)
     {
         Get();
         data.Type = model2mbed.VarType.Int;
     }
     else if (la.kind == 20)
     {
         Get();
         data.Type = model2mbed.VarType.Clock;
     }
     else if (la.kind == 8)
     {
         Get();
         data.Type = model2mbed.VarType.Channel;
     }
     else if (la.kind == 1)
     {
         Ident(out tname);
         data = decls.normalizeType(data, tname);
     }
     else
     {
         SynErr(54);
     }
     if (la.kind == 11)
     {
         Get();
         Expression(out arg1);
         Expect(10);
         Expression(out arg2);
         Expect(12);
         int low, high;
         if (!decls.getExprValue(arg1, out low) || !decls.getExprValue(arg2, out high))
         {
             throw new model2mbed.ParseException("Array ranges must evaluate to consts!");
         }
         data.SetRange(low, high);
     }
 }