本文整理汇总了C#中ICSharpCode.NRefactory.Ast.BlockStatement类的典型用法代码示例。如果您正苦于以下问题:C# BlockStatement类的具体用法?C# BlockStatement怎么用?C# BlockStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BlockStatement类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了BlockStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitBlockStatement
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
foreach(INode statement in blockStatement.Children) {
statement.AcceptVisitor(this, null);
}
return null;
}
示例2: VisitBlockStatement
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
Push();
object result = base.VisitBlockStatement(blockStatement, data);
Pop();
return result;
}
示例3: ConvertBlock
B.Block ConvertBlock(BlockStatement block)
{
B.Block b = new B.Block(GetLexicalInfo(block));
b.EndSourceLocation = GetLocation(block.EndLocation);
ConvertStatements(block.Children, b);
return b;
}
示例4: add_Method
public static MethodDeclaration add_Method(this TypeDeclaration typeDeclaration, string methodName, Dictionary<string, object> invocationParameters, BlockStatement body)
{
var newMethod = new MethodDeclaration
{
Name = methodName,
//Modifier = Modifiers.None | Modifiers.Public | Modifiers.Static,
Modifier = Modifiers.None | Modifiers.Public,
Body = body
};
newMethod.setReturnType();
if (invocationParameters != null)
foreach (var invocationParameter in invocationParameters)
{
var parameterType = new TypeReference(
(invocationParameter.Value != null && invocationParameter.Key != "returnData")
? invocationParameter.Value.typeFullName()
: "System.Object", true);
var parameter = new ParameterDeclarationExpression(parameterType, invocationParameter.Key);
newMethod.Parameters.Add(parameter);
}
typeDeclaration.AddChild(newMethod);
return newMethod;
}
示例5: CreateMethodBody
public BlockStatement CreateMethodBody()
{
Ast.BlockStatement astBlock = new Ast.BlockStatement();
if (methodDef.Body == null) return astBlock;
List<ILNode> body = new ILAstBuilder().Build(methodDef);
MethodBodyGraph bodyGraph = new MethodBodyGraph(body);
bodyGraph.Optimize();
List<string> intNames = new List<string>(new string[] {"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t"});
Dictionary<string, int> typeNames = new Dictionary<string, int>();
foreach(VariableDefinition varDef in methodDef.Body.Variables) {
if (string.IsNullOrEmpty(varDef.Name)) {
if (varDef.VariableType.FullName == Constants.Int32 && intNames.Count > 0) {
varDef.Name = intNames[0];
intNames.RemoveAt(0);
} else {
string name;
if (varDef.VariableType.IsArray) {
name = "array";
} else if (!typeNameToVariableNameDict.TryGetValue(varDef.VariableType.FullName, out name)) {
name = varDef.VariableType.Name;
// remove the 'I' for interfaces
if (name.Length >= 3 && name[0] == 'I' && char.IsUpper(name[1]) && char.IsLower(name[2]))
name = name.Substring(1);
// remove the backtick (generics)
int pos = name.IndexOf('`');
if (pos >= 0)
name = name.Substring(0, pos);
if (name.Length == 0)
name = "obj";
else
name = char.ToLower(name[0]) + name.Substring(1);
}
if (!typeNames.ContainsKey(name)) {
typeNames.Add(name, 0);
}
int count = typeNames[name];
if (count > 0) {
name += count.ToString();
}
varDef.Name = name;
}
}
localVarTypes[varDef.Name] = varDef.VariableType;
localVarDefined[varDef.Name] = false;
// Ast.VariableDeclaration astVar = new Ast.VariableDeclaration(varDef.Name);
// Ast.LocalVariableDeclaration astLocalVar = new Ast.LocalVariableDeclaration(astVar);
// astLocalVar.TypeReference = new Ast.TypeReference(varDef.VariableType.FullName);
// astBlock.Children.Add(astLocalVar);
}
astBlock.Children.AddRange(TransformNodes(bodyGraph.Childs));
return astBlock;
}
示例6: TrackedVisitBlockStatement
public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
{
blockStatement.Children.Clear();
TypeReference notImplmentedException = new TypeReference("System.NotImplementedException");
ObjectCreateExpression objectCreate = new ObjectCreateExpression(notImplmentedException, new List<Expression>());
blockStatement.Children.Add(new ThrowStatement(objectCreate));
return null;
}
示例7: VisitBlockStatement
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
foreach (Statement st in blockStatement.Children)
{
st.Parent = blockStatement;
}
return base.VisitBlockStatement(blockStatement, data);
}
示例8: GenerateAstToInsert
AbstractNode GenerateAstToInsert(string variableName)
{
var block = new BlockStatement();
block.AddChild(new ExpressionStatement(new IdentifierExpression(caretMarker)));
return new IfElseStatement(
new BinaryOperatorExpression(new IdentifierExpression(variableName), BinaryOperatorType.InEquality, new PrimitiveExpression(null)),
block);
}
示例9: CreateEmptyBlockStatement
public static BlockStatement CreateEmptyBlockStatement(string returnTypeName)
{
var block = new BlockStatement();
if (!IsVoid(returnTypeName))
block.AddChildren(new ReturnStatement(new DefaultValueExpression(CreateTypeReference(returnTypeName))));
return block;
}
示例10: VisitBlockStatement
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
Contract.Requires(blockStatement != null);
// Visit children of block statement (E.g. several ExpressionStatement objects)
blockStatement.AcceptChildren(this, data);
return null;
}
示例11: VisitBlockStatement
public override object VisitBlockStatement(BlockStatement blockStatement, object data)
{
for(int i = 0; i < blockStatement.Children.Count; i++) {
if (blockStatement.Children[i] is Statement &&
((Statement)blockStatement.Children[i]).IsNull)
{
blockStatement.Children.RemoveAt(i);
i--;
}
}
return base.VisitBlockStatement(blockStatement, data);
}
示例12: CreateMetodBody
public static BlockStatement CreateMetodBody(MethodDefinition methodDef)
{
AstMetodBodyBuilder builder = new AstMetodBodyBuilder();
builder.methodDef = methodDef;
try {
return builder.CreateMethodBody();
} catch {
BlockStatement block = new BlockStatement();
block.Children.Add(MakeComment("Exception during decompilation"));
return block;
}
}
示例13: GetModifiedName
private string GetModifiedName(BlockStatement blockStatement, string identifier)
{
int hashCode;
while (blockStatement != null)
{
hashCode = blockStatement.GetHashCode();
string identifierHash = identifier + "_" + hashCode;
if (renamedVariables.Contains(identifierHash))
return (string) renamedVariables[identifierHash];
else
blockStatement = (BlockStatement) AstUtil.GetParentOfType(blockStatement, typeof(BlockStatement));
}
return null;
}
示例14: ast_CSharp_CreateCompilableClass
public static string ast_CSharp_CreateCompilableClass(this BlockStatement blockStatement, SnippetParser snippetParser, string codeSnippet,
CSharp_FastCompiler_CompilerOptions compilerOptions,
CSharp_FastCompiler_CompilerArtifacts compilerArtifacts,
CSharp_FastCompiler_ExecutionOptions executionOptions)
{
if (blockStatement.isNull() || compilerOptions.isNull())
return null;
var compilationUnit= compilerArtifacts.CompilationUnit = new CompilationUnit();
compilationUnit.add_Type(compilerOptions.default_TypeName)
.add_Method(compilerOptions.default_MethodName, executionOptions.InvocationParameters,
compilerOptions.ResolveInvocationParametersType, blockStatement);
// remove comments from parsed code
var astCSharp = compilerArtifacts.AstCSharp = new Ast_CSharp(compilerArtifacts.CompilationUnit, snippetParser.Specials);
// add references included in the original source code file
compilerArtifacts.AstCSharp.mapCodeO2References(compilerOptions);
astCSharp.mapAstDetails();
astCSharp.ExtraSpecials.Clear();
var method = compilationUnit.method(compilerOptions.default_MethodName);
var returntype = method.returnType();
var type = compilationUnit.type(compilerOptions.default_TypeName);
type.Children.Clear();
var tempBlockStatement = new BlockStatement();
tempBlockStatement.add_Variable("a", 0);
method.Body = tempBlockStatement;
var newMethod = type.add_Method(compilerOptions.default_MethodName, executionOptions.InvocationParameters,
compilerOptions.ResolveInvocationParametersType, tempBlockStatement);
newMethod.TypeReference = returntype;
if(blockStatement.returnStatements().size() >1)
astCSharp.methodDeclarations().first().remove_LastReturnStatement();
astCSharp.mapAstDetails();
var codeToReplace = "Int32 a = 0;";
var csharpCode = astCSharp.AstDetails.CSharpCode
.replace("\t\t{0}".format(codeToReplace), codeToReplace) // remove tabs
.replace("Int32 a = 0;", codeSnippet); // put the actual code (this should be done via AST, but it was affectting code complete)
return csharpCode;
}
示例15: TrackedVisitBlockStatement
public override object TrackedVisitBlockStatement(BlockStatement blockStatement, object data)
{
BlockStatement replaced = blockStatement;
InsertionBlockData insertionBlockData = new InsertionBlockData();
base.TrackedVisitBlockStatement(blockStatement, insertionBlockData);
if (insertionBlockData.Block != null && insertionBlockData.Statements.Count > 0)
{
if (blockStatement.GetHashCode() == insertionBlockData.Block.GetHashCode())
{
IList<INode> nodes = new List<INode>();
foreach (Statement node in insertionBlockData.Statements)
nodes.Add(node);
replaced.Children.InsertRange(insertionBlockData.BlockChildIndex, nodes);
ReplaceCurrentNode(replaced);
}
}
return null;
}