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 ();
		}	
Beispiel #2
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;
		}
        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();
        }
Beispiel #4
0
		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>> ();
		}
Beispiel #5
0
		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>> ();
		}
Beispiel #6
0
        //
        // This is used when we encounter a #line preprocessing directive during parsing
        // to register additional source file names
        //
        public SourceFile LookupFile(CompilationSourceFile comp_unit, string name)
        {
            if (all_source_files == null)
            {
                all_source_files = new Dictionary <string, SourceFile>();
                foreach (var source in SourceFiles)
                {
                    all_source_files[source.FullPathName] = source;
                }
            }

            string path;

            if (!Path.IsPathRooted(name))
            {
                var    loc  = comp_unit.SourceFile;
                string root = Path.GetDirectoryName(loc.FullPathName);
                path = Path.GetFullPath(Path.Combine(root, name));
                var dir = Path.GetDirectoryName(loc.Name);
                if (!string.IsNullOrEmpty(dir))
                {
                    name = Path.Combine(dir, name);
                }
            }
            else
            {
                path = name;
            }

            SourceFile retval;

            if (all_source_files.TryGetValue(path, out retval))
            {
                return(retval);
            }

            retval = new SourceFile(name, path, all_source_files.Count + 1);
            Location.AddFile(retval);
            all_source_files.Add(path, retval);
            return(retval);
        }
Beispiel #7
0
        public NamespaceEntry(ModuleContainer module, NamespaceEntry parent, CompilationSourceFile sourceFile, string name)
        {
            this.module = module;
            this.parent = parent;
            this.file   = sourceFile;

            if (parent != null)
            {
                ns = parent.NS.GetNamespace(name, true);
            }
            else if (name != null)
            {
                ns = module.GlobalRootNamespace.GetNamespace(name, true);
            }
            else
            {
                ns = module.GlobalRootNamespace;
            }

            SlaveDeclSpace = new RootDeclSpace(module, this);
        }
Beispiel #8
0
		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;
		}
Beispiel #9
0
        public NamespaceContainer(MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
        {
            this.module = module;
            this.parent = parent;
            this.file   = sourceFile;
            this.loc    = name == null ? Location.Null : name.Location;

            if (parent != null)
            {
                ns = parent.NS.GetNamespace(name.GetName(), true);
            }
            else if (name != null)
            {
                ns = module.GlobalRootNamespace.GetNamespace(name.GetName(), true);
            }
            else
            {
                ns = module.GlobalRootNamespace;
            }

            SlaveDeclSpace = new RootDeclSpace(module, this);
        }
Beispiel #10
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)
            {
                IgnorePrivateMembers         = false,
                IgnoreCompilerGeneratedField = false
            };

            InteractiveBaseClass = typeof(InteractiveBase);
            fields = new Dictionary <string, Tuple <FieldSpec, FieldInfo> > ();
        }
Beispiel #11
0
        public bool IsConditionallyExcluded(IMemberContext ctx)
        {
            if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
            {
                return(false);
            }

            var conditions = MemberDefinition.ConditionalConditions();

            if (conditions == null)
            {
                return(false);
            }

            var m = ctx.CurrentMemberDefinition;
            CompilationSourceFile unit = null;

            while (m != null && unit == null)
            {
                unit = m as CompilationSourceFile;
                m    = m.Parent;
            }

            if (unit != null)
            {
                foreach (var condition in conditions)
                {
                    if (unit.IsConditionalDefined(condition))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #12
0
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
	: this (reader, file, file.NamespaceContainer.Module.Compiler.Report)
{
}
Beispiel #13
0
		void AddSourceFile (string fileName, List<CompilationSourceFile> sourceFiles)
		{
			string path = Path.GetFullPath (fileName);

			int index;
			if (source_file_index.TryGetValue (path, out index)) {
				string other_name = sourceFiles[index - 1].Name;
				if (fileName.Equals (other_name))
					report.Warning (2002, 1, "Source file `{0}' specified multiple times", other_name);
				else
					report.Warning (2002, 1, "Source filenames `{0}' and `{1}' both refer to the same file: {2}", fileName, other_name, path);

				return;
			}

			var unit = new CompilationSourceFile (fileName, path, sourceFiles.Count + 1);
			sourceFiles.Add (unit);
			source_file_index.Add (path, unit.Index);
		}
Beispiel #14
0
		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;
		}
		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
					//                                     Driver d = Driver.Create (args, false, null, reportPrinter);
					//                                     if (d == null)
					//                                             return null;
       
					var r = new Report (reportPrinter);
					CommandLineParser cmd = new CommandLineParser (r, Console.Out);
					var setting = cmd.ParseArguments (args);
					if (setting == null || r.Errors > 0)
						return null;

					CompilerContext ctx = new CompilerContext (setting, r);
					
					var files = new List<CompilationSourceFile> ();
					var unit = new CompilationSourceFile (inputFile, inputFile, 0);
					var module = new ModuleContainer (ctx);
					unit.NamespaceContainer = new NamespaceContainer (null, module, null, unit);
					files.Add (unit);
					Location.Initialize (files);

					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
				
					RootContext.ToplevelTypes = module;
					
					CSharpParser parser = new CSharpParser (reader, unit);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { 
						ModuleCompiled = RootContext.ToplevelTypes,
						LocationsBag = parser.LocationsBag, 
						UsingsBag = parser.UsingsBag, 
						SpecialsBag = parser.Lexer.sbag,
						LastYYValue = parser.LastYYVal
					};
				} finally {
					Reset ();
				}
			}
		}
Beispiel #16
0
		//
		// Processes "see" or "seealso" elements from cref attribute.
		//
		void HandleXrefCommon (MemberCore mc, TypeContainer ds, XmlElement xref)
		{
			string cref = xref.GetAttribute ("cref");
			// when, XmlReader, "if (cref == null)"
			if (!xref.HasAttribute ("cref"))
				return;

			// Nothing to be resolved the reference is marked explicitly
			if (cref.Length > 2 && cref [1] == ':')
				return;

			// Additional symbols for < and > are allowed for easier XML typing
			cref = cref.Replace ('{', '<').Replace ('}', '>');

			var encoding = module.Compiler.Settings.Encoding;
			var s = new MemoryStream (encoding.GetBytes (cref));
			SeekableStreamReader seekable = new SeekableStreamReader (s, encoding);

			var source_file = new CompilationSourceFile (doc_module);
			var report = new Report (doc_module.Compiler, new NullReportPrinter ());

			var parser = new CSharpParser (seekable, source_file, report);
			ParsedParameters = null;
			ParsedName = null;
			ParsedBuiltinType = null;
			ParsedOperator = null;
			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);

				xref.SetAttribute ("cref", "!:" + cref);
				return;
			}

			MemberSpec member;
			string prefix = null;
			FullNamedExpression fne = null;

			//
			// Try built-in type first because we are using ParsedName as identifier of
			// member names on built-in types
			//
			if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) {
				member = ParsedBuiltinType.Type;
			} else {
				member = null;
			}

			if (ParsedName != null || ParsedOperator.HasValue) {
				TypeSpec type = null;
				string member_name = null;

				if (member == null) {
					if (ParsedOperator.HasValue) {
						type = mc.CurrentType;
					} else if (ParsedName.Left != null) {
						fne = ResolveMemberName (mc, ParsedName.Left);
						if (fne != null) {
							var ns = fne as Namespace;
							if (ns != null) {
								fne = ns.LookupTypeOrNamespace (mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
								if (fne != null) {
									member = fne.Type;
								}
							} else {
								type = fne.Type;
							}
						}
					} else {
						fne = ResolveMemberName (mc, ParsedName);
						if (fne == null) {
							type = mc.CurrentType;
						} else if (ParsedParameters == null) {
							member = fne.Type;
						} else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) {
							member_name = Constructor.ConstructorName;
							type = fne.Type;
						}
					}
				} else {
					type = (TypeSpec) member;
					member = null;
				}

				if (ParsedParameters != null) {
					var old_printer = mc.Module.Compiler.Report.SetPrinter (new NullReportPrinter ());
					foreach (var pp in ParsedParameters) {
						pp.Resolve (mc);
					}
					mc.Module.Compiler.Report.SetPrinter (old_printer);
				}

				if (type != null) {
					if (member_name == null)
						member_name = ParsedOperator.HasValue ?
							Operator.GetMetadataName (ParsedOperator.Value) : ParsedName.Name;

					int parsed_param_count;
					if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) {
						parsed_param_count = ParsedParameters.Count - 1;
					} else if (ParsedParameters != null) {
						parsed_param_count = ParsedParameters.Count;
					} else {
						parsed_param_count = 0;
					}

					int parameters_match = -1;
					do {
						var members = MemberCache.FindMembers (type, member_name, true);
						if (members != null) {
							foreach (var m in members) {
								if (ParsedName != null && m.Arity != ParsedName.Arity)
									continue;

								if (ParsedParameters != null) {
									IParametersMember pm = m as IParametersMember;
									if (pm == null)
										continue;

									if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue)
										continue;

									int i;
									for (i = 0; i < parsed_param_count; ++i) {
										var pparam = ParsedParameters[i];

										if (i >= pm.Parameters.Count || pparam == null ||
											pparam.TypeSpec != pm.Parameters.Types[i] ||
											(pparam.Modifier & Parameter.Modifier.SignatureMask) != (pm.Parameters.FixedParameters[i].ModFlags & Parameter.Modifier.SignatureMask)) {

											if (i > parameters_match) {
												parameters_match = i;
											}

											i = -1;
											break;
										}
									}

									if (i < 0)
										continue;

									if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) {
										if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec) {
											parameters_match = parsed_param_count + 1;
											continue;
										}
									} else {
										if (parsed_param_count != pm.Parameters.Count)
											continue;
									}
								}

								if (member != null) {
									Report.Warning (419, 3, mc.Location,
										"Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
										cref, member.GetSignatureForError (), m.GetSignatureForError ());

									break;
								}

								member = m;
							}
						}

						// Continue with parent type for nested types
						if (member == null) {
							type = type.DeclaringType;
						} else {
							type = null;
						}
					} while (type != null);

					if (member == null && parameters_match >= 0) {
						for (int i = parameters_match; i < parsed_param_count; ++i) {
							Report.Warning (1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
									(i + 1).ToString (), cref);
						}

						if (parameters_match == parsed_param_count + 1) {
							Report.Warning (1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
						}
					}
				}
			}

			if (member == null) {
				Report.Warning (1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
					mc.GetSignatureForError (), cref);
				cref = "!:" + cref;
			} else if (member == InternalType.Namespace) {
				cref = "N:" + fne.GetSignatureForError ();
			} else {
				prefix = GetMemberDocHead (member);
				cref = prefix + member.GetSignatureForDocumentation ();
			}

			xref.SetAttribute ("cref", cref);
		}
Beispiel #17
0
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session)
	: this (reader, file, file.Compiler.Report, session)
{
}
Beispiel #18
0
		public NamespaceContainer (MemberName name, NamespaceContainer parent)
			: base (parent, name, null, MemberKind.Namespace)
		{
			this.Parent = parent;
			this.ns = parent.NS.AddNamespace (name);

			containers = new List<TypeContainer> ();

			var topParent = this;
			while (topParent.Parent != null) {
				topParent = topParent.Parent;
			}
			compSourceFile = topParent as CompilationSourceFile;
		}
Beispiel #19
0
		public virtual void Visit (CompilationSourceFile csf)
		{
		}
Beispiel #20
0
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file)
{
	this.file = file;
	current_namespace = file.NamespaceContainer;
	
	this.module = current_namespace.Module;
	this.compiler = module.Compiler;
	this.settings = compiler.Settings;
	lang_version = settings.Version;
	doc_support = settings.Documentation != null;
	current_class = current_namespace.SlaveDeclSpace;
	current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
	oob_stack.Clear ();
	lexer = new Tokenizer (reader, file, compiler);
	
	use_global_stacks = true;
}
Beispiel #21
0
		/*
		/// <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;
			}
		}
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, Report report)
{
	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;
	oob_stack.Clear ();
	lexer = new Tokenizer (reader, file);

#if FULL_AST
	lbag = new LocationsBag ();
#else
	lbag = null;
#endif
	
	use_global_stacks = true;
}
Beispiel #23
0
public CSharpParser (SeekableStreamReader reader, CompilationSourceFile file, ParserSession session, bool returnAtSignInVerbatimIdentifiers)
	: this (reader, file, file.Compiler.Report, session, returnAtSignInVerbatimIdentifiers)
{
}
Beispiel #24
0
		public static void Parse (SeekableStreamReader reader, SourceFile sourceFile, ModuleContainer module, ParserSession session, Report report)
		{
			var file = new CompilationSourceFile (module, sourceFile);
			module.AddTypeContainer (file);

			if (sourceFile.FileType == SourceFileType.CSharp) {
				CSharpParser parser = new CSharpParser (reader, file, session);
				parser.parse ();
			} else {
				PlayScriptParser parser = new PlayScriptParser (reader, file, session);
				parser.parsing_playscript = sourceFile.PsExtended;
				parser.parse ();
			}
		}
Beispiel #25
0
 static public void Push(CompilationSourceFile compile_unit, SourceFile file)
 {
     current_source       = file != null ? file.Index : -1;
     current_compile_unit = compile_unit != null ? compile_unit.Index : -1;
     // File is always pushed before being changed.
 }
Beispiel #26
0
 public virtual void Visit(CompilationSourceFile csf)
 {
     VisitTypeContainer(csf);
 }
Beispiel #27
0
        private void ParseFiles([NotNull] ModuleContainer container)
        {
            Location.Initialize(container.Compiler.SourceFiles);
            var session = new ParserSession
            {
                UseJayGlobalArrays = true,
                LocatedTokens = new LocatedToken[15000]
            };

            foreach (var sourceFile in container.Compiler.SourceFiles)
            {
                using (var stream = new FileStream(sourceFile.FullPathName, FileMode.Open))
                {
                    var compilationSourceFile = new CompilationSourceFile(container, sourceFile);
                    container.AddTypeContainer(compilationSourceFile);
                    using (var seekStream = new SeekableStreamReader(stream, Encoding.UTF8))
                    {
                        new CSharpParser(seekStream, compilationSourceFile, _report, session).parse();
                    }
                }
            }
        }
Beispiel #28
0
		private NamespaceContainer (ModuleContainer module, NamespaceContainer parent, CompilationSourceFile file, Namespace ns, bool slave)
		{
			this.module = module;
			this.parent = parent;
			this.file = file;
			this.IsImplicit = true;
			this.ns = ns;
			this.SlaveDeclSpace = slave ? new RootDeclSpace (module, this) : null;
		}
Beispiel #29
0
 private NamespaceContainer(ModuleContainer module, NamespaceContainer parent, CompilationSourceFile file, Namespace ns, bool slave)
 {
     this.module         = module;
     this.parent         = parent;
     this.file           = file;
     this.IsImplicit     = true;
     this.ns             = ns;
     this.SlaveDeclSpace = slave ? new RootDeclSpace(module, this) : null;
 }
Beispiel #30
0
		public virtual void Visit (CompilationSourceFile csf)
		{
			VisitTypeContainer (csf);
		}
Beispiel #31
0
        //
        // Processes "see" or "seealso" elements from cref attribute.
        //
        void HandleXrefCommon(MemberCore mc, XmlElement xref)
        {
            string cref = xref.GetAttribute("cref");

            // when, XmlReader, "if (cref == null)"
            if (!xref.HasAttribute("cref"))
            {
                return;
            }

            // Nothing to be resolved the reference is marked explicitly
            if (cref.Length > 2 && cref [1] == ':')
            {
                return;
            }

            // Additional symbols for < and > are allowed for easier XML typing
            cref = cref.Replace('{', '<').Replace('}', '>');

            var encoding = module.Compiler.Settings.Encoding;
            var s        = new MemoryStream(encoding.GetBytes(cref));

            var source_file = new CompilationSourceFile(doc_module, mc.Location.SourceFile);
            var report      = new Report(doc_module.Compiler, new NullReportPrinter());

            if (session == null)
            {
                session = new ParserSession {
                    UseJayGlobalArrays = true
                }
            }
            ;

            SeekableStreamReader seekable = new SeekableStreamReader(s, encoding, session.StreamReaderBuffer);

            var parser = new CSharpParser(seekable, source_file, report, session);

            ParsedParameters          = null;
            ParsedName                = null;
            ParsedBuiltinType         = null;
            ParsedOperator            = null;
            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);

                xref.SetAttribute("cref", "!:" + cref);
                return;
            }

            MemberSpec          member;
            string              prefix = null;
            FullNamedExpression fne    = null;

            //
            // Try built-in type first because we are using ParsedName as identifier of
            // member names on built-in types
            //
            if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null))
            {
                member = ParsedBuiltinType.Type;
            }
            else
            {
                member = null;
            }

            if (ParsedName != null || ParsedOperator.HasValue)
            {
                TypeSpec type        = null;
                string   member_name = null;

                if (member == null)
                {
                    if (ParsedOperator.HasValue)
                    {
                        type = mc.CurrentType;
                    }
                    else if (ParsedName.Left != null)
                    {
                        fne = ResolveMemberName(mc, ParsedName.Left);
                        if (fne != null)
                        {
                            var ns = fne as NamespaceExpression;
                            if (ns != null)
                            {
                                fne = ns.LookupTypeOrNamespace(mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null);
                                if (fne != null)
                                {
                                    member = fne.Type;
                                }
                            }
                            else
                            {
                                type = fne.Type;
                            }
                        }
                    }
                    else
                    {
                        fne = ResolveMemberName(mc, ParsedName);
                        if (fne == null)
                        {
                            type = mc.CurrentType;
                        }
                        else if (ParsedParameters == null)
                        {
                            member = fne.Type;
                        }
                        else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition)
                        {
                            member_name = Constructor.ConstructorName;
                            type        = fne.Type;
                        }
                    }
                }
                else
                {
                    type   = (TypeSpec)member;
                    member = null;
                }

                if (ParsedParameters != null)
                {
                    var old_printer = mc.Module.Compiler.Report.SetPrinter(new NullReportPrinter());
                    try {
                        var context = new DocumentationMemberContext(mc, ParsedName ?? MemberName.Null);

                        foreach (var pp in ParsedParameters)
                        {
                            pp.Resolve(context);
                        }
                    } finally {
                        mc.Module.Compiler.Report.SetPrinter(old_printer);
                    }
                }

                if (type != null)
                {
                    if (member_name == null)
                    {
                        member_name = ParsedOperator.HasValue ?
                                      Operator.GetMetadataName(ParsedOperator.Value) : ParsedName.Name;
                    }

                    int parsed_param_count;
                    if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit)
                    {
                        parsed_param_count = ParsedParameters.Count - 1;
                    }
                    else if (ParsedParameters != null)
                    {
                        parsed_param_count = ParsedParameters.Count;
                    }
                    else
                    {
                        parsed_param_count = 0;
                    }

                    int parameters_match = -1;
                    do
                    {
                        var members = MemberCache.FindMembers(type, member_name, true);
                        if (members != null)
                        {
                            foreach (var m in members)
                            {
                                if (ParsedName != null && m.Arity != ParsedName.Arity)
                                {
                                    continue;
                                }

                                if (ParsedParameters != null)
                                {
                                    IParametersMember pm = m as IParametersMember;
                                    if (pm == null)
                                    {
                                        continue;
                                    }

                                    if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue)
                                    {
                                        continue;
                                    }

                                    var pm_params = pm.Parameters;

                                    int i;
                                    for (i = 0; i < parsed_param_count; ++i)
                                    {
                                        var pparam = ParsedParameters[i];

                                        if (i >= pm_params.Count || pparam == null || pparam.TypeSpec == null ||
                                            !TypeSpecComparer.Override.IsEqual(pparam.TypeSpec, pm_params.Types[i]) ||
                                            (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask))
                                        {
                                            if (i > parameters_match)
                                            {
                                                parameters_match = i;
                                            }

                                            i = -1;
                                            break;
                                        }
                                    }

                                    if (i < 0)
                                    {
                                        continue;
                                    }

                                    if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit)
                                    {
                                        if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec)
                                        {
                                            parameters_match = parsed_param_count + 1;
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        if (parsed_param_count != pm_params.Count)
                                        {
                                            continue;
                                        }
                                    }
                                }

                                if (member != null)
                                {
                                    Report.Warning(419, 3, mc.Location,
                                                   "Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched",
                                                   cref, member.GetSignatureForError(), m.GetSignatureForError());

                                    break;
                                }

                                member = m;
                            }
                        }

                        // Continue with parent type for nested types
                        if (member == null)
                        {
                            type = type.DeclaringType;
                        }
                        else
                        {
                            type = null;
                        }
                    } while (type != null);

                    if (member == null && parameters_match >= 0)
                    {
                        for (int i = parameters_match; i < parsed_param_count; ++i)
                        {
                            Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'",
                                           (i + 1).ToString(), cref);
                        }

                        if (parameters_match == parsed_param_count + 1)
                        {
                            Report.Warning(1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref);
                        }
                    }
                }
            }

            if (member == null)
            {
                Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved",
                               mc.GetSignatureForError(), cref);
                cref = "!:" + cref;
            }
            else if (member == InternalType.Namespace)
            {
                cref = "N:" + fne.GetSignatureForError();
            }
            else
            {
                prefix = GetMemberDocHead(member);
                cref   = prefix + member.GetSignatureForDocumentation();
            }

            xref.SetAttribute("cref", cref);
        }
		public void Parse (SeekableStreamReader reader, CompilationSourceFile file, ModuleContainer module)
		{
			file.NamespaceContainer = new NamespaceContainer (null, module, null, file);

			CSharpParser parser = new CSharpParser (reader, file);
			parser.parse ();
		}
Beispiel #33
0
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;
}
Beispiel #34
0
 public virtual void Visit(CompilationSourceFile csf)
 {
 }
Beispiel #35
0
        public static CSharpParser 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);

            CSharpParser parser = new CSharpParser (reader, file, report, session);
            parser.Lexer.Line += lineModifier;
            parser.Lexer.Column += colModifier;
            parser.Lexer.sbag = new SpecialsBag ();
            parser.parse ();
            return parser;
        }
Beispiel #36
0
		public NamespaceContainer (MemberName name, ModuleContainer module, NamespaceContainer parent, CompilationSourceFile sourceFile)
		{
			this.module = module;
			this.parent = parent;
			this.file = sourceFile;
			this.loc = name == null ? Location.Null : name.Location;

			if (parent != null)
				ns = parent.NS.GetNamespace (name.GetName (), true);
			else if (name != null)
				ns = module.GlobalRootNamespace.GetNamespace (name.GetName (), true);
			else
				ns = module.GlobalRootNamespace;

			SlaveDeclSpace = new RootDeclSpace (module, this);
		}
Beispiel #37
0
		//
		// This is used when we encounter a #line preprocessing directive during parsing
		// to register additional source file names
		//
		public SourceFile LookupFile (CompilationSourceFile comp_unit, string name)
		{
			if (all_source_files == null) {
				all_source_files = new Dictionary<string, SourceFile> ();
				foreach (var source in SourceFiles)
					all_source_files[source.FullPathName] = source;
			}

			string path;
			if (!Path.IsPathRooted (name)) {
				string root = Path.GetDirectoryName (comp_unit.SourceFile.FullPathName);
				path = Path.Combine (root, name);
			} else
				path = name;

			SourceFile retval;
			if (all_source_files.TryGetValue (path, out retval))
				return retval;

			retval = new SourceFile (name, path, all_source_files.Count + 1);
			Location.AddFile (retval);
			all_source_files.Add (path, retval);
			return retval;
		}
Beispiel #38
0
		public NamespaceEntry (ModuleContainer module, NamespaceEntry parent, CompilationSourceFile sourceFile, string name)
		{
			this.module = module;
			this.parent = parent;
			this.file = sourceFile;

			if (parent != null)
				ns = parent.NS.GetNamespace (name, true);
			else if (name != null)
				ns = module.GlobalRootNamespace.GetNamespace (name, true);
			else
				ns = module.GlobalRootNamespace;

			SlaveDeclSpace = new RootDeclSpace (module, this);
		}