private TypeScope CreateInterfaceCommonType(string name, int offset) { TypeScope ctn = (TypeScope)members[offset]; if (ctn != null) { return(ctn); } bool in_scope = false; if (name != null) { in_scope = true; } bool is_interface = br.ReadBoolean(); if (is_interface)//ïðîïóñêàåì ôëàã - èíòåðôåéñíîñòè { name = GetString(br.ReadInt32()); } else { name = br.ReadString(); } //br.ReadInt32(); //ssyy //×èòàåì, ÿâëÿåòñÿ ëè òèï èíòåðôåéñîì bool type_is_interface = (br.ReadByte() == 1); //×èòàåì, ÿâëÿåòñÿ ëè òèï äåëåãàòîì bool type_is_delegate = (br.ReadByte() == 1); //\ssyy bool type_is_generic_definition = (br.ReadByte() == 1); if (type_is_generic_definition) { throw new Exception(); } TypeScope base_type = GetTypeReference(); bool is_value_type = br.ReadBoolean(); //ssyy //×èòàåì ïîääåðæèâàåìûå èíòåðôåéñû int interf_count = br.ReadInt32(); List <TypeScope> interfaces = new List <TypeScope>(); for (int i = 0; i < interf_count; i++) { interfaces.Add(GetTypeReference()); } //\ssyy object low_val = null; object upper_val = null; PascalABCCompiler.SemanticTree.type_access_level tal = (PascalABCCompiler.SemanticTree.type_access_level)br.ReadByte(); PascalABCCompiler.SemanticTree.type_special_kind tsk = (PascalABCCompiler.SemanticTree.type_special_kind)br.ReadByte(); bool is_sealed = br.ReadBoolean(); bool is_abstract = br.ReadBoolean(); if (tsk == PascalABCCompiler.SemanticTree.type_special_kind.diap_type) { low_val = CreateExpression(); upper_val = CreateExpression(); } TypeScope element_type = null; if (CanReadObject()) { element_type = GetTypeReference(); } switch (tsk) { case PascalABCCompiler.SemanticTree.type_special_kind.none_kind: ctn = new TypeScope(SymbolKind.Class, cur_scope, base_type); break; case PascalABCCompiler.SemanticTree.type_special_kind.record: ctn = new TypeScope(SymbolKind.Struct, cur_scope, base_type); break; case PascalABCCompiler.SemanticTree.type_special_kind.array_wrapper: ctn = new ArrayScope(); break; case PascalABCCompiler.SemanticTree.type_special_kind.enum_kind: ctn = new EnumScope(SymbolKind.Enum, cur_scope, base_type); break; case PascalABCCompiler.SemanticTree.type_special_kind.set_type: ctn = new SetScope(element_type); break; case PascalABCCompiler.SemanticTree.type_special_kind.array_kind: if (!in_scope) { ctn = new ArrayScope(); } else { return(null); } break; case PascalABCCompiler.SemanticTree.type_special_kind.diap_type: ctn = new DiapasonScope(low_val, upper_val); break; case PascalABCCompiler.SemanticTree.type_special_kind.typed_file: ctn = new FileScope(element_type, null); break; case PascalABCCompiler.SemanticTree.type_special_kind.binary_file: ctn = new FileScope(null, null); break; } ctn.declaringUnit = root_scope; ctn.si.name = name; ctn.is_abstract = is_abstract; ctn.is_final = is_sealed; AddMember(ctn, offset); ctn.elementType = element_type; br.ReadInt32(); br.ReadInt32();//attributes //common_namespace_node ns = cun.namespaces[0]; byte flag = br.ReadByte(); int def_prop_off = 0; if (flag == 1) { def_prop_off = br.ReadInt32(); } ReadDebugInfo(); ctn.si.description = ctn.GetDescription(); //ñîçäàåì scope äëÿ êëàññà //ctn = new wrapped_common_type_node(this, base_type, name, tal, ns, scope, loc, offset); //members[offset] = ctn; //AddMember(ctn, offset); RestoreAllMembers(ctn); return(ctn); }
private TypeScope GetTypeReference() { byte b = br.ReadByte(); //(ssyy) Âñòàâèë switch âìåñòî óñëîâèé TypeScope tn; switch (b) { case 255: return(null); case 1: //åñëè òèï îïèñàí â ìîäóëå int offset = br.ReadInt32(); tn = (TypeScope)members[offset]; if (tn == null) { return(GetCommonType(offset)); } return(tn); case 0: //åñëè ýòî èìïîðòèð. òèï tn = null; int pos = br.ReadInt32(); tn = ext_members[pos] as TypeScope; if (tn != null) { return(tn); } int tmp = (int)br.BaseStream.Position; br.BaseStream.Seek(ext_pos + pos, SeekOrigin.Begin); if ((ImportKind)br.ReadByte() == ImportKind.Common) { //tn = ReadCommonExtType(); //ext_members[pos] = tn; tn = new UnknownScope(new SymInfo("$", SymbolKind.Type, "$")); ext_members[pos] = tn; } else // ýòî íåòîâñêèé òèï { tn = ReadNetExtType(); ext_members[pos] = tn; } br.BaseStream.Seek(tmp, SeekOrigin.Begin); return(tn); case 2: //ýòî ìàññèâ //simple_array type = new simple_array(GetTypeReference(),br.ReadInt32()); TypeScope type = new ArrayScope(GetTypeReference(), new TypeScope[0]); return(type); case 3: //ýòî óêàçàòåëü TypeScope pointed_type = GetTypeReference(); return(new PointerScope(pointed_type)); case 4: //ýòî äèíàìè÷åñêèé ìàññèâ ReadDebugInfo(); TypeScope elem_type = GetTypeReference(); return(new ArrayScope(elem_type, null)); case 6: //return GetTemplateInstance(); return(null); case 7: return(GetGenericInstance()); case 8: //return GetShortStringType(); return(null); } return(null); }
private static string GetTypeName(TypeScope typ) { StringBuilder sb = new StringBuilder(); if (typ == null) { return(""); } if (typ is CompiledScope) { sb.Append((typ as CompiledScope).ctn.FullName); } else if (typ is ArrayScope) { ArrayScope arr = typ as ArrayScope; if (arr.is_dynamic_arr) { ArrayScope tmp = arr; int j = 1; while (tmp.elementType is ArrayScope && (tmp.elementType as ArrayScope).is_dynamic_arr) { j++; tmp = tmp.elementType as ArrayScope; } sb.Append(GetTypeName(tmp.elementType)); for (int k = 0; k < j; k++) { sb.Append("[]"); } } else { sb.Append("@array["); for (int j = 0; j < arr.indexes.Length; j++) { sb.Append(GetTypeName(arr.indexes[j])); if (j < arr.indexes.Length - 1) { sb.Append(","); } } sb.Append("]"); sb.Append("[" + GetTypeName(arr.elementType) + "]"); } } else if (typ is ProcType) { sb.Append(GetDelegateName((typ as ProcType).target)); } else if (typ is SetScope) { sb.Append("@set[" + GetTypeName((typ as SetScope).elementType) + "]"); } else if (typ is FileScope) { if (typ.elementType != null) { sb.Append("@fileof[" + GetTypeName(typ.elementType) + "]"); } else { sb.Append("@file"); } } else if (typ is TypeSynonim) { sb.Append(GetTypeName((typ as TypeSynonim).actType)); } else if (typ is PointerScope) { PointerScope ptr = typ as PointerScope; int j = 1; while (ptr.ref_type is PointerScope) { j++; ptr = ptr.ref_type as PointerScope; } for (int k = 0; k < j; k++) { sb.Append("*"); } sb.Append(ptr.ref_type); } else if (typ is ShortStringScope) { sb.Append("@string[" + (typ as ShortStringScope).Length + "]"); } else if (typ is DiapasonScope) { sb.Append("@diap[" + (typ as DiapasonScope).left + ".." + (typ as DiapasonScope).right + "]"); } else { sb.Append(typ.declaringUnit.si.name + "." + typ.si.name); } return(sb.ToString()); }