private static void ParseInnerScope(Queue <Token> tokens, Node parent, Node root) { Token scope1 = Expect(tokens, "operator", "{"); Token scope2 = Optional(tokens, "operator", "}"); while (scope2 == null) { PropNode pnode = new PropNode(); Token t1 = tokens.Dequeue(); Token t1op1 = Optional(tokens, "operator", "<"); Token flagop = null; if (t1op1 != null) { flagop = Expect(tokens, "identifier"); Token t1op2 = Expect(tokens, "operator", ">"); pnode.FlagsOpt = flagop.Value; } Token t2 = Optional(tokens, "identifier"); Token t3 = Optional(tokens, "identifier"); if (t3 != null) { pnode.Name = t3.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t2.Value, false); pnode.Flags = t1.Value; } else if (t2 != null) { pnode.Name = t2.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t1.Value, false); } else { pnode.Name = t1.Value; } Token defop = Optional(tokens, "operator", "="); if (defop != null) { Token value = tokens.Dequeue(); pnode.Default = SymbolLocator.LookupSymbol(root, value.Value, false); } Expect(tokens, "terminator", ";"); parent.childNodes.Add(pnode); scope2 = Optional(tokens, "operator", "}"); } }
public static int GetTypeSize(PropNode prop) { Symbol sym = prop.Type; // no static size for proto if (prop.Flags != null && prop.Flags == "proto") { return(0); } if (sym is WeakSymbol) { WeakSymbol wsym = sym as WeakSymbol; string key = wsym.Identifier; if (!weakTypeMap.ContainsKey(key)) { key = defaultType; } if (!String.IsNullOrEmpty(prop.FlagsOpt)) { return(Int32.Parse(prop.FlagsOpt)); } return(weakTypeMap[key].Size); } else if (sym is StrongSymbol) { StrongSymbol ssym = sym as StrongSymbol; if (ssym.Class is EnumNode) { EnumNode enode = ssym.Class as EnumNode; if (enode.Type is WeakSymbol) { return(weakTypeMap[((WeakSymbol)enode.Type).Identifier].Size); } else { return(weakTypeMap[defaultType].Size); } } } return(0); }
public static int GetTypeSize(PropNode prop) { Symbol sym = prop.Type; // no static size for proto if (prop.Flags != null && prop.Flags == "proto") { return 0; } if (sym is WeakSymbol) { WeakSymbol wsym = sym as WeakSymbol; string key = wsym.Identifier; if (!weakTypeMap.ContainsKey(key)) { key = defaultType; } if (!String.IsNullOrEmpty(prop.FlagsOpt)) { return Int32.Parse(prop.FlagsOpt); } return weakTypeMap[key].Size; } else if (sym is StrongSymbol) { StrongSymbol ssym = sym as StrongSymbol; if (ssym.Class is EnumNode) { EnumNode enode = ssym.Class as EnumNode; if (enode.Type is WeakSymbol) return weakTypeMap[((WeakSymbol)enode.Type).Identifier].Size; else return weakTypeMap[defaultType].Size; } } return 0; }
private static void ParseInnerScope(Queue<Token> tokens, Node parent, Node root) { Token scope1 = Expect(tokens, "operator", "{"); Token scope2 = Optional(tokens, "operator", "}"); while (scope2 == null) { PropNode pnode = new PropNode(); Token t1 = tokens.Dequeue(); Token t1op1 = Optional(tokens, "operator", "<"); Token flagop = null; if (t1op1 != null) { flagop = Expect(tokens, "identifier"); Token t1op2 = Expect(tokens, "operator", ">"); pnode.FlagsOpt = flagop.Value; } Token t2 = Optional(tokens, "identifier"); Token t3 = Optional(tokens, "identifier"); if (t3 != null) { pnode.Name = t3.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t2.Value, false); pnode.Flags = t1.Value; } else if (t2 != null) { pnode.Name = t2.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t1.Value, false); } else { pnode.Name = t1.Value; } Token defop = Optional(tokens, "operator", "="); if ( defop != null ) { while ( true ) { Token value = tokens.Dequeue(); pnode.Default.Add( SymbolLocator.LookupSymbol( root, value.Value, false ) ); if ( Optional( tokens, "operator", "|" ) != null ) continue; Expect( tokens, "terminator", ";" ); break; } } else { Expect( tokens, "terminator", ";" ); } Token obsolete = Optional( tokens, "identifier", "obsolete" ); if ( obsolete != null ) { pnode.Obsolete = ""; Token obsoleteReason = Optional( tokens, "string" ); if ( obsoleteReason != null ) pnode.Obsolete = obsoleteReason.Value; } parent.childNodes.Add(pnode); scope2 = Optional(tokens, "operator", "}"); } }
private long EvalEnum(EnumNode enode, PropNode prop) { long number = 0; foreach (Symbol sym in prop.Default) { long n = 0; var val = (sym as WeakSymbol).Identifier; if (new Regex("^[-0-9]+$|^0x[-0-9a-fA-F]+$").IsMatch(val)) { int bas = 10; if (val.StartsWith("0x", StringComparison.Ordinal)) { bas = 16; val = val.Substring(2); } n = Convert.ToInt64(val, bas); } else { var otherNode = enode.childNodes.Single(o => o is PropNode && (o as PropNode).Name == val) as PropNode; n = EvalEnum(enode, otherNode); } number = number | n; } return number; }
private static void ParseInnerScope(Queue <Token> tokens, Node parent, Node root) { Token scope1 = Expect(tokens, "operator", "{"); Token scope2 = Optional(tokens, "operator", "}"); while (scope2 == null) { PropNode pnode = new PropNode(); Token t1 = tokens.Dequeue(); Token t1op1 = Optional(tokens, "operator", "<"); Token flagop = null; if (t1op1 != null) { flagop = Expect(tokens, "identifier"); Token t1op2 = Expect(tokens, "operator", ">"); pnode.FlagsOpt = flagop.Value; } Token t2 = Optional(tokens, "identifier"); Token t3 = Optional(tokens, "identifier"); if (t3 != null) { pnode.Name = t3.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t2.Value, false); pnode.Flags = t1.Value; } else if (t2 != null) { pnode.Name = t2.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t1.Value, false); } else { pnode.Name = t1.Value; } Token defop = Optional(tokens, "operator", "="); if (defop != null) { while (true) { Token value = tokens.Dequeue(); pnode.Default.Add(SymbolLocator.LookupSymbol(root, value.Value, false)); if (Optional(tokens, "operator", "|") != null) { continue; } Expect(tokens, "terminator", ";"); break; } } else { Expect(tokens, "terminator", ";"); } Token obsolete = Optional(tokens, "identifier", "obsolete"); if (obsolete != null) { pnode.Obsolete = ""; Token obsoleteReason = Optional(tokens, "string"); if (obsoleteReason != null) { pnode.Obsolete = obsoleteReason.Value; } } Token removed = Optional(tokens, "identifier", "removed"); if (removed != null) { pnode.Emit = false; } parent.childNodes.Add(pnode); scope2 = Optional(tokens, "operator", "}"); } }
private static void ParseInnerScope(Queue<Token> tokens, Node parent, Node root) { Token scope1 = Expect(tokens, "operator", "{"); Token scope2 = Optional(tokens, "operator", "}"); while (scope2 == null) { PropNode pnode = new PropNode(); Token t1 = tokens.Dequeue(); Token t1op1 = Optional(tokens, "operator", "<"); Token flagop = null; if (t1op1 != null) { flagop = Expect(tokens, "identifier"); Token t1op2 = Expect(tokens, "operator", ">"); pnode.FlagsOpt = flagop.Value; } Token t2 = Optional(tokens, "identifier"); Token t3 = Optional(tokens, "identifier"); if (t3 != null) { pnode.Name = t3.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t2.Value, false); pnode.Flags = t1.Value; } else if (t2 != null) { pnode.Name = t2.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t1.Value, false); } else { pnode.Name = t1.Value; } Token defop = Optional(tokens, "operator", "="); if (defop != null) { Token value = tokens.Dequeue(); pnode.Default = SymbolLocator.LookupSymbol(root, value.Value, false); } Expect(tokens, "terminator", ";"); parent.childNodes.Add(pnode); scope2 = Optional(tokens, "operator", "}"); } }
private static void ParseInnerScope(Queue <Token> tokens, Node parent, Node root) { Token scope1 = Expect(tokens, "operator", "{"); Token scope2 = Optional(tokens, "operator", "}"); while (scope2 == null) { PropNode pnode = new PropNode(); Token t1 = tokens.Dequeue(); Token t1op1 = Optional(tokens, "operator", "<"); Token flagop = null; if (t1op1 != null) { flagop = Expect(tokens, "identifier"); Token t1op2 = Expect(tokens, "operator", ">"); pnode.FlagsOpt = flagop.Value; } Token t2 = Optional(tokens, "identifier"); Token t3 = Optional(tokens, "identifier"); if (t3 != null) { pnode.Name = t3.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t2.Value, false); pnode.Flags = t1.Value; } else if (t2 != null) { pnode.Name = t2.Value; pnode.Type = SymbolLocator.LookupSymbol(root, t1.Value, false); } else { pnode.Name = t1.Value; } Token defop = Optional(tokens, "operator", "="); if (defop != null) { while (true) { Token value = tokens.Dequeue(); pnode.Default.Add(SymbolLocator.LookupSymbol(root, value.Value, false)); if (Optional(tokens, "operator", "|") != null) { continue; } Expect(tokens, "terminator", ";"); break; } } else { Expect(tokens, "terminator", ";"); } Token obsolete = Optional(tokens, "identifier", "obsolete"); if (obsolete != null) { // Obsolete identifiers are output when generating the language, but include a warning pnode.Obsolete = ""; Token obsoleteReason = Optional(tokens, "string"); if (obsoleteReason != null) { pnode.Obsolete = obsoleteReason.Value; } } Token removed = Optional(tokens, "identifier", "removed"); if (removed != null) { // Removed identifiers are not output when generating the language pnode.Emit = false; // Consume and record the removed reason so it's available in the node graph pnode.Removed = ""; Token removedReason = Optional(tokens, "string"); if (removedReason != null) { pnode.Removed = removedReason.Value; } } parent.childNodes.Add(pnode); scope2 = Optional(tokens, "operator", "}"); } }