getName() public method

public getName ( ) : String
return String
Esempio n. 1
0
File: asm.cs Progetto: 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());
        }
Esempio n. 2
0
File: asm.cs Progetto: 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());
        }
Esempio n. 3
0
        void declFunc(Var e)
        {
#if DEBUG
            Console.WriteLine("declFunc token=[" + tok + "]\n");
#endif
            CommentHolder();           // start new comment
            e.setName(tok.getValue()); /* value is the function name */
            if (e.getName().Equals("main"))
            {
                if (Io.gendll)
                {
                    io.Abort("Using main entrypoint when generating a DLL");
                }
                mainseen = true;
            }
            staticvar.add(e);         /* add function name to static VarList */
            paramvar = paramList();   // track current param list
            e.setParams(paramvar);    // and set it in func var
            localvar = new VarList(); // track new local parameters
            CommentFillPreTok();

            emit.FuncBegin(e);
            if (tok.getFirstChar() != '{')
            {
                io.Abort("Expected '{'");
            }
            blockOuter(null, null);
            emit.FuncEnd();
            emit.IL();
            if (Io.genlist)
            {
                emit.LIST();
            }
            emit.Finish();
        }
Esempio n. 4
0
 public void add(Var e)
   {
   int index = vindex++;
   e.setIndex(index);
   vhash.Add(e.getName(), e);
   vhash.Add(index, e);
   }
Esempio n. 5
0
        public void FuncBegin(IAsm a)
        {
            Var  func    = a.getVar();
            Type funcsig = genDataTypeSig(a.getVar()); /* gen return type info */

            VarList paramlist = func.getParams();      /* get any params */

            Type[] paramTypes = null;                  // in case no params
            if (paramlist.Length() > 0)
            {
                int max = paramlist.Length();
                paramTypes = new Type[max];
                for (int i = 0; i < max; i++)
                {
                    Var e = paramlist.FindByIndex(i);
                    paramTypes[i] = genDataTypeSig(e);
                }
            }

            emethod = eclass.DefineMethod(func.getName(),
                                          MethodAttributes.Static | MethodAttributes.Public,
                                          funcsig, paramTypes);
            func.setMethodBuilder(emethod); // save the method ref

            /*
             * set the argument symbol info
             */
            for (int i = 0; i < paramlist.Length(); i++)
            {
                emethod.DefineParameter(i + 1, 0, paramlist.FindByIndex(i).getName());
            }

            il = emethod.GetILGenerator();     // create new il generator

            if (func.getName().Equals("main")) /* special entry point for main */
            {
                appbuild.SetEntryPoint(emethod);
            }
            //    emodule.SetUserEntryPoint(emethod);

            /*
             * must also re-init the label hashtable for each function
             */
            labelhash = new Hashtable();

            localsdone = false;
        }
Esempio n. 6
0
        public void add(Var e)
        {
            int index = vindex++;

            e.setIndex(index);
            vhash.Add(e.getName(), e);
            vhash.Add(index, e);
        }
Esempio 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);
        }
Esempio n. 8
0
File: asm.cs Progetto: ydunk/masters
        public void FuncBegin(IAsm a)
        {
            Var    func    = a.getVar();
            String funcsig = genDataTypeSig(a.getVar()); /* gen type info */

            VarList x        = func.getParams();         /* get any params */
            String  paramsig = "";

            if (x.Length() > 0)
            {
                int           max = x.Length();
                StringBuilder t   = new StringBuilder(MyC.MAXSTR);
                for (int i = 0; i < max; i++)
                {
                    Var e = x.FindByIndex(i);
                    t.Append(genDataTypeSig(e));
                    if (i < max - 1)
                    {
                        t.Append(",");
                    }
                }
                paramsig = t.ToString();
            }
            StringBuilder sb = new StringBuilder(MyC.MAXSTR);

            sb.Append("\t.method ");
            sb.Append(funcsig);
            sb.Append(" ");
            sb.Append(func.getName());
            sb.Append("(");
            sb.Append(paramsig);
            sb.Append("){\r\n");
            io.Out(sb.ToString());

            if (func.getName().Equals("main")) /* special entry point for main */
            {
                io.Out("\t.entrypoint\r\n");
            }
        }
Esempio n. 9
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);
        }
Esempio n. 10
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
        }
Esempio n. 11
0
  private String genFieldRef(Var e)
    {
    if (e == null)
      return null;

    StringBuilder sb = new StringBuilder(MyC.MAXSTR);

    if (e.getSign() == Tok.T_UNSIGNED)	/* if var is unsigned, put it in sig */
      sb.Append("unsigned ");

    sb.Append(ilSType(e.getTypeId()));	/* get the datatype */
    sb.Append(" ");
    sb.Append(Io.GetClassname());	/* get the current classname */
    sb.Append(".");
    sb.Append(e.getName());	/* copy the variable name */
    return (sb.ToString());
    }
Esempio n. 12
0
        public void LocalVars(VarList v)
        {
            int max = v.Length();

            for (int i = 0; i < max; i++)   // loop thru the local params
            {
                Var  e  = v.FindByIndex(i); // indexed by number
                Type et = genDataTypeSig(e);
                //    LocalToken t = emethod.DeclareLocal(et);
                LocalBuilder t = il.DeclareLocal(et);
                if (Io.gendebug)
                {
                    t.SetLocalSymInfo(e.getName());
                }
                e.setLocalToken(t);
            }
            localsdone = true;
        }
Esempio n. 13
0
File: asm.cs Progetto: ydunk/masters
        private String genFieldRef(Var e)
        {
            if (e == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder(MyC.MAXSTR);

            if (e.getSign() == Tok.T_UNSIGNED) /* if var is unsigned, put it in sig */
            {
                sb.Append("unsigned ");
            }

            sb.Append(ilSType(e.getTypeId())); /* get the datatype */
            sb.Append(" ");
            sb.Append(Io.GetClassname());      /* get the current classname */
            sb.Append(".");
            sb.Append(e.getName());            /* copy the variable name */
            return(sb.ToString());
        }
Esempio n. 14
0
        public void Call(IAsm a)
        {
            Var    func = a.getVar();
            Object o    = func.getMethodBuilder(); // get previous declared reference

            if (o == null)
            {
                Io.ICE("No previous extern for (" + func.getName() + ")");
            }
            MethodBuilder mb = (MethodBuilder)o;

//  il.Emit(OpCodes.Ldc_I4_0);	// push 0 for the "this" ptr
//  VarList x = func.getParams(); /* get any params */
//  if (x.Length() > 0)
//    {
//    int max = x.Length();
//    for (int i = 0; i < max; i++)
//      {
//      Var e = x.FindByIndex(i);
//      genLoad(e);
//      }
//    }
            il.Emit(OpCodes.Call, mb); // call the MethodBuilder
        }
Esempio n. 15
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);
  }
Esempio n. 16
0
/*
 * parse the outerBlock seperately from inner block.
 * specifically parse the declarations at the beginning of an outerblock
 * the variable r tracks if the last statement was a return or not
 */
        void blockOuter(String olabel, String ilabel)
        {
            bool r = false;

#if DEBUG
            Console.WriteLine("blockOuter1 token=[" + tok + "]\n");
#endif
            CommentToken(); /* mark the position in insn stream */
            tok.scan();
#if DEBUG
            Console.WriteLine("blockOuter2 token=[" + tok + "]\n");
#endif
            declInner();
            emit.LocalVars(localvar);

            while (tok.getFirstChar() != '}')
            {
#if DEBUG
                Console.WriteLine("blockOuter3 token=[" + tok + "]\n");
#endif
                if (io.EOF())
                {
                    io.Abort("Expected statement, end of file encountered");
                }
                r = false;
                switch (tok.getId())
                {
                case Tok.T_IF: fcIf(olabel, ilabel); continue; /* fcIf updates tok */

                case Tok.T_WHILE: fcWhile(); break;

                case Tok.T_FOR: fcFor(); break;

                case Tok.T_BREAK: fcBreak(olabel); break;

                case Tok.T_CONTINUE: fcContinue(ilabel); break;

                case Tok.T_RETURN: fcReturn(); r = true; break;

                default: statement(); break;
                }
#if DEBUG
                Console.WriteLine("blockOuter4 token=[" + tok + "]\n");
#endif
            }
            if (!r)                                  /* if no outerscope return specified, try to default */
            {
                Var e = emit.GetFunc();              /* get function def */
                if (e.getTypeId() != Tok.T_VOID)     /* make sure we can default to void */
                {
                    if (!e.getName().Equals("main")) /* is it not main? */
                    {
                        io.Abort("No return value specified for non void function");
                    }
                    emit.LoadConst("0"); /* special case a dummy ret value */
                }
                emit.Ret();
            }
            CommentToken(); /* mark the position in insn stream */
            tok.scan();     /* read beyond end of block */
#if DEBUG
            Console.WriteLine("blockOuter5 token=[" + tok + "]\n");
#endif
        }
Esempio n. 17
0
void declFunc(Var e)
  {
#if DEBUG
  Console.WriteLine("declFunc token=["+tok+"]\n");
#endif
  CommentHolder();	// start new comment
  e.setName(tok.getValue()); /* value is the function name */
  if (e.getName().Equals("main"))
    {
    if (Io.gendll)
      io.Abort("Using main entrypoint when generating a DLL");
    mainseen = true;
    }
  staticvar.add(e);		/* add function name to static VarList */
  paramvar = paramList();	// track current param list
  e.setParams(paramvar);	// and set it in func var
  localvar = new VarList();	// track new local parameters
  CommentFillPreTok();

  emit.FuncBegin(e);
  if (tok.getFirstChar() != '{')
    io.Abort("Expected '{'");
  blockOuter(null, null);
  emit.FuncEnd();
  emit.IL();
  if (Io.genlist)
    emit.LIST();
  emit.Finish();
  }
Esempio n. 18
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);
  }