Inheritance: TypeContainer
コード例 #1
0
		void Parse (ModuleContainer module)
		{
			bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var session = new ParserSession () {
				UseJayGlobalArrays = true,
				LocatedTokens = new Tokenizer.LocatedToken[15000],
				AsLocatedTokens = new Mono.PlayScript.Tokenizer.LocatedToken[15000]
			};

			bool has_playscript_files = false;

			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i], module, session);
				} else {
					Parse (sources[i], module, session, Report);
				}
				if (sources[i].FileType == SourceFileType.PlayScript) {
					has_playscript_files = true;
				}
			}

			// PlayScript needs to add generated code after parsing.
			if (has_playscript_files) {
				Mono.PlayScript.CodeGenerator.GenerateCode(module, session, Report);
			}
		}
コード例 #2
0
ファイル: Compiler.cs プロジェクト: Tauron1990/Radio-Streamer
        private static ModuleContainer CreateModuleContainer([NotNull] CompilerContext context)
        {
            var container = new ModuleContainer(context);
            RootContext.ToplevelTypes = container;

            return container;
        }
コード例 #3
0
ファイル: ASTVisitorTest.cs プロジェクト: ItsVeryWindy/mono
		public void Simple ()
		{
			//string content = @"class A { }";
			string content = @"

class Foo
{
	void Bar ()
	{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
	}
}"
	;


			var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));

			var ctx = new CompilerContext (new CompilerSettings (), new AssertReportPrinter ());

			ModuleContainer module = new ModuleContainer (ctx);
			var file = new SourceFile ("test", "asdfas", 0);
			CSharpParser parser = new CSharpParser (
				new SeekableStreamReader (stream, Encoding.UTF8),
				new CompilationSourceFile (module, file),
				ctx.Report,
				new ParserSession ());

			RootContext.ToplevelTypes = module;
			Location.Initialize (new List<SourceFile> { file });
			parser.parse ();

			Assert.AreEqual (0, ctx.Report.Errors);

			module.Accept (new TestVisitor ());
		}
コード例 #4
0
ファイル: module.cs プロジェクト: chriswebb/mono
			public StaticDataContainer (ModuleContainer module)
				: base (module, new MemberName ("<PrivateImplementationDetails>", Location.Null),
					Modifiers.STATIC | Modifiers.INTERNAL)
			{
				size_types = new Dictionary<int, Struct> ();
				data_hashes = new Dictionary<string, FieldSpec> (StringComparer.Ordinal);
			}
コード例 #5
0
		public void Parse (CompilationSourceFile file, ModuleContainer module)
		{
			Stream input;

			try {
				input = File.OpenRead (file.Name);
			} catch {
				Report.Error (2001, "Source file `{0}' could not be found", file.Name);
				return;
			}

			// Check 'MZ' header
			if (input.ReadByte () == 77 && input.ReadByte () == 90) {
				Report.Error (2015, "Source file `{0}' is a binary file and not a text file", file.Name);
				input.Close ();
				return;
			}

			input.Position = 0;
			SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);

			Parse (reader, file, module);
			reader.Dispose ();
			input.Close ();
		}	
コード例 #6
0
ファイル: visit.cs プロジェクト: KAW0/Alter-Native
		public virtual void Visit (ModuleContainer mc)
		{
			foreach (var container in mc.Containers) {
				container.Accept (this);
			}
			
		}
コード例 #7
0
		void tokenize_file (SourceFile sourceFile, ModuleContainer module)
		{
			Stream input;

			try {
				input = File.OpenRead (sourceFile.Name);
			} catch {
				Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
				return;
			}

			using (input){
				SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
				var file = new CompilationSourceFile (module, sourceFile);

				Tokenizer lexer = new Tokenizer (reader, file);
				int token, tokens = 0, errors = 0;

				while ((token = lexer.token ()) != Token.EOF){
					tokens++;
					if (token == Token.ERROR)
						errors++;
				}
				Console.WriteLine ("Tokenized: " + tokens + " found " + errors + " errors");
			}
			
			return;
		}
コード例 #8
0
ファイル: DynamicContext.cs プロジェクト: wutiejun/mono
        public static DynamicContext Create()
        {
            if (dc != null)
            {
                return(dc);
            }

            lock (compiler_initializer) {
                if (dc != null)
                {
                    return(dc);
                }

                var settings = new Compiler.CompilerSettings()
                {
                    WarningLevel = 0
                };

                var cc = new Compiler.CompilerContext(settings, ErrorPrinter.Instance)
                {
                    IsRuntimeBinder = true
                };

                //
                // Any later loaded assemblies are handled internally by GetAssemblyDefinition
                // domain.AssemblyLoad cannot be used as that would be too destructive as we
                // would hold all loaded assemblies even if they can be never visited
                //
                // TODO: Remove this code and rely on GetAssemblyDefinition only
                //
                var module = new Compiler.ModuleContainer(cc);
                module.HasTypesFullyDefined = true;

                // Setup fake assembly, it's used mostly to simplify checks like friend-access
                var temp = new Compiler.AssemblyDefinitionDynamic(module, "dynamic");
                module.SetDeclaringAssembly(temp);

                var importer = new Compiler.ReflectionImporter(module, cc.BuiltinTypes)
                {
                    IgnorePrivateMembers         = false,
                    IgnoreCompilerGeneratedField = false
                };

                // Import all currently loaded assemblies
                // TODO: Rewrite this to populate type cache on-demand, that should greatly
                // reduce our start-up cost
                var domain = AppDomain.CurrentDomain;
                foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
                {
                    importer.ImportAssembly(a, module.GlobalRootNamespace);
                }

                cc.BuiltinTypes.CheckDefinitions(module);
                module.InitializePredefinedTypes();

                dc = new DynamicContext(module, importer);
            }

            return(dc);
        }
コード例 #9
0
        public void Parse(ModuleContainer module)
        {
            bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
            var sources = module.Compiler.SourceFiles;

            Location.Initialize(sources);

            var session = new ParserSession
            {
                UseJayGlobalArrays = true,
                LocatedTokens = new LocatedToken[15000]
            };

            for (int i = 0; i < sources.Count; ++i)
            {
                if (tokenize_only)
                {
                    tokenize_file(sources[i], module, session);
                }
                else
                {
                    Parse(sources[i], module, session, Report);
                }
            }
        }
コード例 #10
0
        public static void Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
        {
            var file = new CompilationSourceFile(module, sourceFile);
            module.AddTypeContainer(file);

            CSharpParser parser = new CSharpParser(reader, file, report, session);
            parser.parse();
        }
コード例 #11
0
ファイル: doc.cs プロジェクト: royleban/mono
		public DocumentationBuilder (ModuleContainer module)
		{
			doc_module = new ModuleContainer (module.Compiler);
			doc_module.DocumentationBuilder = this;

			this.module = module;
			XmlDocumentation = new XmlDocument ();
			XmlDocumentation.PreserveWhitespace = false;
		}
コード例 #12
0
			public override void Visit(ModuleContainer mc)
			{
				bool first = true;
				foreach (var container in mc.Containers) {
					var nspace = container as NamespaceContainer;
					if (nspace == null) {
						container.Accept(this);
						continue;
					}
					NamespaceDeclaration nDecl = null;
					var loc = LocationsBag.GetLocations(nspace);
					
					if (nspace.NS != null && !string.IsNullOrEmpty(nspace.NS.Name)) {
						nDecl = new NamespaceDeclaration ();
						if (loc != null) {
							nDecl.AddChild(new CSharpTokenNode (Convert(loc [0])), Roles.NamespaceKeyword);
						}
						ConvertNamespaceName(nspace.RealMemberName, nDecl);
						if (loc != null && loc.Count > 1) {
							nDecl.AddChild(new CSharpTokenNode (Convert(loc [1])), Roles.LBrace);
						}
						AddToNamespace(nDecl);
						namespaceStack.Push(nDecl);
					}
					
					if (nspace.Usings != null) {
						foreach (var us in nspace.Usings) {
							us.Accept(this);
						}
					}
					
					if (first) {
						first = false;
						AddAttributeSection(Unit, mc);
					}
					
					if (nspace.Containers != null) {
						foreach (var subContainer in nspace.Containers) {
							subContainer.Accept(this);
						}
					}
					if (nDecl != null) {
						AddAttributeSection (nDecl, nspace.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
						if (loc != null && loc.Count > 2)
							nDecl.AddChild (new CSharpTokenNode (Convert (loc [2])), Roles.RBrace);
						if (loc != null && loc.Count > 3)
							nDecl.AddChild (new CSharpTokenNode (Convert (loc [3])), Roles.Semicolon);
						
						namespaceStack.Pop ();
					} else {
						AddAttributeSection (unit, nspace.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
					}
				}
				AddAttributeSection (unit, mc.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
			}
コード例 #13
0
		public static void GenerateCode (ModuleContainer module, ParserSession session, Report report)
		{
			GenerateDynamicPartialClasses(module, session, report);
			if (report.Errors > 0)
				return;

			GenerateEmbedClasses(module, session, report);
			if (report.Errors > 0)
				return;

		}
コード例 #14
0
ファイル: visit.cs プロジェクト: nylen/SharpDevelop
		public virtual void Visit (ModuleContainer mc)
		{/*
			if (mc.Delegates != null) {
				foreach (TypeContainer tc in mc.Delegates) {
					tc.Accept (this);
				}
			}*/
			if (mc.Types != null) {
				foreach (TypeContainer tc in mc.Types) {
					tc.Accept (this);
				}
			}
		}
コード例 #15
0
		void Parse (ModuleContainer module)
		{
			Location.Initialize (module.Compiler.SourceFiles);

			bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
			var sources = module.Compiler.SourceFiles;
			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i]);
				} else {
					Parse (sources[i], module);
				}
			}
		}
コード例 #16
0
ファイル: eval.cs プロジェクト: famousthom/monodevelop
		public Evaluator (CompilerSettings settings, Report report)
		{
			ctx = new CompilerContext (settings, report);

			module = new ModuleContainer (ctx);
			module.Evaluator = this;

			// FIXME: Importer needs this assembly for internalsvisibleto
			module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
			importer = new ReflectionImporter (module, ctx.BuildinTypes);

			InteractiveBaseClass = typeof (InteractiveBase);
			fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
		}
コード例 #17
0
ファイル: driver.cs プロジェクト: sandyarmstrong/monodevelop
		void Parse (ModuleContainer module)
		{
			Location.Initialize ();

			bool tokenize_only = ctx.Settings.TokenizeOnly;
			var cu = Location.SourceFiles;
			for (int i = 0; i < cu.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (cu[i]);
				} else {
					Parse (cu[i], module);
				}
			}
		}
コード例 #18
0
ファイル: assembly.cs プロジェクト: Tak/monodevelop-novell
		//
		// In-memory only assembly container
		//
		public AssemblyDefinition (ModuleContainer module, string name)
		{
			this.module = module;
			this.name = Path.GetFileNameWithoutExtension (name);

			wrap_non_exception_throws = true;

			delay_sign = RootContext.StrongNameDelaySign;

			//
			// Load strong name key early enough for assembly importer to be able to
			// use the keys for InternalsVisibleTo
			// This should go somewhere close to ReferencesLoading but don't have the place yet
			//
			if (RootContext.StrongNameKeyFile != null || RootContext.StrongNameKeyContainer != null) {
				LoadPublicKey (RootContext.StrongNameKeyFile, RootContext.StrongNameKeyContainer);
			}
		}
コード例 #19
0
ファイル: eval.cs プロジェクト: KAW0/Alter-Native
		public Evaluator (CompilerContext ctx)
		{
			this.ctx = ctx;

			module = new ModuleContainer (ctx);
			module.Evaluator = this;

			source_file = new CompilationSourceFile (module);
			module.AddTypeContainer (source_file);

			startup_files = ctx.SourceFiles.Count;

			// FIXME: Importer needs this assembly for internalsvisibleto
			module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
			importer = new ReflectionImporter (module, ctx.BuiltinTypes);

			InteractiveBaseClass = typeof (InteractiveBase);
			fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
		}
コード例 #20
0
ファイル: eval.cs プロジェクト: constructor-igor/cudafy
		public Evaluator (CompilerSettings settings, Report report)
		{
			ctx = new CompilerContext (settings, report);

			module = new ModuleContainer (ctx);
			module.Evaluator = this;

			source_file = new CompilationSourceFile ("{interactive}", "", 1);
 			source_file.NamespaceContainer = new NamespaceContainer (null, module, null, source_file);

			ctx.SourceFiles.Add (source_file);

			// FIXME: Importer needs this assembly for internalsvisibleto
			module.SetDeclaringAssembly (new AssemblyDefinitionDynamic (module, "evaluator"));
			importer = new ReflectionImporter (module, ctx.BuiltinTypes);

			InteractiveBaseClass = typeof (InteractiveBase);
			fields = new Dictionary<string, Tuple<FieldSpec, FieldInfo>> ();
		}
コード例 #21
0
ファイル: driver.cs プロジェクト: erik-kallen/NRefactory
		void Parse (ModuleContainer module, bool returnAtSignInVerbatimIdentifiers)
		{
			bool tokenize_only = module.Compiler.Settings.TokenizeOnly;
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var session = new ParserSession {
				UseJayGlobalArrays = true,
				LocatedTokens = new LocatedToken[15000],
				LocationsBag = new LocationsBag()
			};

			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i], module, session, returnAtSignInVerbatimIdentifiers);
				} else {
					Parse (sources[i], module, session, Report, returnAtSignInVerbatimIdentifiers);
				}
			}
		}
コード例 #22
0
ファイル: driver.cs プロジェクト: robterrell/playscript-mono
		void tokenize_file (SourceFile sourceFile, ModuleContainer module, ParserSession session)
		{
			Stream input;

			try {
				input = File.OpenRead (sourceFile.Name);
			} catch {
				Report.Error (2001, "Source file `" + sourceFile.Name + "' could not be found");
				return;
			}

			using (input) {
				SeekableStreamReader reader = new SeekableStreamReader (input, ctx.Settings.Encoding);
				var file = new CompilationSourceFile (module, sourceFile);

				if (sourceFile.FileType == SourceFileType.CSharp) {
					Tokenizer lexer = new Tokenizer (reader, file, session);
					int token, tokens = 0, errors = 0;
	
					while ((token = lexer.token ()) != Token.EOF){
						tokens++;
						if (token == Token.ERROR)
							errors++;
					}
				} else {
					Mono.PlayScript.Tokenizer lexer = new Mono.PlayScript.Tokenizer (reader, file, session);
					lexer.ParsingPlayScript = sourceFile.PsExtended;
					int token, tokens = 0, errors = 0;
	
					while ((token = lexer.token ()) != Mono.PlayScript.Token.EOF){
						tokens++;
						if (token == Mono.PlayScript.Token.ERROR)
							errors++;
					}
				}
			}
			
			return;
		}
コード例 #23
0
ファイル: ASTVisitorTest.cs プロジェクト: nlhepler/mono
		public void Simple ()
		{
			//string content = @"class A { }";
			string content = @"

class Foo
{
	void Bar ()
	{
completionList.Add (""delegate"" + sb, ""md-keyword"", GettextCatalog.GetString (""Creates anonymous delegate.""), ""delegate"" + sb + "" {"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent + TextEditorProperties.IndentString + ""|"" + Document.Editor.EolMarker + stateTracker.Engine.ThisLineIndent +""};"");
	}
}"
	;


			var stream = new MemoryStream (Encoding.UTF8.GetBytes (content));

			var ctx = new CompilerContext (new CompilerSettings (), new Report (new AssertReportPrinter ()));

			ModuleContainer module = new ModuleContainer (ctx);
			CSharpParser parser = new CSharpParser (
				new SeekableStreamReader (stream, Encoding.UTF8),
				new CompilationUnit ("name", "path", 0),
				module);

			RootContext.ToplevelTypes = module;
			Location.AddFile (ctx.Report, "asdfas");
			Location.Initialize ();
			parser.LocationsBag = new LocationsBag ();
			parser.parse ();

			var m = module.Types[0].Methods[0] as Method;
			var s = m.Block.FirstStatement;
			var o = s.loc.Column;
			

			module.Accept (new TestVisitor ());
		}
コード例 #24
0
 public static TypeSpec Resolve(ModuleContainer module, MemberKind kind, string ns, string name, int arity)
 {
     return(Resolve(module, kind, ns, name, arity, true));
 }
コード例 #25
0
 public PatternMatchingHelper(ModuleContainer module)
     : base(module, new MemberName("<PatternMatchingHelper>", Location.Null),
            Modifiers.STATIC | Modifiers.INTERNAL | Modifiers.DEBUGGER_HIDDEN)
 {
 }
コード例 #26
0
 public static ArrayContainer MakeType(ModuleContainer module, TypeSpec element)
 {
     return(MakeType(module, element, 1));
 }
コード例 #27
0
 public RuntimeBinderContext(DynamicContext ctx, Type callingType)
 {
     this.ctx         = ctx;
     this.module      = ctx.Module;
     this.callingType = callingType;
 }
コード例 #28
0
ファイル: driver.cs プロジェクト: mono-soc-2011/monodevelop
        //
        // Main compilation method
        //
        public bool Compile()
        {
            var settings = ctx.Settings;

            //
            // If we are an exe, require a source file for the entry point or
            // if there is nothing to put in the assembly, and we are not a library
            //
            if (settings.FirstSourceFile == null &&
                ((settings.Target == Target.Exe || settings.Target == Target.WinExe || settings.Target == Target.Module) ||
                 settings.Resources == null))
            {
                Report.Error(2008, "No files to compile were specified");
                return(false);
            }

            TimeReporter tr = new TimeReporter(settings.Timestamps);

            ctx.TimeReporter = tr;
            tr.StartTotal();

            var module = new ModuleContainer(ctx);

            RootContext.ToplevelTypes = module;

            tr.Start(TimeReporter.TimerType.ParseTotal);
            Parse(module);
            tr.Stop(TimeReporter.TimerType.ParseTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            if (settings.TokenizeOnly || settings.ParseOnly)
            {
                tr.StopTotal();
                tr.ShowStats();
                return(true);
            }

            var    output_file = settings.OutputFile;
            string output_file_name;

            if (output_file == null)
            {
                var source_file = settings.FirstSourceFile;

                if (source_file == null)
                {
                    Report.Error(1562, "If no source files are specified you must specify the output file with -out:");
                    return(false);
                }

                output_file_name = source_file.Name;
                int pos = output_file_name.LastIndexOf('.');

                if (pos > 0)
                {
                    output_file_name = output_file_name.Substring(0, pos);
                }

                output_file_name += settings.TargetExt;
                output_file       = output_file_name;
            }
            else
            {
                output_file_name = Path.GetFileName(output_file);
            }

#if STATIC
            var importer          = new StaticImporter(module);
            var references_loader = new StaticLoader(importer, ctx);

            tr.Start(TimeReporter.TimerType.AssemblyBuilderSetup);
            var assembly = new AssemblyDefinitionStatic(module, references_loader, output_file_name, output_file);
            assembly.Create(references_loader.Domain);
            tr.Stop(TimeReporter.TimerType.AssemblyBuilderSetup);

            // Create compiler types first even before any referenced
            // assembly is loaded to allow forward referenced types from
            // loaded assembly into compiled builder to be resolved
            // correctly
            tr.Start(TimeReporter.TimerType.CreateTypeTotal);
            module.CreateType();
            importer.AddCompiledAssembly(assembly);
            tr.Stop(TimeReporter.TimerType.CreateTypeTotal);

            references_loader.LoadReferences(module);

            tr.Start(TimeReporter.TimerType.PredefinedTypesInit);
            if (!ctx.BuiltinTypes.CheckDefinitions(module))
            {
                return(false);
            }

            tr.Stop(TimeReporter.TimerType.PredefinedTypesInit);

            references_loader.LoadModules(assembly, module.GlobalRootNamespace);
#else
            var assembly = new AssemblyDefinitionDynamic(module, output_file_name, output_file);
            module.SetDeclaringAssembly(assembly);

            var importer = new ReflectionImporter(module, ctx.BuiltinTypes);
            assembly.Importer = importer;

            var loader = new DynamicLoader(importer, ctx);
            loader.LoadReferences(module);

            if (!ctx.BuiltinTypes.CheckDefinitions(module))
            {
                return(false);
            }

            if (!assembly.Create(AppDomain.CurrentDomain, AssemblyBuilderAccess.Save))
            {
                return(false);
            }

            module.CreateType();

            loader.LoadModules(assembly, module.GlobalRootNamespace);
#endif
            module.InitializePredefinedTypes();

            tr.Start(TimeReporter.TimerType.UsingResolve);
            foreach (var source_file in ctx.SourceFiles)
            {
                source_file.NamespaceContainer.Resolve();
            }
            tr.Stop(TimeReporter.TimerType.UsingResolve);

            tr.Start(TimeReporter.TimerType.ModuleDefinitionTotal);
            module.Define();
            tr.Stop(TimeReporter.TimerType.ModuleDefinitionTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            if (settings.DocumentationFile != null)
            {
                var doc = new DocumentationBuilder(module);
                doc.OutputDocComment(output_file, settings.DocumentationFile);
            }

            assembly.Resolve();

            if (Report.Errors > 0)
            {
                return(false);
            }


            tr.Start(TimeReporter.TimerType.EmitTotal);
            assembly.Emit();
            tr.Stop(TimeReporter.TimerType.EmitTotal);

            if (Report.Errors > 0)
            {
                return(false);
            }

            tr.Start(TimeReporter.TimerType.CloseTypes);
            module.CloseType();
            tr.Stop(TimeReporter.TimerType.CloseTypes);

            tr.Start(TimeReporter.TimerType.Resouces);
            assembly.EmbedResources();
            tr.Stop(TimeReporter.TimerType.Resouces);

            if (Report.Errors > 0)
            {
                return(false);
            }

            assembly.Save();

#if STATIC
            references_loader.Dispose();
#endif
            tr.StopTotal();
            tr.ShowStats();

            return(Report.Errors == 0);
        }
コード例 #29
0
 //
 // Assembly container with file output
 //
 public AssemblyDefinitionStatic(ModuleContainer module, StaticLoader loader, string name, string fileName)
     : base(module, name, fileName)
 {
     this.loader = loader;
     Importer    = loader.MetadataImporter;
 }
コード例 #30
0
 private ArrayContainer(ModuleContainer module, TypeSpec element, int rank)
     : base(MemberKind.ArrayType, element, null)
 {
     this.module = module;
     this.rank   = rank;
 }
コード例 #31
0
ファイル: assembly.cs プロジェクト: tkokof/NRefactory
        protected void LoadReferencesCore(ModuleContainer module, out T corlib_assembly, out List <Tuple <RootNamespace, T> > loaded)
        {
            compiler.TimeReporter.Start(TimeReporter.TimerType.ReferencesLoading);

            loaded = new List <Tuple <RootNamespace, T> > ();

            //
            // Load mscorlib.dll as the first
            //
            if (module.Compiler.Settings.StdLib)
            {
                corlib_assembly = LoadAssemblyFile("mscorlib.dll", true);
            }
            else
            {
                corlib_assembly = default(T);
            }

            T a;

            foreach (string r in module.Compiler.Settings.AssemblyReferences)
            {
                a = LoadAssemblyFile(r, false);
                if (a == null || EqualityComparer <T> .Default.Equals(a, corlib_assembly))
                {
                    continue;
                }

                var key = Tuple.Create(module.GlobalRootNamespace, a);
                if (loaded.Contains(key))
                {
                    continue;
                }

                loaded.Add(key);
            }

            if (corlib_assembly == null)
            {
                //
                // Requires second pass because HasObjectType can trigger assembly load event
                //
                for (int i = 0; i < loaded.Count; ++i)
                {
                    var assembly = loaded [i];

                    //
                    // corlib assembly is the first referenced assembly which contains System.Object
                    //
                    if (HasObjectType(assembly.Item2))
                    {
                        corlib_assembly = assembly.Item2;
                        loaded.RemoveAt(i);
                        break;
                    }
                }
            }

            foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases)
            {
                a = LoadAssemblyFile(entry.Item2, false);
                if (a == null)
                {
                    continue;
                }

                var key = Tuple.Create(module.CreateRootNamespace(entry.Item1), a);
                if (loaded.Contains(key))
                {
                    continue;
                }

                loaded.Add(key);
            }

            if (compiler.Settings.LoadDefaultReferences)
            {
                foreach (string r in GetDefaultReferences())
                {
                    a = LoadAssemblyFile(r, true);
                    if (a == null)
                    {
                        continue;
                    }

                    var key = Tuple.Create(module.GlobalRootNamespace, a);
                    if (loaded.Contains(key))
                    {
                        continue;
                    }

                    loaded.Add(key);
                }
            }

            compiler.TimeReporter.Stop(TimeReporter.TimerType.ReferencesLoading);
        }
コード例 #32
0
ファイル: CSharpParser.cs プロジェクト: 0xb1dd1e/NRefactory
		SyntaxTree Parse(ITextSource program, string fileName, int initialLine, int initialColumn)
		{
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter("");
				var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader(program);
				var file = new SourceFile(fileName, fileName, 0);
				Location.Initialize(new List<SourceFile>(new [] { file }));
				var module = new ModuleContainer(ctx);
				var session = new ParserSession();
				session.LocationsBag = new LocationsBag();
				var report = new Report(ctx, errorReportPrinter);
				var parser = Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
				var top = new CompilerCompilationUnit {
					ModuleCompiled = module,
					LocationsBag = session.LocationsBag,
					SpecialsBag = parser.Lexer.sbag,
					Conditionals = parser.Lexer.SourceFile.Conditionals
				};
				var unit = Parse(top, fileName);
				unit.Errors.AddRange(errorReportPrinter.Errors);
				CompilerCallableEntryPoint.Reset();
				return unit;
			}
		}
コード例 #33
0
        public PredefinedTypes(ModuleContainer module)
        {
            TypedReference = new PredefinedType(module, MemberKind.Struct, "System", "TypedReference");
            ArgIterator    = new PredefinedType(module, MemberKind.Struct, "System", "ArgIterator");

            MarshalByRefObject    = new PredefinedType(module, MemberKind.Class, "System", "MarshalByRefObject");
            RuntimeHelpers        = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "RuntimeHelpers");
            IAsyncResult          = new PredefinedType(module, MemberKind.Interface, "System", "IAsyncResult");
            AsyncCallback         = new PredefinedType(module, MemberKind.Delegate, "System", "AsyncCallback");
            RuntimeArgumentHandle = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeArgumentHandle");
            CharSet               = new PredefinedType(module, MemberKind.Enum, "System.Runtime.InteropServices", "CharSet");
            IsVolatile            = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "IsVolatile");
            IEnumeratorGeneric    = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerator", 1);
            IListGeneric          = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IList", 1);
            ICollectionGeneric    = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "ICollection", 1);
            IEnumerableGeneric    = new PredefinedType(module, MemberKind.Interface, "System.Collections.Generic", "IEnumerable", 1);
            Nullable              = new PredefinedType(module, MemberKind.Struct, "System", "Nullable", 1);
            Activator             = new PredefinedType(module, MemberKind.Class, "System", "Activator");
            Interlocked           = new PredefinedType(module, MemberKind.Class, "System.Threading", "Interlocked");
            Monitor               = new PredefinedType(module, MemberKind.Class, "System.Threading", "Monitor");
            NotSupportedException = new PredefinedType(module, MemberKind.Class, "System", "NotSupportedException");
            RuntimeFieldHandle    = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeFieldHandle");
            RuntimeMethodHandle   = new PredefinedType(module, MemberKind.Struct, "System", "RuntimeMethodHandle");
            SecurityAction        = new PredefinedType(module, MemberKind.Enum, "System.Security.Permissions", "SecurityAction");
            Dictionary            = new PredefinedType(module, MemberKind.Class, "System.Collections.Generic", "Dictionary", 2);
            Hashtable             = new PredefinedType(module, MemberKind.Class, "System.Collections", "Hashtable");

            Expression          = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression");
            ExpressionGeneric   = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "Expression", 1);
            MemberBinding       = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "MemberBinding");
            ParameterExpression = new PredefinedType(module, MemberKind.Class, "System.Linq.Expressions", "ParameterExpression");
            FieldInfo           = new PredefinedType(module, MemberKind.Class, "System.Reflection", "FieldInfo");
            MethodBase          = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodBase");
            MethodInfo          = new PredefinedType(module, MemberKind.Class, "System.Reflection", "MethodInfo");
            ConstructorInfo     = new PredefinedType(module, MemberKind.Class, "System.Reflection", "ConstructorInfo");

            CallSite        = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite");
            CallSiteGeneric = new PredefinedType(module, MemberKind.Class, "System.Runtime.CompilerServices", "CallSite", 1);
            Binder          = new PredefinedType(module, MemberKind.Class, "Microsoft.CSharp.RuntimeBinder", "Binder");
            BinderFlags     = new PredefinedType(module, MemberKind.Enum, "Microsoft.CSharp.RuntimeBinder", "CSharpBinderFlags");

            Action = new PredefinedType(module, MemberKind.Delegate, "System", "Action");
            AsyncVoidMethodBuilder        = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncVoidMethodBuilder");
            AsyncTaskMethodBuilder        = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder");
            AsyncTaskMethodBuilderGeneric = new PredefinedType(module, MemberKind.Struct, "System.Runtime.CompilerServices", "AsyncTaskMethodBuilder", 1);
            Task        = new PredefinedType(module, MemberKind.Class, "System.Threading.Tasks", "Task");
            TaskGeneric = new PredefinedType(module, MemberKind.Class, "System.Threading.Tasks", "Task", 1);

            //
            // Define types which are used for comparison. It does not matter
            // if they don't exist as no error report is needed
            //
            if (TypedReference.Define())
            {
                TypedReference.TypeSpec.IsSpecialRuntimeType = true;
            }

            if (ArgIterator.Define())
            {
                ArgIterator.TypeSpec.IsSpecialRuntimeType = true;
            }

            if (IEnumerableGeneric.Define())
            {
                IEnumerableGeneric.TypeSpec.IsGenericIterateInterface = true;
            }

            if (IListGeneric.Define())
            {
                IListGeneric.TypeSpec.IsGenericIterateInterface = true;
            }

            if (ICollectionGeneric.Define())
            {
                ICollectionGeneric.TypeSpec.IsGenericIterateInterface = true;
            }

            if (Nullable.Define())
            {
                Nullable.TypeSpec.IsNullableType = true;
            }

            if (ExpressionGeneric.Define())
            {
                ExpressionGeneric.TypeSpec.IsExpressionTreeType = true;
            }

            Task.Define();
            if (TaskGeneric.Define())
            {
                TaskGeneric.TypeSpec.IsGenericTask = true;
            }
        }
コード例 #34
0
 protected NamespaceContainer(ModuleContainer parent)
     : base(parent, null, null, MemberKind.Namespace)
 {
     ns = parent.GlobalRootNamespace;
     containers = new List<TypeContainer> (2);
 }
コード例 #35
0
 public CompilationSourceFile(ModuleContainer parent, SourceFile sourceFile)
     : this(parent)
 {
     this.file = sourceFile;
 }
コード例 #36
0
        public PredefinedMembers(ModuleContainer module)
        {
            var types  = module.PredefinedTypes;
            var atypes = module.PredefinedAttributes;
            var btypes = module.Compiler.BuiltinTypes;

            ActivatorCreateInstance = new PredefinedMember <MethodSpec> (module, types.Activator,
                                                                         MemberFilter.Method("CreateInstance", 1, ParametersCompiled.EmptyReadOnlyParameters, null));

            AsyncTaskMethodBuilderCreate = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                                                              MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncTaskMethodBuilder.TypeSpec));

            AsyncTaskMethodBuilderSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                                                                 MemberFilter.Method("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));

            AsyncTaskMethodBuilderSetException = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilder,
                                                                                    MemberFilter.Method("SetException", 0,
                                                                                                        ParametersCompiled.CreateFullyResolved(btypes.Exception), btypes.Void));

            AsyncTaskMethodBuilderTask = new PredefinedMember <PropertySpec> (module, types.AsyncTaskMethodBuilder,
                                                                              MemberFilter.Property("Task", null));

            AsyncTaskMethodBuilderGenericCreate = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                     MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));

            AsyncTaskMethodBuilderGenericSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                        "SetResult", MemberKind.Method, () => new TypeSpec[] {
                types.AsyncTaskMethodBuilderGeneric.TypeSpec.MemberDefinition.TypeParameters[0]
            });

            AsyncTaskMethodBuilderGenericSetException = new PredefinedMember <MethodSpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                           MemberFilter.Method("SetException", 0,
                                                                                                               ParametersCompiled.CreateFullyResolved(btypes.Exception), btypes.Void));

            AsyncTaskMethodBuilderGenericTask = new PredefinedMember <PropertySpec> (module, types.AsyncTaskMethodBuilderGeneric,
                                                                                     MemberFilter.Property("Task", null));

            AsyncVoidMethodBuilderCreate = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                              MemberFilter.Method("Create", 0, ParametersCompiled.EmptyReadOnlyParameters, types.AsyncVoidMethodBuilder.TypeSpec));

            AsyncVoidMethodBuilderSetException = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                                    MemberFilter.Method("SetException", 0, null, btypes.Void));

            AsyncVoidMethodBuilderSetResult = new PredefinedMember <MethodSpec> (module, types.AsyncVoidMethodBuilder,
                                                                                 MemberFilter.Method("SetResult", 0, ParametersCompiled.EmptyReadOnlyParameters, btypes.Void));

            DecimalCtor = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                             MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                          btypes.Int, btypes.Int, btypes.Int, btypes.Bool, btypes.Byte)));

            DecimalCtorInt = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                                MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Int)));

            DecimalCtorLong = new PredefinedMember <MethodSpec> (module, btypes.Decimal,
                                                                 MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Long)));

            DecimalConstantAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.DecimalConstant,
                                                                              MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                                           btypes.Byte, btypes.Byte, btypes.UInt, btypes.UInt, btypes.UInt)));

            DefaultMemberAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.DefaultMember,
                                                                            MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.String)));

            DelegateCombine = new PredefinedMember <MethodSpec> (module, btypes.Delegate, "Combine", btypes.Delegate, btypes.Delegate);
            DelegateRemove  = new PredefinedMember <MethodSpec> (module, btypes.Delegate, "Remove", btypes.Delegate, btypes.Delegate);

            DelegateEqual = new PredefinedMember <MethodSpec> (module, btypes.Delegate,
                                                               new MemberFilter(Operator.GetMetadataName(Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));

            DelegateInequal = new PredefinedMember <MethodSpec> (module, btypes.Delegate,
                                                                 new MemberFilter(Operator.GetMetadataName(Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));

            DynamicAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.Dynamic,
                                                                      MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(
                                                                                                   ArrayContainer.MakeType(module, btypes.Bool))));

            FieldInfoGetFieldFromHandle = new PredefinedMember <MethodSpec> (module, types.FieldInfo,
                                                                             "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle);

            FieldInfoGetFieldFromHandle2 = new PredefinedMember <MethodSpec> (module, types.FieldInfo,
                                                                              "GetFieldFromHandle", MemberKind.Method, types.RuntimeFieldHandle, new PredefinedType(btypes.RuntimeTypeHandle));

            FixedBufferAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.FixedBuffer,
                                                                          MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Type, btypes.Int)));

            IDisposableDispose = new PredefinedMember <MethodSpec> (module, btypes.IDisposable, "Dispose", TypeSpec.EmptyTypes);

            IEnumerableGetEnumerator = new PredefinedMember <MethodSpec> (module, btypes.IEnumerable,
                                                                          "GetEnumerator", TypeSpec.EmptyTypes);

            InterlockedCompareExchange = new PredefinedMember <MethodSpec> (module, types.Interlocked,
                                                                            MemberFilter.Method("CompareExchange", 0,
                                                                                                new ParametersImported(
                                                                                                    new[] {
                new ParameterData(null, Parameter.Modifier.REF),
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.NONE)
            },
                                                                                                    new[] {
                btypes.Int, btypes.Int, btypes.Int
            },
                                                                                                    false),
                                                                                                btypes.Int));

            InterlockedCompareExchange_T = new PredefinedMember <MethodSpec> (module, types.Interlocked,
                                                                              MemberFilter.Method("CompareExchange", 1,
                                                                                                  new ParametersImported(
                                                                                                      new[] {
                new ParameterData(null, Parameter.Modifier.REF),
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.NONE)
            },
                                                                                                      new[] {
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
                new TypeParameterSpec(0, null, SpecialConstraint.None, Variance.None, null),
            }, false),
                                                                                                  null));

            MethodInfoGetMethodFromHandle = new PredefinedMember <MethodSpec> (module, types.MethodBase,
                                                                               "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle);

            MethodInfoGetMethodFromHandle2 = new PredefinedMember <MethodSpec> (module, types.MethodBase,
                                                                                "GetMethodFromHandle", MemberKind.Method, types.RuntimeMethodHandle, new PredefinedType(btypes.RuntimeTypeHandle));

            MonitorEnter = new PredefinedMember <MethodSpec> (module, types.Monitor, "Enter", btypes.Object);

            MonitorEnter_v4 = new PredefinedMember <MethodSpec> (module, types.Monitor,
                                                                 MemberFilter.Method("Enter", 0,
                                                                                     new ParametersImported(new[] {
                new ParameterData(null, Parameter.Modifier.NONE),
                new ParameterData(null, Parameter.Modifier.REF)
            },
                                                                                                            new[] {
                btypes.Object, btypes.Bool
            }, false), null));

            MonitorExit = new PredefinedMember <MethodSpec> (module, types.Monitor, "Exit", btypes.Object);

            RuntimeCompatibilityWrapNonExceptionThrows = new PredefinedMember <PropertySpec> (module, atypes.RuntimeCompatibility,
                                                                                              MemberFilter.Property("WrapNonExceptionThrows", btypes.Bool));

            RuntimeHelpersInitializeArray = new PredefinedMember <MethodSpec> (module, types.RuntimeHelpers,
                                                                               "InitializeArray", btypes.Array, btypes.RuntimeFieldHandle);

            RuntimeHelpersOffsetToStringData = new PredefinedMember <PropertySpec> (module, types.RuntimeHelpers,
                                                                                    MemberFilter.Property("OffsetToStringData", btypes.Int));

            SecurityActionRequestMinimum = new PredefinedMember <ConstSpec> (module, types.SecurityAction, "RequestMinimum",
                                                                             MemberKind.Field, types.SecurityAction);

            StringEmpty = new PredefinedMember <FieldSpec> (module, btypes.String, MemberFilter.Field("Empty", btypes.String));

            StringEqual = new PredefinedMember <MethodSpec> (module, btypes.String,
                                                             new MemberFilter(Operator.GetMetadataName(Operator.OpType.Equality), 0, MemberKind.Operator, null, btypes.Bool));

            StringInequal = new PredefinedMember <MethodSpec> (module, btypes.String,
                                                               new MemberFilter(Operator.GetMetadataName(Operator.OpType.Inequality), 0, MemberKind.Operator, null, btypes.Bool));

            StructLayoutAttributeCtor = new PredefinedMember <MethodSpec> (module, atypes.StructLayout,
                                                                           MemberFilter.Constructor(ParametersCompiled.CreateFullyResolved(btypes.Short)));

            StructLayoutCharSet = new PredefinedMember <FieldSpec> (module, atypes.StructLayout, "CharSet",
                                                                    MemberKind.Field, types.CharSet);

            StructLayoutSize = new PredefinedMember <FieldSpec> (module, atypes.StructLayout,
                                                                 MemberFilter.Field("Size", btypes.Int));

            TypeGetTypeFromHandle = new PredefinedMember <MethodSpec> (module, btypes.Type, "GetTypeFromHandle", btypes.RuntimeTypeHandle);
        }
コード例 #37
0
 //
 // Assembly container with file output
 //
 public AssemblyDefinitionDynamic(ModuleContainer module, string name, string fileName)
     : base(module, name, fileName)
 {
 }
コード例 #38
0
ファイル: assembly.cs プロジェクト: yehia2amer/Alter-Native
        protected void LoadReferencesCore(ModuleContainer module, out T corlib_assembly, out List <Tuple <RootNamespace, T> > loaded)
        {
            compiler.TimeReporter.Start(TimeReporter.TimerType.ReferencesLoading);

            loaded = new List <Tuple <RootNamespace, T> > ();

            //
            // Load mscorlib.dll as the first
            //
            if (module.Compiler.Settings.StdLib)
            {
                corlib_assembly = LoadAssemblyFile("mscorlib.dll", true);
            }
            else
            {
                corlib_assembly = default(T);
            }

            T a;

            foreach (string r in module.Compiler.Settings.AssemblyReferences)
            {
                a = LoadAssemblyFile(r, false);
                if (a == null || EqualityComparer <T> .Default.Equals(a, corlib_assembly))
                {
                    continue;
                }

                var key = Tuple.Create(module.GlobalRootNamespace, a);
                if (loaded.Contains(key))
                {
                    continue;
                }

                // A corlib assembly is the first assembly which contains System.Object
                if (corlib_assembly == null && HasObjectType(a))
                {
                    corlib_assembly = a;
                    continue;
                }

                loaded.Add(key);
            }

            foreach (var entry in module.Compiler.Settings.AssemblyReferencesAliases)
            {
                a = LoadAssemblyFile(entry.Item2, false);
                if (a == null)
                {
                    continue;
                }

                var key = Tuple.Create(module.CreateRootNamespace(entry.Item1), a);
                if (loaded.Contains(key))
                {
                    continue;
                }

                loaded.Add(key);
            }

            if (compiler.Settings.LoadDefaultReferences)
            {
                foreach (string r in GetDefaultReferences())
                {
                    a = LoadAssemblyFile(r, true);
                    if (a == null)
                    {
                        continue;
                    }

                    var key = Tuple.Create(module.GlobalRootNamespace, a);
                    if (loaded.Contains(key))
                    {
                        continue;
                    }

                    loaded.Add(key);
                }
            }

            compiler.TimeReporter.Stop(TimeReporter.TimerType.ReferencesLoading);
        }
コード例 #39
0
 public ReflectionImporter(ModuleContainer module, BuiltinTypes builtin)
 {
     throw new NotSupportedException();
 }
コード例 #40
0
ファイル: namespace.cs プロジェクト: raj581/Marvin
        public void AddType(ModuleContainer module, TypeSpec ts)
        {
            if (types == null)
            {
                types = new Dictionary <string, IList <TypeSpec> > (64);
            }

            var name = ts.Name;
            IList <TypeSpec> existing;

            if (types.TryGetValue(name, out existing))
            {
                TypeSpec better_type;
                TypeSpec found;
                if (existing.Count == 1)
                {
                    found = existing[0];
                    if (ts.Arity == found.Arity)
                    {
                        better_type = IsImportedTypeOverride(module, ts, found);
                        if (better_type == found)
                        {
                            return;
                        }

                        if (better_type != null)
                        {
                            existing [0] = better_type;
                            return;
                        }
                    }

                    existing = new List <TypeSpec> ();
                    existing.Add(found);
                    types[name] = existing;
                }
                else
                {
                    for (int i = 0; i < existing.Count; ++i)
                    {
                        found = existing[i];
                        if (ts.Arity != found.Arity)
                        {
                            continue;
                        }

                        better_type = IsImportedTypeOverride(module, ts, found);
                        if (better_type == found)
                        {
                            return;
                        }

                        if (better_type != null)
                        {
                            existing.RemoveAt(i);
                            --i;
                            continue;
                        }
                    }
                }

                existing.Add(ts);
            }
            else
            {
                types.Add(name, new TypeSpec[] { ts });
            }
        }
コード例 #41
0
 public static NamedTupleSpec MakeType(ModuleContainer module, InflatedTypeSpec tupleType, IList <string> names)
 {
     // TODO: cache it
     return(new NamedTupleSpec(tupleType, names));
 }
コード例 #42
0
ファイル: visit.cs プロジェクト: LuoWeiweiGithub/ILTools
 public virtual void Visit(ModuleContainer module)
 {
     VisitTypeContainer(module);
 }
コード例 #43
0
 private DynamicContext(Compiler.ModuleContainer module, Compiler.ReflectionImporter importer)
 {
     this.module   = module;
     this.importer = importer;
 }
コード例 #44
0
ファイル: module.cs プロジェクト: HusterYP/VimConf
 public StaticDataContainer(ModuleContainer module)
     : base(module, new MemberName("<PrivateImplementationDetails>" + module.builder.ModuleVersionId.ToString("B"), Location.Null),
            Modifiers.STATIC | Modifiers.INTERNAL)
 {
     size_types = new Dictionary <int, Struct> ();
 }
コード例 #45
0
 public PredefinedMember(ModuleContainer module, PredefinedType type, string name, MemberKind kind, params PredefinedType[] types)
     : this(module, type, new MemberFilter(name, 0, kind, null, null))
 {
     parameters_predefined = types;
 }
コード例 #46
0
ファイル: driver.cs プロジェクト: yehia2amer/Alter-Native
        public CSharpParser Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module)
        {
            var file = new CompilationSourceFile(module, sourceFile);

            module.AddTypeContainer(file);

            CSharpParser parser = new CSharpParser(reader, file);

            parser.Lexer.sbag = new SpecialsBag();
            parser.parse();
            return(parser);
        }
コード例 #47
0
 public RuntimeBinderContext(DynamicContext ctx, Compiler.TypeSpec callingType)
 {
     this.ctx    = ctx;
     this.module = ctx.Module;
     this.callingTypeImported = callingType;
 }
コード例 #48
0
 public RootDeclSpace(ModuleContainer module, NamespaceContainer ns)
     : base(ns, null, MemberName.Null, null, 0)
 {
     PartialContainer = module;
 }
コード例 #49
0
        public static TypeSpec Resolve(ModuleContainer module, MemberKind kind, string ns, string name, int arity, bool reportErrors)
        {
            Namespace type_ns = module.GlobalRootNamespace.GetNamespace(ns, true);
            var       found   = type_ns.GetAllTypes(name);

            if (found == null)
            {
                if (reportErrors)
                {
                    module.Compiler.Report.Error(518, "The predefined type `{0}.{1}' is not defined or imported", ns, name);
                }

                return(null);
            }

            TypeSpec best_match = null;

            foreach (var candidate in found)
            {
                if (candidate.Kind != kind)
                {
                    if (candidate.Kind == MemberKind.Struct && kind == MemberKind.Void && candidate.MemberDefinition is TypeContainer)
                    {
                        // Void is declared as struct but we keep it internally as
                        // special kind, the swap will be done by caller
                    }
                    else
                    {
                        continue;
                    }
                }

                if (candidate.Arity != arity)
                {
                    continue;
                }

                if ((candidate.Modifiers & Modifiers.INTERNAL) != 0 && !candidate.MemberDefinition.IsInternalAsPublic(module.DeclaringAssembly))
                {
                    continue;
                }

                if (best_match == null)
                {
                    best_match = candidate;
                    continue;
                }

                var other_match = best_match;
                if (!best_match.MemberDefinition.IsImported &&
                    module.Compiler.BuiltinTypes.Object.MemberDefinition.DeclaringAssembly == candidate.MemberDefinition.DeclaringAssembly)
                {
                    best_match = candidate;
                }

                string location;
                if (best_match.MemberDefinition is MemberCore)
                {
                    location = ((MemberCore)best_match.MemberDefinition).Location.Name;
                }
                else
                {
                    var assembly = (ImportedAssemblyDefinition)best_match.MemberDefinition.DeclaringAssembly;
                    location = Path.GetFileName(assembly.Location);
                }

                module.Compiler.Report.SymbolRelatedToPreviousError(other_match);
                module.Compiler.Report.SymbolRelatedToPreviousError(candidate);

                module.Compiler.Report.Warning(1685, 1,
                                               "The predefined type `{0}.{1}' is defined multiple times. Using definition from `{2}'",
                                               ns, name, location);

                break;
            }

            if (best_match == null && reportErrors)
            {
                Location loc;
                if (found[0].MemberDefinition is MemberCore)
                {
                    loc = ((MemberCore)found[0].MemberDefinition).Location;
                }
                else
                {
                    loc = Location.Null;
                    module.Compiler.Report.SymbolRelatedToPreviousError(found[0]);
                }

                module.Compiler.Report.Error(520, loc, "The predefined type `{0}.{1}' is not declared correctly", ns, name);
            }

            return(best_match);
        }
コード例 #50
0
 public PredefinedType(ModuleContainer module, MemberKind kind, string ns, string name, int arity)
     : this(module, kind, ns, name)
 {
     this.arity = arity;
 }
コード例 #51
0
        public void AddType(ModuleContainer module, TypeSpec ts)
        {
            if (types == null) {
                types = new Dictionary<string, IList<TypeSpec>> (64);
            }

            if (ts.IsClass && ts.Arity == 0) {
                var extension_method_allowed = ts.MemberDefinition.IsImported ? (ts.Modifiers & Modifiers.METHOD_EXTENSION) != 0 : (ts.IsStatic || ts.MemberDefinition.IsPartial);
                if (extension_method_allowed) {
                    if (extension_method_types == null)
                        extension_method_types = new List<TypeSpec> ();

                    extension_method_types.Add (ts);
                }
            }

            var name = ts.Name;
            IList<TypeSpec> existing;
            if (types.TryGetValue (name, out existing)) {
                TypeSpec better_type;
                TypeSpec found;
                if (existing.Count == 1) {
                    found = existing[0];
                    if (ts.Arity == found.Arity) {
                        better_type = IsImportedTypeOverride (module, ts, found);
                        if (better_type == found)
                            return;

                        if (better_type != null) {
                            existing [0] = better_type;
                            return;
                        }
                    }

                    existing = new List<TypeSpec> ();
                    existing.Add (found);
                    types[name] = existing;
                } else {
                    for (int i = 0; i < existing.Count; ++i) {
                        found = existing[i];
                        if (ts.Arity != found.Arity)
                            continue;

                        better_type = IsImportedTypeOverride (module, ts, found);
                        if (better_type == found)
                            return;

                        if (better_type != null) {
                            existing.RemoveAt (i);
                            --i;
                            continue;
                        }
                    }
                }

                existing.Add (ts);
            } else {
                types.Add (name, new TypeSpec[] { ts });
            }
        }
コード例 #52
0
 public PredefinedMember(ModuleContainer module, TypeSpec type, MemberFilter filter)
 {
     this.module         = module;
     this.declaring_type = type;
     this.filter         = filter;
 }
コード例 #53
0
 public CompilationSourceFile(ModuleContainer parent)
     : base(parent)
 {
 }
コード例 #54
0
 public PredefinedMember(ModuleContainer module, PredefinedType type, string name, MemberKind kind, Func <TypeSpec[]> typesBuilder)
     : this(module, type, new MemberFilter(name, 0, kind, null, null))
 {
     filter_builder = typesBuilder;
 }
コード例 #55
0
			public override void Visit (ModuleContainer mc)
			{
				foreach (var at in ConvertAttributes (mc.OptAttributes, mc))
					Unit.Add (at);
			}
コード例 #56
0
 public PredefinedMember(ModuleContainer module, BuiltinTypeSpec type, string name, params TypeSpec[] types)
     : this(module, type, MemberFilter.Method(name, 0, ParametersCompiled.CreateFullyResolved(types), null))
 {
 }
コード例 #57
0
ファイル: CSharpParser.cs プロジェクト: 0xb1dd1e/NRefactory
		/*
		/// <summary>
		/// Parses a file snippet; guessing what the code snippet represents (whole file, type members, block, type reference, expression).
		/// </summary>
		public AstNode ParseSnippet (string code)
		{
			// TODO: add support for parsing a part of a file
			throw new NotImplementedException ();
		}
		 */
		public DocumentationReference ParseDocumentationReference(string cref)
		{
			// see Mono.CSharp.DocumentationBuilder.HandleXrefCommon
			if (cref == null)
				throw new ArgumentNullException("cref");
			
			// Additional symbols for < and > are allowed for easier XML typing
			cref = cref.Replace('{', '<').Replace('}', '>');
			
			lock (parseLock) {
				errorReportPrinter = new ErrorReportPrinter("");
				var ctx = new CompilerContext(compilerSettings.ToMono(), errorReportPrinter);
				ctx.Settings.TabSize = 1;
				var reader = new SeekableStreamReader(new StringTextSource(cref));
				var file = new SourceFile("", "", 0);
				Location.Initialize(new List<SourceFile>(new [] { file }));
				var module = new ModuleContainer(ctx);
				module.DocumentationBuilder = new DocumentationBuilder(module);
				var source_file = new CompilationSourceFile(module);
				var report = new Report(ctx, errorReportPrinter);
				var session = new ParserSession();
				session.LocationsBag = new LocationsBag();
				var parser = new Mono.CSharp.CSharpParser(reader, source_file, report, session);
				parser.Lexer.Line += initialLocation.Line - 1;
				parser.Lexer.Column += initialLocation.Column - 1;
				parser.Lexer.putback_char = Tokenizer.DocumentationXref;
				parser.Lexer.parsing_generic_declaration_doc = true;
				parser.parse();
				if (report.Errors > 0) {
//					Report.Warning (1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'",
//					                mc.GetSignatureForError (), cref);
				}
				
				var conversionVisitor = new ConversionVisitor(false, session.LocationsBag);
				var docRef = conversionVisitor.ConvertXmlDoc(module.DocumentationBuilder);
				CompilerCallableEntryPoint.Reset();
				return docRef;
			}
		}
コード例 #58
0
ファイル: assembly.cs プロジェクト: yehia2amer/Alter-Native
 protected AssemblyDefinition(ModuleContainer module, string name, string fileName)
     : this(module, name)
 {
     this.file_name = fileName;
 }
コード例 #59
0
ファイル: anonymous.cs プロジェクト: rabink/mono
		private AnonymousTypeClass (ModuleContainer parent, MemberName name, IList<AnonymousTypeParameter> parameters, Location loc)
			: base (parent, name, parent.Evaluator != null ? Modifiers.PUBLIC : Modifiers.INTERNAL)
		{
			this.parameters = parameters;
		}
コード例 #60
0
ファイル: assembly.cs プロジェクト: yehia2amer/Alter-Native
 public abstract void LoadReferences(ModuleContainer module);