Example #1
0
        void AddModuleDefinition(ModuleDefinition moduleDefinition, bool loadInternal, bool instantiateTypeParameter)
        {
            InstantiatedParamResolver resolver = new InstantiatedParamResolver();
            Module module = new Module(moduleDefinition);

            foreach (TypeDefinition type in moduleDefinition.Types)
            {
                if (!loadInternal && IsInternal(DomCecilType.GetModifiers(type.Attributes)))
                {
                    continue;
                }
//				if (type.Name == "SimplePropertyDescriptor")
//					System.Console.WriteLine(type.Attributes + "/" + DomCecilType.GetModifiers (type.Attributes) + "/" + IsInternal (DomCecilType.GetModifiers (type.Attributes)));
                DomCecilType loadType = new DomCecilType(type, loadInternal, loadMonotouchDocumentation);
                if (instantiateTypeParameter)
                {
                    resolver.Visit(loadType, null);
                    resolver.ClearTypes();
                }
                loadMonotouchDocumentation &= loadType.LoadMonotouchDocumentation;
                Add(loadType);
                module.Types.Add(loadType);
            }
            this.modules.Add(module);
        }
Example #2
0
        void AddModuleDefinition(ModuleDefinition moduleDefinition, bool loadInternal, bool instantiateTypeParameter)
        {
            InstantiatedParamResolver resolver = new InstantiatedParamResolver(xmlDocumentation);
            Module module = new Module(moduleDefinition);

            foreach (TypeDefinition type in moduleDefinition.Types)
            {
                // filter nested types, they're handled in DomCecilType.
                if ((type.Attributes & TypeAttributes.NestedPublic) == TypeAttributes.NestedPublic ||
                    (type.Attributes & TypeAttributes.NestedFamily) == TypeAttributes.NestedFamily ||
                    (type.Attributes & TypeAttributes.NestedAssembly) == TypeAttributes.NestedAssembly ||
                    (type.Attributes & TypeAttributes.NestedPrivate) == TypeAttributes.NestedPrivate ||
                    (type.Attributes & TypeAttributes.NestedFamANDAssem) == TypeAttributes.NestedFamANDAssem)
                {
                    continue;
                }
                if (!loadInternal && IsInternal(DomCecilType.GetModifiers(type.Attributes)))
                {
                    continue;
                }
//				if (type.Name == "SimplePropertyDescriptor")
//					System.Console.WriteLine(type.Attributes + "/" + DomCecilType.GetModifiers (type.Attributes) + "/" + IsInternal (DomCecilType.GetModifiers (type.Attributes)));
                DomCecilType loadType = new DomCecilType(type, loadInternal);
                if (instantiateTypeParameter)
                {
                    resolver.Visit(loadType, null);
                    resolver.ClearTypes();
                }
                Add(loadType);
                module.Types.Add(loadType);
            }
            this.modules.Add(module);
        }
/*		FieldDefinition fieldDefinition;
 *
 *              public FieldDefinition FieldDefinition {
 *                      get {
 *                              return fieldDefinition;
 *                      }
 *              }
 */

        public DomCecilField(FieldDefinition fieldDefinition)
        {
            base.name       = fieldDefinition.Name;
            base.Modifiers  = DomCecilType.GetModifiers(fieldDefinition);
            base.ReturnType = DomCecilMethod.GetReturnType(fieldDefinition.FieldType);
            DomCecilMethod.AddAttributes(this, fieldDefinition.CustomAttributes);
        }
Example #4
0
 public DomCecilType(TypeReference typeReference)
 {
     this.classType = ClassType.Unknown;
     this.Modifiers = Modifiers.None;
     this.Name      = DomCecilType.RemoveGenericParamSuffix(typeReference.Name);
     this.Namespace = typeReference.Namespace;
 }
Example #5
0
 public static IReturnType GetReturnType(MethodReference methodReference)
 {
     if (methodReference == null)
     {
         return(DomReturnType.Void);
     }
     return(DomReturnType.GetSharedReturnType(DomCecilType.RemoveGenericParamSuffix(methodReference.DeclaringType.FullName)));
 }
Example #6
0
        public DomCecilMethod(MethodDefinition methodDefinition)
        {
            this.methodDefinition = methodDefinition;
            this.name             = methodDefinition.Name;
            if (methodDefinition.Name == ".ctor")
            {
                MethodModifier |= MethodModifier.IsConstructor;
            }

            foreach (GenericParameter param in methodDefinition.GenericParameters)
            {
                TypeParameter tp = new TypeParameter(param.FullName);
                tp.Variance = (TypeParameterVariance)(((uint)param.Attributes) & 3);

                if (param.HasDefaultConstructorConstraint)
                {
                    tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
                }

                foreach (TypeReference tr in param.Constraints)
                {
                    tp.AddConstraint(DomCecilMethod.GetReturnType(tr));
                }
                AddTypeParameter(tp);
            }

            AddAttributes(this, methodDefinition.CustomAttributes);
            base.Modifiers  = DomCecilType.GetModifiers(methodDefinition);
            base.ReturnType = DomCecilMethod.GetReturnType(methodDefinition.ReturnType);
            foreach (ParameterDefinition paramDef in methodDefinition.Parameters)
            {
                Add(new DomCecilParameter(paramDef));
            }

            if (this.IsStatic)
            {
                foreach (IAttribute attr in this.Attributes)
                {
                    if (attr.Name == "System.Runtime.CompilerServices.ExtensionAttribute")
                    {
                        MethodModifier |= MethodModifier.IsExtension;
                        break;
                    }
                }
            }

            foreach (MethodReference overrideRef in methodDefinition.Overrides)
            {
                if (overrideRef.Name == this.name && IsPublic)
                {
                    continue;
                }
                AddExplicitInterface(GetReturnType(overrideRef.DeclaringType));
            }
        }
Example #7
0
 public DomCecilEvent(EventDefinition eventDefinition)
 {
     this.eventDefinition = eventDefinition;
     base.name            = eventDefinition.Name;
     base.Modifiers       = DomCecilType.GetModifiers(eventDefinition.AddMethod);
     base.ReturnType      = DomCecilMethod.GetReturnType(eventDefinition.EventType);
     DomCecilMethod.AddAttributes(this, eventDefinition.CustomAttributes);
     if (!eventDefinition.IsSpecialName)
     {
         base.Modifiers &= ~MonoDevelop.Projects.Dom.Modifiers.SpecialName;
     }
 }
Example #8
0
        public DomCecilType(TypeDefinition typeDefinition, bool loadInternal, bool loadMonotouchDocumentation = true)
        {
            this.LoadMonotouchDocumentation = loadMonotouchDocumentation;
            this.typeDefinition             = typeDefinition;
            this.loadInternal = loadInternal;
            this.classType    = GetClassType(typeDefinition);

            this.Name      = DomCecilType.RemoveGenericParamSuffix(typeDefinition.Name);
            this.Namespace = typeDefinition.Namespace;

            this.Modifiers = GetModifiers(typeDefinition.Attributes);

            if (typeDefinition.BaseType != null)
            {
                this.baseType = DomCecilMethod.GetReturnType(typeDefinition.BaseType);
            }
            DomCecilMethod.AddAttributes(this, typeDefinition.CustomAttributes);

            foreach (TypeReference interfaceReference in typeDefinition.Interfaces)
            {
                this.AddInterfaceImplementation(DomCecilMethod.GetReturnType(interfaceReference));
            }
            foreach (GenericParameter parameter in typeDefinition.GenericParameters)
            {
                TypeParameter tp = new TypeParameter(parameter.FullName);
                tp.Variance = (TypeParameterVariance)(((uint)parameter.Attributes) & 3);
                if (parameter.HasDefaultConstructorConstraint)
                {
                    tp.TypeParameterModifier |= TypeParameterModifier.HasDefaultConstructorConstraint;
                }
                foreach (TypeReference tr in parameter.Constraints)
                {
                    tp.AddConstraint(DomCecilMethod.GetReturnType(tr));
                }
                AddTypeParameter(tp);
            }
            AddDocumentation(this);
        }
Example #9
0
		void CheckInitialization ()
		{
			if (isInitialized)
				return;
			isInitialized = true;
			
			foreach (FieldDefinition fieldDefinition in typeDefinition.Fields) {
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (fieldDefinition)))
					continue;
				base.Add (new DomCecilField (fieldDefinition));
			}
			foreach (MethodDefinition methodDefinition in typeDefinition.Methods.Where (m => !m.IsConstructor)) {
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (methodDefinition)))
					continue;
				base.Add (new DomCecilMethod (methodDefinition));
			}
			
			bool internalOnly    = true;
			bool hasConstructors = false;
			foreach (MethodDefinition methodDefinition in typeDefinition.Methods.Where (m => m.IsConstructor)) {
				hasConstructors = true;
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (methodDefinition)))
					continue;
				internalOnly = false;
				base.Add (new DomCecilMethod (methodDefinition));
			}
			if (hasConstructors && internalOnly) 
				base.TypeModifier |= TypeModifier.HasOnlyHiddenConstructors;
			
			foreach (PropertyDefinition propertyDefinition in typeDefinition.Properties) {
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (propertyDefinition.Attributes)))
					continue;
				base.Add (new DomCecilProperty (propertyDefinition));
			}
			foreach (EventDefinition eventDefinition in typeDefinition.Events) {
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (eventDefinition.Attributes)))
					continue;
				base.Add (new DomCecilEvent (eventDefinition));
			}
			
			foreach (TypeDefinition nestedType in typeDefinition.NestedTypes) {
				if (!loadInternal && DomCecilCompilationUnit.IsInternal (DomCecilType.GetModifiers (nestedType.Attributes)))
					continue;
				DomCecilType innerType = new DomCecilType (nestedType, loadInternal);
				base.Add (innerType);
				if (typeParameters != null && innerType.typeParameters != null)
					innerType.typeParameters.RemoveAll (para => typeParameters.Any (myPara => myPara.Name == para.Name));
			}
		}
Example #10
0
        /*
         *      // Check if 'type' has some decorations applied to it
         *              if (type is Mono.Cecil.TypeSpecification) {
         *                      // Go through all levels of 'indirection', 'array dimensions'
         *                      // and 'generic types' - in the end, we should get the actual
         *                      // type of the ReturnType (but all data about its array
         *                      // dimensions, levels of indirection and even its generic
         *                      // parameters is correctly stored within ArrayCount and
         *                      // ArrayDimensions, PointerNestingLevel and GenericArguments
         *                      // respectively).
         *                      if (type is ArrayType) {
         *                              // This return type is obviously an array - add the rank
         *                              ArrayType at = (ArrayType) type;
         *                              if (arrays == null)
         *                                      arrays = new Stack<int>();
         *                              arrays.Push(at.Rank);
         *                              type = at.ElementType;
         *                      } else else if (type is Mono.Cecil.ReferenceType) {
         *                              Mono.Cecil.ReferenceType rt = (Mono.Cecil.ReferenceType) type;
         *                              byRef = true;
         *                              type = rt.ElementType;
         *                      } else if (type is PointerType) {
         *                              // The type is a pointer
         *                              PointerType pt = (PointerType) type;
         ++pointerNestingLevel;
         *                              type = pt.ElementType;
         *                              // Go down one level
         *                      } else {
         *                              // TODO: Check if we loose some relevant info here
         *                              type = ((TypeSpecification)type).ElementType;
         *                      }*/
        public static DomReturnType GetReturnType(TypeReference typeReference)
        {
            if (typeReference == null)
            {
                return(new DomReturnType(DomReturnType.Void.ToInvariantString()));
            }

            if (typeReference is Mono.Cecil.GenericInstanceType)
            {
                Mono.Cecil.GenericInstanceType genType = (Mono.Cecil.GenericInstanceType)typeReference;
                DomReturnType result = GetReturnType(genType.ElementType);

                foreach (TypeReference typeRef in genType.GenericArguments)
                {
                    DomReturnType param = GetReturnType(typeRef);

                    foreach (IReturnTypePart part in result.Parts)
                    {
                        if (part.Tag is TypeDefinition)
                        {
                            TypeDefinition typeDef = (TypeDefinition)part.Tag;
                            foreach (TypeReference typeParam in typeDef.GenericParameters)
                            {
                                if (typeParam.Name == param.Name)
                                {
                                    part.AddTypeParameter(param);
                                    goto skip;
                                }
                            }
                        }
                    }
                    result.AddTypeParameter(param);
                    skip :;
                }
                return(result);
            }

            if (typeReference is Mono.Cecil.ArrayType)
            {
                Mono.Cecil.ArrayType arrType = (Mono.Cecil.ArrayType)typeReference;
                DomReturnType        result  = GetReturnType(arrType.ElementType);
                result.ArrayDimensions++;
                result.SetDimension(result.ArrayDimensions - 1, arrType.Rank - 1);
                return(result);
            }

            if (typeReference is Mono.Cecil.PointerType)
            {
                Mono.Cecil.PointerType ptrType = (Mono.Cecil.PointerType)typeReference;
                DomReturnType          result  = GetReturnType(ptrType.ElementType);
                if (result.ArrayDimensions > 0)
                {
                    result.ArrayPointerNestingLevel++;
                }
                else
                {
                    result.PointerNestingLevel++;
                }
                return(result);
            }
            if (typeReference is Mono.Cecil.ByReferenceType)
            {
                return(GetReturnType(((Mono.Cecil.ByReferenceType)typeReference).ElementType));
            }

            if (typeReference is Mono.Cecil.TypeDefinition)
            {
                Mono.Cecil.TypeDefinition typeDefinition = (Mono.Cecil.TypeDefinition)typeReference;
                DomReturnType             result;
                if (typeDefinition.DeclaringType != null)
                {
                    result = GetReturnType(typeDefinition.DeclaringType);
                    result.Parts.Add(new ReturnTypePart(typeDefinition.Name));
                    result.Tag = typeDefinition;
                }
                else
                {
                    result           = new DomReturnType(typeDefinition.Name);
                    result.Namespace = typeDefinition.Namespace;
                    result.Tag       = typeDefinition;
                }
                return(result);
            }

            return(new DomReturnType(DomCecilType.RemoveGenericParamSuffix(typeReference.FullName)));
        }
Example #11
0
        void CheckInitialization()
        {
            if (isInitialized)
            {
                return;
            }
            isInitialized = true;

            foreach (FieldDefinition fieldDefinition in typeDefinition.Fields)
            {
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(fieldDefinition)))
                {
                    continue;
                }
                base.Add(new DomCecilField(fieldDefinition));
            }
            foreach (MethodDefinition methodDefinition in typeDefinition.Methods.Where(m => !m.IsConstructor))
            {
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(methodDefinition)))
                {
                    continue;
                }
                base.Add(new DomCecilMethod(methodDefinition));
            }

            bool internalOnly    = true;
            bool hasConstructors = false;

            foreach (MethodDefinition methodDefinition in typeDefinition.Methods.Where(m => m.IsConstructor))
            {
                hasConstructors = true;
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(methodDefinition)))
                {
                    continue;
                }
                internalOnly = false;
                base.Add(new DomCecilMethod(methodDefinition));
            }
            if (hasConstructors && internalOnly)
            {
                base.TypeModifier |= TypeModifier.HasOnlyHiddenConstructors;
            }

            foreach (PropertyDefinition propertyDefinition in typeDefinition.Properties)
            {
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(propertyDefinition.Attributes)))
                {
                    continue;
                }
                base.Add(new DomCecilProperty(propertyDefinition));
            }
            foreach (EventDefinition eventDefinition in typeDefinition.Events)
            {
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(eventDefinition.Attributes)))
                {
                    continue;
                }
                base.Add(new DomCecilEvent(eventDefinition));
            }

            foreach (TypeDefinition nestedType in typeDefinition.NestedTypes)
            {
                if (!loadInternal && DomCecilCompilationUnit.IsInternal(DomCecilType.GetModifiers(nestedType.Attributes)))
                {
                    continue;
                }
                DomCecilType innerType = new DomCecilType(nestedType, loadInternal);
                base.Add(innerType);
                if (typeParameters != null && innerType.typeParameters != null)
                {
                    innerType.typeParameters.RemoveAll(para => typeParameters.Any(myPara => myPara.Name == para.Name));
                }
            }
        }