/// <summary>
        /// performs lazy initialization to ensure our current code model is up-to-date.
        ///
        /// If we haven't yet created our CodeDom backing we'll create it for the 1st time.  If we've
        /// created our backing, but some elements have been changed that we haven't yet reparsed
        /// then we'll reparse & merge any of the appropriate changes.
        /// </summary>
        private void Initialize()
        {
            if (ccu != null)
            {
                if (isDirty)
                {
                    Reparse();
                    isDirty = false;
                }
                return;
            }

            IMergeDestination merger = MergeDestination;

            if (null == textBuffer)
            {
                using (FileStream fs = new FileStream(Name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
                    if ((null == merger) && (null != parent))
                    {
                        merger = new FileCodeMerger(parent);
                    }
                    ccu = provider.ParseMergable(new StreamReader(fs), merger);
                }
            }
            else
            {
                // Find the size of the buffer.
                int lastLine;
                int lastColumn;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLastLineIndex(out lastLine, out lastColumn));
                // Get the text in the buffer.
                string text;
                ErrorHandler.ThrowOnFailure(textBuffer.GetLineText(0, 0, lastLine, lastColumn, out text));
                if (null == merger)
                {
                    merger = new TextBufferMerger(textBuffer);
                }
                ccu = provider.ParseMergable(text, Name, merger);
            }
        }
예제 #2
0
        public CodeCompileUnit ParseMergeable(System.IO.TextReader codeStream, IMergeDestination destination)
        {
            // get a better filename if we can
            string name = "<unknown>";
            StreamReader sw = codeStream as StreamReader;
            if (sw != null) {
                FileStream fs = sw.BaseStream as FileStream;
                if (fs != null) name = fs.Name;
            }
            //!!! it'd be nice to have Parser.FromStream to get proper decodings here
            string codeText = codeStream.ReadToEnd();
            CodeCompileUnit tree = Parse(Parser.FromString(state, new CompilerContext(), codeText), name);

            if (destination != null) CodeMerger.CacheCode(tree, destination);
            else CodeMerger.CacheCode(tree, codeText);

            return tree;
        }
예제 #3
0
        public CodeCompileUnit ParseMergeable(string text, string filename, IMergeDestination destination)
        {
            CodeCompileUnit tree = Parse(Parser.FromString(state, new CompilerContext(), text), filename);

            CodeMerger.CacheCode(tree, destination);
            return tree;
        }
예제 #4
0
 public CodeCompileUnit ParseMergable(System.IO.StreamReader sw, IMergeDestination mergeDestination)
 {
     return new PythonParser(references).ParseMergeable(sw, mergeDestination);
 }
예제 #5
0
 public CodeCompileUnit ParseMergable(string text, string filename, IMergeDestination mergeDestination)
 {
     return new PythonParser(references).ParseMergeable(text, filename, mergeDestination);
 }
예제 #6
0
 public static void CacheCode(CodeCompileUnit ccu, IMergeDestination mergeDestination)
 {
     ccu.UserData["MergerCache"] = new CodeMerger(mergeDestination);
 }
예제 #7
0
 private CodeMerger(IMergeDestination destination)
 {
     this.destination = destination;
 }