getClassId() public method

public getClassId ( ) : int
return int
Exemplo n.º 1
0
        void genLoad(Var e)
        {
            int id = e.getClassId();

            if (e == null)
            {
                Io.ICE("Load instruction with no variable ptr");
            }
            if (e.getLocalToken() != null)
            {
                //    LocalToken lt = (LocalToken) e.getLocalToken();
                LocalBuilder lt = (LocalBuilder)e.getLocalToken();
                il.Emit(OpCodes.Ldloc, lt);
            }
            else if (e.getFieldBuilder() != null)
            {
                FieldBuilder fb = (FieldBuilder)e.getFieldBuilder();
                if (id == Tok.T_STATIC)
                {
                    il.Emit(OpCodes.Ldsfld, fb);
                }
                else
                {
                    il.Emit(OpCodes.Ldfld, fb);
                }
            }
            else
            {
                int index = e.getIndex();
                if (id == Tok.T_PARAM)
                {
                    if (index <= 256)
                    {
                        il.Emit(OpCodes.Ldarg_S, index);
                    }
                    else
                    {
                        il.Emit(OpCodes.Ldarg, index);
                    }
                }
                else if (id == Tok.T_AUTO || id == Tok.T_DEFCLASS)
                {
                    if (index <= 256)
                    {
                        il.Emit(OpCodes.Ldloc_S, e.getIndex());
                    }
                    else
                    {
                        il.Emit(OpCodes.Ldloc, e.getIndex());
                    }
                }
                else
                {
                    Io.ICE("Instruction load of unknown class ("
                           + e.getClassId() + ")");
                }
            }
        }
Exemplo n.º 2
0
Arquivo: asm.cs Projeto: ydunk/masters
        public void Load(IAsm a)
        {
            StringBuilder sb = new StringBuilder(MyC.MAXSTR);
            Var           e  = a.getVar();

            if (e == null)
            {
                Console.WriteLine("?Load instruction with no variable ptr");
                Environment.Exit(1);
            }
            switch (e.getClassId())
            {
            case Tok.T_STATIC:
            {
                sb.Append("\tldsfld ");
                sb.Append(genFieldRef(e));
                sb.Append("\t//");
                sb.Append(a.getICount());
                sb.Append(", ");
                sb.Append(e.getName());
                sb.Append("\r\n");
                break;
            }

            case Tok.T_AUTO:
            case Tok.T_DEFCLASS:
                sb.Append("\tldloc ");
                sb.Append(e.getIndex());
                sb.Append("\t//");
                sb.Append(a.getICount());
                sb.Append(", ");
                sb.Append(e.getName());
                sb.Append("\r\n");
                break;

            case Tok.T_PARAM:
                sb.Append("\tldarg ");
                sb.Append(e.getIndex());
                sb.Append("\t//");
                sb.Append(a.getICount());
                sb.Append(", ");
                sb.Append(e.getName());
                sb.Append("\r\n");
                break;

            default:
                Console.Write("?Instruction load of unknown class (");
                Console.Write(e.getClassId());
                Console.WriteLine(")");
                Environment.Exit(1);
                break;
            }
            io.Out(sb.ToString());
        }
Exemplo n.º 3
0
        public void Store(IAsm a)
        {
            Var e  = a.getVar();
            int id = e.getClassId();

            if (e == null)
            {
                Io.ICE("Store instruction with no variable ptr");
            }
            if (e.getLocalToken() != null)
            {
                //    LocalToken lt = (LocalToken) e.getLocalToken();
                LocalBuilder lt = (LocalBuilder)e.getLocalToken();
                il.Emit(OpCodes.Stloc, lt);
            }
            else if (e.getFieldBuilder() != null)
            {
                FieldBuilder fb = (FieldBuilder)e.getFieldBuilder();
                if (id == Tok.T_STATIC)
                {
                    il.Emit(OpCodes.Stsfld, fb);
                }
                else
                {
                    il.Emit(OpCodes.Stfld, fb);
                }
            }
            else
            {
                int index = e.getIndex();
                if (id == Tok.T_PARAM)
                {
                    if (index <= 256)
                    {
                        il.Emit(OpCodes.Starg_S, index);
                    }
                    else
                    {
                        il.Emit(OpCodes.Starg, index);
                    }
                }
                else if (id == Tok.T_AUTO || id == Tok.T_DEFCLASS)
                {
                    il.Emit(OpCodes.Stloc, index);
                }
                else
                {
                    Io.ICE("Instruction load of unknown class ("
                           + e.getClassId() + ")");
                }
            }
        }
Exemplo n.º 4
0
/*
 * declOuter presumes that class & type have already been parsed
 * this is done to distinguish between a function declaration and a
 * variable declaration
 */
        void declOuter(Var e)
        {
#if DEBUG
            Console.WriteLine("declOuter1 token=[" + tok + "]\n");
#endif
            e.setName(tok.getValue()); /* use value as the variable name */
            addOuter(e);               /* add this variable */
            emit.FieldDef(e);          /* issue the declaration */
            if (e.getClassId() == Tok.T_DEFCLASS)
            {
                e.setClassId(Tok.T_STATIC); /* make sure it knows its storage class */
            }

            /*
             * loop while there are additional variable names
             */
            while (io.getNextChar() == ',')
            {
                tok.scan();
                if (tok.getFirstChar() != ',')
                {
                    io.Abort("Expected ','");
                }
                tok.scan();
                if (tok.getId() != Tok.T_IDENT)
                {
                    io.Abort("Expected identifier");
                }
                e.setName(tok.getValue()); /* use value as the variable name */
                addOuter(e);               /* add this variable */
                emit.FieldDef(e);          /* issue the declaration */
                if (e.getClassId() == Tok.T_DEFCLASS)
                {
                    e.setClassId(Tok.T_STATIC); /* make sure it knows its storage class */
                }
            }

            /*
             * move beyond end of statement indicator
             */
            tok.scan();
            if (tok.getFirstChar() != ';')
            {
                io.Abort("Expected ';'");
            }
            CommentFill();
            tok.scan();
#if DEBUG
            Console.WriteLine("declOuter2 token=[" + tok + "]\n");
#endif
        }
Exemplo n.º 5
0
Arquivo: asm.cs Projeto: ydunk/masters
        public void FieldDef(IAsm a)
        {
            Var    e      = a.getVar(); /* get the field var ptr */
            String prefix = "";

            switch (e.getClassId())
            {
            case Tok.T_STATIC:
                prefix = "\t.field ";
                break;

            case Tok.T_AUTO:
            case Tok.T_DEFCLASS:
                prefix = "\t.field ";
                break;

            default:
                Console.WriteLine("?Unhandled field def type\n");
                Environment.Exit(1);
                break;
            }

            StringBuilder sb = new StringBuilder(MyC.MAXSTR);

            sb.Append(prefix);            /* copy the prefix */
            sb.Append(genDataTypeSig(e)); /* gen type info, rets updated dp */
            sb.Append(" ");
            sb.Append(e.getName());       /* copy the variable name */
            sb.Append("\r\n");
            io.Out(sb.ToString());
        }
Exemplo n.º 6
0
        public void FieldDef(IAsm a)
        {
            Var             e    = a.getVar();              /* get the field var ptr */
            FieldAttributes attr = FieldAttributes.Private; /* default attributes is private */

            if (e.getClassId() == Tok.T_STATIC)
            {
                attr |= FieldAttributes.Static;
            }

            Type t = genDataTypeSig(e);                                /* gen type info */

            FieldBuilder f = eclass.DefineField(e.getName(), t, attr); // returns token

            e.setFieldBuilder((Object)f);                              // store token for later usage
        }
Exemplo n.º 7
0
        void addOuter(Var e)
        {
#if DEBUG
            Console.WriteLine("addOuter e=[" + e + "]\n");
#endif

            /*
             * validate this declaration as a potential variable
             */
            if (e.getClassId() == Tok.T_AUTO)
            {
                io.Abort("?Cannot allocate automatic variable outside a function\n");
            }
            if (staticvar.FindByName(e.getName()) != null)
            {
                io.Abort("?Cannot redefine static name '" + e.getName() + "'\n");
            }
            staticvar.add(e);
        }
Exemplo n.º 8
0
        void addInner(Var e)
        {
            /*
             * validate this declaration as a potential variable
             */
            int id = e.getClassId();

#if DEBUG
            Console.WriteLine("addInner e=[" + e + "]\n");
#endif
            if (id == Tok.T_EXTERN || id == Tok.T_STATIC)
            {
                io.Abort("Cannot allocate static within a method\n");
            }
            if (paramvar.FindByName(e.getName()) != null) /* cannot redefine param name */
            {
                io.Abort("Cannot redefine parameter name '" + e.getName() + "'\n");
            }
            if (localvar.FindByName(e.getName()) != null) /* check not already set */
            {
                io.Abort("Local variable '" + e.getName() + "' already defined\n");
            }
            localvar.add(e);
        }
Exemplo n.º 9
0
/*
 * declOuter presumes that class & type have already been parsed
 * this is done to distinguish between a function declaration and a
 * variable declaration
 */
void declOuter(Var e)
  {
#if DEBUG
  Console.WriteLine("declOuter1 token=["+tok+"]\n");
#endif
  e.setName(tok.getValue());	/* use value as the variable name */
  addOuter(e);		/* add this variable */
  emit.FieldDef(e);		/* issue the declaration */
  if (e.getClassId() == Tok.T_DEFCLASS)
    e.setClassId(Tok.T_STATIC);	/* make sure it knows its storage class */

  /*
   * loop while there are additional variable names
   */
  while (io.getNextChar() == ',')
    {
    tok.scan();
    if (tok.getFirstChar() != ',')
	io.Abort("Expected ','");
    tok.scan();
    if (tok.getId() != Tok.T_IDENT)
	io.Abort("Expected identifier");
    e.setName(tok.getValue()); /* use value as the variable name */
    addOuter(e);		/* add this variable */
    emit.FieldDef(e);		/* issue the declaration */
    if (e.getClassId() == Tok.T_DEFCLASS)
      e.setClassId(Tok.T_STATIC);	/* make sure it knows its storage class */
    }
  /*
   * move beyond end of statement indicator
   */
  tok.scan();
  if (tok.getFirstChar() != ';')
    io.Abort("Expected ';'");
  CommentFill();
  tok.scan();
#if DEBUG
  Console.WriteLine("declOuter2 token=["+tok+"]\n");
#endif
  }
Exemplo n.º 10
0
void addOuter(Var e)
  {
#if DEBUG
  Console.WriteLine("addOuter e=["+e+"]\n");
#endif
  /*
   * validate this declaration as a potential variable
   */
  if (e.getClassId() == Tok.T_AUTO)
    io.Abort("?Cannot allocate automatic variable outside a function\n");
  if (staticvar.FindByName(e.getName()) != null)
    io.Abort("?Cannot redefine static name '" + e.getName() + "'\n");
  staticvar.add(e);
  }
Exemplo n.º 11
0
void addInner(Var e)
  {
  /*
   * validate this declaration as a potential variable
   */
  int id = e.getClassId();
#if DEBUG
  Console.WriteLine("addInner e=["+e+"]\n");
#endif
  if (id == Tok.T_EXTERN || id == Tok.T_STATIC)
    io.Abort("Cannot allocate static within a method\n");
  if (paramvar.FindByName(e.getName()) != null) /* cannot redefine param name */
    io.Abort("Cannot redefine parameter name '" + e.getName() + "'\n");
  if (localvar.FindByName(e.getName()) != null) /* check not already set */
    io.Abort("Local variable '" + e.getName() + "' already defined\n");
  localvar.add(e);
  }
Exemplo n.º 12
0
void genLoad(Var e)
  {
  int id = e.getClassId();
  if (e == null)
    Io.ICE("Load instruction with no variable ptr");
  if (e.getLocalToken() != null)
    {
    //    LocalToken lt = (LocalToken) e.getLocalToken();
    LocalBuilder lt = (LocalBuilder) e.getLocalToken();
    il.Emit(OpCodes.Ldloc, lt);
    }
  else if (e.getFieldBuilder() != null)
    {
    FieldBuilder fb = (FieldBuilder) e.getFieldBuilder();
    if (id == Tok.T_STATIC)
      il.Emit(OpCodes.Ldsfld, fb);
    else
      il.Emit(OpCodes.Ldfld, fb);
    }
  else
    {
    int index = e.getIndex();
    if (id == Tok.T_PARAM)
      {
      if (index <= 256)
	il.Emit(OpCodes.Ldarg_S, index);
      else
	il.Emit(OpCodes.Ldarg, index);
      }
    else if (id == Tok.T_AUTO || id == Tok.T_DEFCLASS)
      {
      if (index <= 256)
	il.Emit(OpCodes.Ldloc_S, e.getIndex());
      else
	il.Emit(OpCodes.Ldloc, e.getIndex());
      }
    else
      Io.ICE("Instruction load of unknown class ("
				     + e.getClassId()+")");
    }
  }