codecbuilderinfo.java
来自「ASN.1工具源代码,包括编译源码生成工具和各种基本类型构造类型的编解码实现代码」· Java 代码 · 共 582 行 · 第 1/2 页
JAVA
582 行
{ // We are registering an import into the current module..... System.err.println("Registering import of "+module_reference+"."+type_reference+" in module "+getCurrentModuleName()); getCurrentModule().registerImport(module_reference, type_reference); } public void createTypeInfoFor(String type_reference, ASTType t) { CodecBuilderInfo info = CodecBuilderInfo.getInfo(); System.err.println("createTypeInfoFor("+type_reference+")"); boolean has_tagging = false; int tag_class = -1; int tag_number = -1; boolean is_implicit = ( info.default_tagging_is_explicit == true ? false : true ); String base_type = null; // Firstly, we are interested if this is a tagged type, in which case // we need to do a bit of extra work if ( t.which == 1 ) // It's a builtin type { ASTBuiltinType bit = (ASTBuiltinType) (t.jjtGetChild(0)); if ( bit.which == 6 ) { has_tagging = true; // It's a tagged type, extract tagging information and proceed // with the actual type info... ASTTaggedType tt = (ASTTaggedType) (bit.jjtGetChild(0)); is_implicit = tt.isImplicit(); t = tt.getType(); ASTTag tag = tt.getTag(); if ( tag.hasTagClass ) tag_class = tag.getTagClass().tag_class; else tag_class = 0x80; // Assume context tag class if none given ASTClassNumber cn = tag.getClassNumber(); if ( cn.which == 1 ) { // It's a number tag_number = cn.getNumber().getNumber().intValue(); } else { System.err.println("Unhandled tag number type"); System.exit(0); // LATER: Should throw an exception here } } } TypeInfo ti = null; // If the type was tagged, we have all the tagging info and for sure, // t is now the type definition, incuding base type & other info if ( t.which == 1 ) // It's a builtin type { ASTBuiltinType bit = (ASTBuiltinType) (t.jjtGetChild(0)); switch ( bit.which ) { case 0: // Integer ti = new IntegerTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); break; case 1: // BitString ti = new BitStringTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); break; case 2: // SetOrSequence // Get type to see which it really is ASTSetOrSequenceType sos = (ASTSetOrSequenceType)(bit.jjtGetChild(0)); if ( sos.which == 1 ) { // It's a set System.err.println("Set not yet handled"); System.exit(1); } else { // It's a Sequence ti = new SequenceTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); sos.getSequenceMembers((SequenceTypeInfo)ti); } break; case 3: // SetOrSequenceOf <<type>> System.err.println("Processing SetOrSequenceOf Type"); ASTSetOrSequenceOfType soso = (ASTSetOrSequenceOfType)(bit.jjtGetChild(0)); // Hmmm... We need to think about what we are going to do with the X part of Sequence Of X // We may need to create a type reference if it's (for example SequenceOf Sequence) // So... Figure out what the type we have a sequence of... ASTType sot = null; ASTSizeConstraint sc = null; // We need to account for size constriants here... if ( soso.has_size_constraint ) { sc = (ASTSizeConstraint) (soso.jjtGetChild(0)); sot = (ASTType) (soso.jjtGetChild(1)); } else { sot = (ASTType) (soso.jjtGetChild(0)); } String subtype_reference = null; if ( sot.which == 1 ) { ASTBuiltinType sub_bit = (ASTBuiltinType) (sot.jjtGetChild(0)); System.err.println("SEQUENCEOF Built in type ("+sub_bit.which+")"); // subtype_reference depends upon internal type.... switch ( sub_bit.which ) { case 2: System.err.println("SEQUENCEOF SEQUENCE "+info.getInternalClass(bit.which)); subtype_reference = type_reference+"Item"+getNextInlineCounter(); createTypeInfoFor(subtype_reference, sot); break; case 4: System.err.println("SEQUENCEOF CHOICE "+info.getInternalClass(bit.which)); subtype_reference = type_reference+"_choice"+getNextInlineCounter(); createTypeInfoFor(subtype_reference, sot); break; default: // System.err.println("cbi SEQUENCEOF something ok.. "+sub_bit.which+" "+info.getInternalClass(bit.which)); System.err.println("cbi SEQUENCEOF something ok.. "+sub_bit.which+" "+info.getInternalClass(sub_bit.which)); // subtype_reference = info.getInternalClass(sub_bit.which); subtype_reference = sub_bit.getTypeName(); break; } } else { ASTDefinedType sub_dt = (ASTDefinedType) (sot.jjtGetChild(0)); System.err.println("SEQUENCEOF defined type "+ sub_dt.getTypeReference().typeref); subtype_reference = sub_dt.getTypeReference().typeref; } if ( soso.which == 1 ) { // It's a set of System.err.println("SetOf not yet handled"); System.exit(1); } else { // It's a sequence of // ti = new SequenceOfTypeInfo("SequenceOf", // We create a custom codec, but the base type is Vector // Need to figure out what this is a sequence of... might have embedded type info ti = new SequenceOfTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), "java.util.Vector", info.getCurrentModule(), subtype_reference); } break; case 4: // Choice ti = new ChoiceTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); ((ASTChoiceType)(bit.jjtGetChild(0))).getChoiceMembers((ChoiceTypeInfo)ti); break; case 5: // Selection System.out.println("Better add typeinfo for selection"); System.exit(1); break; case 6: System.err.println("Fatal error: Can't have tagged type under a tagged type"); System.exit(0); break; case 7: // Any System.out.println("Better add typeinfo for Any"); System.exit(1); break; case 8: // Enumeration ti = new EnumTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); // Need to process enum types ((ASTEnumeratedType)(bit.jjtGetChild(0))).getEnumerations((EnumTypeInfo)ti); break; case 9: // OctetString ti = new OctetStringTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); break; case 10: // OID ti = new OIDTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); break; case 11: // Real System.out.println("Better add typeinfo for Real"); System.exit(1); break; case 12: // Boolean System.out.println("Better add typeinfo for Boolean"); System.exit(1); break; case 13: // Null ti = new NullTypeInfo(type_reference, true, tag_class, tag_number, is_implicit, bit.getTypeName(), info.getInternalClass(bit.which), info.getCurrentModule()); break; default: System.out.println("Unhandled internal type"); System.exit(1); break; } info.registerType(info.getCurrentModuleName(),type_reference,ti); } else { ASTDefinedType dt = (ASTDefinedType) (t.jjtGetChild(0)); System.err.print("Defined Type: "); ti = new DefinedTypeInfo(type_reference, false, tag_class, tag_number, is_implicit, dt.getTypeReference().typeref, null, info.getCurrentModule()); info.registerType(info.getCurrentModuleName(),type_reference,ti); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?