Exemplo n.º 1
0
 public override Compilation GetDummyCompilationFor(string fileName){
   if (this.dummyCompilationFor == null) this.dummyCompilationFor = new Hashtable();
   WeakReference wref = (WeakReference)this.dummyCompilationFor[fileName];
   if (wref != null && wref.IsAlive) return (Compilation)wref.Target;
   string fContents = null;
   if (File.Exists(fileName)){
     StreamReader sr = new StreamReader(fileName);
     fContents = sr.ReadToEnd(); sr.Close();
   }
   Compilation compilation = new Compilation();
   compilation.CompilerParameters = this.GetDummyCompilerParameters();
   compilation.TargetModule = new Module();
   DocumentText docText = new DocumentText(new StringSourceText(fContents, true));
   SourceContext sctx = new SourceContext(Compiler.CreateSpecSharpDocument(fileName, 0, docText));
   compilation.CompilationUnits = new CompilationUnitList(new CompilationUnitSnippet(new Identifier(fileName), new ParserFactory(), sctx));
   compilation.CompilationUnits[0].Compilation = compilation;
   this.dummyCompilationFor[fileName] = new WeakReference(compilation);
   return compilation;
 }
Exemplo n.º 2
0
 public static Document CreateSpecSharpDocument(string fileName, int lineNumber, DocumentText text){
   //return new Document(fileName, lineNumber, text, SymDocumentType.Text, typeof(DebuggerLanguage).GUID, SymLanguageVendor.Microsoft);
   return new Document(fileName, lineNumber, text, SymDocumentType.Text, SymLanguageType.CSharp, SymLanguageVendor.Microsoft);
 }
Exemplo n.º 3
0
 public override Document CreateDocument(string fileName, int lineNumber, DocumentText text){
   return Compiler.CreateSpecSharpDocument(fileName, lineNumber, text);
 }
Exemplo n.º 4
0
    public override CompilationUnitSnippet CreateCompilationUnitSnippet(string fileName, int lineNumber, DocumentText text, Compilation compilation){
      if (fileName == null) return null;
      SpecSharpCompilerOptions options = compilation == null ? null : (compilation.CompilerParameters as SpecSharpCompilerOptions);
      if (options != null && options.Compatibility)
        return base.CreateCompilationUnitSnippet(fileName, lineNumber, text, compilation);
#if Xaml
      if (this.CompileAsXaml || string.Compare(Path.GetExtension(fileName), ".xaml", true, CultureInfo.InvariantCulture) == 0){
        Document doc = Microsoft.XamlCompiler.Compiler.CreateXamlDocument(fileName, 1, text);
        CompilationUnitSnippet cu = new CompilationUnitSnippet();
        cu.Name = Identifier.For(doc.Name);
        cu.SourceContext = new SourceContext(doc);
        cu.ParserFactory = new XamlParserFactory();
        cu.Compilation = compilation;
        return cu;
      }else
#endif
        return base.CreateCompilationUnitSnippet(fileName, lineNumber, text, compilation);
    }
Exemplo n.º 5
0
 public Document(string/*!*/ name, int lineNumber, DocumentText text, System.Guid documentType, System.Guid language, System.Guid languageVendor)
 {
     this.DocumentType = documentType;
     this.Language = language;
     this.LanguageVendor = languageVendor;
     this.LineNumber = lineNumber;
     this.Name = name;
     this.Text = text;
     //^ base();
 }
Exemplo n.º 6
0
        private unsafe bool HasSameNameAs(CanonicalIdentifier id)
        {
            int myLength = this.length;
            int idLength = id.Name.Length;
            if(myLength != idLength)
                return false;
            string myName = this.name;
            string idName = id.Name;

            if(myName == null)
            {
                int myOffset = this.offset;
                if(this.text != null && this.text.Equals(idName, myOffset, myLength))
                {
                    this.name = idName;
                    this.text = null;
                    return true;
                }
                return false;
            }

            return myName == idName;
        }
Exemplo n.º 7
0
 public static Identifier/*!*/ For(SourceContext sctx)
 {
     DocumentText text = null;
     if(sctx.Document != null)
         text = sctx.Document.Text;
     if(text == null)
         text = new DocumentText("");
     Identifier id = new Identifier(text, sctx.StartPos, sctx.EndPos - sctx.StartPos);
     id.SourceContext = sctx;
     return id;
 }
Exemplo n.º 8
0
 public void SetSourceText(DocumentText sourceText, int offset){
   this.sourceText = sourceText;
   this.endPos = this.startPos = offset;
   this.maxPos = sourceText.Length;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Compares the substring of the specified length starting at offset, with the substring in DocumentText starting at textOffset.
 /// </summary>
 /// <param name="offset">The index of the first character of the substring of this DocumentText.</param>
 /// <param name="text">The Document text with the substring being compared to.</param>
 /// <param name="textOffset">The index of the first character of the substring of the DocumentText being compared to.</param>
 /// <param name="length">The number of characters in the substring being compared.</param>
 /// <returns></returns>
 public bool Equals(int offset, DocumentText text, int textOffset, int length)
 { //TODO: (int position, int length, DocumentText text, int textPosition)
     if(offset < 0 || length < 0 || offset + length > this.Length) { Debug.Assert(false); return false; }
     if(textOffset < 0 || text == null || textOffset + length > text.Length) { Debug.Assert(false); return false; }
     unsafe
     {
         byte* p = this.AsciiStringPtr;
         if(p != null)
         {
             unsafe
             {
                 byte* q = text.AsciiStringPtr;
                 if(q != null)
                 {
                     for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                         if(*(p + i) != *(q + j))
                             return false;
                     return true;
                 }
             }
             string textSource = text.Source;
             if(textSource != null)
             {
                 for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                     if(((char)*(p + i)) != textSource[j])
                         return false;
                 return true;
             }
             ISourceText textProvider = text.TextProvider;
             if(textProvider == null) { Debug.Assert(false); return false; }
             for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                 if(((char)*(p + i)) != textProvider[j])
                     return false;
             return true;
         }
     }
     string source = this.Source;
     if(source != null)
     {
         unsafe
         {
             byte* q = text.AsciiStringPtr;
             if(q != null)
             {
                 for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                     if(source[i] != (char)*(q + j))
                         return false;
                 return true;
             }
         }
         string textSource = text.Source;
         if(textSource != null)
         {
             for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                 if(source[i] != textSource[j])
                     return false;
             return true;
         }
         ISourceText textProvider = text.TextProvider;
         if(textProvider == null) { Debug.Assert(false); return false; }
         for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
             if(source[i] != textProvider[j])
                 return false;
         return true;
     }
     {
         ISourceText myProvider = this.TextProvider;
         if(myProvider == null) { Debug.Assert(false); return false; }
         unsafe
         {
             byte* q = text.AsciiStringPtr;
             if(q != null)
             {
                 for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                     if(myProvider[i] != (char)*(q + j))
                         return false;
                 return true;
             }
         }
         string textSource = text.Source;
         if(textSource != null)
         {
             for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
                 if(myProvider[i] != textSource[j])
                     return false;
             return true;
         }
         ISourceText textProvider = text.TextProvider;
         if(textProvider == null) { Debug.Assert(false); return false; }
         for(int i = offset, j = textOffset, n = offset + length; i < n; i++, j++)
             if(myProvider[i] != textProvider[j])
                 return false;
         return true;
     }
 }
Exemplo n.º 10
0
 internal Scanner(Document document, ErrorNodeList errors, CompilerOptions options)
 {
     this.document = document;
     this.originalDocument = document;
     this.sourceText = document.Text;
     this.endPos = 0;
     this.maxPos = document.Text.Length;
     this.errors = errors;
     this.lastReportedErrorPos = 0;
     this.PreprocessorDefinedSymbols = new Hashtable();
     this.PreprocessorDefinedSymbols["true"] = "true";
     this.PreprocessorDefinedSymbols["false"] = null;
     if (options != null)
     {
         StringList syms = options.DefinedPreProcessorSymbols;
         for (int i = 0, n = syms == null ? 0 : syms.Count; i < n; i++)
         {
             string sym = syms[i];
             if (sym == null) continue;
             this.PreprocessorDefinedSymbols[sym] = sym;
         }
     }
 }
Exemplo n.º 11
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();
 }
Exemplo n.º 12
0
        internal Token GetKeyword(DocumentText source, int startPos, int endPos)
        {
            int length = endPos - startPos;
            Keyword keyword = this;
            nextToken:
            while (null != keyword)
            {
                if (length == keyword.length)
                {
                    // we know the first char has to match
                    string name = keyword.name;
                    for (int i = 1, j = startPos + 1; i < length; i++, j++)
                    {
                        char ch1 = name[i];
                        char ch2 = source[j];
                        if (ch1 == ch2)
                            continue;
                        else if (ch2 < ch1)
                            return Token.Identifier;
                        else
                        {
                            keyword = keyword.next;
                            goto nextToken;
                        }
                    }
                    return keyword.token;
                }
                else if (length < keyword.length)
                    return Token.Identifier;

                keyword = keyword.next;
            }
            return Token.Identifier;
        }
Exemplo n.º 13
0
 public override IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errorNodes, CompilerParameters options)
 {
     Document document = this.CreateDocument(fileName, lineNumber, text);
     return new Parser(document, errorNodes, symbolTable, options as ZingCompilerOptions);
 }
Exemplo n.º 14
0
 public override Document CreateDocument(string fileName, int lineNumber, DocumentText text)
 {
     return new Document(fileName, lineNumber, text, SymDocumentType.Text, typeof(DebuggerLanguage).GUID, SymLanguageVendor.Microsoft);
 }
Exemplo n.º 15
0
 public IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errorNodes, CompilerParameters options){
   Document document = Compiler.CreateSpecSharpDocument(fileName, lineNumber, text);
   return new Parser(document, errorNodes, symbolTable, options as SpecSharpCompilerOptions);
 }
Exemplo n.º 16
0
 private Identifier(DocumentText/*!*/ text, int offset, int length)
     : base(NodeType.Identifier)
 {
     this.text = text;
     this.offset = offset;
     this.length = length;
     ulong hcode = 0;
     for(int i = offset, n = length + i; i < n; i++)
     {
         char ch = text[i];
         hcode = hcode * 17 + ch;
     }
     this.hashCode = ((int)hcode) & int.MaxValue;
 }
Exemplo n.º 17
0
 public IParser CreateParser(string fileName, int lineNumber, DocumentText text, Module symbolTable, ErrorNodeList errorNodes, CompilerParameters options){
   return new XamlParserStub(errorNodes, options as CompilerOptions);
 }
Exemplo n.º 18
0
 internal Scanner(Document document, ErrorNodeList errors, SpecSharpCompilerOptions options){
   this.document = document;
   this.originalDocument = document;
   this.sourceText = document.Text;
   if (document.Text != null) this.sourceString = document.Text.Source;
   this.endPos = 0;
   this.maxPos = document.Text.Length;
   this.errors = errors;
   this.ignoreDocComments = true;
   this.SetOptions(options);
 }