本文整理汇总了C#中SymbolTable.RemoveLocal方法的典型用法代码示例。如果您正苦于以下问题:C# SymbolTable.RemoveLocal方法的具体用法?C# SymbolTable.RemoveLocal怎么用?C# SymbolTable.RemoveLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.RemoveLocal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenStmt
//.........这里部分代码省略.........
var ilMeth = symbolTable.functionTable[functionName].GetILGenerator();
GenStmt(stmt.ChildNodes[1], ilMeth, localSymbols);
ilMeth.Emit(OpCodes.Ret);
}
else if (stmt.Term.Name == "result")
{
GenExpr(stmt.ChildNodes[1], TypeOfExpr(stmt.ChildNodes[1], symbolTable), il, symbolTable);
var result = il.DeclareLocal(TypeOfExpr(stmt.ChildNodes[1], symbolTable));
il.Emit(OpCodes.Stloc, result);
il.Emit(OpCodes.Ldloc, result);
il.Emit(OpCodes.Ret, result);
}
else if (stmt.Term.Name == "functionCall" | stmt.Term.Name == "memberCall")
{
GenExpr(stmt, null, il, symbolTable);
}
else if (stmt.Term.Name == "ifBlock")
{
Label ifTrue = il.DefineLabel();
Label ifFalse = il.DefineLabel();
Label endLabel = il.DefineLabel();
GenExpr(stmt.ChildNodes[0], typeof(bool), il, symbolTable);//expression to check if true
il.Emit(OpCodes.Brtrue, ifTrue);//if true then jump to true block
il.Emit(OpCodes.Br, ifFalse);//otherwise jump to false block
il.MarkLabel(ifTrue);//true block
GenStmt(stmt.ChildNodes[1], il, symbolTable);
il.Emit(OpCodes.Br, endLabel);//jump to after false block
il.MarkLabel(ifFalse);//false block
if (stmt.ChildNodes[2].ChildNodes.Count > 0)//then there's an else-if, this takes place in the else section
{
ParseTreeNode elseBlockStmt = stmt.ChildNodes[2];//Turn the elsif to an inner if statement
elseBlockStmt.ChildNodes.Add(stmt.ChildNodes[3]);//Move the optional else statement to the inner if statement
elseBlockStmt.Term.Name = "ifBlock";
GenStmt(elseBlockStmt, il, symbolTable);
}
else if (stmt.ChildNodes[3].ChildNodes.Count > 0)
GenStmt(stmt.ChildNodes[3].ChildNodes[0], il, symbolTable);//generate expresson for false section, otherwise the label will be at the same spot as the end
il.MarkLabel(endLabel);//the end of the if statement
}
else if (stmt.Term.Name == "loop")
{
Label beginLoop = il.DefineLabel();
Label endLoop = il.DefineLabel();
il.MarkLabel(beginLoop);
GenStmt(stmt.ChildNodes[0], il, symbolTable, endLoop);
il.Emit(OpCodes.Br, beginLoop);
il.MarkLabel(endLoop);
}
else if (stmt.Term.Name == "forLoop")
{
il.BeginScope();
Label beginLoop = il.DefineLabel();
Label endLoop = il.DefineLabel();
LocalBuilder i = il.DeclareLocal(typeof(int));
string identName = stmt.ChildNodes[1].Token.ValueString;
symbolTable.AddLocal(identName, i);
symbolTable.AddLocal("___endLoop", il.DeclareLocal(typeof(int)));
if (stmt.ChildNodes[2].ChildNodes.Count == 1)//then an identifier is used as a range, or char. We just fail for now
throw new NotImplementedException();
else
{
GenExpr(stmt.ChildNodes[2].ChildNodes[0], typeof(int), il, symbolTable);
symbolTable.Store(identName, typeof(int), il);
GenExpr(stmt.ChildNodes[2].ChildNodes[1], typeof(int), il, symbolTable);
symbolTable.Store("___endLoop", typeof(int), il);
}
il.MarkLabel(beginLoop);
GenStmt(stmt.ChildNodes[4], il, symbolTable, endLoop);
symbolTable.PushVar(identName, il);
il.Emit(OpCodes.Ldc_I4_1);
if (stmt.ChildNodes[3].ChildNodes.Count > 0)//then there is a decreasing statement, so do decreasing
il.Emit(OpCodes.Sub);
else
il.Emit(OpCodes.Add);
il.Emit(OpCodes.Dup);
symbolTable.Store(identName, typeof(int), il);
symbolTable.PushVar("___endLoop", il);
if (stmt.ChildNodes[3].ChildNodes.Count > 0)//then there is a decreasing statement, so do decreasing
il.Emit(OpCodes.Bge, beginLoop);
else
il.Emit(OpCodes.Ble, beginLoop);
il.MarkLabel(endLoop);
symbolTable.RemoveLocal(identName);
symbolTable.RemoveLocal("___endLoop");
il.EndScope();
}
else
{
throw new System.Exception("don't know how to gen a " + stmt.Term.Name);
}
}