public override CILInstructionR BuildNode(ParseTreeNode node) { var instrRParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_R); CILInstructionR result = null; var ldcr4ParseTreeNode = instrRParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldcr4); if (ldcr4ParseTreeNode != null) { result = new LoadConstantFloatInstruction(); } var ldcr8ParseTreeNode = instrRParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldcr8); if (ldcr8ParseTreeNode != null) { result = new LoadConstantDoubleInstruction(); } if (result != null) { var float64ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.float64); result.Value = Float64ParseTreeNodeHelper.GetValue(float64ParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction r."); }
public static CILType GetType(ParseTreeNode node) { var valuetypeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_valuetype); if (valuetypeParseTreeNode != null) { return(GetValueType(node)); } var classParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_class); if (classParseTreeNode != null) { return(GetClassType(node)); } var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); if (typeParseTreeNode != null) { return(GetArrayType(node)); } return(GetSimpleType(node)); }
public static CILTypeSpecification GetValue(ParseTreeNode node) { CILClassName className = null; CILType type = null; var classNameParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.className); if (classNameParseTreeNode != null) { className = ClassNameParseTreeNodeHelper.GetClassName(classNameParseTreeNode); } var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); if (typeParseTreeNode != null) { type = TypeParseTreeNodeHelper.GetType(typeParseTreeNode); } return(new CILTypeSpecification { ClassName = className, Type = type }); }
public static string GetMethodName(ParseTreeNode node) { var dotCtorParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.dotCtor); if (dotCtorParseTreeNode != null) { return(".ctor"); } var dotCctorParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_dotCctor); if (dotCctorParseTreeNode != null) { return(".cctor"); } var name1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.name1); if (name1ParseTreeNode != null) { return(Name1ParseTreeNodeHelper.GetValue(name1ParseTreeNode)); } throw new ArgumentException("Cannot get method name value."); }
public override CILClassField BuildNode(ParseTreeNode node) { var result = new CILClassField(); var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id); var fieldName = IdParseTreeNodeHelper.GetValue(idParseTreeNode); result.Name = fieldName; var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); var fieldType = TypeParseTreeNodeHelper.GetType(typeParseTreeNode); result.Type = fieldType; var fieldAttrParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.fieldAttr); result.Attributes = FieldAttrParseTreeNodeHelper.GetAllAttributes(fieldAttrParseTreeNode); var initOptParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.initOpt); var fieldInitParseTreeNode = initOptParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.fieldInit); if (fieldInitParseTreeNode != null) { var int64ParseTreeNode = fieldInitParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.int64); var fieldInitValue = Int64ParseTreeNodeHelper.GetValue(int64ParseTreeNode); result.InitValue = fieldInitValue; } return(result); }
public override CILInstructionI BuildNode(ParseTreeNode node) { var instrIParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_I); CILInstructionI result = null; var ldci4ParseTreeNode = instrIParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci4); if (ldci4ParseTreeNode != null) { result = new LoadConstantIntInstruction(); } var ldci4sParseTreeNode = instrIParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci4s); if (ldci4sParseTreeNode != null) { result = new LoadConstantIntShortInstruction(); } if (result != null) { var int32ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.int32); result.Value = Int32ParseTreeNodeHelper.GetValue(int32ParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction i."); }
public override CILInstructionField BuildNode(ParseTreeNode node) { CILInstructionField result = null; var instrFieldParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_FIELD); var ldfldParseTreeNode = instrFieldParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldfld); if (ldfldParseTreeNode != null) { result = new LoadFieldInstruction(); } var ldfldaParseTreeNode = instrFieldParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldflda); if (ldfldaParseTreeNode != null) { result = new LoadFieldAddressInstruction(); } var ldsfldParseTreeNode = instrFieldParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldsfld); if (ldsfldParseTreeNode != null) { result = new LoadStaticFieldInstruction(); } var stfldParseTreeNode = instrFieldParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stfld); if (stfldParseTreeNode != null) { result = new SetFieldInstruction(); } var stsfldParseTreeNode = instrFieldParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stsfld); if (stsfldParseTreeNode != null) { result = new SetStaticFieldInstruction(); } if (result != null) { var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); result.FieldType = TypeParseTreeNodeHelper.GetType(typeParseTreeNode); var typeSpecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.typeSpec); result.FieldOwnerTypeSpecification = TypeSpecParseTreeNodeHelper.GetValue(typeSpecParseTreeNode); var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id); result.FieldName = IdParseTreeNodeHelper.GetValue(idParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction field."); }
public override CILProgram BuildNode(ParseTreeNode node) { var classes = new List <CILClass>(); var assemblies = new List <CILAssembly>(); var externalAssemblies = new List <CILExternalAssembly>(); var modules = new List <CILModule>(); var declsParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.decls); while (declsParseTreeNode != null) { var declParseTreeNode = declsParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.decl); var classDeclsParseTreeNode = declParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.classDecls); if (classDeclsParseTreeNode != null) { var cilClass = _classBuilder.BuildNode(declParseTreeNode); classes.Add(cilClass); } var assemblyDeclsParseTreeNode = declParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.assemblyDecls); if (assemblyDeclsParseTreeNode != null) { var cilAssembly = _assemblyBuilder.BuildNode(declParseTreeNode); assemblies.Add(cilAssembly); } var assemblyRefDeclsParseTreeNode = declParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.assemblyRefDecls); if (assemblyRefDeclsParseTreeNode != null) { var cilExternalAssembly = _externalAssemblyBuilder.BuildNode(declParseTreeNode); externalAssemblies.Add(cilExternalAssembly); } var moduleHeadParseTreeNode = declParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.moduleHead); if (moduleHeadParseTreeNode != null) { var cilModule = _moduleBuilder.BuildNode(moduleHeadParseTreeNode); modules.Add(cilModule); } declsParseTreeNode = declsParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.decls); } foreach (var cilClass in classes) { cilClass.ExtendsClass = classes.FirstOrDefault(c => c.ClassName.UniqueName == cilClass.Extends.UniqueName); } var result = new CILProgram { Classes = classes, Assemblies = assemblies, ExternalAssemblies = externalAssemblies, Modules = modules }; return(result); }
public static string GetValue(ParseTreeNode node) { var lexicalsIdParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.LEXICALS_ID); if (lexicalsIdParseTreeNode != null) { return(lexicalsIdParseTreeNode.Token.ValueString); } var lexicalsSqstringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.LEXICALS_SQSTRING); if (lexicalsSqstringParseTreeNode != null) { return(lexicalsSqstringParseTreeNode.Token.ValueString); } throw new ArgumentException("Canno recognize id."); }
public override CILInstructionVar BuildNode(ParseTreeNode node) { var instrVarParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_VAR); CILInstructionVar result = null; var ldargsParseTreeNode = instrVarParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldargs); if (ldargsParseTreeNode != null) { result = new LoadArgumentShortInstruction(); } var ldlocasParseTreeNode = instrVarParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldlocas); if (ldlocasParseTreeNode != null) { result = new LoadLocalVariableAddressShortInstruction(); } var ldlocsParseTreeNode = instrVarParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldlocs); if (ldlocsParseTreeNode != null) { result = new LoadLocalVariableShortInstruction(); } var stlocsParseTreeNode = instrVarParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stlocs); if (stlocsParseTreeNode != null) { result = new SetLocalVariableShortInstruction(); } if (result != null) { var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id); result.VariableId = IdParseTreeNodeHelper.GetValue(idParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction var."); }
public static CILType GetClassType(ParseTreeNode node) { var classNameParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.className); var className = ClassNameParseTreeNodeHelper.GetClassName(classNameParseTreeNode); return(new CILType { ClassName = className }); }
public static CILClassName GetClassName(ParseTreeNode node) { var assemblyName = string.Empty; var name1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.name1); if (name1ParseTreeNode != null) { assemblyName = Name1ParseTreeNodeHelper.GetValue(name1ParseTreeNode); } var slashedNameParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.slashedName); var className = SlashedNameParseTreeNodeHelper.GetValue(slashedNameParseTreeNode); return(new CILClassName { AssemblyName = assemblyName, ClassName = className }); }
public static CILOwnerType GetValue(ParseTreeNode node) { var result = new CILOwnerType(); var typeSpecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.typeSpec); result.TypeSpecification = TypeSpecParseTreeNodeHelper.GetValue(typeSpecParseTreeNode); return(result); }
public override CILModule BuildNode(ParseTreeNode node) { var result = new CILModule(); var name1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.name1); var moduleName = Name1ParseTreeNodeHelper.GetValue(name1ParseTreeNode); result.ModuleName = moduleName; return(result); }
public static int GetValue(ParseTreeNode node) { var lexicalsInt32DecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.LEXICALS_INT32_DEC); if (lexicalsInt32DecParseTreeNode != null) { var decLiteral = lexicalsInt32DecParseTreeNode.Token.ValueString; return(int.Parse(decLiteral)); } var lexicalsInt32HexParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.LEXICALS_INT32_HEX); if (lexicalsInt32HexParseTreeNode != null) { var hexLiteral = lexicalsInt32HexParseTreeNode.Token.ValueString; hexLiteral = hexLiteral.Substring(2); return(int.Parse(hexLiteral, NumberStyles.HexNumber)); } throw new ArgumentException("Cannot recognize int32 lexical."); }
public override CILExternalAssembly BuildNode(ParseTreeNode node) { var result = new CILExternalAssembly(); var assemblyRefHeadParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.assemblyRefHead); var assemblyRefHeadName1ParseTreeNode = assemblyRefHeadParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.name1); var assemblyName = Name1ParseTreeNodeHelper.GetValue(assemblyRefHeadName1ParseTreeNode); result.AssemblyName = assemblyName; return(result); }
public static List <string> GetNames(ParseTreeNode node) { var sigArgs1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.sigArgs1); if (sigArgs1ParseTreeNode != null) { var result = SigArgs1ParseTreeNodeHelper.GetNames(sigArgs1ParseTreeNode); return(result); } return(new List <string>()); }
public static OrderedDictionary GetLocalsDictionary(ParseTreeNode node) { var sigArgs1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.sigArgs1); if (sigArgs1ParseTreeNode != null) { var result = SigArgs1ParseTreeNodeHelper.GetLocalsDictionary(sigArgs1ParseTreeNode); return(result); } return(new OrderedDictionary()); }
public static CILType GetArrayType(ParseTreeNode node) { var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); var elementsType = GetType(typeParseTreeNode); var dimensions = 1; var bounds1ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.bounds1); if (bounds1ParseTreeNode != null) { var bounds = Bounds1ParseTreeNodeHelper.GetBounds(bounds1ParseTreeNode); dimensions = bounds.Count; } var arrayType = elementsType.SimpleType.MakeArrayType(dimensions); return(new CILType { SimpleType = arrayType }); }
public override CILInstructionSwitch BuildNode(ParseTreeNode node) { var instructionSwitchParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_SWITCH); CILInstructionSwitch result = null; var switchParseTreeNode = instructionSwitchParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_switch); if (switchParseTreeNode != null) { result = new SwitchInstruction(); } if (result != null) { var labelsParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.labels); result.Labels = LabelsParseTreeNodeHelper.GetLabels(labelsParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction switch."); }
public override CILInstructionString BuildNode(ParseTreeNode node) { CILInstructionString result = null; var instrStringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_STRING); var ldstrParseTreeNode = instrStringParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldstr); if (ldstrParseTreeNode != null) { result = new LoadStringInstruction(); } if (result != null) { var compQstringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.compQstring); result.StringValue = CompQstringParseTreeNodeHelper.GetValue(compQstringParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction string."); }
public override CILInstructionType BuildNode(ParseTreeNode node) { var instrTypeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_TYPE); CILInstructionType result = null; var boxParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_box); if (boxParseTreeNode != null) { result = new BoxInstruction(); } var newarrParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_newarr); if (newarrParseTreeNode != null) { result = new NewArrayInstruction(); } var unboxanyParseTreeNode = instrTypeParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_unboxany); if (unboxanyParseTreeNode != null) { result = new UnboxAnyInstruction(); } if (result != null) { var typeSpecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.typeSpec); result.TypeSpecification = TypeSpecParseTreeNodeHelper.GetValue(typeSpecParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction type."); }
public override CILInstructionTok BuildNode(ParseTreeNode node) { var instrTokHeadParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.instr_tok_head); var instrTokParseTreeNode = instrTokHeadParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.INSTR_TOK); CILInstructionTok result = null; var ldtokenParseTreeNode = instrTokParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.keyword_ldtoken); if (ldtokenParseTreeNode != null) { result = new LoadTokenInstruction(); } if (result != null) { var ownerTypeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.ownerType); result.OwnerType = OwnerTypeParseTreeNodeHelper.GetValue(ownerTypeParseTreeNode); return(result); } throw new NotImplementedException(); }
public static string GetValue(ParseTreeNode node) { var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id); if (idParseTreeNode != null) { return(IdParseTreeNodeHelper.GetValue(idParseTreeNode)); } var name1ParseTreeNodes = node.GetAllChildsWithGrammarName(GrammarNames.name1); if (name1ParseTreeNodes != null) { return(string.Join(".", name1ParseTreeNodes.Select(n1 => GetValue(n1)))); } throw new ArgumentException("Cannot get name1 value."); }
public override CILInstructionMethod BuildNode(ParseTreeNode node) { CILInstructionMethod result = null; var instrMethodParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_METHOD); var callParseTreeNode = instrMethodParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_call); if (callParseTreeNode != null) { result = new CallInstruction(); } var callvirtParseTreeNode = instrMethodParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_callvirt); if (callvirtParseTreeNode != null) { result = new CallVirtualInstruction(); } var newobjParseTreeNode = instrMethodParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_newobj); if (newobjParseTreeNode != null) { result = new NewObjectInstruction(); } if (result != null) { var typeParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.type); result.MethodReturnType = TypeParseTreeNodeHelper.GetType(typeParseTreeNode); var typeSpecParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.typeSpec); result.TypeSpecification = TypeSpecParseTreeNodeHelper.GetValue(typeSpecParseTreeNode); var methodNameParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.methodName); result.MethodName = MethodNameParseTreeNodeHelper.GetMethodName(methodNameParseTreeNode); var sigArgs0ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.sigArgs0); result.MethodArgumentTypes = SigArgs0ParseTreeNodeHelper.GetTypes(sigArgs0ParseTreeNode); var callConvParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.callConv); result.CallConvention = CallConvParseTreeNodeHelper.GetValue(callConvParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction method."); }
public override CILClass BuildNode(ParseTreeNode node) { var methods = new List <CILMethod>(); var constructors = new List <CILMethod>(); var fields = new List <CILClassField>(); var classHeadParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.classHead); var classNameParseTreeNode = classHeadParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.className); var className = ClassNameParseTreeNodeHelper.GetClassName(classNameParseTreeNode); var extendsClauseParseTreeNode = classHeadParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.extendsClause); var extendsClassNameParseTreeNode = extendsClauseParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.className); var extendsClassName = ClassNameParseTreeNodeHelper.GetClassName(extendsClassNameParseTreeNode); var classDeclsParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.classDecls); while (classDeclsParseTreeNode != null) { var classDeclParseTreeNode = classDeclsParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.classDecl); var methodDeclsParseTreeNode = classDeclParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.methodDecls); if (methodDeclsParseTreeNode != null) { var method = _methodBuilder.BuildNode(classDeclParseTreeNode); if (method.IsConstructor) { constructors.Add(method); } else { methods.Add(method); } } var fieldDeclParseTreeNode = classDeclParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.fieldDecl); if (fieldDeclParseTreeNode != null) { var field = _fieldBuilder.BuildNode(fieldDeclParseTreeNode); fields.Add(field); } classDeclsParseTreeNode = classDeclsParseTreeNode.GetFirstChildWithGrammarName(GrammarNames.classDecls); } fields.Reverse(); var staticFields = new Dictionary <string, object>(); foreach (var field in fields) { if (field.IsStatic()) { staticFields.Add(field.Name, null); } } var result = new CILClass { Fields = fields, Methods = methods, Constructors = constructors, ClassName = className, Extends = extendsClassName, StaticFields = staticFields }; foreach (var resultMethod in result.Methods) { resultMethod.ParentClass = result; } foreach (var resultConstructor in result.Constructors) { resultConstructor.ParentClass = result; } return(result); }
public static CILType GetSimpleType(ParseTreeNode node) { Type simpleType = null; var boolParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_bool); if (boolParseTreeNode != null) { simpleType = typeof(bool); } var charParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_char); if (charParseTreeNode != null) { simpleType = typeof(char); } var float32ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_float32); if (float32ParseTreeNode != null) { simpleType = typeof(float); } var float64ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_float64); if (float64ParseTreeNode != null) { simpleType = typeof(double); } var int8ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_int8); if (int8ParseTreeNode != null) { simpleType = typeof(sbyte); } var int16ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_int16); if (int16ParseTreeNode != null) { simpleType = typeof(short); } var int32ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_int32); if (int32ParseTreeNode != null) { simpleType = typeof(int); } var int64ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_int64); if (int64ParseTreeNode != null) { simpleType = typeof(long); } var stringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_string); if (stringParseTreeNode != null) { simpleType = typeof(string); } var uint8ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_uint8); if (uint8ParseTreeNode != null) { simpleType = typeof(byte); } var uint16ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_uint16); if (uint16ParseTreeNode != null) { simpleType = typeof(ushort); } var uint32ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_uint32); if (uint32ParseTreeNode != null) { simpleType = typeof(uint); } var uint64ParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_uint64); if (uint64ParseTreeNode != null) { simpleType = typeof(ulong); } var voidParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_void); if (voidParseTreeNode != null) { simpleType = typeof(void); } var objectParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.keyword_object); if (objectParseTreeNode != null) { simpleType = typeof(object); } if (simpleType != null) { return(new CILType { SimpleType = simpleType }); } throw new ArgumentException("Cannot recognize simple type."); }
public static string GetValue(ParseTreeNode node) { var lexicalsQstringParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.LEXICALS_QSTRING); return(lexicalsQstringParseTreeNode.Token.ValueString); }
public override CILInstructionNone BuildNode(ParseTreeNode node) { var instrNoneParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_NONE); var addParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_add); if (addParseTreeNode != null) { var addInstruction = new AddInstruction(); return(addInstruction); } var andParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_and); if (andParseTreeNode != null) { var andInstruction = new AndInstruction(); return(andInstruction); } var ceqParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ceq); if (ceqParseTreeNode != null) { var checkIfEqualInstruction = new CheckIfEqualInstruction(); return(checkIfEqualInstruction); } var cgtParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_cgt); if (cgtParseTreeNode != null) { var checkIfGreaterInstruction = new CheckIfGreaterInstruction(); return(checkIfGreaterInstruction); } var cltParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_clt); if (cltParseTreeNode != null) { var checkIfLessInstruction = new CheckIfLessInstruction(); return(checkIfLessInstruction); } var convi1ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convi1); if (convi1ParseTreeNode != null) { var convertToSByteInstruction = new ConvertToSByteInstruction(); return(convertToSByteInstruction); } var convi2ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convi2); if (convi2ParseTreeNode != null) { var convertToShortInstruction = new ConvertToShortInstruction(); return(convertToShortInstruction); } var convi4ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convi4); if (convi4ParseTreeNode != null) { var convertToIntInstruction = new ConvertToIntInstruction(); return(convertToIntInstruction); } var convi8ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convi8); if (convi8ParseTreeNode != null) { var convertToLongInstruction = new ConvertToLongInstruction(); return(convertToLongInstruction); } var convr4ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convr4); if (convr4ParseTreeNode != null) { var convertToFloatInstruction = new ConvertToFloatInstruction(); return(convertToFloatInstruction); } var convr8ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convr8); if (convr8ParseTreeNode != null) { var convertToDoubleInstruction = new ConvertToDoubleInstruction(); return(convertToDoubleInstruction); } var convu8ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_convu8); if (convu8ParseTreeNode != null) { var convertToUnsignedLongInstruction = new ConvertToUnsignedLongInstruction(); return(convertToUnsignedLongInstruction); } var divParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_div); if (divParseTreeNode != null) { var divideInstruction = new DivideInstruction(); return(divideInstruction); } var dupParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_dup); if (dupParseTreeNode != null) { var duplicateInstruction = new DuplicateInstruction(); return(duplicateInstruction); } var ldarg0ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldarg0); if (ldarg0ParseTreeNode != null) { var loadArgument0Instruction = new LoadArgument0Instruction(); return(loadArgument0Instruction); } var ldarg1ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldarg1); if (ldarg1ParseTreeNode != null) { var loadArgument1Instruction = new LoadArgument1Instruction(); return(loadArgument1Instruction); } var ldarg2ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldarg2); if (ldarg2ParseTreeNode != null) { var loadArgument2Instruction = new LoadArgument2Instruction(); return(loadArgument2Instruction); } var ldarg3ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldarg3); if (ldarg3ParseTreeNode != null) { var loadArgument3Instruction = new LoadArgument3Instruction(); return(loadArgument3Instruction); } var ldci40ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci40); if (ldci40ParseTreeNode != null) { var loadConstantInt0Instruction = new LoadConstantInt0Instruction(); return(loadConstantInt0Instruction); } var ldci41ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci41); if (ldci41ParseTreeNode != null) { var loadConstantInt1Instruction = new LoadConstantInt1Instruction(); return(loadConstantInt1Instruction); } var ldci42ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci42); if (ldci42ParseTreeNode != null) { var loadConstantInt2Instruction = new LoadConstantInt2Instruction(); return(loadConstantInt2Instruction); } var ldci43ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci43); if (ldci43ParseTreeNode != null) { var loadConstantInt3Instruction = new LoadConstantInt3Instruction(); return(loadConstantInt3Instruction); } var ldci44ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci44); if (ldci44ParseTreeNode != null) { var loadConstantInt4Instruction = new LoadConstantInt4Instruction(); return(loadConstantInt4Instruction); } var ldci45ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci45); if (ldci45ParseTreeNode != null) { var loadConstantInt5Instruction = new LoadConstantInt5Instruction(); return(loadConstantInt5Instruction); } var ldci46ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci46); if (ldci46ParseTreeNode != null) { var loadConstantInt6Instruction = new LoadConstantInt6Instruction(); return(loadConstantInt6Instruction); } var ldci47ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci47); if (ldci47ParseTreeNode != null) { var loadConstantInt7Instruction = new LoadConstantInt7Instruction(); return(loadConstantInt7Instruction); } var ldci48ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci48); if (ldci48ParseTreeNode != null) { var loadConstantInt8Instruction = new LoadConstantInt8Instruction(); return(loadConstantInt8Instruction); } var ldci4m1ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldci4m1); if (ldci4m1ParseTreeNode != null) { var loadConstantIntMinus1Instruction = new LoadConstantIntMinus1Instruction(); return(loadConstantIntMinus1Instruction); } var ldelemi4ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldelemi4); if (ldelemi4ParseTreeNode != null) { var loadElementIntInstruction = new LoadElementIntInstruction(); return(loadElementIntInstruction); } var ldelemrefParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldelemref); if (ldelemrefParseTreeNode != null) { var loadElementRefInstruction = new LoadElementRefInstruction(); return(loadElementRefInstruction); } var ldlenParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldlen); if (ldlenParseTreeNode != null) { var loadLengthInstruction = new LoadLengthInstruction(); return(loadLengthInstruction); } var ldloc0ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldloc0); if (ldloc0ParseTreeNode != null) { var loadLocalVariable0Instruction = new LoadLocalVariable0Instruction(); return(loadLocalVariable0Instruction); } var ldloc1ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldloc1); if (ldloc1ParseTreeNode != null) { var loadLocalVariable1Instruction = new LoadLocalVariable1Instruction(); return(loadLocalVariable1Instruction); } var ldloc2ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldloc2); if (ldloc2ParseTreeNode != null) { var loadLocalVariable2Instruction = new LoadLocalVariable2Instruction(); return(loadLocalVariable2Instruction); } var ldloc3ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ldloc3); if (ldloc3ParseTreeNode != null) { var loadLocalVariable3Instruction = new LoadLocalVariable3Instruction(); return(loadLocalVariable3Instruction); } var mulParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_mul); if (mulParseTreeNode != null) { var multiplyInstruction = new MultiplyInstruction(); return(multiplyInstruction); } var notParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_not); if (notParseTreeNode != null) { var notInstruction = new NotInstruction(); return(notInstruction); } var orParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_or); if (orParseTreeNode != null) { var orInstruction = new OrInstruction(); return(orInstruction); } var popParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_pop); if (popParseTreeNode != null) { var popInstruction = new PopInstruction(); return(popInstruction); } var remParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_rem); if (remParseTreeNode != null) { var remainderInstruction = new RemainderInstruction(); return(remainderInstruction); } var retParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_ret); if (retParseTreeNode != null) { var returnInstruction = new ReturnInstruction(); return(returnInstruction); } var shlParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_shl); if (shlParseTreeNode != null) { var shiftLeftInstruction = new ShiftLeftInstruction(); return(shiftLeftInstruction); } var shrParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_shr); if (shrParseTreeNode != null) { var shiftRightInstruction = new ShiftRightInstruction(); return(shiftRightInstruction); } var stelemi4ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stelemi4); if (stelemi4ParseTreeNode != null) { var setElementIntInstruction = new SetElementIntInstruction(); return(setElementIntInstruction); } var stelemrefParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stelemref); if (stelemrefParseTreeNode != null) { var setElementRefInstruction = new SetElementRefInstruction(); return(setElementRefInstruction); } var stloc0ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stloc0); if (stloc0ParseTreeNode != null) { var setLocalVariable0Instruction = new SetLocalVariable0Instruction(); return(setLocalVariable0Instruction); } var stloc1ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stloc1); if (stloc1ParseTreeNode != null) { var setLocalVariable1Instruction = new SetLocalVariable1Instruction(); return(setLocalVariable1Instruction); } var stloc2ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stloc2); if (stloc2ParseTreeNode != null) { var setLocalVariable2Instruction = new SetLocalVariable2Instruction(); return(setLocalVariable2Instruction); } var stloc3ParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_stloc3); if (stloc3ParseTreeNode != null) { var setLocalVariable3Instruction = new SetLocalVariable3Instruction(); return(setLocalVariable3Instruction); } var subParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_sub); if (subParseTreeNode != null) { var subtractInstruction = new SubtractInstruction(); return(subtractInstruction); } var xorParseTreeNode = instrNoneParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_xor); if (xorParseTreeNode != null) { var xorInstruction = new XorInstruction(); return(xorInstruction); } throw new ArgumentException("Cannot recognize CIL instruction none."); }
public override CILInstructionBranchTarget BuildNode(ParseTreeNode node) { var instructionBranchTargetParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.INSTR_BRTARGET); CILInstructionBranchTarget result = null; var beqsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_beqs); if (beqsParseTreeNode != null) { result = new BranchOnEqualShortInstruction(); } var bgesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bges); if (bgesParseTreeNode != null) { result = new BranchOnGreaterOrEqualShortInstruction(); } var blesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bles); if (blesParseTreeNode != null) { result = new BranchOnLessOrEqualShortInstruction(); } var bltsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_blts); if (bltsParseTreeNode != null) { result = new BranchOnLessShortInstruction(); } var bneunsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_bneuns); if (bneunsParseTreeNode != null) { result = new BranchOnNotEqualOrUnorderedShortInstruction(); } var brParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_br); if (brParseTreeNode != null) { result = new BranchInstruction(); } var brfalsesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brfalses); if (brfalsesParseTreeNode != null) { result = new BranchOnFalseShortInstruction(); } var brsParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brs); if (brsParseTreeNode != null) { result = new BranchShortInstruction(); } var brtruesParseTreeNode = instructionBranchTargetParseTreeNode?.GetFirstChildWithGrammarName(GrammarNames.keyword_brtrues); if (brtruesParseTreeNode != null) { result = new BranchOnTrueShortInstruction(); } if (result != null) { var idParseTreeNode = node.GetFirstChildWithGrammarName(GrammarNames.id); result.Label = IdParseTreeNodeHelper.GetValue(idParseTreeNode); return(result); } throw new ArgumentException("Cannot recognize CIL instruction branch target."); }