本文整理汇总了C#中BlockStatement.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# BlockStatement.AddChild方法的具体用法?C# BlockStatement.AddChild怎么用?C# BlockStatement.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockStatement
的用法示例。
在下文中一共展示了BlockStatement.AddChild方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBlockChildren
void AddBlockChildren (BlockStatement result, Block blockStatement, List<LocalInfo> localVariables, ref int curLocal)
{
foreach (Statement stmt in blockStatement.Statements) {
if (stmt == null)
continue;
if (curLocal < localVariables.Count && IsLower (localVariables[curLocal].Location, stmt.loc)) {
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), AbstractCSharpNode.Roles.Statement);
curLocal++;
}
if (stmt is Block && !(stmt is ToplevelBlock || stmt is ExplicitBlock)) {
AddBlockChildren (result, (Block)stmt, localVariables, ref curLocal);
} else {
result.AddChild ((INode)stmt.Accept (this), AbstractCSharpNode.Roles.Statement);
}
}
}
示例2: Visit
public override object Visit (Block blockStatement)
{
if (blockStatement.IsGenerated) {
if (blockStatement.Statements.First () is Using)
return CreateUsingStatement (blockStatement);
return blockStatement.Statements.Last ().Accept (this);
}
var result = new BlockStatement ();
result.AddChild (new CSharpTokenNode (Convert (blockStatement.StartLocation), 1), AbstractCSharpNode.Roles.LBrace);
int curLocal = 0;
List<LocalInfo> localVariables = new List<LocalInfo> (blockStatement.Variables.Values);
AddBlockChildren (result, blockStatement, localVariables, ref curLocal);
while (curLocal < localVariables.Count) {
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), AbstractCSharpNode.Roles.Statement);
curLocal++;
}
result.AddChild (new CSharpTokenNode (Convert (blockStatement.EndLocation), 1), AbstractCSharpNode.Roles.RBrace);
return result;
}
示例3: Visit
public override object Visit(Block blockStatement)
{
if (blockStatement.IsCompilerGenerated && blockStatement.Statements.Any()) {
if (blockStatement.Statements.First() is Using)
return CreateUsingStatement(blockStatement);
return blockStatement.Statements.Last().Accept(this);
}
var result = new BlockStatement();
result.AddChild(new CSharpTokenNode(Convert(blockStatement.StartLocation), Roles.LBrace), Roles.LBrace);
int curLocal = 0;
AddBlockChildren(result, blockStatement, ref curLocal);
result.AddChild(new CSharpTokenNode(Convert(blockStatement.EndLocation), Roles.RBrace), Roles.RBrace);
return result;
}
示例4: AddBlockChildren
void AddBlockChildren(BlockStatement result, Block blockStatement, ref int curLocal)
{
if (convertTypeSystemMode) {
return;
}
foreach (Mono.CSharp.Statement stmt in blockStatement.Statements) {
if (stmt == null)
continue;
/* if (curLocal < localVariables.Count && IsLower (localVariables[curLocal].Location, stmt.loc)) {
result.AddChild (CreateVariableDeclaration (localVariables[curLocal]), Roles.Statement);
curLocal++;
}*/
if (stmt is Block && !(stmt is ToplevelBlock || stmt is ExplicitBlock)) {
AddBlockChildren(result, (Block)stmt, ref curLocal);
} else {
result.AddChild((Statement)stmt.Accept(this), BlockStatement.StatementRole);
}
}
}
示例5: ConvertTo
/// <summary>
/// Generates code that converts an object to the target type.
/// </summary>
public static Expression ConvertTo(string name, Expression value, TypeReference targetType,
BlockStatement blockStatement, Statement failStmt, bool allowNull, bool isOptional, int seqNum)
{
if (Utility.IsType(targetType, "System.Object"))
{
// no conversion needed
return value;
}
string temp_local_name = String.Format("tmp{0}", seqNum);
// create the "conversion failed" block
ArrayList parameters = new ArrayList();
parameters.Add(value);
parameters.Add(new PrimitiveExpression(targetType.Type, targetType.Type));
parameters.Add(new PrimitiveExpression(name, name));
// the statements to execute when the cast failed
BlockStatement fail_block = new BlockStatement();
fail_block.AddChild(new StatementExpression(new InvocationExpression(new FieldReferenceExpression(
new TypeReferenceExpression("PhpException"), "InvalidImplicitCast"),
parameters)));
fail_block.AddChild(failStmt);
// try to determine whether the target type is a reference or value type
Type system_type = Type.GetType(targetType.SystemType);
if (system_type != null && system_type.IsValueType)
{
// value type
LocalVariableDeclaration temp_local;
if (isOptional)
{
temp_local = new LocalVariableDeclaration(targetType);
temp_local.Variables.Add(new VariableDeclaration(temp_local_name));
blockStatement.AddChild(temp_local);
BlockStatement new_block_stmt = new BlockStatement();
IfElseStatement opt_stmt = new IfElseStatement(new BinaryOperatorExpression(
value, BinaryOperatorType.InEquality, new FieldReferenceExpression(
new IdentifierExpression("Arg"), "Default")), new_block_stmt,
new StatementExpression(new AssignmentExpression(new IdentifierExpression(temp_local_name),
AssignmentOperatorType.Assign, new ObjectCreateExpression(targetType, new ArrayList()))));
blockStatement.AddChild(opt_stmt);
blockStatement = new_block_stmt;
}
IfElseStatement if_stmt = new IfElseStatement(new UnaryOperatorExpression(
new ParenthesizedExpression(new BinaryOperatorExpression(value, BinaryOperatorType.TypeCheck,
new TypeReferenceExpression(targetType))), UnaryOperatorType.Not), fail_block);
blockStatement.AddChild(if_stmt);
if (isOptional)
{
blockStatement.AddChild(new StatementExpression(new AssignmentExpression(
new IdentifierExpression(temp_local_name), AssignmentOperatorType.Assign,
new CastExpression(targetType, value))));
return new IdentifierExpression(temp_local_name);
}
else return new CastExpression(targetType, value);
}
else
{
// probably a reference type
LocalVariableDeclaration temp_local = new LocalVariableDeclaration(targetType);
blockStatement.AddChild(temp_local);
if (isOptional)
{
// first check for Arg.Default
temp_local.Variables.Add(
new VariableDeclaration(temp_local_name, new PrimitiveExpression(null, String.Empty)));
BlockStatement new_block_stmt = new BlockStatement();
IfElseStatement opt_stmt = new IfElseStatement(new BinaryOperatorExpression(
value, BinaryOperatorType.InEquality, new FieldReferenceExpression(
new IdentifierExpression("Arg"), "Default")), new_block_stmt);
blockStatement.AddChild(opt_stmt);
blockStatement = new_block_stmt;
// then perform the as-cast
blockStatement.AddChild(new StatementExpression(new AssignmentExpression(
new IdentifierExpression(temp_local_name), AssignmentOperatorType.Assign,
CreateAsCastExpression(value, targetType))));
}
else
{
// perform the as-cast
temp_local.Variables.Add(
new VariableDeclaration(temp_local_name, CreateAsCastExpression(value, targetType)));
}
//.........这里部分代码省略.........
示例6: Run
public void Run (AstNode compilationUnit)
{
compilationUnit.AcceptVisitor (this);
var ts = compilationUnit.Descendants.OfType<TypeDeclaration> ().Where (x => x.Members.Any (y => y.Name.EndsWith ("_cctor", StringComparison.Ordinal))).ToList ();
if (ts.Count == 0)
return;
var p = ts [0].Parent;
var b = new BlockStatement ();
foreach (var t in ts) {
var cctor = t.Members.First (y => y.Name.EndsWith ("_cctor", StringComparison.Ordinal));
b.AddChild (new ExpressionStatement (new InvocationExpression (
new MemberReferenceExpression (new TypeReferenceExpression (new SimpleType (t.Name)), cctor.Name)
)), BlockStatement.StatementRole);
}
p.AddChild (b, SyntaxTree.MemberRole);
}