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), Roles.NamespaceKeyword);
						}
						ConvertNamespaceName(nspace.RealMemberName, nDecl);
						if (loc != null && loc.Count > 1) {
							nDecl.AddChild(new CSharpTokenNode (Convert(loc [1]), Roles.LBrace), Roles.LBrace);
						}
						AddToNamespace(nDecl);
						namespaceStack.Push(nDecl);
					}
					
					if (nspace.Usings != null) {
						foreach (var us in nspace.Usings) {
							us.Accept(this);
						}
					}
					
					if (first) {
						first = false;
						if (mc.OptAttributes != null) {
							foreach (var attr in mc.OptAttributes.Sections) {
								unit.AddChild (ConvertAttributeSection (attr), SyntaxTree.MemberRole);
							}
						}
					}
					
					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), Roles.RBrace);
						if (loc != null && loc.Count > 3)
							nDecl.AddChild (new CSharpTokenNode (Convert (loc [3]), Roles.Semicolon), Roles.Semicolon);
						
						namespaceStack.Pop ();
					} else {
						AddAttributeSection (unit, nspace.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
					}
				}
				AddAttributeSection (unit, mc.UnattachedAttributes, EntityDeclaration.UnattachedAttributeRole);
			}
Example #2
0
		public Evaluator (CompilerContext ctx)
		{
			this.ctx = ctx;

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

			source_file = new CompilationSourceFile (module, null);
			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>> ();
		}
		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]
			};

			for (int i = 0; i < sources.Count; ++i) {
				if (tokenize_only) {
					tokenize_file (sources[i], module, session);
				} else {
					Parse (sources[i], module, session, Report);
				}
			}
		}
		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;
		}
		protected NamespaceContainer (ModuleContainer parent)
			: base (parent, null, null, MemberKind.Namespace)
		{
			ns = parent.GlobalRootNamespace;
			containers = new List<TypeContainer> (2);
		}
		public CompilationSourceFile (ModuleContainer parent, SourceFile sourceFile)
			: this (parent)
		{
			this.file = sourceFile;
		}
		public CompilationSourceFile (ModuleContainer parent)
			: base (parent)
		{
		}
		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 });
			}
		}
		//
		// We import any types but in the situation there are same types
		// but one has better visibility (either public or internal with friend)
		// the less visible type is removed from the namespace cache
		//
		public static TypeSpec IsImportedTypeOverride (ModuleContainer module, TypeSpec ts, TypeSpec found)
		{
			var ts_accessible = (ts.Modifiers & Modifiers.PUBLIC) != 0 || ts.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);
			var found_accessible = (found.Modifiers & Modifiers.PUBLIC) != 0 || found.MemberDefinition.IsInternalAsPublic (module.DeclaringAssembly);

			if (ts_accessible && !found_accessible)
				return ts;

			// found is better always better for accessible or inaccessible ts
			if (!ts_accessible)
				return found;

			return null;
		}
        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);
        }
 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> ();
 }
 //
 // Assembly container with file output
 //
 public AssemblyDefinitionDynamic(ModuleContainer module, string name, string fileName)
     : base(module, name, fileName)
 {
 }
 protected AssemblyDefinition(ModuleContainer module, string name, string fileName)
     : this(module, name)
 {
     this.file_name = fileName;
 }
		public static object Parse (SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report, int lineModifier = 0, int colModifier = 0)
		{
			var file = new CompilationSourceFile (module, sourceFile);
			module.AddTypeContainer(file);

			object parser = null;
			
			if (sourceFile.FileType == SourceFileType.CSharp) {
				CSharpParser csParser = new CSharpParser (reader, file, report, session);
				csParser.Lexer.Line += lineModifier;
				csParser.Lexer.Column += colModifier;
				csParser.Lexer.sbag = new SpecialsBag ();
				csParser.parse ();
				parser = csParser;
			} else {
				PlayScriptParser psParser = new PlayScriptParser (reader, file, report, session);
				psParser.parsing_playscript = sourceFile.PsExtended;
				psParser.Lexer.Line += lineModifier;
				psParser.Lexer.Column += colModifier;
				psParser.Lexer.sbag = new SpecialsBag ();
				psParser.parse ();
				parser = psParser;
			}
			
			return parser;
		}
		//
		// 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;
			}

			if (settings.Platform == Platform.AnyCPU32Preferred && (settings.Target == Target.Library || settings.Target == Target.Module)) {
				Report.Error (4023, "Platform option `anycpu32bitpreferred' is valid only for executables");
				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 (string.IsNullOrEmpty (Path.GetFileNameWithoutExtension (output_file_name)) ||
					output_file_name.IndexOfAny (Path.GetInvalidFileNameChars ()) >= 0) {
					Report.Error (2021, "Output file name is not valid");
					return false;
				}
			}

#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.CreateContainer ();
			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.CreateContainer ();

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

			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.CloseContainer ();
			tr.Stop (TimeReporter.TimerType.CloseTypes);

			tr.Start (TimeReporter.TimerType.Resouces);
			if (!settings.WriteMetadataOnly)
				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;
		}
		public void Parse (SourceFile file, ModuleContainer module, ParserSession session, Report report)
		{
			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, session.StreamReaderBuffer);

			Parse (reader, file, module, session, report);

			if (ctx.Settings.GenerateDebugInfo && report.Errors == 0 && !file.HasChecksum) {
				input.Position = 0;
				var checksum = session.GetChecksumAlgorithm ();
				file.SetChecksum (checksum.ComputeHash (input));
			}

			reader.Dispose ();
			input.Close ();
		}
		void ParseParallel (ModuleContainer module)
		{
			var sources = module.Compiler.SourceFiles;

			Location.Initialize (sources);

			var pcount = Environment.ProcessorCount;
			var threads = new Thread[System.Math.Max (2, pcount - 1)];

			for (int i = 0; i < threads.Length; ++i) {
				var t = new Thread (l => {
					var session = new ParserSession () {
						//UseJayGlobalArrays = true,
					};

					var report = new Report (ctx, Report.Printer); // TODO: Implement flush at once printer

					for (int ii = (int) l; ii < sources.Count; ii += threads.Length) {
						Parse (sources[ii], module, session, report);
					}

					// TODO: Merge warning regions
				});

				t.Start (i);
				threads[i] = t;
			}

			for (int t = 0; t < threads.Length; ++t) {
				threads[t].Join ();
			}
		}
Example #18
0
        //
        // 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);
            }

            if (settings.Platform == Platform.AnyCPU32Preferred && (settings.Target == Target.Library || settings.Target == Target.Module))
            {
                Report.Error(4023, "Platform option `anycpu32bitpreferred' is valid only for executables");
                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 (string.IsNullOrEmpty(Path.GetFileNameWithoutExtension(output_file_name)) ||
                    output_file_name.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
                {
                    Report.Error(2021, "Output file name is not valid");
                    return(false);
                }
            }

#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.CreateContainer();
            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.CreateContainer();

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

            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.CloseContainer();
            tr.Stop(TimeReporter.TimerType.CloseTypes);

            tr.Start(TimeReporter.TimerType.Resouces);
            if (!settings.WriteMetadataOnly)
            {
                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);
        }
Example #19
0
        public static object Parse(SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report, int lineModifier = 0, int colModifier = 0)
        {
            var file = new CompilationSourceFile(module, sourceFile);

            module.AddTypeContainer(file);

            object parser = null;

            if (sourceFile.FileType == SourceFileType.CSharp)
            {
                CSharpParser csParser = new CSharpParser(reader, file, report, session);
                csParser.Lexer.Line   += lineModifier;
                csParser.Lexer.Column += colModifier;
                csParser.Lexer.sbag    = new SpecialsBag();
                csParser.parse();
                parser = csParser;
            }
            else
            {
                PlayScriptParser psParser = new PlayScriptParser(reader, file, report, session);
                psParser.parsing_playscript = sourceFile.PsExtended;
                psParser.Lexer.Line        += lineModifier;
                psParser.Lexer.Column      += colModifier;
                psParser.Lexer.sbag         = new SpecialsBag();
                psParser.parse();
                parser = psParser;
            }

            return(parser);
        }
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report, ParserSession session)
{
	this.file = file;
	current_container = current_namespace = file;
	
	this.module = file.Module;
	this.compiler = file.Compiler;
	this.settings = compiler.Settings;
	this.report = report;
	
	lang_version = settings.Version;
	yacc_verbose_flag = settings.VerboseParserFlag;
	doc_support = settings.DocumentationFile != null;
	lexer = new Tokenizer (reader, file, session);
	oob_stack = new Stack<object> ();
	lbag = session.LocationsBag;
	use_global_stacks = session.UseJayGlobalArrays;
	parameters_bucket = session.ParametersStack;
}
 public ReflectionImporter(ModuleContainer module, BuiltinTypes builtin)
 {
     throw new NotSupportedException();
 }
		/*
		/// <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.CSharpPs.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);
				ParserSession session = new ParserSession ();
				session.LocationsBag = new LocationsBag ();
				var parser = new Mono.PlayScript.PlayScriptParser (reader, source_file, report, session);
				parser.parsing_playscript = (source_file.SourceFile != null) ? source_file.SourceFile.PsExtended : true;
				parser.Lexer.Line += initialLocation.Line - 1;
				parser.Lexer.Column += initialLocation.Column - 1;
				parser.Lexer.putback_char = Mono.PlayScript.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);
				}
				
				ConversionVisitor conversionVisitor = new ConversionVisitor (false, session.LocationsBag);
				DocumentationReference docRef = conversionVisitor.ConvertXmlDoc(module.DocumentationBuilder);
				CompilerCallableEntryPoint.Reset();
				return docRef;
			}
		}
 public abstract void LoadReferences(ModuleContainer module);
		protected MetadataImporter (ModuleContainer module)
		{
			this.module = module;

			import_cache = new Dictionary<MetaType, TypeSpec> (1024, ReferenceEquality<MetaType>.Default);
			compiled_types = new Dictionary<MetaType, TypeSpec> (40, ReferenceEquality<MetaType>.Default);
			assembly_2_definition = new Dictionary<Assembly, IAssemblyDefinition> (ReferenceEquality<Assembly>.Default);
			IgnorePrivateMembers = true;
		}
		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);
				CompilerCompilationUnit top;
				if (String.IsNullOrEmpty(fileName) || fileName.EndsWith(".play") || fileName.EndsWith(".as")) {
					if (String.IsNullOrEmpty(fileName) || fileName.EndsWith(".play"))
						file.PsExtended = true; // Assume playscript unless we have an actual file ext.
					var parser = (Mono.PlayScript.PlayScriptParser)Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
					top = new CompilerCompilationUnit() {
						ModuleCompiled = module,
						LocationsBag = session.LocationsBag,
						SpecialsBag = parser.Lexer.sbag,
						Conditionals = parser.Lexer.SourceFile.Conditionals
					};
				} else {
					var parser = (Mono.CSharpPs.CSharpParser)Driver.Parse(reader, file, module, session, report, initialLine - 1, initialColumn - 1);
					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;
			}
		}
			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> ();
			}
Example #27
0
		public virtual void Visit (ModuleContainer mc)
		{
			foreach (var container in mc.Containers) {
				container.Accept (this);
			}
		}
		private AnonymousTypeClass (ModuleContainer parent, MemberName name, IList<AnonymousTypeParameter> parameters, Location loc)
			: base (parent, name, parent.Evaluator != null ? Modifiers.PUBLIC : Modifiers.INTERNAL)
		{
			this.parameters = parameters;
		}