本文整理汇总了C#中Statement.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Statement.GetType方法的具体用法?C# Statement.GetType怎么用?C# Statement.GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statement
的用法示例。
在下文中一共展示了Statement.GetType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateStatements
private void GenerateStatements(Statement stmt)
{
if (stmt is StatementList)
{
var seq = (StatementList)stmt;
GenerateStatements(seq.First);
GenerateStatements(seq.Second);
}
else if (stmt is DeclareVariable)
{
var declare = (DeclareVariable)stmt;
symbolsTable[declare.Ident] = ilgenerator.DeclareLocal(TypeOfExpr(declare.Expr));
var assign = new Assign { Ident = declare.Ident, Expr = declare.Expr };
GenerateStatements(assign);
}
else if (stmt is Assign)
{
var assign = (Assign)stmt;
GenerateExpression(assign.Expr, TypeOfExpr(assign.Expr));
Store(assign.Ident, TypeOfExpr(assign.Expr));
}
else if (stmt is Print)
{
GenerateExpression(((Print)stmt).Expr, typeof(string));
ilgenerator.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new[] { typeof(string) }));
}
else if (stmt is ReadInteger)
{
ilgenerator.Emit(OpCodes.Call, typeof(Console).GetMethod("ReadLine", BindingFlags.Public | BindingFlags.Static, null, new Type[] { }, null));
ilgenerator.Emit(OpCodes.Call, typeof(int).GetMethod("Parse", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(string) }, null));
Store(((ReadInteger)stmt).Ident, typeof(int));
}
else if (stmt is ForLoop)
{
var forLoop = (ForLoop)stmt;
var assign = new Assign { Ident = forLoop.Ident, Expr = forLoop.From };
GenerateStatements(assign);
var test = ilgenerator.DefineLabel();
ilgenerator.Emit(OpCodes.Br, test);
var body = ilgenerator.DefineLabel();
ilgenerator.MarkLabel(body);
GenerateStatements(forLoop.Body);
ilgenerator.Emit(OpCodes.Ldloc, symbolsTable[forLoop.Ident]);
ilgenerator.Emit(OpCodes.Ldc_I4, 1);
ilgenerator.Emit(OpCodes.Add);
Store(forLoop.Ident, typeof(int));
ilgenerator.MarkLabel(test);
ilgenerator.Emit(OpCodes.Ldloc, symbolsTable[forLoop.Ident]);
GenerateExpression(forLoop.To, typeof(int));
ilgenerator.Emit(OpCodes.Blt, body);
}
else
{
throw new CodeGeneratorException("Cant generate a " + stmt.GetType().Name);
}
}
示例2: AnalyzeStmt
/// <summary>
/// Visits and updates the method info based on the current statement
/// </summary>
/// <param name="st"></param>
private void AnalyzeStmt(Statement st)
{
if(st is BlockStatement) {
AnalyzeBlockStmt((BlockStatement)st);
}
if(st is DeclarationStatement) {
AnalyzeDeclarationStatement((DeclarationStatement)st);
} else if(st is ReturnStatement) {
InReturnStmt++;
AnalyzeReturnStmt((ReturnStatement)st);
InReturnStmt--;
} else {
if(!st.GetType().IsSubclassOf(typeof(Statement))) {
AnalyzeOtherStmt(st);
}
}
}
示例3: VisitStatement
/// <summary>
/// Visit the statement. It calls the instruction visitor to perform the transfer function
/// </summary>
/// <param name="block"></param>
/// <param name="statement"></param>
/// <param name="dfstate"></param>
/// <returns></returns>
protected override IDataFlowState VisitStatement(CfgBlock block, Statement statement, IDataFlowState dfstate)
{
if (PointsToAnalysis.debug)
{
Console.Out.WriteLine("Before: {0} ({1}) {2}", CodePrinter.StatementToString(statement),
statement.SourceContext.StartLine, statement.GetType());
dfstate.Dump();
}
PointsToState currentState = dfstate as PointsToState;
/*
if (PointsToAnalysis.IsCompilerGenerated(currentState.Method))
if (!this.pointsToStateAnalysys.enclosingState.ContainsKey(currentState.Method.DeclaringType))
return currentState;
*/
if (PointsToAnalysis.verbose)
{
iterationsCounter++;
if (iterationsCounter % 5000 == 0)
{
Console.Out.WriteLine("Counter: {3} {4} {0} ({1}) {2}", CodePrinter.StatementToString(statement),
statement.SourceContext.StartLine, statement.GetType(), iterationsCounter, currentState.Method.FullName);
dfstate.Dump();
}
}
//if (CodePrinter.StatementToString(statement).Contains("return value := this.f"))
// System.Diagnostics.Debugger.Break();
IDataFlowState result = (IDataFlowState)currentState;
// For Debug...
if (currentState.Method.Name.Name.Equals("Push"))
{ }
// If there are too many calls to non analyzable methods
// starts to ignore the statements
// if (!pointsToStateAnalysys.BoogieMode || currentState.CallsToNonAnalyzable.Count < pointsToStateAnalysys.maxCallToNonAnalyzable)
if (HasToVisit(currentState))
result = (IDataFlowState)(iVisitor.Visit(statement, dfstate));
if (PointsToAnalysis.debug)
{
Console.Out.WriteLine("After: {0} ({1})", CodePrinter.StatementToString(statement), statement.SourceContext.StartLine);
dfstate.Dump();
}
//return dfstate;
return result;
}
示例4: ProcessStatement
private string ProcessStatement(Statement node)
{
if (node is EmptyStatement)
{
return ";";
}
StringBuilder sb = new StringBuilder(100);
if (node == null) throw new ArgumentNullException("node");
switch (node.NodeType)
{
case DotNetNodeType.RegionPreProcessorDirective:
break;
case DotNetNodeType.BlockStatement:
Process_Block_Statement(sb, (BlockStatement)node);
break;
case DotNetNodeType.BranchStatement:
Process_Branch_Statement(node, sb);
break;
case DotNetNodeType.ForEachStatement:
Process_ForEach_Statement(sb, (ForEachStatement)node);
break;
case DotNetNodeType.ForStatement:
Process_For_Statement(sb, (ForStatement)node);
break;
case DotNetNodeType.IfStatement:
Process_If_Statement(sb, (IfStatement)node);
break;
case DotNetNodeType.LocalVariableDeclaration:
Process_Local_Variable_Declaration(sb, (LocalVariableDeclaration)node);
sb.Append(";");
break;
case DotNetNodeType.StatementExpression:
Process_Statement_Expression(sb, (StatementExpression)node);
break;
// working down from here.
case DotNetNodeType.WhileStatement:
Process_While_Statement(sb, (WhileStatement)node);
break;
case DotNetNodeType.ReturnStatement:
Process_Return_Statement(sb, (ReturnStatement)node);
break;
case DotNetNodeType.SwitchStatement:
Process_Switch_Statement(sb, (SwitchStatement)node);
break;
case DotNetNodeType.BreakStatement:
Process_Break_Statement(sb, (BreakStatement)node);
break;
case DotNetNodeType.ContinueStatement:
Process_Continue_Statement(sb, (ContinueStatement)node);
break;
case DotNetNodeType.DoStatement:
Process_Do_Statement(sb, (DoStatement)node);
break;
case DotNetNodeType.TryStatement:
Process_Try_Statement(sb, (TryStatement)node);
break;
case DotNetNodeType.ThrowStatement:
Process_Throw_Statement(sb, (ThrowStatement)node);
break;
case DotNetNodeType.LockStatement:
Process_Lock_Statement(sb, (LockStatement)node);
break;
case DotNetNodeType.CheckedStatement:
Process_Checked_Statement(sb, (CheckedStatement)node);
break;
case DotNetNodeType.UncheckedStatement:
Process_Unchecked_Statement(sb, (UncheckedStatement)node);
break;
case DotNetNodeType.GoToStatement:
Process_Goto_Statement(sb, (GotoStatement)node);
break;
case DotNetNodeType.UnsafeStatement:
Process_Unsafe_Statement(sb, (UnsafeStatement)node);
break;
case DotNetNodeType.FixedStatement:
Process_Fixed_Statement(sb, (FixedStatement)node);
break;
case DotNetNodeType.LabeledStatement:
Process_Labeled_Statement(sb, (LabeledStatement)node);
break;
case DotNetNodeType.YieldStatement:
Process_Yield_Statement(sb, (YieldStatement)node);
break;
case DotNetNodeType.UsingStatement:
Process_Using_Statement(sb, (UsingStatement)node);
break;
default:
throw new ParserException("We do not currently handle " + node.GetType() + " statements");
}
return sb.ToString();
}
示例5: EvaluateStatement
/// <summary>
/// Function for evaluating statments
/// </summary>
/// <param name="statement"></param>
protected void EvaluateStatement(Statement statement)
{
if (statement == null)
return;
if (statement is ForAllStatement)
{
var forAllStatement = statement as ForAllStatement;
IEnumerable<object> collections = forAllStatement.Collection.Eval(_evaluationContext) as IEnumerable<object>;
if (collections.Count() == 0)
return;
// Declare the iterator in value table
_evaluationContext.ValuesTable.Add(forAllStatement.Iterator.Name, null);
foreach (var item in collections)
{
_evaluationContext.ValuesTable[forAllStatement.Iterator.Name] = item;
forAllStatement.Iterator.SetType(item.GetType());
// evaluate statments recursively
EvaluateStatement(forAllStatement.InnerStatement);
}
_evaluationContext.ValuesTable.Remove(forAllStatement.Iterator.Name);
}
else if (statement is IfStatement)
{
var ifStatement = statement as IfStatement;
if ((bool)ifStatement.ConditionalExpression.Eval(_evaluationContext) == true)
{
EvaluateStatement(ifStatement.InnerStatement);
}
else if (ifStatement.IfFalseStatement != null)
{
EvaluateStatement(ifStatement.IfFalseStatement);
}
}
else if (statement is Assignment)
{
var assignment = statement as Assignment;
// assign to the variable object from the values table
_evaluationContext.ValuesTable[assignment.Target.Name] = assignment.Expression.Eval(_evaluationContext);
}
else if (statement is Declaration)
{
var declaration = statement as Declaration;
_evaluationContext.ValuesTable.Add(declaration.Variable.Name, null);
}
else if (statement is OpenPosition)
{
var openPositionStatement = statement as OpenPosition;
PositionSetRuntime positionSetRT = PositionSetTable[openPositionStatement.PositionSet.Name];
string currency = (string)openPositionStatement.Currency.Eval(_evaluationContext);
positionSetRT.OpenPosition(_currencyTable[currency], _evaluationContext.CurrentDate);
}
else if (statement is ClosePosition)
{
var closePositionStatement = statement as ClosePosition;
PositionRuntime positionRT = closePositionStatement.Position.Eval(_evaluationContext) as PositionRuntime;
positionRT.ClosePosition(_evaluationContext.CurrentDate);
}
else if (statement is PositionStopLoss)
{
var positionStopLoss = statement as PositionStopLoss;
PositionRuntime positionRT = _evaluationContext.ValuesTable[positionStopLoss.Position.Name] as PositionRuntime;
positionRT.StopLoss(_evaluationContext.CurrentDate);
}
else if (statement is CompositeStatement)
{
var compositeStatement = statement as CompositeStatement;
compositeStatement.Statements.ForEach(s => EvaluateStatement(s));
}
else
throw new Exception("Unknown statement type: " + statement.GetType().Name);
}
示例6: PushTarget
public void PushTarget(Statement s)
{
Debug.Assert(s is LoopStatement || s is SwitchStatement || s is LabelStatement, "Invalid target statement type {0}", s.GetType());
Targets.Add(s);
}
示例7: RecordStatement
/// <summary>
/// Records information about the given statement, under the given node.
/// </summary>
/// <param name="statement">
/// The statement to record.
/// </param>
/// <param name="parentNode">
/// The Xml node to record this statement beneath.
/// </param>
/// <returns>
/// Returns the new Xml node describing this statement.
/// </returns>
private static XmlNode RecordStatement(Statement statement, XmlNode parentNode)
{
Param.AssertNotNull(statement, "statement");
Param.AssertNotNull(parentNode, "parentNode");
// Create a new node for this statement and add it to the parent.
XmlNode statementNode = parentNode.OwnerDocument.CreateElement("Statement");
parentNode.AppendChild(statementNode);
// Add the name and contents of the statement.
////XmlAttribute text = parentNode.OwnerDocument.CreateAttribute("Text");
////text.Value = statement.ToString();
////statementNode.Attributes.Append(text);
XmlAttribute type = parentNode.OwnerDocument.CreateAttribute("Type");
type.Value = statement.GetType().Name;
statementNode.Attributes.Append(type);
return statementNode;
}