Пример #1
0
 public int ParseTypeMembers(TypeNode type, int startColumn, string terminator, AuthoringSink sink){
   this.sink = sink;
   TokenSet followers = Parser.EndOfFile;
   if (terminator != null)
     followers |= this.GetTokenFor(terminator);
   this.scanner.endPos = startColumn;
   this.currentToken = Token.None;
   this.GetNextToken();
   this.ParseTypeMembers(type, followers);
   return this.scanner.CurrentSourceContext.StartPos;
 }
Пример #2
0
 public Expression ParseExpression(int startPosition, string terminator, AuthoringSink sink){
   this.sink = sink;
   TokenSet followers = Parser.EndOfFile;
   if (terminator != null)
     followers |= this.GetTokenFor(terminator);
   this.scanner.endPos = startPosition;
   this.currentToken = Token.None;
   this.GetNextToken();
   return this.ParseExpression(followers);
 }
Пример #3
0
 public void ParseMethodBody(Method method, int startPosition, AuthoringSink sink){
   this.sink = sink;
   this.scanner.endPos = startPosition;
   this.currentToken = Token.None;
   this.GetNextToken();
   method.Body.Statements = new StatementList();
   method.Body.Statements.Add(this.ParseBlock(Parser.EndOfFile | Parser.TypeMemberStart | Token.RightBrace | Token.Semicolon));
 }
Пример #4
0
 public CompilationUnit ParseCompilationUnit(string source, string fname, CompilerParameters parameters, ErrorNodeList errors, AuthoringSink sink){
   Guid dummy = Parser.dummyGuid;
   Document document = new Document(fname, 1, source, dummy, dummy, dummy);
   this.errors = errors;
   this.scanner = new Scanner(document, errors, parameters as SpecSharpCompilerOptions);
   this.currentToken = Token.None;
   this.errors = errors;
   this.ProcessOptions(parameters as SpecSharpCompilerOptions);
   CompilationUnit cu = new CompilationUnit(Identifier.For(fname));
   cu.Compilation = new Compilation(this.module, new CompilationUnitList(cu), parameters, null);
   cu.SourceContext = new SourceContext(document);
   this.ParseCompilationUnit(cu, false, true, sink);//This overload is only called for intellisense, not the background error check.
   cu.PragmaWarnInformation = this.scanner.pragmaInformation;
   this.errors = null;
   this.scanner = null;
   return cu;
 }
Пример #5
0
 internal void ParseCompilationUnit(CompilationUnit cu, bool omitBodies, bool ignoreDocComments, AuthoringSink sink){
   if (cu == null) throw new ArgumentNullException("cu");
   this.sink = sink;
   Namespace ns = new Namespace(Identifier.Empty, Identifier.Empty, new AliasDefinitionList(), new UsedNamespaceList(), new NamespaceList(), new TypeNodeList());
   ns.SourceContext = cu.SourceContext;
   cu.Nodes = new NodeList(ns);
   this.omitBodies = omitBodies || this.parsingContractAssembly;
   this.scanner.ignoreDocComments = ignoreDocComments;
   this.scanner.sink = sink;
   this.GetNextToken();
   cu.PreprocessorDefinedSymbols = this.scanner.PreprocessorDefinedSymbols;
 tryAgain:
   this.ParseExternalAliasDirectives(ns, Parser.AttributeOrNamespaceOrTypeDeclarationStart|Token.Using|Token.LastIdentifier|Parser.EndOfFile);
   this.ParseUsingDirectives(ns, Parser.AttributeOrNamespaceOrTypeDeclarationStart|Token.Extern|Token.LastIdentifier|Parser.EndOfFile);
   if (this.currentToken == Token.Extern){
     this.HandleError(Error.ExternAfterElements);
     goto tryAgain;
   }
   this.ParseNamespaceMemberDeclarations(ns, Parser.EndOfFile);
   cu.PragmaWarnInformation = this.scanner.pragmaInformation;
   this.scanner.sink = null;
   this.sink = null;
 }
Пример #6
0
    public override CompilationUnit ParseCompilationUnit(string fname, string source, ErrorNodeList errors, Compilation compilation, AuthoringSink sink){
      this.parsingStatement = false;
      if (fname == null || source == null || errors == null || compilation == null){Debug.Assert(false); return null;}
      if (compilation != null && compilation.CompilerParameters is SpecSharpCompilerOptions)
        this.allowSpecSharpExtensions = !((SpecSharpCompilerOptions)compilation.CompilerParameters).Compatibility;
      CompilationUnit cu;
#if Xaml
      if (fname.Length > 5 && string.Compare(fname, fname.Length-5, ".xaml", 0, 5, true, CultureInfo.InvariantCulture) == 0){
        Document xamlDocument = Microsoft.XamlCompiler.Compiler.CreateXamlDocument(fname, 1, new DocumentText(source));
        Microsoft.XamlCompiler.ErrorHandler xamlErrorHandler = new Microsoft.XamlCompiler.ErrorHandler(errors);
        Microsoft.XamlCompiler.Compiler xamlCompiler =
          new Microsoft.XamlCompiler.Compiler(xamlDocument, compilation.TargetModule, xamlErrorHandler, new ParserFactory(), compilation.CompilerParameters as CompilerOptions);
        cu = xamlCompiler.GetCompilationUnit();
      }else{
#endif
        Parser p = new Parser(compilation.TargetModule);
        cu = p.ParseCompilationUnit(source, fname, compilation.CompilerParameters, errors, sink);
        if (cu != null) cu.Compilation = compilation;
        this.parsingStatement = p.parsingStatement;
#if Xaml
      }
#endif
      this.partialCompilationUnit = cu;
      return cu;
    }
Пример #7
0
 public override Cci.AuthoringScope GetAuthoringScopeForMethodBody(string text, Compilation/*!*/ compilation, Method/*!*/ method, AuthoringSink asink) {
   this.parsingStatement = true;
   if (text == null || compilation == null || method == null || method.Body == null || method.Body.SourceContext.Document == null)
     throw new ArgumentNullException();
   if (compilation != null && compilation.CompilerParameters is SpecSharpCompilerOptions)
     this.allowSpecSharpExtensions = !((SpecSharpCompilerOptions)compilation.CompilerParameters).Compatibility;
   this.currentSymbolTable = compilation.TargetModule;
   SourceContext sctx = method.Body.SourceContext;
   DocumentText docText = new DocumentText(text);
   Document doc = Compiler.CreateSpecSharpDocument(sctx.Document.Name, 1, docText);
   ErrorNodeList errors = new ErrorNodeList(0);
   Parser p = new Parser(doc, errors, compilation.TargetModule, compilation.CompilerParameters as SpecSharpCompilerOptions);
   p.ParseMethodBody(method, sctx.StartPos, asink);
   ErrorHandler errorHandler = new ErrorHandler(errors);
   TrivialHashtable ambiguousTypes = new TrivialHashtable();
   TrivialHashtable referencedLabels = new TrivialHashtable();
   Looker looker = new Looker(null, errorHandler, this.scopeFor, ambiguousTypes, referencedLabels);
   looker.currentAssembly = (looker.currentModule = compilation.TargetModule) as AssemblyNode;
   TypeNode currentType = method.DeclaringType;
   looker.currentType = currentType;
   looker.scope = method.Scope;
   if (looker.scope != null) looker.scope = looker.scope.OuterScope;
   looker.identifierInfos = this.identifierInfos = new NodeList();
   looker.identifierPositions = this.identifierPositions = new Int32List();
   looker.identifierLengths = this.identifierLengths = new Int32List();
   looker.identifierContexts = this.identifierContexts = new Int32List();
   looker.identifierScopes = this.identifierScopes = new ScopeList();
   looker.allScopes = this.allScopes = new ScopeList();
   looker.Visit(method);
   Resolver resolver = new Resolver(errorHandler, new TypeSystem(errorHandler));
   resolver.currentAssembly = (resolver.currentModule = this.currentSymbolTable) as AssemblyNode;
   resolver.currentType = currentType;
   if (currentType != null) {
     if (resolver.currentType.Template == null && resolver.currentType.ConsolidatedTemplateParameters != null && resolver.currentType.ConsolidatedTemplateParameters.Count > 0)
       resolver.currentTypeInstance = resolver.GetDummyInstance(resolver.currentType);
     else
       resolver.currentTypeInstance = resolver.currentType;
   }
   resolver.Visit(method);
   method.Body.Statements = null;
   return this.GetAuthoringScope();
 }
Пример #8
0
    public override void ParseAndAnalyzeCompilationUnit(string fname, string text, int line, int col, ErrorNodeList errors, Compilation compilation, AuthoringSink sink) {
      if (fname == null || text == null || errors == null || compilation == null){Debug.Assert(false); return;}
      if (compilation != null && compilation.CompilerParameters is SpecSharpCompilerOptions)
        this.allowSpecSharpExtensions = !((SpecSharpCompilerOptions)compilation.CompilerParameters).Compatibility;
      CompilationUnitList compilationUnitSnippets = compilation.CompilationUnits;
      if (compilationUnitSnippets == null){Debug.Assert(false); return;}
      //Fix up the CompilationUnitSnippet corresponding to fname with the new source text
      CompilationUnitSnippet cuSnippet = this.GetCompilationUnitSnippet(compilation, fname);
      if (cuSnippet == null) return;
      Compiler compiler = new Compiler();
      compiler.CurrentCompilation = compilation;
      cuSnippet.SourceContext.Document = compiler.CreateDocument(fname, 1, new DocumentText(text));
      cuSnippet.SourceContext.EndPos = text.Length;
      //Parse all of the compilation unit snippets
      Module symbolTable = compilation.TargetModule = compiler.CreateModule(compilation.CompilerParameters, errors);
      AttributeList assemblyAttributes = symbolTable is AssemblyNode ? symbolTable.Attributes : null;
      AttributeList moduleAttributes = symbolTable is AssemblyNode ? ((AssemblyNode)symbolTable).ModuleAttributes : symbolTable.Attributes;
      int n = compilationUnitSnippets.Count;
      for (int i = 0; i < n; i++){
        CompilationUnitSnippet compilationUnitSnippet = compilationUnitSnippets[i] as CompilationUnitSnippet;
        if (compilationUnitSnippet == null){Debug.Assert(false); continue;}
        Document doc = compilationUnitSnippet.SourceContext.Document;
        doc = compilationUnitSnippet.SourceContext.Document;
        if (doc == null || doc.Text == null){Debug.Assert(false); continue;}
        IParserFactory factory = compilationUnitSnippet.ParserFactory;
        if (factory == null) continue;
        compilationUnitSnippet.Nodes = null;
        compilationUnitSnippet.PreprocessorDefinedSymbols = null;
        IParser p = factory.CreateParser(doc.Name, doc.LineNumber, doc.Text, symbolTable, compilationUnitSnippet == cuSnippet ? errors : new ErrorNodeList(), compilation.CompilerParameters);
        if (p == null){Debug.Assert(false); continue;}
        if (p is ResgenCompilerStub) continue;
        Parser specSharpParser = p as Parser;
        if (specSharpParser == null)
          p.ParseCompilationUnit(compilationUnitSnippet);
        else
          specSharpParser.ParseCompilationUnit(compilationUnitSnippet, compilationUnitSnippet != cuSnippet, false);
        //TODO: this following is a good idea only if the files will not be frequently reparsed from source
        //StringSourceText stringSourceText = doc.Text.TextProvider as StringSourceText;
        //if (stringSourceText != null && stringSourceText.IsSameAsFileContents)
        //  doc.Text.TextProvider = new CollectibleSourceText(doc.Name, doc.Text.Length);
      }
      //Construct symbol table for entire project
      ErrorHandler errorHandler = new ErrorHandler(errors);
      SpecSharpCompilation ssCompilation = new SpecSharpCompilation();
      TrivialHashtable ambiguousTypes = new TrivialHashtable();
      TrivialHashtable referencedLabels = new TrivialHashtable();
      TrivialHashtable scopeFor = this.scopeFor = new TrivialHashtable();
      Scoper scoper = new Scoper(scopeFor);
      scoper.currentModule = symbolTable;
      Looker symLooker = new Looker(null, new ErrorHandler(new ErrorNodeList(0)), scopeFor, ambiguousTypes, referencedLabels);
      symLooker.currentAssembly = (symLooker.currentModule = symbolTable) as AssemblyNode;
      Looker looker = new Looker(null, errorHandler, scopeFor, ambiguousTypes, referencedLabels);
      looker.currentAssembly = (looker.currentModule = symbolTable) as AssemblyNode;
      looker.VisitAttributeList(assemblyAttributes);
      bool dummyCompilation = compilation.CompilerParameters is SpecSharpCompilerOptions && ((SpecSharpCompilerOptions)compilation.CompilerParameters).DummyCompilation;
      if (dummyCompilation){
        //This happens when there is no project. In this case, semantic errors should be ignored since the references and options are unknown.
        //But proceed with the full analysis anyway so that some measure of Intellisense can still be provided.
        errorHandler.Errors = new ErrorNodeList(0);
      }
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = compilationUnitSnippets[i];
        scoper.VisitCompilationUnit(cUnit);
      }
      for (int i = 0; i < n; i++){
        CompilationUnit cUnit = compilationUnitSnippets[i];
        if (cUnit == cuSnippet)
          looker.VisitCompilationUnit(cUnit); //Uses real error message list and populate the identifier info lists
        else
          symLooker.VisitCompilationUnit(cUnit); //Errors are discarded
      }
      //Run resolver over symbol table so that custom attributes on member signatures are known and can be used
      //to error check the the given file.
      TypeSystem typeSystem = new TypeSystem(errorHandler);
      Resolver resolver = new Resolver(errorHandler, typeSystem);
      resolver.currentAssembly = (resolver.currentModule = symbolTable) as AssemblyNode;
      Resolver symResolver = new Resolver(new ErrorHandler(new ErrorNodeList(0)), typeSystem);
      symResolver.currentAssembly = resolver.currentAssembly;
      symResolver.VisitAttributeList(assemblyAttributes);
      for (int i = 0; i < n; i++) {
        CompilationUnit cUnit = compilationUnitSnippets[i];
        if (cUnit == cuSnippet)
          resolver.VisitCompilationUnit(cUnit); //Uses real error message list and populate the identifier info lists
        else
          symResolver.VisitCompilationUnit(cUnit); //Errors are discarded
      }
      if (dummyCompilation) return;
      //Now analyze the given file for errors
      Checker checker = new Checker(ssCompilation, errorHandler, typeSystem, scopeFor, ambiguousTypes, referencedLabels);
      checker.currentAssembly = (checker.currentModule = symbolTable) as AssemblyNode;
      checker.VisitAttributeList(assemblyAttributes, checker.currentAssembly);
      checker.VisitModuleAttributes(moduleAttributes);
      checker.VisitCompilationUnit(cuSnippet);
       
      MemberFinder finder = new MemberFinder(line, col);
      finder.VisitCompilationUnit(cuSnippet);
      Node node = finder.Member;
      if (node == null){
        if (line == 0 && col == 0) 
          node = cuSnippet;
        else
          return;
      }

      SpecSharpCompilerOptions options = (SpecSharpCompilerOptions) compilation.CompilerParameters;
      if (options.IsContractAssembly) return;
      ssCompilation.RunPlugins(node, errorHandler);
      Normalizer normalizer = new Normalizer(typeSystem);
      normalizer.Visit(node);
      Analyzer analyzer = new Analyzer(typeSystem, compilation);
      analyzer.Visit(node);

      if (options.RunProgramVerifierWhileEditing)
        ssCompilation.AddProgramVerifierPlugin(typeSystem, compilation);
      ssCompilation.analyzer = analyzer; // make the analyzer available to plugins for access to method CFGs
      ssCompilation.RunPlugins(node, errorHandler);
      ssCompilation.analyzer = null;
      analyzer = null;
    }
Пример #9
0
 public abstract CompilationUnit ParseCompilationUnit(String source, string fname, CompilerParameters parameters, ErrorNodeList errors, AuthoringSink sink);
Пример #10
0
 public abstract int ParseTypeMembers(TypeNode type, int startColumn, string terminator, AuthoringSink sink);
Пример #11
0
 public abstract int ParseStatements(StatementList statements, int startColumn, string terminator, AuthoringSink sink);
Пример #12
0
 public abstract Expression ParseExpression(int startColumn, string terminator, AuthoringSink sink);