Ejemplo n.º 1
0
        // IMPORTANT: This method is to be called only from UI thread.
        public void UpdateDatabase(string codeSnapshot, string scriptPath)
        {
            if (string.IsNullOrEmpty(codeSnapshot))
            {
                return;
            }

            // "AutoCompleteEngine.UpdateDatabase" method is called by background
            // parser of the IDE, when the code does not have any syntactical
            // errors. The interval of that happening is around 200ms as of this
            // comment, and user could continue typing as the background parser
            // is working. That leads to this method being called very frequently,
            // but we do not want to process each and every call of this method.
            // Instead, we rely on a timer that expires few moments after this
            // method is called, ignoring all the prior calls of the method that
            // may happen too frequently.
            //
            if (null == updateTrigger)
            {
                updateTrigger          = new DispatcherTimer();
                updateTrigger.Tick    += new EventHandler(OnUpdateTriggered);
                updateTrigger.Interval = TimeSpan.FromMilliseconds(2000);
            }

            if ((null != updateWorker) && updateWorker.IsBusy)
            {
                return; // The database is being updated right now.
            }
            // The background worker isn't busy, so take a snapshot of
            // the code and then process it later when the timer expires.
            this.workData = new AutoCompleteWorkData(scriptPath, codeSnapshot);

            updateTrigger.Stop();
            if (false != HandleNextUpdateRequest)
            {
                // In the event of user pressing keys like semi-colon (;) or
                // closing curly bracket (}), "HandleNextUpdateRequest" will be
                // set to "true", in which case the "UpdateDatabase" call should
                // be handled immediately without waiting for a timer to expire.
                //
                HandleNextUpdateRequest = false;
                UpdateDatabaseInternal();
            }
            else
            {
                // No immediate update is requested, we should start processing
                // after a few moment (just in case the next update comes along
                // before the timer expires, we will stop the timer and restart
                // it).
                //
                updateTrigger.Start();
            }
        }
Ejemplo n.º 2
0
        private ProtoCore.Core CompileCodeSnapshot(AutoCompleteWorkData workData)
        {
            if (null != this.scopeIdentifiers)
            {
                this.scopeIdentifiers.Clear();
                this.scopeIdentifiers = null;
            }

            ProtoCore.Options options = new ProtoCore.Options();
            options.RootModulePathName = workData.ScriptPath;
            ProtoCore.Core core = new ProtoCore.Core(options);

            core.CurrentDSFileName = workData.ScriptPath;
            ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper());

            // Register a message stream if we do have one.
            if (null != this.MessageHandler)
            {
                core.BuildStatus.MessageHandler = this.MessageHandler;
            }

            MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(workData.CodeSnapshot));

            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(stream);
            ProtoCore.DesignScriptParser.Parser  p = new ProtoCore.DesignScriptParser.Parser(s, core);

            try
            {
                p.Parse();
                CoreCodeGen.arrayTypeTable = new ArrayTypeTable();
                AssociativeCodeGen codegen = new AssociativeCodeGen(core);

                codegen.Emit(p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception Caught in CodeGen");
                System.Diagnostics.Debug.WriteLine(ex.Message);
                core = null;
            }
            finally
            {
                // Do necessary clean-up here.
            }

            return(core);
        }
Ejemplo n.º 3
0
        private void OnUpdateDatabaseDoWork(object sender, DoWorkEventArgs e)
        {
            lock (updateSyncRoot)
            {
                AutoCompleteWorkData workData = e.Argument as AutoCompleteWorkData;

                // At the beginning of build and database population, assume
                // that at any point if we return earlier, the operation is
                // considered a failure, and no further database promotion
                // should be done.
                e.Result = false;

                ProtoCore.Core core = CompileCodeSnapshot(workData);
                if (null != core)
                {
                    stagingDatabase = new SymbolDatabaseProxy(core, scopeIdentifiers);
                    e.Result        = true;
                }
            }
        }
Ejemplo n.º 4
0
        private ProtoCore.Core CompileCodeSnapshot(AutoCompleteWorkData workData)
        {
            if (null != this.scopeIdentifiers)
            {
                this.scopeIdentifiers.Clear();
                this.scopeIdentifiers = null;
            }

            ProtoCore.Options options = new ProtoCore.Options();
            options.RootModulePathName = workData.ScriptPath;
            ProtoCore.Core core = new ProtoCore.Core(options);

            core.CurrentDSFileName = workData.ScriptPath;
            ProtoFFI.DLLFFIHandler.Register(ProtoFFI.FFILanguage.CSharp, new ProtoFFI.CSModuleHelper());

            // Register a message stream if we do have one.
            if (null != this.MessageHandler)
                core.BuildStatus.MessageHandler = this.MessageHandler;

            MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(workData.CodeSnapshot));
            ProtoCore.DesignScriptParser.Scanner s = new ProtoCore.DesignScriptParser.Scanner(stream);
            ProtoCore.DesignScriptParser.Parser p = new ProtoCore.DesignScriptParser.Parser(s, core);

            try
            {
                p.Parse();
                CoreCodeGen.arrayTypeTable = new ArrayTypeTable();
                AssociativeCodeGen codegen = new AssociativeCodeGen(core);

                codegen.Emit(p.root as ProtoCore.AST.AssociativeAST.CodeBlockNode);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception Caught in CodeGen");
                System.Diagnostics.Debug.WriteLine(ex.Message);
                core = null;
            }
            finally
            {
                // Do necessary clean-up here.
            }

            return core;
        }
Ejemplo n.º 5
0
        // IMPORTANT: This method is to be called only from UI thread.
        public void UpdateDatabase(string codeSnapshot, string scriptPath)
        {
            if (string.IsNullOrEmpty(codeSnapshot))
                return;

            // "AutoCompleteEngine.UpdateDatabase" method is called by background
            // parser of the IDE, when the code does not have any syntactical
            // errors. The interval of that happening is around 200ms as of this
            // comment, and user could continue typing as the background parser
            // is working. That leads to this method being called very frequently,
            // but we do not want to process each and every call of this method.
            // Instead, we rely on a timer that expires few moments after this
            // method is called, ignoring all the prior calls of the method that
            // may happen too frequently.
            //
            if (null == updateTrigger)
            {
                updateTrigger = new DispatcherTimer();
                updateTrigger.Tick += new EventHandler(OnUpdateTriggered);
                updateTrigger.Interval = TimeSpan.FromMilliseconds(2000);
            }

            if ((null != updateWorker) && updateWorker.IsBusy)
                return; // The database is being updated right now.

            // The background worker isn't busy, so take a snapshot of
            // the code and then process it later when the timer expires.
            this.workData = new AutoCompleteWorkData(scriptPath, codeSnapshot);

            updateTrigger.Stop();
            if (false != HandleNextUpdateRequest)
            {
                // In the event of user pressing keys like semi-colon (;) or
                // closing curly bracket (}), "HandleNextUpdateRequest" will be
                // set to "true", in which case the "UpdateDatabase" call should
                // be handled immediately without waiting for a timer to expire.
                //
                HandleNextUpdateRequest = false;
                UpdateDatabaseInternal();
            }
            else
            {
                // No immediate update is requested, we should start processing
                // after a few moment (just in case the next update comes along
                // before the timer expires, we will stop the timer and restart
                // it).
                //
                updateTrigger.Start();
            }
        }