示例#1
0
 public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit){
   if (cUnit == null) return null;
   if (cUnit.Compilation != null){
     SpecSharpCompilerOptions coptions = cUnit.Compilation.CompilerParameters as SpecSharpCompilerOptions;
     if (coptions != null) this.inCompatibilityMode = coptions.Compatibility;
   }
   return base.VisitCompilationUnit(cUnit);
 }
示例#2
0
        public static TypeNode GetTypeTemplateByName(CompilationUnit template, string name)
        {
            for (int i = 0, n = ((Namespace)template.Nodes[0]).Types.Count; i < n; i++)
            {
                TypeNode tn = ((Namespace)template.Nodes[0]).Types[i];

                if (tn.Name.Name == name)
                    return tn;
            }
            throw new ArgumentException("Type node '" + name + "' not found");
        }
示例#3
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;
 }
示例#4
0
文件: main.cs 项目: hesam/SketchSharp
 void ConstructCompilationUnit(){
   CompilationUnitSnippet cu = new CompilationUnitSnippet();
   this.compilationUnit = cu;
   this.compilation.CompilationUnits.Add(cu);
   cu.Compilation = this.compilation;
   cu.Name = new Identifier(this.inputLine.Substring(5));
   string snippetText = this.ReadString();
   cu.SourceContext.Document = this.currentDocument = this.compiler.CreateDocument(cu.Name.ToString(), 1, snippetText);
   cu.SourceContext.EndPos = snippetText.Length;
   cu.ParserFactory = new Microsoft.SpecSharp.ParserFactory();
 }
 public EventingVisitor(Action<CompilationUnit> visitCompilationUnit) { VisitedCompilationUnit += visitCompilationUnit; } public event Action<CompilationUnit> VisitedCompilationUnit; public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit) { if (VisitedCompilationUnit != null) VisitedCompilationUnit(cUnit); return base.VisitCompilationUnit(cUnit); }
示例#6
0
    CompilationUnit CreateCompilationUnit(Module module, TypeNode type) {
      
      CompilationUnit cu = new CompilationUnit();
      cu.Namespaces = new NamespaceList();      
      cu.TargetModule = module;
      this.cunit = cu;
      this.module = module;

      Namespace ns = new Namespace(Identifier.Empty, Identifier.Empty, new AliasDefinitionList(), new UsedNamespaceList(), new NamespaceList(), new TypeNodeList());
      cu.Namespaces.Add(ns);      

      ns.UsedNamespaces.Add(new UsedNamespace(Identifier.For("System")));
      ns.UsedNamespaces.Add(new UsedNamespace(Identifier.For("System.Xml")));
      ns.UsedNamespaces.Add(new UsedNamespace(Identifier.For("Microsoft.Comega"))); // XmlSerializationWriter

      CreateSerializerFor(type);
      return cu;
    }
示例#7
0
 public virtual CompilationUnit VisitCompilationUnit(CompilationUnit cUnit)
 {
     if (cUnit == null) return null;
     cUnit.Nodes = this.VisitNodeList(cUnit.Nodes);
     return cUnit;
 }
示例#8
0
 public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit)
 {
     if (cUnit == null) return null;
     this.FindTypesToBeDuplicated(cUnit.Nodes);
     return base.VisitCompilationUnit((CompilationUnit)cUnit.Clone());
 }
示例#9
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;
 }
示例#10
0
 public bool ParseStatementTemplate(string templateName, System.Reflection.Assembly assembly)
 {
     this.cuStatements = ParseBaseTemplate(templateName, assembly);
     return (this.cuStatements != null);
 }
示例#11
0
 public bool ParseExpressionTemplate(string templateName, System.Reflection.Assembly assembly)
 {
     this.cuExprs = ParseBaseTemplate(templateName, assembly);
     return (this.cuExprs != null);
 }
示例#12
0
        public CompilationUnit CodeGen(Compilation compilation)
        {
            try
            {
                // Debugging message
                /*
                for (int c = 0, nc = compilation.CompilationUnits.Length; c < nc; c++)
                {
                    Namespace ns = (Namespace)compilation.CompilationUnits[c].Nodes[0];
                    Console.WriteLine("X" + ns.Name.ToString() + "X");

                    for (int i = 0, n = ns.Types.Length; i < n; i++)
                    {
                        TypeNode tn = (TypeNode)ns.Types[i];

                        Console.WriteLine("\t" + tn.Name.ToString());
                    }
                }
                 */
                // END

                this.cZing = compilation;
                Templates.module = compilation.TargetModule;
                Templates.InitializeTemplates();

                // Scan the Zing AST for interesting high-level information.
                MemberList globals = CollectGlobals();
                TypeNodeList classes = CollectClasses();

                // Compile the "base" template and get the interesting nodes from it.
                cuBase = Templates.GetApplicationTemplate(compilation.TargetModule, options, globals.Count > 0, HeapUsed());

                Debug.Assert(((Namespace)cuBase.Nodes[0]).Types.Count == 0);
                Debug.Assert(((Namespace)cuBase.Nodes[0]).NestedNamespaces.Count == 1);
                Debug.Assert(((Namespace)cuBase.Nodes[0]).NestedNamespaces[0].Types.Count == 1);

                appClass = (Class)((Namespace)cuBase.Nodes[0]).NestedNamespaces[0].Types[0];

                // Begin transforming the output

                SetSourceStrings(compilation);
                SetExceptionList();

                // for each Zing type definition, call a helper to splice it into the
                // generated compilation unit.

                for (int c = 0, nc = cZing.CompilationUnits.Count; c < nc; c++)
                {
                    for (int i = 0, n = ((Namespace)cZing.CompilationUnits[c].Nodes[0]).Types.Count; i < n; i++)
                    {
                        TypeNode tn = (TypeNode)((Namespace)cZing.CompilationUnits[c].Nodes[0]).Types[i];

                        if (tn is Interface)
                            GenerateInterface((Interface)tn);
                        else if (tn is Class)
                            GenerateClass((Class)tn);
                        else if (tn is EnumNode)
                            GenerateEnum((EnumNode)tn);
                        else if (tn is Range)
                            GenerateRange((Range)tn);
                        else if (tn is Set)
                            GenerateSet((Set)tn);
                        else if (tn is Chan)
                            GenerateChan((Chan)tn);
                        else if (tn is Struct)
                            GenerateStruct((Struct)tn);
                        else if (tn is ZArray)
                            GenerateArray((ZArray)tn);
                        else
                            throw new ApplicationException("Unknown Zing type: " + tn.GetType().ToString());
                    }
                }

                GenerateTypeChoiceHelper();

                // NOTE: this must be done after processing the classes because we turn off
                // the "static" flag on the globals during processing which confuses GenerateClass.
                ProcessGlobals(globals);

                return cuBase;
            }
            finally
            {
                Templates.module = null;
                Templates.ReleaseTemplates();
            }
        }
示例#13
0
 public static void ReleaseTemplates()
 {
     cuParts = null;
     cuExpressions = null;
     cuStatements = null;
     cuProperties = null;
 }
示例#14
0
 public static void InitializeTemplates()
 {
     // Compile the templates from which we'll duplicate nodes later.
     cuParts = Templates.CompileTemplate("TemplateParts");
     cuExpressions = Templates.CompileTemplate("TemplateExprs");
     cuStatements = Templates.CompileTemplate("TemplateStmts");
     cuProperties = Templates.CompileTemplate("TemplateProps");
 }
示例#15
0
    public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit) {
      this.writer.WriteStartElement("CompilationUnit");
      this.writer.WriteAttributeString("file", cUnit.Name.Name);

      CompilationUnit result = base.VisitCompilationUnit(cUnit);

      this.writer.WriteEndElement(); // Namespace
      return result;
    }
示例#16
0
 void IParser.ParseCompilationUnit(CompilationUnit cu){
   this.ParseCompilationUnit(cu, false, this.scanner.ignoreDocComments, null);
 }
示例#17
0
 public void ParseCompilationUnit(CompilationUnit cu, bool omitBodies, bool ignoreDocComments){
   this.ParseCompilationUnit(cu, omitBodies, ignoreDocComments, null);
 }
示例#18
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;
    }
示例#19
0
 public void ParseCompilationUnit(CompilationUnit compilationUnit){
   CompilationUnitSnippet cuSnippet = compilationUnit as CompilationUnitSnippet;
   if (cuSnippet == null || cuSnippet.Compilation == null){Debug.Assert(false); return;}
   XamlSnippet xamlSnippet = new XamlSnippet();
   xamlSnippet.CodeModule = cuSnippet.Compilation.TargetModule;
   xamlSnippet.ErrorHandler = new Microsoft.XamlCompiler.ErrorHandler(this.errorNodes);
   xamlSnippet.Options = this.options;
   xamlSnippet.ParserFactory = new ParserFactory();
   xamlSnippet.XamlDocument = cuSnippet.SourceContext.Document;
   cuSnippet.Nodes = new NodeList(xamlSnippet);
 }
示例#20
0
    public override void Resolve(CompilationUnit partialCompilationUnit){
      if (partialCompilationUnit == null){Debug.Assert(false); return;}
      TrivialHashtable scopeFor = new TrivialHashtable();
      Scoper scoper = new Scoper(scopeFor);
      scoper.currentModule = this.currentSymbolTable;
      scoper.VisitCompilationUnit(partialCompilationUnit);

      ErrorHandler errorHandler = new ErrorHandler(new ErrorNodeList(0));
      TrivialHashtable ambiguousTypes = new TrivialHashtable();
      TrivialHashtable referencedLabels = new TrivialHashtable();
      Looker looker = new Looker(null, errorHandler, scopeFor, ambiguousTypes, referencedLabels);
      looker.currentAssembly = (looker.currentModule = this.currentSymbolTable) as AssemblyNode;
      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.VisitCompilationUnit(partialCompilationUnit);
      //Walk IR inferring types and resolving overloads
      Resolver resolver = new Resolver(errorHandler, new TypeSystem(errorHandler));
      resolver.currentAssembly = (resolver.currentModule = this.currentSymbolTable) as AssemblyNode;
      resolver.Visit(partialCompilationUnit);
    }
示例#21
0
        public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit)
        {

            CompilationUnit retCUnit = base.VisitCompilationUnit(cUnit);

            if (cUnit != null && cUnit.Name != null && this.WeakPurityAnalyzer != null)
            {
                Console.Out.WriteLine("*** Declared Pure:{0}, Pure: {1}, Methods {3}, {2}",
                    this.WeakPurityAnalyzer.numberOfDeclaredPure,
                    this.WeakPurityAnalyzer.numberOfPures, cUnit.Name, this.WeakPurityAnalyzer.numberOfMethods);
            }
            return retCUnit;
        }
示例#22
0
 public override CompilationUnit VisitCompilationUnit(CompilationUnit cUnit) {
   this.cUnit = cUnit;
   if (this.ErrorHandler != null)
     this.ErrorHandler.SetPragmaWarnInformation(cUnit.PragmaWarnInformation);
   CompilationUnit retCUnit = base.VisitCompilationUnit(cUnit);
   if (this.ErrorHandler != null)
     this.ErrorHandler.ResetPragmaWarnInformation();
   return retCUnit;
 }
示例#23
0
 public override void DetermineIfNonNullCheckingIsDesired(CompilationUnit cUnit){
   SpecSharpCompilerOptions soptions = this.currentOptions as SpecSharpCompilerOptions;
   if (soptions != null && soptions.Compatibility) return;
   this.NonNullChecking = !(this.currentPreprocessorDefinedSymbols != null && this.currentPreprocessorDefinedSymbols.ContainsKey("NONONNULLTYPECHECK"));
 }
示例#24
0
 /// <summary>
 /// Updates the state of the drop down bars to match the current contents of the text editor window. Call this initially and every time
 /// the cursor position changes.
 /// </summary>
 /// <param name="textView">The editor window</param>
 /// <param name="line">The line on which the cursor is now positioned</param>
 /// <param name="col">The column on which the cursor is now position</param>
 public void SynchronizeDropdowns(IVsTextView textView, int line, int col){
   this.textView = textView;
   string fname = this.languageService.GetFileName(textView); if (fname == null) return;
   LanguageService.Project proj = this.languageService.GetProjectFor(fname); if (proj == null) return;
   object indx = proj.IndexForFileName[Identifier.For(fname).UniqueKey]; if (!(indx is int)) return;
   int index = (int)indx;
   if (index >= proj.parseTrees.Length) return;
   CompilationUnit cu = proj.parseTrees[index] as CompilationUnit; 
   if (cu == null) return;
   AuthoringHelper helper = this.languageService.GetAuthoringHelper();
   TypeNodeList types = this.dropDownTypes;
   TypeNodeList sortedTypes = this.sortedDropDownTypes;
   if (cu != this.currentCompilationUnit){
     this.currentCompilationUnit = cu;
     //Need to reconstruct the type lists. First get the types in text order.
     types = this.dropDownTypes = new TypeNodeList();
     this.PopulateTypeList(types, cu.Namespaces);
     //Now sort by full text name.
     int n = types.Length;
     if (n == 0) return;
     sortedTypes = this.sortedDropDownTypes = new TypeNodeList(n);
     int[] dropDownTypeGlyphs = this.dropDownTypeGlyphs = new int[n];
     for (int i = 0; i < n; i++){
       TypeNode t = types[i];
       if (t == null){Debug.Assert(false); continue;}
       string tName = t.FullName;
       int glyph = dropDownTypeGlyphs[sortedTypes.Length] = helper.GetGlyph(t);
       sortedTypes.Add(t);
       for (int j = i-1; j >= 0; j--){
         if (string.Compare(tName, sortedTypes[j].FullName) >= 0) break;
         sortedTypes[j+1] = sortedTypes[j];
         sortedTypes[j] = t;
         dropDownTypeGlyphs[j+1] = dropDownTypeGlyphs[j];
         dropDownTypeGlyphs[j] = glyph;
       }
     }
     this.selectedType = -1;
   }
   //Find the type matching the given source position
   int newType = 0;
   for (int i = 0, n = types.Length; i < n; i++){
     TypeNode t = types[i];
     if (t.SourceContext.StartLine > line+1 || (t.SourceContext.StartLine == line+1 && t.SourceContext.StartColumn > col+1)){
       if (i > 0) t = types[i-1];
     }else if (i < n-1)
       continue;
     for (int j = 0; j < n; j++){
       if (sortedTypes[j] != t) continue;
       newType = j;
       break;
     }
     break;
   }
   MemberList members = this.dropDownMembers;
   MemberList sortedMembers = this.sortedDropDownMembers;
   if (newType != this.selectedType){
     TypeNode t = sortedTypes[newType];
     if (t.Members == null) return;
     //Need to reconstruct the member list. First get the members in text order.
     members = t.Members;
     int n = members == null ? 0 : members.Length;
     MemberList newMembers = this.dropDownMembers = new MemberList(n);
     //Now sort them
     sortedMembers = this.sortedDropDownMembers = new MemberList(n);
     string[] memSignatures = this.dropDownMemberSignatures = new string[n];
     int[] dropDownMemberGlyphs = this.dropDownMemberGlyphs = new int[n];
     for (int i = 0; i < n; i++){
       Member mem = members[i];
       if (mem == null) continue;
       string memSignature = this.languageService.errorHandler.GetUnqualifiedMemberSignature(mem);
       if (memSignature == null) continue;
       memSignatures[sortedMembers.Length] = memSignature;
       int glyph = dropDownMemberGlyphs[sortedMembers.Length] = helper.GetGlyph(mem);
       newMembers.Add(mem);
       sortedMembers.Add(mem);
       for (int j = i-1; j >= 0; j--){
         if (string.Compare(memSignature, memSignatures[j]) >= 0) break;
         memSignatures[j+1] = memSignatures[j];
         memSignatures[j] = memSignature;
         sortedMembers[j+1] = sortedMembers[j];
         sortedMembers[j] = mem;
         dropDownMemberGlyphs[j+1] = dropDownMemberGlyphs[j];
         dropDownMemberGlyphs[j] = glyph;
       }
     }
     this.selectedMember = -1;
   }
   //Find the member matching the given source position
   members = this.dropDownMembers;
   int newMember = 0;
   for (int i = 0, n = sortedMembers.Length; i < n; i++){
     Member mem = members[i];
     if (mem == null) continue;
     if (mem.SourceContext.StartLine > line+1 || (mem.SourceContext.StartLine == line+1 && mem.SourceContext.StartColumn > col+1)){
       if (i > 0) mem = members[i-1];
     }else if (i < n-1)
       continue;
     for (int j = 0; j < n; j++){
       if (sortedMembers[j] != mem) continue;
       newMember = j;
       break;
     }
     break;
   }
   if (this.dropDownBar == null) return;
   if (this.selectedType != newType){
     this.selectedType = newType;
     this.dropDownBar.RefreshCombo(TypeAndMemberDropdownBars.DropClasses, newType);
   }
   if (this.selectedMember != newMember) {
     this.selectedMember = newMember;
     this.dropDownBar.RefreshCombo(TypeAndMemberDropdownBars.DropMethods, newMember);
   }
 }
示例#25
0
 internal SerializationProvider(CompilationUnit cunit) {
   this.cunit = cunit;
   this.module = cunit.TargetModule;
   Init();
 }
示例#26
0
 public abstract void ParseCompilationUnit(CompilationUnit compilationUnit);