void dataType(Var e)
  {
  int id = tok.getId();
#if DEBUG
  Console.WriteLine("dataType1 token=["+tok+"]\n");
#endif
  e.setSign(Tok.T_SIGNED);
  if (id == Tok.T_SIGNED || id == Tok.T_UNSIGNED)
    {
    e.setSign(id);
    tok.scan();
    id = tok.getId();
#if DEBUG
    Console.WriteLine("dataType2 token=["+tok+"]\n");
#endif
    }
  if (id == Tok.T_VOID || id == Tok.T_INT)
    {
    e.setTypeId(id);
    tok.scan();
#if DEBUG
    Console.WriteLine("dataType3 token=["+tok+"]\n");
#endif
    }
  else if (id == Tok.T_LONG)
    Io.ICE("Unhandled type LONG");
  else if (id == Tok.T_CHAR)
    Io.ICE("Unhandled type CHAR");
  else if (id == Tok.T_FLOAT)
    Io.ICE("Unhandled type FLOAT");
  else if (id == Tok.T_DOUBLE)
    Io.ICE("Unhandled type DOUBLE");
  else
    e.setTypeId(Tok.T_DEFTYPE);
  }
Beispiel #2
0
 public void add(Var e)
   {
   int index = vindex++;
   e.setIndex(index);
   vhash.Add(e.getName(), e);
   vhash.Add(index, e);
   }
Beispiel #3
0
  /*
   * common routine to construct a signature string for a given varlist item
   * requires a destination ptr, will return the updated dest ptr
   */
  private String genDataTypeSig(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 */
    return (sb.ToString());
    }
Beispiel #4
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());
    }
void dataClass(Var e)
  {
#if DEBUG
  Console.WriteLine("dataClass1 token=["+tok+"]\n");
#endif
  int id = tok.getId();
  if (id == Tok.T_EXTERN || id == Tok.T_STATIC || id == Tok.T_AUTO)
    {
    e.setClassId(tok.getId());
    tok.scan();
#if DEBUG
    Console.WriteLine("dataClass2 token=["+tok+"]\n");
#endif
    }
  else
    {
    e.setClassId(Tok.T_DEFCLASS); /* default to current context */
    }
  }
 public void setVar(Var v)
 {
     ivar = v;
 }
Beispiel #7
0
/*
 * Emit a field def to ilist
 */
public void FieldDef(Var e)
  {
  NextInsn(0);
  icur.setIType(IAsm.I_FIELD);
  icur.setVar(e);
  }
Beispiel #8
0
/*
 * Emit function begin to ilist
 */
public void FuncBegin(Var e)
  {
  NextInsn(0);
  icur.setIType(IAsm.I_FUNC_BEGIN);
  icur.setVar(e);
  }
Beispiel #9
0
public void Load(Var e)
  {
  NextInsn(1);
  icur.setIType(IAsm.I_INSN_LOAD);
  icur.setVar(e);
  }
Beispiel #10
0
public void Call(Var e)
  {
  NextInsn(1);
  icur.setIType(IAsm.I_CALL);
  icur.setVar(e);			/* this is the callname */
  }
Beispiel #11
0
/*
 * common routine to construct a signature string for a given varlist item
 * requires a destination ptr, will return the updated dest ptr
 */
private Type genDataTypeSig(Var e)
  {
  bool sign = true;
  if (e == null)
    return null;

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

  Type sig = ilSType(sign, e.getTypeId());	/* get the datatype */
  return (sig);
  }
Beispiel #12
0
public void Store(Var e)
  {
  NextInsn(1);
  icur.setIType(IAsm.I_INSN_STORE);
  icur.setVar(e);
  }
Beispiel #13
0
VarList paramList()
  {
  VarList v;
  tok.scan();
  if (tok.getFirstChar() != '(')
    io.Abort("Expected '('");

  v = new VarList();		/* init the param list */
  tok.scan();			/* get the next token */
  while (tok.getFirstChar() != ')')
    {
    Var e = new Var();
    e.setClassId(Tok.T_PARAM);	/* mark this as a parameter */
    dataType(e);		/* get the specified datatype */
    e.setName(tok.getValue()); /* copy the variable name */
    v.add(e);			/* add parameter to param list */
    tok.scan();
    if (tok.getFirstChar() == ',')	/* if more params */
      tok.scan();		/* get the next token */
    }
  tok.scan();		/* move to the next token */
  return v;
  }
Beispiel #14
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()+")");
    }
  }
Beispiel #15
0
 public void setVar(Var v) { ivar = v; }
Beispiel #16
0
void outerDecl()
  {
  Var e = new Var();
#if DEBUG
  Console.WriteLine("outerDecl token=["+tok+"]\n");
#endif

  CommentHolder();	/* mark the position in insn stream */

  dataClass(e);
  dataType(e);

  if (io.getNextChar() == '(')
    declFunc(e);
  else
    declOuter(e);
  }
Beispiel #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();
  }
Beispiel #18
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
  }
Beispiel #19
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);
  }
Beispiel #20
0
/*
 * parse an inner declaration
 */
void declInner()
  {
  while (tok.IsDeclKeyword())
    {
    Var e = new Var();
#if DEBUG
    Console.WriteLine("declInner1 token=["+tok+"]\n");
#endif

    CommentHolder();	/* mark comment position in insn stream */

    dataClass(e);		// parse the data class (static, auto, etc)
    dataType(e);		// parse the type (int, unsigned, etc)
    e.setName(tok.getValue()); // save the name in var
#if DEBUG
    Console.WriteLine("declInner2.0 token=["+tok+"]\n");
    Console.WriteLine("declInner2.0 e=["+e+"]\n");
#endif
    addInner(e);			/* add this variable */
    /*
     * 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 */
#if DEBUG
      Console.WriteLine("declInner2.1 token=["+tok+"]\n");
      Console.WriteLine("declInner2.1 e=["+e+"]\n");
#endif
      addInner(e);		/* reuse the class & type */
      }
    /*
     * move beyond end of statement indicator
     */
    tok.scan();
    if (tok.getFirstChar() != ';')
	io.Abort("Expected ';'");
    CommentFill();
    tok.scan();		/* get token ready nor next parser step */
#if DEBUG
    Console.WriteLine("declInner3 token=["+tok+"]\n");
#endif
    }
  }
Beispiel #21
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);
  }