Example #1
0
        public void ImportOpenGenericType()
        {
            // class C<T, U> { void M<X>() {} }

            var c = new DefaultUnresolvedTypeDefinition(string.Empty, "C");
            c.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.TypeDefinition, 0, "T"));
            c.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.TypeDefinition, 1, "U"));
            var m = new DefaultUnresolvedMethod(c, "M");
            m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.Method, 0, "X"));
            c.Members.Add(m);

            var resolvedC1 = TypeSystemHelper.CreateCompilationAndResolve(c);
            var resolvedM1 = resolvedC1.Methods.Single(method => method.Name == "M");

            var resolvedC2 = TypeSystemHelper.CreateCompilationAndResolve(c);
            var resolvedM2 = resolvedC2.Methods.Single(method => method.Name == "M");

            // the types, methods and type parameters differ in the two compilations:
            Assert.AreNotEqual(resolvedC1, resolvedC2);
            Assert.AreNotEqual(resolvedM1, resolvedM2);
            Assert.AreNotEqual(resolvedC1.TypeParameters[1], resolvedC2.TypeParameters[1]);
            Assert.AreNotEqual(resolvedM1.TypeParameters[0], resolvedM2.TypeParameters[0]);

            // C<U, X>
            var pt1 = new ParameterizedType(resolvedC1, new[] { resolvedC1.TypeParameters[1], resolvedM1.TypeParameters[0] });
            var pt2 = (ParameterizedType)resolvedC2.Compilation.Import(pt1);

            // importing resulted in C<U, X> in the new compilation:
            Assert.AreEqual(resolvedC2, pt2.GetDefinition());
            Assert.AreEqual(resolvedC2.TypeParameters[1], pt2.TypeArguments[0]);
            Assert.AreEqual(resolvedM2.TypeParameters[0], pt2.TypeArguments[1]);
        }
Example #2
0
        static IUnresolvedMethod CreateDummyConstructor()
        {
            var m = new DefaultUnresolvedMethod {
                EntityType    = EntityType.Constructor,
                Name          = ".ctor",
                Accessibility = Accessibility.Public,
                IsSynthetic   = true,
                ReturnType    = KnownTypeReference.Void
            };

            m.Freeze();
            return(m);
        }
		DefaultUnresolvedMethod MakeUnresolvedMethod(params object[] parameterTypesOrDefaultValues)
		{
			var m = new DefaultUnresolvedMethod();
			m.Name = "Method";
			foreach (var typeOrDefaultValue in parameterTypesOrDefaultValues) {
				Type type = typeOrDefaultValue as Type;
				if (type != null)
					m.Parameters.Add(new DefaultUnresolvedParameter(type.ToTypeReference(), string.Empty));
				else if (Type.GetTypeCode(typeOrDefaultValue.GetType()) > TypeCode.Object)
					m.Parameters.Add(new DefaultUnresolvedParameter(typeOrDefaultValue.GetType().ToTypeReference(), string.Empty) {
					                 	DefaultValue = new SimpleConstantValue(typeOrDefaultValue.GetType().ToTypeReference(), typeOrDefaultValue)
					                 });
				else
					throw new ArgumentException(typeOrDefaultValue.ToString());
			}
			return m;
		}
		void UpdateMethodRegions(DefaultUnresolvedMethod method, NavigationBarItem item, IDocument document)
		{
			DomRegion region = item.ToRegionStartingFromOpeningCurlyBrace(document);
			method.Region = new DomRegion(
				region.BeginLine,
				region.BeginColumn,
				region.BeginLine,
				region.BeginColumn);
			method.BodyRegion = region;
		}
		void AddMethod(TypeScriptUnresolvedTypeDefinition parent, NavigationBarItem item, IDocument document)
		{
			var method = new DefaultUnresolvedMethod(parent, item.text);
			UpdateMethodRegions(method, item, document);
			parent.Members.Add(method);
		}
Example #6
0
        MemberList GetMemberList()
        {
            var result = LazyInit.VolatileRead(ref this.memberList);

            if (result != null)
            {
                return(result);
            }
            List <IUnresolvedMember>   unresolvedMembers  = new List <IUnresolvedMember>();
            List <ITypeResolveContext> contextPerMember   = new List <ITypeResolveContext>();
            List <PartialMethodInfo>   partialMethodInfos = null;
            bool addDefaultConstructorIfRequired          = false;

            foreach (IUnresolvedTypeDefinition part in parts)
            {
                ITypeResolveContext parentContextForPart = part.CreateResolveContext(parentContext);
                ITypeResolveContext contextForPart       = parentContextForPart.WithCurrentTypeDefinition(this);
                foreach (var member in part.Members)
                {
                    IUnresolvedMethod method = member as IUnresolvedMethod;
                    if (method != null && method.IsPartial)
                    {
                        // Merge partial method declaration and implementation
                        if (partialMethodInfos == null)
                        {
                            partialMethodInfos = new List <PartialMethodInfo>();
                        }
                        PartialMethodInfo newInfo      = new PartialMethodInfo(method, contextForPart);
                        PartialMethodInfo existingInfo = null;
                        foreach (var info in partialMethodInfos)
                        {
                            if (newInfo.IsSameSignature(info, Compilation.NameComparer))
                            {
                                existingInfo = info;
                                break;
                            }
                        }
                        if (existingInfo != null)
                        {
                            // Add the unresolved method to the PartialMethodInfo:
                            existingInfo.AddPart(method, contextForPart);
                        }
                        else
                        {
                            partialMethodInfos.Add(newInfo);
                        }
                    }
                    else
                    {
                        unresolvedMembers.Add(member);
                        contextPerMember.Add(contextForPart);
                    }
                }

                addDefaultConstructorIfRequired |= part.AddDefaultConstructorIfRequired;
            }
            if (addDefaultConstructorIfRequired)
            {
                TypeKind kind = this.Kind;
                if (kind == TypeKind.Class && !this.IsStatic && !unresolvedMembers.Any(m => m.SymbolKind == SymbolKind.Constructor && !m.IsStatic) ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    contextPerMember.Add(parts[0].CreateResolveContext(parentContext).WithCurrentTypeDefinition(this));
                    unresolvedMembers.Add(DefaultUnresolvedMethod.CreateDefaultConstructor(parts[0]));
                }
            }
            result = new MemberList(contextPerMember, unresolvedMembers, partialMethodInfos);
            return(LazyInit.GetOrSet(ref this.memberList, result));
        }
Example #7
0
		static void GenerateCU (XmlParsedDocument doc)
		{
			if (doc.XDocument == null || doc.XDocument.RootElement == null) {
				doc.Add (new Error (ErrorType.Error, "No root node found.", 1, 1));
				return;
			}

			XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName ("x", "Class")];
			if (rootClass == null) {
				doc.Add (new Error (ErrorType.Error, "Root node does not contain an x:Class attribute.", 1, 1));
				return;
			}

			bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";
			
			string rootNamespace, rootType, rootAssembly;
			XamlG.ParseXmlns (rootClass.Value, out rootType, out rootNamespace, out rootAssembly);

			var cu = new DefaultParsedDocument (doc.FileName);

			DomRegion rootRegion = doc.XDocument.RootElement.Region;
			if (doc.XDocument.RootElement.IsClosed)
				rootRegion = new DomRegion (doc.XDocument.RootElement.Region.FileName, doc.XDocument.RootElement.Region.Begin, doc.XDocument.RootElement.ClosingTag.Region.End); 
			
			var declType = new DefaultUnresolvedTypeDefinition (rootNamespace, rootType) {
				Kind = TypeKind.Class,
				Accessibility = Accessibility.Public,
				Region = rootRegion
			};
			cu.TopLevelTypeDefinitions.Add (declType);
			
			var initcomp = new DefaultUnresolvedMethod (declType, "InitializeComponent") {
				ReturnType = KnownTypeReference.Void,
				Accessibility = Accessibility.Public
			};
			declType.Members.Add (initcomp);
			
			var _contentLoaded = new DefaultUnresolvedField (declType, "_contentLoaded") {
				ReturnType = KnownTypeReference.Boolean
			};
// was missing in the original code: correct ? 
//			declType.Fields.Add (_contentLoaded);

			if (isApplication)
				return;
			
//			cu.Add (new DomUsing (DomRegion.Empty, "System"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Documents"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Input"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Media.Animation"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Shapes"));
//			cu.Add (new DomUsing (DomRegion.Empty, "System.Windows.Controls.Primitives"));
			
	//		Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
	//		namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";
			
			XName nameAtt = new XName ("x", "Name");
			
			foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements) {
				XAttribute name = el.Attributes [nameAtt];
				if (name != null && name.IsComplete) {
					string type = ResolveType (el);
					if (type == null || type.Length == 0)
						cu.Add (new Error (ErrorType.Error, "Could not find namespace for '" + el.Name.FullName + "'.", el.Region.Begin));
					else
						declType.Members.Add (new DefaultUnresolvedField (declType, name.Value) {
							Accessibility = Accessibility.Internal,
							Region = el.Region,
							ReturnType = new DefaultUnresolvedTypeDefinition (type)
						});
				}
			}
		}
 public DefaultResolvedMethod(DefaultUnresolvedMethod unresolved, ITypeResolveContext parentContext)
     : this(unresolved, parentContext, unresolved.IsExtensionMethod)
 {
 }
Example #9
0
		//TODO: handle generics
		public static IUnresolvedMethod CodeDomToMDDomMethod (CodeMemberMethod method)
		{
			var meth = new DefaultUnresolvedMethod (null, method.Name);
			meth.ReturnType = new DefaultUnresolvedTypeDefinition (method.ReturnType.BaseType);
			
			CodeDomModifiersToMDDom (meth, method.Attributes);
			
			foreach (CodeParameterDeclarationExpression dec in method.Parameters) {
				var paramType = new DefaultUnresolvedTypeDefinition (dec.Type.BaseType);
				var par = new  DefaultUnresolvedParameter (paramType, dec.Name);
				if (dec.Direction == FieldDirection.Ref)
					par.IsRef = true;
				else if (dec.Direction == FieldDirection.Out)
					par.IsOut = true;
				meth.Parameters.Add (par);
			}
			
			return meth;
		}
Example #10
0
 protected IMethod GenerateDefaultConstructor(ITypeDefinition ce)
 {
     var compilerGeneratedCtor = ce.GetConstructors(true, false).FirstOrDefault(t => t.GetDeclarationBody() == null); //TODO: where is this phantom ctor coming from??? (dan-el)
     if (compilerGeneratedCtor == null)
     {
         var cePart = ce.Parts.First();
         var me2 = new DefaultUnresolvedMethod(cePart, ".ctor");
         me2.SymbolKind = SymbolKind.Constructor;
         me2.IsSynthetic = true;
         me2.UnresolvedFile = cePart.UnresolvedFile;
         var x = new DefaultResolvedMethod(me2, Compiler.Project.Compilation.TypeResolveContext.WithCurrentTypeDefinition(ce));
         compilerGeneratedCtor = x;
     }
     return compilerGeneratedCtor;
 }
		internal static Task<IUnresolvedAssembly> LoadModuleAsync(Module module, ICorDebugModule corModule)
		{
			string name = corModule.GetName();
			if (corModule.IsDynamic() == 1 || corModule.IsInMemory() == 1) {
				var defaultUnresolvedAssembly = new DefaultUnresolvedAssembly(name);
				var defaultUnresolvedTypeDefinition = new DefaultUnresolvedTypeDefinition("UnknownDynamicType");
				var defaultUnresolvedMethod = new DefaultUnresolvedMethod(defaultUnresolvedTypeDefinition, "UnknownMethod");
				var defaultUnresolvedField = new DefaultUnresolvedField(defaultUnresolvedTypeDefinition, "UnknownField");
				defaultUnresolvedTypeDefinition.Members.Add(defaultUnresolvedMethod);
				defaultUnresolvedTypeDefinition.Members.Add(defaultUnresolvedField);
				defaultUnresolvedAssembly.AddTypeDefinition(defaultUnresolvedTypeDefinition);
				weakTable.Add(defaultUnresolvedAssembly, new ModuleMetadataInfo(module, null));
				return Task.FromResult<IUnresolvedAssembly>(defaultUnresolvedAssembly);
			}
			
			//return Task.FromResult(LoadModule(module, name));
			return Task.Run(() => LoadModule(module, name));
		}
		public static IMethod CreateDummyMethodForFieldInitialization(IMember member, ICompilation compilation) {
			var unresolved = new DefaultUnresolvedMethod(member.DeclaringTypeDefinition.Parts[0], "initialization for " + member.Name) {
				Parameters = { new DefaultUnresolvedParameter(member.ReturnType.ToTypeReference(), "value") },
				IsStatic = member.IsStatic,
			};
			IMethod method = new DefaultResolvedMethod(unresolved, compilation.TypeResolveContext.WithCurrentTypeDefinition(member.DeclaringTypeDefinition));
			if (member.DeclaringType is ParameterizedType)
				method = new SpecializedMethod(method, new TypeParameterSubstitution(classTypeArguments: ((ParameterizedType)member.DeclaringType).TypeArguments, methodTypeArguments: null));
			return method;
		}
        static void InitTypeDefinition(Dictionary<string, MemberAnnotation[]> typeSemanticInfo, DefaultUnresolvedTypeDefinition typeDef)
        {
            foreach(var method_name in typeSemanticInfo.Keys){
                var method_info = typeSemanticInfo[method_name];
                EntityType type = EntityType.Method;

                foreach(var method_overload in method_info){
                    var m = new DefaultUnresolvedMethod(typeDef, method_name);
                    m.EntityType = type;
                    m.HasBody = false;
                    m.ReturnType = PrimitiveTypeReference.Void;     //All BVE5 methods have the return type 'void'

                    if(method_overload.Args.Length > 0){
                        foreach(var arg_annot in method_overload.Args)
                            m.Parameters.Add(TransformParameterInfo(arg_annot));
                    }

                    typeDef.Members.Add(m);
                }
            }
        }
Example #14
0
			public override void VisitDocument(AXmlDocument document)
			{
				currentDocument = document;
				AXmlElement rootElement = currentDocument.Children.OfType<AXmlElement>().FirstOrDefault();
				if (rootElement != null) {
					string className = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "Class");
					string modifier = rootElement.GetAttributeValue(XamlConst.XamlNamespace, "ClassModifier");
					if (className != null) {
						TypeDefinition = new DefaultUnresolvedTypeDefinition(className) {
							Kind = TypeKind.Class,
							UnresolvedFile = file,
							Accessibility = Accessibility.Public,
							Region = new DomRegion(file.FileName, textDocument.GetLocation(rootElement.StartOffset), textDocument.GetLocation(rootElement.EndOffset))
						};
						TypeDefinition.Members.Add(
							new DefaultUnresolvedMethod(TypeDefinition, "InitializeComponent") {
								Accessibility = Accessibility.Public,
								ReturnType = KnownTypeReference.Void
							});
						TypeDefinition.Members.Add(
							new DefaultUnresolvedField(TypeDefinition, "_contentLoaded") {
								Accessibility = Accessibility.Private,
								ReturnType = KnownTypeReference.Boolean
							});
						
						var connectMember =
							new DefaultUnresolvedMethod(TypeDefinition, "Connect") {
							Accessibility = Accessibility.Private,
							ReturnType = KnownTypeReference.Void
						};
						connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Int32, "connectionId"));
						connectMember.Parameters.Add(new DefaultUnresolvedParameter(KnownTypeReference.Object, "target"));
						TypeDefinition.Members.Add(connectMember);
						connectMember.ExplicitInterfaceImplementations.Add(
							new DefaultMemberReference(SymbolKind.Method, new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName)), "Connect"));
						
						var browsableAttribute = new DefaultUnresolvedAttribute(new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName)));
						
						browsableAttribute.PositionalArguments.Add(
							new SimpleConstantValue(
								new GetClassTypeReference(new FullTypeName(typeof(System.ComponentModel.EditorBrowsableAttribute).FullName)), System.ComponentModel.EditorBrowsableState.Never
							));
						
						connectMember.Attributes.Add(browsableAttribute);
						TypeDefinition.BaseTypes.Add(CreateTypeReference(rootElement.Namespace, rootElement.LocalName));
						TypeDefinition.BaseTypes.Add(new GetClassTypeReference(new FullTypeName(typeof(System.Windows.Markup.IComponentConnector).FullName)));
						if (modifier != null)
							TypeDefinition.Accessibility = ParseAccessibility(modifier);
					}
				}
				base.VisitDocument(document);
			}
		public void TestMethodSpecifiedInInitialize()
		{
			var method = new DefaultUnresolvedMethod(new DefaultUnresolvedTypeDefinition("TestFixture"), "Test");
			var testMethod = new NUnitTestMethod(testProject, method);
			NUnitConsoleApplication app = new NUnitConsoleApplication(new[] { testMethod });
			app.NoLogo = false;
			app.ShadowCopy = true;
			app.NoXmlOutputFile = false;
			
			string expectedCommandLine = "\"C:\\Projects\\MyTests\\MyTests.dll\" /run=\"TestFixture.Test\"";
			Assert.AreEqual(expectedCommandLine, app.GetArguments());
		}
Example #16
0
        bool isSynthetic = true;         // true if all parts are synthetic

        public DefaultResolvedTypeDefinition(ITypeResolveContext parentContext, params IUnresolvedTypeDefinition[] parts)
        {
            if (parentContext == null || parentContext.CurrentAssembly == null)
            {
                throw new ArgumentException("Parent context does not specify any assembly", "parentContext");
            }
            if (parts == null || parts.Length == 0)
            {
                throw new ArgumentException("No parts were specified", "parts");
            }
            this.parentContext = parentContext;
            this.parts         = parts;
            ITypeResolveContext contextForTypeParameters = parts[0].CreateResolveContext(parentContext);

            contextForTypeParameters = contextForTypeParameters.WithCurrentTypeDefinition(this);
            this.TypeParameters      = parts[0].TypeParameters.CreateResolvedTypeParameters(contextForTypeParameters);
            List <IUnresolvedAttribute> unresolvedAttributes = new List <IUnresolvedAttribute>();
            List <ITypeResolveContext>  contextPerAttribute  = new List <ITypeResolveContext>();
            List <ITypeResolveContext>  contextPerMember     = new List <ITypeResolveContext>();
            bool addDefaultConstructorIfRequired             = false;

            foreach (IUnresolvedTypeDefinition part in parts)
            {
                ITypeResolveContext parentContextForPart = part.CreateResolveContext(parentContext);
                ITypeResolveContext contextForPart       = parentContextForPart.WithCurrentTypeDefinition(this);
                foreach (var attr in part.Attributes)
                {
                    unresolvedAttributes.Add(attr);
                    contextPerAttribute.Add(parentContextForPart);
                }
                foreach (var member in part.Members)
                {
                    unresolvedMembers.Add(member);
                    contextPerMember.Add(contextForPart);
                }

                isAbstract  |= part.IsAbstract;
                isSealed    |= part.IsSealed;
                isShadowing |= part.IsShadowing;
                isSynthetic &= part.IsSynthetic;                 // true if all parts are synthetic

                DefaultUnresolvedTypeDefinition dutd = part as DefaultUnresolvedTypeDefinition;
                if (dutd != null)
                {
                    addDefaultConstructorIfRequired |= dutd.AddDefaultConstructorIfRequired;
                }

                // internal is the default, so use another part's accessibility until we find a non-internal accessibility
                if (accessibility == Accessibility.Internal)
                {
                    accessibility = part.Accessibility;
                }
            }
            if (addDefaultConstructorIfRequired)
            {
                TypeKind kind = this.Kind;
                if (kind == TypeKind.Class && !this.IsStatic && !unresolvedMembers.Any(m => m.EntityType == EntityType.Constructor && !m.IsStatic) ||
                    kind == TypeKind.Enum || kind == TypeKind.Struct)
                {
                    contextPerMember.Add(parts[0].CreateResolveContext(parentContext).WithCurrentTypeDefinition(this));
                    unresolvedMembers.Add(DefaultUnresolvedMethod.CreateDefaultConstructor(parts[0]));
                }
            }
            this.Attributes      = new ProjectedListWithContextPerElement <ITypeResolveContext, IUnresolvedAttribute, IAttribute>(contextPerAttribute, unresolvedAttributes, (c, a) => a.CreateResolvedAttribute(c));
            this.resolvedMembers = new ProjectedListWithContextPerElement <ITypeResolveContext, IUnresolvedMember, IMember>(contextPerMember, unresolvedMembers, (c, m) => m.CreateResolved(c));
        }
		public DefaultResolvedMethod(DefaultUnresolvedMethod unresolved, ITypeResolveContext parentContext)
			: this(unresolved, parentContext, unresolved.IsExtensionMethod)
		{
		}
Example #18
0
		static void CodeDomModifiersToMDDom (DefaultUnresolvedMethod method, MemberAttributes modifiers)
		{
			if ((modifiers & MemberAttributes.FamilyOrAssembly) != 0) {
				method.Accessibility = Accessibility.ProtectedOrInternal;
			}
			else if ((modifiers & MemberAttributes.FamilyOrAssembly) != 0) {
				method.Accessibility = Accessibility.ProtectedAndInternal;
			}
			else if ((modifiers & MemberAttributes.Family) != 0) {
				method.Accessibility = Accessibility.Protected;
			}
			else if ((modifiers & MemberAttributes.Assembly) != 0) {
				method.Accessibility = Accessibility.Internal;
			}
			else if ((modifiers & MemberAttributes.Public) != 0) {
				method.Accessibility = Accessibility.Public;
			}
			else  if ((modifiers & MemberAttributes.Private) != 0) {
				method.Accessibility = Accessibility.Private;
			}
			
			if ((modifiers & MemberAttributes.Abstract) != 0) {
				method.IsAbstract = true;
			}
			else if ((modifiers & MemberAttributes.Final) != 0) {
				method.IsSealed = true;
			}
			else if ((modifiers & MemberAttributes.Static) != 0) {
				method.IsStatic = true;
			}
			else if ((modifiers & MemberAttributes.Override) != 0) {
				method.IsOverride = true;
			}
//			else if ((modifiers & MemberAttributes.Const) != 0) { // methods are never const.
//				initialState = (initialState & ~ScopeMask) | Modifiers.Const;
//			}
		}
		/// Adds a signal handler to the class
		public void BindSignal (Stetic.Signal signal)
		{
			if (targetObject == null)
				return;

			var cls = GetClass ();
			if (cls == null)
				return;
			
			if (FindSignalHandler (cls.Resolve (project), signal) != null)
				return;
			
			var met = new DefaultUnresolvedMethod (cls, signal.Handler) {
				Accessibility = Accessibility.Protected,
				ReturnType = ReflectionHelper.ParseReflectionName (signal.SignalDescriptor.HandlerReturnTypeName)
			};
			foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters)
				met.Parameters.Add (new DefaultUnresolvedParameter (ReflectionHelper.ParseReflectionName (pinfo.TypeName), pinfo.Name));
			var resolvedCls = cls.Resolve (cls.UnresolvedFile.GetTypeResolveContext (TypeSystemService.GetCompilation (project), cls.Region.Begin)).GetDefinition ();
			CodeGenerationService.AddNewMember (resolvedCls, cls, met);
		}
Example #20
0
        IUnresolvedMethod ReadConstructor(ConstructorInfo method, IUnresolvedTypeDefinition parentType, EntityType methodType, IUnresolvedMember accessorOwner)
        {
            if (method == null)
                return null;
            var m = new DefaultUnresolvedMethod(parentType, method.Name);
            m.EntityType = methodType;
            m.AccessorOwner = accessorOwner;
            m.HasBody = method.GetMethodBody () != null;
            var genericArguments = method.GetGenericArguments ();
            if (genericArguments != null) {
                for (int i = 0; i < genericArguments.Length; i++) {
                    if (genericArguments[i].GenericParameterPosition != i)
                        throw new InvalidOperationException("g.Position != i");
                    m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(
                        EntityType.Method, i, genericArguments[i].Name));
                }
                for (int i = 0; i < genericArguments.Length; i++) {
                    var tp = (DefaultUnresolvedTypeParameter)m.TypeParameters[i];
                    AddConstraints(tp, genericArguments[i]);
                    tp.ApplyInterningProvider(interningProvider);
                }
            }
            m.ReturnType = KnownTypeReference.Void;

            if (HasAnyAttributes(method))
                AddAttributes(method, m.Attributes, m.ReturnTypeAttributes);
            TranslateModifiers(method, m);

            foreach (var p in method.GetParameters ()) {
                m.Parameters.Add(ReadParameter(p));
            }

            FinishReadMember(m, method);
            return m;
        }
Example #21
0
		static IUnresolvedMethod CreateDummyConstructor()
		{
			var m = new DefaultUnresolvedMethod {
				EntityType = EntityType.Constructor,
				Name = ".ctor",
				Accessibility = Accessibility.Public,
				IsSynthetic = true,
				ReturnType = KnownTypeReference.Void
			};
			m.Freeze();
			return m;
		}
Example #22
0
        IUnresolvedMethod ReadMethod(MethodInfo method, IUnresolvedTypeDefinition parentType, EntityType methodType, IUnresolvedMember accessorOwner)
        {
            if (method == null)
                return null;
            var m = new DefaultUnresolvedMethod(parentType, method.Name);
            m.EntityType = methodType;
            m.AccessorOwner = accessorOwner;
            m.HasBody = method.GetMethodBody () != null;
            var genericArguments = method.GetGenericArguments ();
            if (genericArguments != null) {
                for (int i = 0; i < genericArguments.Length; i++) {
                    if (genericArguments[i].GenericParameterPosition != i)
                        throw new InvalidOperationException("g.Position != i");
                    m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(
                        EntityType.Method, i, genericArguments[i].Name));
                }
                for (int i = 0; i < genericArguments.Length; i++) {
                    var tp = (DefaultUnresolvedTypeParameter)m.TypeParameters[i];
                    AddConstraints(tp, genericArguments[i]);
                    tp.ApplyInterningProvider(interningProvider);
                }
            }

            m.ReturnType = ReadTypeReference(method.ReturnType, typeAttributes: method.ReturnParameter.CustomAttributes);

            if (HasAnyAttributes(method))
                AddAttributes(method, m.Attributes, m.ReturnTypeAttributes);
            TranslateModifiers(method, m);

            foreach (var p in method.GetParameters ()) {
                m.Parameters.Add(ReadParameter(p));
            }

            // mark as extension method if the attribute is set
            if (method.IsStatic && HasExtensionAttribute(method)) {
                m.IsExtensionMethod = true;
            }

            int lastDot = method.Name.LastIndexOf('.');
            if (lastDot >= 0 /*&& method.HasOverrides*/) {
                // To be consistent with the parser-initialized type system, shorten the method name:
                m.Name = method.Name.Substring(lastDot + 1);
                m.IsExplicitInterfaceImplementation = true;

                foreach (var or in method.__GetMethodImpls ()) {
                    m.ExplicitInterfaceImplementations.Add(new DefaultMemberReference(
                        accessorOwner != null ? EntityType.Accessor : EntityType.Method,
                        ReadTypeReference(or.DeclaringType),
                        or.Name, or.GetGenericArguments ().Length, m.Parameters.Select(p => p.Type).ToList()));
                }
            }

            FinishReadMember(m, method);
            return m;
        }
Example #23
0
		static IUnresolvedMethod FunctionToIMethod (ProjectInformation pi, IUnresolvedTypeDefinition type, Function function, string[] contentLines)
		{
			var method = new DefaultUnresolvedMethod (type, function.Name);
			method.Region = new DomRegion ((int)function.Line, 1, FindFunctionEnd (contentLines, (int)function.Line-1)+2, 1);
			
			Match match;
			bool abort = false;
			var parameters = new List<IUnresolvedParameter> ();
			foreach (string parameter in function.Parameters) {
				match = paramExpression.Match (parameter);
				if (null == match) {
					abort = true;
					break;
				}
				var typeRef = new DefaultUnresolvedTypeDefinition (string.Format ("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value));
				var p =  new DefaultUnresolvedParameter (typeRef, match.Groups["name"].Value);
				parameters.Add (p);
			}
			if (!abort)
				parameters.ForEach (p => method.Parameters.Add (p));
			return method;
		}
		ICodeContext CreateContext(ITextEditor editor)
		{
			var compilation = SD.ParserService.GetCompilationForFile(editor.FileName);
			var project = SD.ProjectService.FindProjectContainingFile(editor.FileName);
			
			var resolveContext = new SimpleTypeResolveContext(compilation.MainAssembly);
			
			var currentTypeDefinition = new DefaultUnresolvedTypeDefinition(project.RootNamespace, Path.GetFileNameWithoutExtension(editor.FileName));
			ITypeReference baseTypeReference = new GetClassTypeReference("System.Web.Mvc", "WebViewPage", 1);
			baseTypeReference = new ParameterizedTypeReference(baseTypeReference, new[] { FindModelType(editor) });
			currentTypeDefinition.BaseTypes.Add(baseTypeReference);
			
			var currentMethod = new DefaultUnresolvedMethod(currentTypeDefinition, "__ContextStub__");
			currentMethod.ReturnType = KnownTypeReference.Void;
			currentTypeDefinition.Members.Add(currentMethod);
			
			var currentResolvedTypeDef = new DefaultResolvedTypeDefinition(resolveContext, currentTypeDefinition);
			
			var projectContent = compilation.MainAssembly.UnresolvedAssembly as IProjectContent;
			
			var currentFile = new CSharpUnresolvedFile();
			
			currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc");
			currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Ajax");
			currentFile.RootUsingScope.AddSimpleUsing("System.Web.Mvc.Html");
			currentFile.RootUsingScope.AddSimpleUsing("System.Web.Routing");
			
			currentFile.TopLevelTypeDefinitions.Add(currentTypeDefinition);
			
			if (projectContent != null) {
				compilation = projectContent.AddOrUpdateFiles(currentFile).CreateCompilation(SD.ParserService.GetCurrentSolutionSnapshot());
			}
			
			var context = new CSharpTypeResolveContext(compilation.MainAssembly,
			                                           currentFile.RootUsingScope.Resolve(compilation),
			                                           currentResolvedTypeDef,
			                                           currentMethod.CreateResolved(resolveContext.WithCurrentTypeDefinition(currentResolvedTypeDef)));
			return new CSharpResolver(context);
		}