本文整理汇总了C#中Ast.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Ast.GetType方法的具体用法?C# Ast.GetType怎么用?C# Ast.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ast
的用法示例。
在下文中一共展示了Ast.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Walk
private string Walk(Ast.Tree tree, string ret)
{
Type type = tree.GetType().UnderlyingSystemType;
PropertyInfo item = type.GetProperty("Item");
if (tree.IsVar)
{
Ast.Tree next = ((Ast.Tree.Var) tree).Item;
ret += string.Format("'var',[{0}]", Walk(next, ret));
}
else if (tree.IsIdentifier)
{
string identifier = ((Ast.Tree.Identifier) tree).Item;
ret += string.Format("'{0}'", identifier);
}
else if (tree.IsCompoundAssign)
{
Ast.Tree.CompoundAssign compoundAssign = (Ast.Tree.CompoundAssign)tree;
// ret += string.Format("[{0},{1}]", Walk(compoundAssign.Item1, ret), Walk(compoundAssign.Item2, ret));
throw new NotImplementedException();
}
else if (tree.IsAssign)
{
Ast.Tree.Assign assign = (Ast.Tree.Assign) tree;
ret += string.Format("[{0},{1}]", Walk(assign.Item1, ret), Walk(assign.Item2, ret));
}
else if (tree.IsBinary)
{
Ast.Tree.Binary binary = (Ast.Tree.Binary) tree;
var operators = new Dictionary<string, string>
{
//{"add", "+"},
{"Add", "+"}
};
ret += string.Format("['binary','{0}',{1},{2}]",
operators[binary.Item1.ToString()],
Walk(binary.Item2, ret),
Walk(binary.Item3, ret));
}
else if (tree.IsNumber)
{
double number = ((Ast.Tree.Number) tree).Item;
ret += string.Format("['num',{0}]", number);
}
else if (tree.IsBlock)
{
FSharpList<Ast.Tree> trees = ((Ast.Tree.Block) tree).Item;
IList<string> arr = new List<string>();
foreach (Ast.Tree next in trees)
{
arr.Add(Walk(next, ret));
}
ret += string.Format("[{0}]", string.Join(",",arr.ToArray()));
}
else if (tree.IsArray)
{
ret += "array";
FSharpList<Ast.Tree> trees = ((Ast.Tree.Array) tree).Item;
foreach (Ast.Tree next in trees)
{
ret += string.Format("[{0}]", Walk(next, ret));
}
}
else
{
throw new NotImplementedException("Type: " + type);
}
return ret;
}
示例2: Walk
public void Walk(Ast.INode node, StringBuilder sb)
{
if(node is Ast.SequenceNode)
{
sb.AppendLine(string.Format("{0} (seq)", node.GetType()));
Ast.SequenceNode seq = (Ast.SequenceNode)node;
foreach(Ast.INode child in seq.Elements) {
Walk(child, sb);
}
}
else
sb.AppendLine(string.Format("{0} = {1}", node.GetType(), node.ToString()));
}
示例3: AnalyzeImpl
/// <summary>
/// Used to analyze scriptbloct, functionmemberast or functiondefinitionast
/// </summary>
/// <param name="ast"></param>
/// <returns></returns>
public void AnalyzeImpl(Ast ast, VariableAnalysis outerAnalysis)
{
if (!(ast is ScriptBlockAst || ast is FunctionMemberAst || ast is FunctionDefinitionAst))
{
return;
}
_variables = FindAllVariablesVisitor.Visit(ast);
Init();
if (ast is FunctionMemberAst || ast is FunctionDefinitionAst)
{
IEnumerable<ParameterAst> parameters = FindParameters(ast, ast.GetType());
if (parameters != null)
{
ProcessParameters(parameters);
}
}
else
{
ScriptBlockAst sbAst = ast as ScriptBlockAst;
if (sbAst != null && sbAst.ParamBlock != null && sbAst.ParamBlock.Parameters != null)
{
ProcessParameters(sbAst.ParamBlock.Parameters);
}
}
if (ast is FunctionMemberAst)
{
(ast as FunctionMemberAst).Body.Visit(this.Decorator);
}
else if (ast is FunctionDefinitionAst)
{
(ast as FunctionDefinitionAst).Body.Visit(this.Decorator);
}
else
{
ast.Visit(this.Decorator);
}
Ast parent = ast;
while (parent.Parent != null)
{
parent = parent.Parent;
}
List<TypeDefinitionAst> classes = parent.FindAll(item =>
item is TypeDefinitionAst && (item as TypeDefinitionAst).IsClass, true)
.Cast<TypeDefinitionAst>().ToList();
if (outerAnalysis != null)
{
// Initialize the variables from outside
var outerDictionary = outerAnalysis.InternalVariablesDictionary;
foreach (var details in outerDictionary.Values)
{
if (details.DefinedBlock != null)
{
var assignTarget = new AssignmentTarget(details.RealName, details.Type);
assignTarget.Constant = details.Constant;
if (!_variables.ContainsKey(assignTarget.Name))
{
_variables.Add(assignTarget.Name, new VariableAnalysisDetails
{
Name = assignTarget.Name,
RealName = assignTarget.Name,
Type = assignTarget.Type
});
}
Entry.AddFirstAst(assignTarget);
}
}
foreach (var key in _variables.Keys)
{
if (outerDictionary.ContainsKey(key))
{
var outerItem = outerDictionary[key];
var innerItem = _variables[key];
innerItem.Constant = outerItem.Constant;
innerItem.Name = outerItem.Name;
innerItem.RealName = outerItem.RealName;
innerItem.Type = outerItem.Type;
}
}
}
var dictionaries = Block.SparseSimpleConstants(_variables, Entry, classes);
VariablesDictionary = dictionaries.Item1;
InternalVariablesDictionary = new Dictionary<string, VariableAnalysisDetails>(StringComparer.OrdinalIgnoreCase);
foreach (var KVP in dictionaries.Item2)
{
//.........这里部分代码省略.........