本文整理汇总了C#中AstNode.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# AstNode.GetType方法的具体用法?C# AstNode.GetType怎么用?C# AstNode.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstNode
的用法示例。
在下文中一共展示了AstNode.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetNodeTitle
string GetNodeTitle(AstNode node)
{
StringBuilder b = new StringBuilder();
b.Append(node.Role.ToString());
b.Append(": ");
b.Append(node.GetType().Name);
bool hasProperties = false;
foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
if (p.Name == "NodeType" || p.Name == "IsNull")
continue;
if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) {
if (!hasProperties) {
hasProperties = true;
b.Append(" (");
} else {
b.Append(", ");
}
b.Append(p.Name);
b.Append(" = ");
try {
object val = p.GetValue(node, null);
b.Append(val != null ? val.ToString() : "**null**");
} catch (TargetInvocationException ex) {
b.Append("**" + ex.InnerException.GetType().Name + "**");
}
}
}
if (hasProperties)
b.Append(")");
return b.ToString();
}
示例2: AreEqual
public static bool? AreEqual(AstNode node1, AstNode node2)
{
if (node1 == node2)
return true;
if (node1 == null || node1.IsNull || node2 == null || node2.IsNull)
return false;
Type nodeType = node1.GetType();
if (nodeType != node2.GetType())
return false;
if (node1.Role != node2.Role)
return false;
AstNode child1 = node1.FirstChild;
AstNode child2 = node2.FirstChild;
bool? result = true;
while (result != false && (child1 != null || child2 != null)) {
result &= AreEqual(child1, child2);
child1 = child1.NextSibling;
child2 = child2.NextSibling;
}
if (nodeTypesWithoutExtraInfo.Contains(nodeType))
return result;
if (nodeType == typeof(Identifier))
return ((Identifier)node1).Name == ((Identifier)node2).Name;
return null;
}
示例3: PrintNode
static void PrintNode (AstNode node)
{
Console.WriteLine ("Parent:" + node.GetType ());
Console.WriteLine ("Children:");
foreach (var c in node.Children)
Console.WriteLine (c.GetType () +" at:"+ c.StartLocation +"-"+ c.EndLocation + " Role: "+ c.Role);
Console.WriteLine ("----");
}
示例4: CreateException
public virtual IVisitorException CreateException(AstNode node, string message)
{
if (String.IsNullOrEmpty(message))
{
message = String.Format("Language construction {0} is not supported", node.GetType().Name);
}
return new EmitterException(node, message);
}
示例5: Serialize
public static string Serialize(AstNode Node)
{
var Parameters = new List<string>();
foreach (var Child in Node.Childs)
{
Parameters.Add(Serialize(Child));
}
return Node.GetType().Name + "(" + String.Join(", ", Parameters) + ")";
}
示例6: GenerateNode
public static void GenerateNode(JSContext context, TextWriter textWriter, AstNode node)
{
if (node == null)
{
throw new ArgumentNullException("node");
}
if (node is IJSBasicNode)
{
IJSBasicNode jsBasicNode = (IJSBasicNode)node;
jsBasicNode.GenerateJavaScript(context, textWriter);
}
else if (node is Token)
{
Token t = (Token)node;
switch (t.Terminal.Name)
{
case "VARIABLE":
if (t.Text.EndsWith("$"))
{
textWriter.Write("s_" + t.Text.Substring(0, t.Text.Length - 1));
}
else
{
throw new BasicSyntaxErrorException("Invalid variable name: " + t.Text);
}
break;
case "BOOLEAN_OP":
{
switch (t.Text.ToLowerInvariant())
{
case "and":
textWriter.Write("&&");
break;
case "or":
textWriter.Write("||");
break;
default:
textWriter.Write(t.Text);
break;
}
}
break;
default:
textWriter.Write(ConvertToJavascript(t.Text));
break;
}
textWriter.Write(" ");
}
else
{
throw new ApplicationException("Unhandled statement type: " + node.GetType().FullName);
}
}
示例7: Optimize
public AstNode Optimize(AstNode AstNode)
{
//if (AstNode != null)
{
//Console.WriteLine("Optimize.AstNode: {0}", AstNode);
AstNode.TransformNodes(Optimize);
var AstNodeType = AstNode.GetType();
if (GenerateMappings.ContainsKey(AstNodeType))
{
AstNode = (AstNode)GenerateMappings[AstNodeType].Invoke(this, new[] { AstNode });
}
else
{
//throw(new NotImplementedException(String.Format("Don't know how to optimize {0}", AstNodeType)));
}
}
return AstNode;
}
示例8: SerializeAsXml
private static void SerializeAsXml(AstNode Node, IndentedStringBuilder Out, bool Spaces)
{
var NodeName = Node.GetType().Name;
Out.Write("<" + NodeName);
var Parameters = Node.Info;
if (Parameters != null)
{
foreach (var Pair in Parameters)
{
Out.Write(String.Format(" {0}=\"{1}\"", Pair.Key, Pair.Value));
}
}
if (Node.Childs.Count() > 0)
{
Out.Write(">");
if (Spaces) Out.WriteNewLine();
if (Spaces)
{
Out.Indent(() =>
{
foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
});
}
else
{
foreach (var Child in Node.Childs) SerializeAsXml(Child, Out, Spaces);
}
Out.Write("</" + NodeName + ">");
if (Spaces) Out.WriteNewLine();
}
else
{
Out.Write(" />");
if (Spaces) Out.WriteNewLine();
}
}
示例9: CheckPositionConsistency
public static void CheckPositionConsistency (AstNode node, string currentFileName, IDocument currentDocument = null)
{
if (currentDocument == null)
currentDocument = new ReadOnlyDocument(File.ReadAllText(currentFileName));
string comment = "(" + node.GetType ().Name + " at " + node.StartLocation + " in " + currentFileName + ")";
var pred = node.StartLocation <= node.EndLocation;
if (!pred)
PrintNode (node);
Assert.IsTrue(pred, "StartLocation must be before EndLocation " + comment);
var prevNodeEnd = node.StartLocation;
var prevNode = node;
for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
bool assertion = child.StartLocation >= prevNodeEnd;
if (!assertion) {
PrintNode (prevNode);
PrintNode (node);
}
Assert.IsTrue(assertion, currentFileName + ": Child " + child.GetType () +" (" + child.StartLocation + ")" +" must start after previous sibling " + prevNode.GetType () + "(" + prevNode.StartLocation + ")");
CheckPositionConsistency(child, currentFileName, currentDocument);
prevNodeEnd = child.EndLocation;
prevNode = child;
}
Assert.IsTrue(prevNodeEnd <= node.EndLocation, "Last child must end before parent node ends " + comment);
}
示例10: CompileRecursive
private void CompileRecursive(AstNode node, Syt syt, StringBuilder sb)
{
if (node is AstBinOp) CompileBinOp((AstBinOp)node, syt, sb);
else if (node is AstBoolLit) CompileBoolLit((AstBoolLit)node, syt, sb);
else if (node is AstCall) CompileCall((AstCall)node, syt, sb);
else if (node is AstClass) CompileClass((AstClass)node, syt, sb);
else if (node is AstClassDecl) CompileClassDecl((AstClassDecl)node, syt, sb);
else if (node is AstDo) CompileDo((AstDo)node, syt, sb);
else if (node is AstDot) CompileDot((AstDot)node, syt, sb);
else if (node is AstIf) CompileIf((AstIf)node, syt, sb);
else if (node is AstIndex) CompileIndex((AstIndex)node, syt, sb);
else if (node is AstIntLit) CompileIntLit((AstIntLit)node, syt, sb);
else if (node is AstLet) CompileLet((AstLet)node, syt, sb);
else if (node is AstNull) CompileNull((AstNull)node, syt, sb);
else if (node is AstReturn) CompileReturn((AstReturn)node, syt, sb);
else if (node is AstStringLit) CompileStringLit((AstStringLit)node, syt, sb);
else if (node is AstSubroutine) CompileSubroutine((AstSubroutine)node, syt, sb);
else if (node is AstThis) CompileThis((AstThis)node, syt, sb);
else if (node is AstUnOp) CompileUnOp((AstUnOp)node, syt, sb);
else if (node is AstVarDecl) CompileVarDecl((AstVarDecl)node, syt, sb);
else if (node is AstVarRef) CompileVarRef((AstVarRef)node, syt, sb);
else if (node is AstWhile) CompileWhile((AstWhile)node, syt, sb);
else throw new ArgumentException("Unkonwn node " + node.GetType());
}
示例11: Enter
/// <summary>
/// Get the first expression to be excecuted if the instruction pointer is at the start of the given node.
/// Try blocks may not be entered in any way. If possible, the try block is returned as the node to be executed.
/// </summary>
AstNode Enter(AstNode node, HashSet<AstNode> visitedNodes)
{
if (node == null)
throw new ArgumentNullException();
if (!visitedNodes.Add(node))
return null; // Infinite loop
AstLabel label = node as AstLabel;
if (label != null) {
return Exit(label, visitedNodes);
}
AstExpression expr = node as AstExpression;
if (expr != null) {
if (expr.Code == AstCode.Br || expr.Code == AstCode.Leave) {
AstLabel target = (AstLabel)expr.Operand;
// Early exit - same try-block
if (GetParents(expr).OfType<AstTryCatchBlock>().FirstOrDefault() == GetParents(target).OfType<AstTryCatchBlock>().FirstOrDefault())
return Enter(target, visitedNodes);
// Make sure we are not entering any try-block
var srcTryBlocks = GetParents(expr).OfType<AstTryCatchBlock>().Reverse().ToList();
var dstTryBlocks = GetParents(target).OfType<AstTryCatchBlock>().Reverse().ToList();
// Skip blocks that we are already in
int i = 0;
while(i < srcTryBlocks.Count && i < dstTryBlocks.Count && srcTryBlocks[i] == dstTryBlocks[i]) i++;
if (i == dstTryBlocks.Count) {
return Enter(target, visitedNodes);
} else {
AstTryCatchBlock dstTryBlock = dstTryBlocks[i];
// Check that the goto points to the start
AstTryCatchBlock current = dstTryBlock;
while(current != null) {
foreach(AstNode n in current.TryBlock.Body) {
if (n is AstLabel) {
if (n == target)
return dstTryBlock;
} else if (!n.Match(AstCode.Nop)) {
current = n as AstTryCatchBlock;
break;
}
}
}
return null;
}
} else if (expr.Code == AstCode.Nop) {
return Exit(expr, visitedNodes);
} else if (expr.Code == AstCode.LoopOrSwitchBreak) {
AstNode breakBlock = GetParents(expr).First(n => n is AstSwitch);
return Exit(breakBlock, new HashSet<AstNode>() { expr });
} else {
return expr;
}
}
AstBlock block = node as AstBlock;
if (block != null) {
if (block.EntryGoto != null) {
return Enter(block.EntryGoto, visitedNodes);
} else if (block.Body.Count > 0) {
return Enter(block.Body[0], visitedNodes);
} else {
return Exit(block, visitedNodes);
}
}
AstTryCatchBlock tryCatch = node as AstTryCatchBlock;
if (tryCatch != null) {
return tryCatch;
}
AstSwitch astSwitch = node as AstSwitch;
if (astSwitch != null) {
return astSwitch.Condition;
}
throw new NotSupportedException(node.GetType().ToString());
}
示例12: StartNew
public static JavaScriptSymbol StartNew(AstNode node, int startLine, int startColumn, int sourceFileId)
{
if (startLine == int.MaxValue)
{
throw new ArgumentOutOfRangeException("startLine");
}
if (startColumn == int.MaxValue)
{
throw new ArgumentOutOfRangeException("startColumn");
}
return new JavaScriptSymbol
{
// destination line/col number are fed to us as zero-based, so add one to get to
// the one-based values we desire. Context objects store the source line/col as
// one-based already.
m_startLine = startLine + 1,
m_startColumn = startColumn + 1,
m_sourceContext = node != null ? node.Context : null,
m_symbolType = node != null ? node.GetType().Name : "[UNKNOWN]",
m_sourceFileId = sourceFileId,
};
}
示例13: GetDefaultXMLNamespace
private string GetDefaultXMLNamespace(AstNode astNode)
{
return GetDefaultXMLNamespace(astNode.GetType());
}
示例14: GetPropertyBinding
private PropertyBindingAttributePair GetPropertyBinding(AstNode astNode, XName xObjectName, bool patchDefaultNamespace)
{
Type astNodeType = astNode.GetType();
if (this._PropertyMappingDictionary.ContainsKey(astNodeType))
{
Dictionary<XName, PropertyBindingAttributePair> propertyBinding = this._PropertyMappingDictionary[astNodeType];
if (propertyBinding.ContainsKey(xObjectName))
{
return propertyBinding[xObjectName];
}
else if (patchDefaultNamespace && xObjectName.NamespaceName.Equals(String.Empty))
{
// targetNamespace is not applied to attributes, so this code will use the DefaultXMLNamespace to perform XName matching when specified (i.e. for attributes)
return GetPropertyBinding(astNode, XName.Get(xObjectName.LocalName, GetDefaultXMLNamespace(astNode)), false);
}
}
return null;
}
示例15: NotSupported
private void NotSupported(AstNode node)
{
context.ReportError(node.Region, node.GetType().Name + " is unsupported");
wasSuccessful = false;
}