private void RestoreAllMembers(TypeScope scope) { int num = br.ReadInt32(); Hashtable ht = new Hashtable(); for (int i = 0; i < num; i++) { string name = br.ReadString(); int offset = br.ReadInt32(); SymScope tmp = cur_scope; cur_scope = scope; SymScope ss = CreateInterfaceInClassMember(name, offset); br.ReadByte(); br.ReadByte(); if (ht.ContainsKey(name) && ss is ProcScope) { (ht[name] as ProcScope).nextProc = ss as ProcScope; ht[name] = ss; } else if (ss is ProcScope) { ht[name] = ss; } cur_scope = tmp; if (ss != null) { scope.AddName(name, ss); } } }
internal XmlMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access) { _scope = scope; _accessor = accessor; _access = access; _shallow = scope == null; }
private ElementScope GetParameter(ProcScope func) { int offset = (int)br.BaseStream.Position - start_pos; br.ReadByte(); string s = br.ReadString(); TypeScope tn = GetTypeReference(); concrete_parameter_type cpt = (concrete_parameter_type)br.ReadByte(); ElementScope p = new ElementScope(new SymInfo(s, SymbolKind.Parameter, s), tn, null, null); bool is_params = br.ReadBoolean(); if (is_params) { p.param_kind = parametr_kind.params_parametr; } else { switch (cpt) { case concrete_parameter_type.cpt_const: p.param_kind = parametr_kind.const_parametr; break; case concrete_parameter_type.cpt_var: p.param_kind = parametr_kind.var_parametr; break; case concrete_parameter_type.cpt_none: p.param_kind = parametr_kind.none; break; } } br.ReadBoolean(); if (CanReadObject()) { br.ReadInt32(); //CreateExpression(); } br.ReadInt32(); //attributes //members[offset] = p; return(p); }
private ElementScope CreateInterfaceProperty(string name, int offset) { ElementScope prop = members[offset] as ElementScope; if (prop != null) { return(prop); } int name_ref = br.ReadInt32(); TypeScope type = GetTypeReference(); if (br.ReadByte() == 1) { br.ReadInt32(); } if (br.ReadByte() == 1) { br.ReadInt32(); } int num = br.ReadInt32(); List <ElementScope> prms = new List <ElementScope>(); for (int i = 0; i < num; i++) { prms.Add(GetParameter(null)); } br.ReadInt32(); field_access_level fal = (field_access_level)br.ReadByte(); polymorphic_state ps = (polymorphic_state)br.ReadByte(); //ReadDebugInfo(); prop = new ElementScope(new SymInfo(name, SymbolKind.Property, name), type, cur_scope); prop.declaringUnit = root_scope; switch (fal) { case field_access_level.fal_internal: prop.acc_mod = access_modifer.internal_modifer; break; case field_access_level.fal_private: prop.acc_mod = access_modifer.private_modifer; return(null); case field_access_level.fal_protected: prop.acc_mod = access_modifer.protected_modifer; break; case field_access_level.fal_public: prop.acc_mod = access_modifer.public_modifer; break; } switch (ps) { case polymorphic_state.ps_static: prop.is_static = true; break; case polymorphic_state.ps_virtual: prop.is_virtual = true; break; } //members[offset] = prop; AddMember(prop, offset); return(prop); }
private void CheckScope(TypeScope scope) { if (_scope == null) { _scope = scope; } else if (_scope != scope) { throw new InvalidOperationException(ResXml.XmlMappingsScopeMismatch); } }
public AstHelper(ModuleBuilder moduleBuilder) { ModuleBuilder = moduleBuilder; Expecting = new Expecting(); Functions = new FunctionScope(); Variables = new VariableScope(); Types = new TypeScope(); Errors = new ErrorSet(); ReturnScope = new ReturnScope(); }
private TypeScope GetTemplateInstance() { TypeScope tc = null;//GetTemplateClassReference(); int params_count = br.ReadInt32(); for (int i = 0; i < params_count; i++) { tc.AddGenericInstanciation(GetTypeReference()); } return(tc); }
private ElementScope CreateInterfaceNamespaceVariable(string name, int offset) { br.ReadInt32(); br.ReadBoolean(); br.ReadInt32(); TypeScope type = GetTypeReference(); ElementScope nv = new ElementScope(new SymInfo(name, SymbolKind.Variable, name), type, cur_scope); nv.declaringUnit = root_scope; AddMember(nv, offset); return(nv); }
private TypeScope GetGenericInstance() { TypeScope ts = GetTypeReference(); int params_count = br.ReadInt32(); ts.ClearInstances(); for (int i = 0; i < params_count; i++) { ts.AddGenericInstanciation(GetTypeReference()); } ts.si.description = ts.ToString(); return(ts); }
/// <include file='doc\SoapReflectionImporter.uex' path='docs/doc[@for="SoapReflectionImporter.SoapReflectionImporter3"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public SoapReflectionImporter(SoapAttributeOverrides attributeOverrides, string defaultNamespace) { if (defaultNamespace == null) { defaultNamespace = String.Empty; } if (attributeOverrides == null) { attributeOverrides = new SoapAttributeOverrides(); } _attributeOverrides = attributeOverrides; _defaultNs = defaultNamespace; _typeScope = new TypeScope(); _modelScope = new ModelScope(_typeScope); }
private ElementScope CreateInterfaceClassField(string name, int offset) { ElementScope field = members[offset] as ElementScope; if (field != null) { return(field); } int name_off = br.ReadInt32(); TypeScope type = GetTypeReference(); field = new ElementScope(new SymInfo(name, SymbolKind.Field, name), type, cur_scope); field.declaringUnit = root_scope; AddMember(field, offset); object initv = null; if (CanReadObject()) { initv = CreateExpression(); } br.ReadInt32(); PascalABCCompiler.SemanticTree.field_access_level fal = (PascalABCCompiler.SemanticTree.field_access_level)br.ReadByte(); PascalABCCompiler.SemanticTree.polymorphic_state ps = (PascalABCCompiler.SemanticTree.polymorphic_state)br.ReadByte(); switch (fal) { case PascalABCCompiler.SemanticTree.field_access_level.fal_internal: field.acc_mod = access_modifer.internal_modifer; break; case PascalABCCompiler.SemanticTree.field_access_level.fal_private: field.acc_mod = access_modifer.private_modifer; return(null); case PascalABCCompiler.SemanticTree.field_access_level.fal_protected: field.acc_mod = access_modifer.protected_modifer; break; case PascalABCCompiler.SemanticTree.field_access_level.fal_public: field.acc_mod = access_modifer.public_modifer; break; } switch (ps) { case PascalABCCompiler.SemanticTree.polymorphic_state.ps_static: field.is_static = true; break; case PascalABCCompiler.SemanticTree.polymorphic_state.ps_virtual: field.is_virtual = true; break; } //field = new class_field(name,type,cont,ps,fal,loc); field.cnst_val = initv; //members[offset] = field; AddMember(field, offset); return(field); }
public TypeScope GetCommonType(int offset) { TypeScope ctn = members[offset] as TypeScope; if (ctn != null) { return(ctn); } int pos = (int)br.BaseStream.Position; br.BaseStream.Seek(start_pos + offset, SeekOrigin.Begin); br.ReadByte(); ctn = CreateInterfaceCommonType(null, offset); br.BaseStream.Seek(pos, SeekOrigin.Begin); return(ctn); }
internal XmlMembersMapping(TypeScope scope, ElementAccessor accessor, XmlMappingAccess access) : base(scope, accessor, access) { MembersMapping mapping = (MembersMapping)accessor.Mapping; StringBuilder key = new StringBuilder(); key.Append(":"); _mappings = new XmlMemberMapping[mapping.Members.Length]; for (int i = 0; i < _mappings.Length; i++) { if (mapping.Members[i].TypeDesc.Type != null) { key.Append(GenerateKey(mapping.Members[i].TypeDesc.Type, null, null)); key.Append(":"); } _mappings[i] = new XmlMemberMapping(mapping.Members[i]); } SetKeyInternal(key.ToString()); }
public static string stringFromScope(TypeScope the_enum) { switch (the_enum) { case TypeScope.Scope_all: return("all"); case TypeScope.Scope_last: return("last"); case TypeScope.Scope_movement: return("movement"); default: Debug.Assert(false); return(null); } }
public static string GetDocumentation(TypeScope t) { try { if (t.declaringUnit != null) { CodeCompletionTools.XmlDoc xdoc = (CodeCompletionTools.XmlDoc)ht[t.declaringUnit]; if (xdoc != null) { string s = GetNormalHint(xdoc.GetDocumentation("T:" + t.si.name, true)); return(s); } } } catch (Exception e) { } return(""); }
protected override void InitCallbacks() { TypeScope scope = _mapping.Scope; foreach (TypeMapping mapping in scope.TypeMappings) { if (mapping.IsSoap && (mapping is StructMapping || mapping is EnumMapping) && !mapping.TypeDesc.IsRoot) { AddWriteCallback( mapping.TypeDesc.Type, mapping.TypeName, mapping.Namespace, CreateXmlSerializationWriteCallback(mapping, mapping.TypeName, mapping.Namespace, mapping.TypeDesc.IsNullable) ); } } }
public MissingTypeError(string typeName, TypeScope scope, SourceLocation location) : base(location) { _typeName = typeName; _scope = scope; }
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 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()); }
public TypeWithSameNameAlreadyDefinedError(string typeName, TypeScope scope, SourceLocation location) : base(location) { _typeName = typeName; _scope = scope; }
internal XmlMapping(TypeScope scope, ElementAccessor accessor) : this(scope, accessor, XmlMappingAccess.Read | XmlMappingAccess.Write) { }
private ArrayMapping ImportArrayMapping(XmlSchemaType type, string ns) { ArrayMapping arrayMapping; if (type.Name == Soap.Array && ns == Soap.Encoding) { arrayMapping = new ArrayMapping(); TypeMapping mapping = GetRootMapping(); ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = Soap.UrType; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } if (!(type.DerivedFrom.Name == Soap.Array && type.DerivedFrom.Namespace == Soap.Encoding)) { return(null); } // the type should be a XmlSchemaComplexType XmlSchemaContentModel model = ((XmlSchemaComplexType)type).ContentModel; // the Content should be an restriction if (!(model.Content is XmlSchemaComplexContentRestriction)) { return(null); } arrayMapping = new ArrayMapping(); XmlSchemaComplexContentRestriction restriction = (XmlSchemaComplexContentRestriction)model.Content; for (int i = 0; i < restriction.Attributes.Count; i++) { XmlSchemaAttribute attribute = restriction.Attributes[i] as XmlSchemaAttribute; if (attribute != null && attribute.RefName.Name == Soap.ArrayType && attribute.RefName.Namespace == Soap.Encoding) { // read the value of the wsdl:arrayType attribute string arrayType = null; if (attribute.UnhandledAttributes != null) { foreach (XmlAttribute a in attribute.UnhandledAttributes) { if (a.LocalName == Wsdl.ArrayType && a.NamespaceURI == Wsdl.Namespace) { arrayType = a.Value; break; } } } if (arrayType != null) { string dims; XmlQualifiedName typeName = TypeScope.ParseWsdlArrayType(arrayType, out dims, attribute); TypeMapping mapping; TypeDesc td = Scope.GetTypeDesc(typeName.Name, typeName.Namespace); if (td != null && td.IsPrimitive) { mapping = new PrimitiveMapping(); mapping.TypeDesc = td; mapping.TypeName = td.DataType.Name; } else { mapping = ImportType(typeName, false); } ElementAccessor itemAccessor = new ElementAccessor(); itemAccessor.IsSoap = true; itemAccessor.Name = typeName.Name; itemAccessor.Namespace = ns; itemAccessor.Mapping = mapping; itemAccessor.IsNullable = true; itemAccessor.Form = XmlSchemaForm.None; arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = itemAccessor.Mapping.TypeDesc.CreateArrayTypeDesc(); arrayMapping.TypeName = "ArrayOf" + CodeIdentifier.MakePascal(itemAccessor.Mapping.TypeName); return(arrayMapping); } } } XmlSchemaParticle particle = restriction.Particle; if (particle is XmlSchemaAll || particle is XmlSchemaSequence) { XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle; if (group.Items.Count != 1 || !(group.Items[0] is XmlSchemaElement)) { return(null); } XmlSchemaElement itemElement = (XmlSchemaElement)group.Items[0]; if (!itemElement.IsMultipleOccurrence) { return(null); } ElementAccessor itemAccessor = ImportElement(itemElement, ns); arrayMapping.Elements = new ElementAccessor[] { itemAccessor }; arrayMapping.TypeDesc = ((TypeMapping)itemAccessor.Mapping).TypeDesc.CreateArrayTypeDesc(); } else { return(null); } return(arrayMapping); }
internal XmlTypeMapping(TypeScope scope, ElementAccessor accessor) : base(scope, accessor) { }
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); }
internal void Depends(XmlSchemaObject item, ArrayList refs) { if (item == null || _scope[item] != null) { return; } Type t = item.GetType(); if (typeof(XmlSchemaType).IsAssignableFrom(t)) { XmlQualifiedName baseName = XmlQualifiedName.Empty; XmlSchemaType baseType = null; XmlSchemaParticle particle = null; XmlSchemaObjectCollection attributes = null; if (item is XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType)item; if (ct.ContentModel != null) { XmlSchemaContent content = ct.ContentModel.Content; if (content is XmlSchemaComplexContentRestriction) { baseName = ((XmlSchemaComplexContentRestriction)content).BaseTypeName; attributes = ((XmlSchemaComplexContentRestriction)content).Attributes; } else if (content is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content; if (restriction.BaseType != null) { baseType = restriction.BaseType; } else { baseName = restriction.BaseTypeName; } attributes = restriction.Attributes; } else if (content is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content; attributes = extension.Attributes; particle = extension.Particle; baseName = extension.BaseTypeName; } else if (content is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content; attributes = extension.Attributes; baseName = extension.BaseTypeName; } } else { attributes = ct.Attributes; particle = ct.Particle; } if (particle is XmlSchemaGroupRef) { XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle; particle = ((XmlSchemaGroup)_schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle; } else if (particle is XmlSchemaGroupBase) { particle = (XmlSchemaGroupBase)particle; } } else if (item is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)item; XmlSchemaSimpleTypeContent content = simpleType.Content; if (content is XmlSchemaSimpleTypeRestriction) { baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType; baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (content is XmlSchemaSimpleTypeList) { XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content; if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty) { baseName = list.ItemTypeName; } if (list.ItemType != null) { baseType = list.ItemType; } } else if (content is XmlSchemaSimpleTypeRestriction) { baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (t == typeof(XmlSchemaSimpleTypeUnion)) { XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes; if (memberTypes != null) { for (int i = 0; i < memberTypes.Length; i++) { XmlSchemaType type = (XmlSchemaType)_schemas.Find(memberTypes[i], typeof(XmlSchemaType), false); AddRef(refs, type); } } } } if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace) { baseType = (XmlSchemaType)_schemas.Find(baseName, typeof(XmlSchemaType), false); } if (baseType != null) { AddRef(refs, baseType); } if (particle != null) { Depends(particle, refs); } if (attributes != null) { for (int i = 0; i < attributes.Count; i++) { Depends(attributes[i], refs); } } } else if (t == typeof(XmlSchemaElement)) { XmlSchemaElement el = (XmlSchemaElement)item; if (!el.SubstitutionGroup.IsEmpty) { if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace) { XmlSchemaElement head = (XmlSchemaElement)_schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false); AddRef(refs, head); } } if (!el.RefName.IsEmpty) { el = (XmlSchemaElement)_schemas.Find(el.RefName, typeof(XmlSchemaElement), false); AddRef(refs, el); } else if (!el.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)_schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(el.SchemaType, refs); } } else if (t == typeof(XmlSchemaGroup)) { Depends(((XmlSchemaGroup)item).Particle); } else if (t == typeof(XmlSchemaGroupRef)) { XmlSchemaGroup group = (XmlSchemaGroup)_schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false); AddRef(refs, group); } else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t)) { foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttributeGroupRef)) { XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)_schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false); AddRef(refs, group); } else if (t == typeof(XmlSchemaAttributeGroup)) { foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttribute)) { XmlSchemaAttribute at = (XmlSchemaAttribute)item; if (!at.RefName.IsEmpty) { at = (XmlSchemaAttribute)_schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false); AddRef(refs, at); } else if (!at.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)_schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(at.SchemaType, refs); } } if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t)) { XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes; if (attrs != null) { for (int i = 0; i < attrs.Length; i++) { XmlAttribute attribute = attrs[i]; if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace) { string dims; XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item); XmlSchemaType type = (XmlSchemaType)_schemas.Find(qname, typeof(XmlSchemaType), false); AddRef(refs, type); } } } } }
internal static bool GenerateSerializerToStream(XmlMapping[] xmlMappings, Type[] types, string defaultNamespace, Assembly assembly, Hashtable assemblies, Stream stream) { var compiler = new Compiler(); try { var scopeTable = new Hashtable(); foreach (XmlMapping mapping in xmlMappings) { scopeTable[mapping.Scope] = mapping; } var scopes = new TypeScope[scopeTable.Keys.Count]; scopeTable.Keys.CopyTo(scopes, 0); assemblies.Clear(); var importedTypes = new Hashtable(); foreach (TypeScope scope in scopes) { foreach (Type t in scope.Types) { compiler.AddImport(t, importedTypes); Assembly a = t.Assembly; string name = a.FullName; if (assemblies[name] != null) { continue; } if (!a.GlobalAssemblyCache) { assemblies[name] = a; } } } for (int i = 0; i < types.Length; i++) { compiler.AddImport(types[i], importedTypes); } compiler.AddImport(typeof(object).Assembly); compiler.AddImport(typeof(System.Xml.Serialization.XmlSerializer).Assembly); var writer = new IndentedWriter(compiler.Source, false); writer.WriteLine("[assembly:System.Security.AllowPartiallyTrustedCallers()]"); writer.WriteLine("[assembly:System.Security.SecurityTransparent()]"); writer.WriteLine("[assembly:System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]"); if (assembly != null && types.Length > 0) { for (int i = 0; i < types.Length; i++) { Type type = types[i]; if (type == null) { continue; } if (DynamicAssemblies.IsTypeDynamic(type)) { throw new InvalidOperationException(SR.Format(SR.XmlPregenTypeDynamic, types[i].FullName)); } } writer.Write("[assembly:"); writer.Write(typeof(XmlSerializerVersionAttribute).FullName); writer.Write("("); writer.Write("ParentAssemblyId="); ReflectionAwareCodeGen.WriteQuotedCSharpString(writer, GenerateAssemblyId(types[0])); writer.Write(", Version="); ReflectionAwareCodeGen.WriteQuotedCSharpString(writer, ThisAssembly.Version); if (defaultNamespace != null) { writer.Write(", Namespace="); ReflectionAwareCodeGen.WriteQuotedCSharpString(writer, defaultNamespace); } writer.WriteLine(")]"); } var classes = new CodeIdentifiers(); classes.AddUnique("XmlSerializationWriter", "XmlSerializationWriter"); classes.AddUnique("XmlSerializationReader", "XmlSerializationReader"); string suffix = null; if (types != null && types.Length == 1 && types[0] != null) { suffix = CodeIdentifier.MakeValid(types[0].Name); if (types[0].IsArray) { suffix += "Array"; } } writer.WriteLine("namespace " + GeneratedAssemblyNamespace + " {"); writer.Indent++; writer.WriteLine(); string writerClass = "XmlSerializationWriter" + suffix; writerClass = classes.AddUnique(writerClass, writerClass); var writerCodeGen = new XmlSerializationWriterCodeGen(writer, scopes, "public", writerClass); writerCodeGen.GenerateBegin(); string[] writeMethodNames = new string[xmlMappings.Length]; for (int i = 0; i < xmlMappings.Length; i++) { writeMethodNames[i] = writerCodeGen.GenerateElement(xmlMappings[i]); } writerCodeGen.GenerateEnd(); writer.WriteLine(); string readerClass = "XmlSerializationReader" + suffix; readerClass = classes.AddUnique(readerClass, readerClass); var readerCodeGen = new XmlSerializationReaderCodeGen(writer, scopes, "public", readerClass); readerCodeGen.GenerateBegin(); string[] readMethodNames = new string[xmlMappings.Length]; for (int i = 0; i < xmlMappings.Length; i++) { readMethodNames[i] = readerCodeGen.GenerateElement(xmlMappings[i]); } readerCodeGen.GenerateEnd(readMethodNames, xmlMappings, types); string baseSerializer = readerCodeGen.GenerateBaseSerializer("XmlSerializer1", readerClass, writerClass, classes); var serializers = new Hashtable(); for (int i = 0; i < xmlMappings.Length; i++) { if (serializers[xmlMappings[i].Key] == null) { serializers[xmlMappings[i].Key] = readerCodeGen.GenerateTypedSerializer(readMethodNames[i], writeMethodNames[i], xmlMappings[i], classes, baseSerializer, readerClass, writerClass); } } readerCodeGen.GenerateSerializerContract("XmlSerializerContract", xmlMappings, types, readerClass, readMethodNames, writerClass, writeMethodNames, serializers); writer.Indent--; writer.WriteLine("}"); string codecontent = compiler.Source.ToString(); Byte[] info = new UTF8Encoding(true).GetBytes(codecontent); stream.Write(info, 0, info.Length); stream.Flush(); return(true); } finally { compiler.Close(); } }
public static void AddDescribeToComplete(TypeScope value) { elem_cache.Add(value); }
internal ModelScope(TypeScope typeScope) { _typeScope = typeScope; }
internal static Assembly GenerateRefEmitAssembly(XmlMapping[] xmlMappings, Type[] types, string defaultNamespace) { var scopeTable = new Dictionary <TypeScope, XmlMapping>(); foreach (XmlMapping mapping in xmlMappings) { scopeTable[mapping.Scope] = mapping; } TypeScope[] scopes = new TypeScope[scopeTable.Keys.Count]; scopeTable.Keys.CopyTo(scopes, 0); string assemblyName = "Microsoft.GeneratedCode"; AssemblyBuilder assemblyBuilder = CodeGenerator.CreateAssemblyBuilder(assemblyName); // Add AssemblyVersion attribute to match parent accembly version if (types != null && types.Length > 0 && types[0] != null) { ConstructorInfo AssemblyVersionAttribute_ctor = typeof(AssemblyVersionAttribute).GetConstructor( new Type[] { typeof(String) } ); string assemblyVersion = types[0].Assembly.GetName().Version.ToString(); assemblyBuilder.SetCustomAttribute(new CustomAttributeBuilder(AssemblyVersionAttribute_ctor, new Object[] { assemblyVersion })); } CodeIdentifiers classes = new CodeIdentifiers(); classes.AddUnique("XmlSerializationWriter", "XmlSerializationWriter"); classes.AddUnique("XmlSerializationReader", "XmlSerializationReader"); string suffix = null; if (types != null && types.Length == 1 && types[0] != null) { suffix = CodeIdentifier.MakeValid(types[0].Name); if (types[0].IsArray) { suffix += "Array"; } } ModuleBuilder moduleBuilder = CodeGenerator.CreateModuleBuilder(assemblyBuilder, assemblyName); string writerClass = "XmlSerializationWriter" + suffix; writerClass = classes.AddUnique(writerClass, writerClass); XmlSerializationWriterILGen writerCodeGen = new XmlSerializationWriterILGen(scopes, "public", writerClass); writerCodeGen.ModuleBuilder = moduleBuilder; writerCodeGen.GenerateBegin(); string[] writeMethodNames = new string[xmlMappings.Length]; for (int i = 0; i < xmlMappings.Length; i++) { writeMethodNames[i] = writerCodeGen.GenerateElement(xmlMappings[i]); } Type writerType = writerCodeGen.GenerateEnd(); string readerClass = "XmlSerializationReader" + suffix; readerClass = classes.AddUnique(readerClass, readerClass); XmlSerializationReaderILGen readerCodeGen = new XmlSerializationReaderILGen(scopes, "public", readerClass); readerCodeGen.ModuleBuilder = moduleBuilder; readerCodeGen.CreatedTypes.Add(writerType.Name, writerType); readerCodeGen.GenerateBegin(); string[] readMethodNames = new string[xmlMappings.Length]; for (int i = 0; i < xmlMappings.Length; i++) { readMethodNames[i] = readerCodeGen.GenerateElement(xmlMappings[i]); } readerCodeGen.GenerateEnd(readMethodNames, xmlMappings, types); string baseSerializer = readerCodeGen.GenerateBaseSerializer("XmlSerializer1", readerClass, writerClass, classes); var serializers = new Dictionary <string, string>(); for (int i = 0; i < xmlMappings.Length; i++) { if (!serializers.ContainsKey(xmlMappings[i].Key)) { serializers[xmlMappings[i].Key] = readerCodeGen.GenerateTypedSerializer(readMethodNames[i], writeMethodNames[i], xmlMappings[i], classes, baseSerializer, readerClass, writerClass); } } readerCodeGen.GenerateSerializerContract("XmlSerializerContract", xmlMappings, types, readerClass, readMethodNames, writerClass, writeMethodNames, serializers); return(writerType.Assembly); }
// SxS: This method does not take any resource name and does not expose any resources to the caller. // It's OK to suppress the SxS warning. internal void AddImport(Type type, Hashtable types) { if (type == null) { return; } if (TypeScope.IsKnownType(type)) { return; } if (types[type] != null) { return; } types[type] = type; Type baseType = type.BaseType; if (baseType != null) { AddImport(baseType, types); } Type declaringType = type.DeclaringType; if (declaringType != null) { AddImport(declaringType, types); } foreach (Type intf in type.GetInterfaces()) { AddImport(intf, types); } ConstructorInfo[] ctors = type.GetConstructors(); for (int i = 0; i < ctors.Length; i++) { ParameterInfo[] parms = ctors[i].GetParameters(); for (int j = 0; j < parms.Length; j++) { AddImport(parms[j].ParameterType, types); } } if (type.IsGenericType) { Type[] arguments = type.GetGenericArguments(); for (int i = 0; i < arguments.Length; i++) { AddImport(arguments[i], types); } } Module module = type.Module; Assembly assembly = module.Assembly; if (DynamicAssemblies.IsTypeDynamic(type)) { DynamicAssemblies.Add(assembly); return; } object[] typeForwardedFromAttribute = type.GetCustomAttributes(typeof(TypeForwardedFromAttribute), false); if (typeForwardedFromAttribute.Length > 0) { TypeForwardedFromAttribute originalAssemblyInfo = typeForwardedFromAttribute[0] as TypeForwardedFromAttribute; Assembly originalAssembly = Assembly.Load(new AssemblyName(originalAssemblyInfo.AssemblyFullName)); //_imports[originalAssembly] = originalAssembly.Location; } //_imports[assembly] = assembly.Location; }
public virtual TypeNode LookupTypeOrTypeParameter(Identifier identifier, TypeScope parentTypeScope, int numTemplateArgs, out TypeNode inaccessibleNestedType){ inaccessibleNestedType = null; if (identifier == null || parentTypeScope == null) return null; TypeNode parentType = parentTypeScope.Type; if (parentType == null) return null; TypeNodeList tparams = parentType.TemplateParameters; if (parentType.Template != null) tparams = parentType.Template.TemplateParameters; for (int i = 0, n = tparams == null ? 0 : tparams.Count; i < n; i++){ TypeNode t = tparams[i]; if (t == null) continue; if (t.Name.UniqueIdKey == identifier.UniqueIdKey){ if (tparams == parentType.TemplateParameters) return t; if (parentType.TemplateArguments == null || parentType.TemplateArguments.Count <= i) return t; return parentType.TemplateArguments[i]; } } if (numTemplateArgs > 0 && TargetPlatform.GenericTypeNamesMangleChar != 0) identifier = new Identifier(identifier.ToString() + TargetPlatform.GenericTypeNamesMangleChar + numTemplateArgs.ToString()); while (parentType != null){ MemberList members = this.GetTypeView(parentType).GetMembersNamed(identifier); for (int i = 0, n = members == null ? 0 : members.Count; i < n; i++){ Member mem = members[i]; if (mem is TypeParameter || mem is ClassParameter) continue; TypeNode dummy = this.currentType; if (Checker.NotAccessible(mem, ref dummy, this.currentModule, this.currentType, this.TypeViewer)){ if (mem is TypeNode) inaccessibleNestedType = (TypeNode)mem; continue; } TypeNode t = mem as TypeNode; if (t != null){ if (this.TypeIsVisible(t)) return t; inaccessibleNestedType = t; } } Class c = parentType as Class; if (c != null && c.BaseClass == null && c.DeclaringModule == this.currentModule) this.VisitBaseClassReference(c); if (parentType == SystemTypes.Object) break; parentType = parentType.BaseType; } return null; }