private void EmitLanguageBlockNode(AssociativeNode node, ref ProtoCore.Type inferedType, ProtoCore.DSASM.AssociativeSubCompilePass subPass = ProtoCore.DSASM.AssociativeSubCompilePass.kNone)
        {
            if (IsParsingGlobal() || IsParsingGlobalFunctionBody() || IsParsingMemberFunctionBody())
            {
                if (subPass == ProtoCore.DSASM.AssociativeSubCompilePass.kUnboundIdentifier)
                {
                    return;
                }

                LanguageBlockNode langblock = node as LanguageBlockNode;

                //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language);
                if (ProtoCore.Language.kInvalid == langblock.codeblock.language)
                    throw new BuildHaltException("Invalid language block type");

                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();

                int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

                // Top block signifies the auto inserted global block
                bool isTopBlock = null == codeBlock.parent;

                // Set the current class scope so the next language can refer to it
                core.ClassIndex = globalClassIndex;

                if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && core.ProcNode == null)
                {
                    if (globalClassIndex != ProtoCore.DSASM.Constants.kInvalidIndex)
                        core.ProcNode = core.ClassTable.ClassNodes[globalClassIndex].vtable.procList[globalProcIndex];
                    else
                        core.ProcNode = codeBlock.procedureTable.procList[globalProcIndex];
                }

                if (langblock.codeblock.language == Language.kAssociative)
                {
                    AssociativeCodeGen codegen = new AssociativeCodeGen(core, codeBlock);
                    blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode);
                }
                else if (langblock.codeblock.language == Language.kImperative)
                {
                    ImperativeCodeGen codegen = new ImperativeCodeGen(core, codeBlock);
                    blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode);
                }
                //core.Executives[langblock.codeblock.language].Compile(out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode);
                inferedType = core.InferedType;

                ExceptionRegistration registration = core.ExceptionHandlingManager.ExceptionTable.GetExceptionRegistration(blockId, globalProcIndex, globalClassIndex);
                if (registration == null)
                {
                    registration = core.ExceptionHandlingManager.ExceptionTable.Register(blockId, globalProcIndex, globalClassIndex);
                    Debug.Assert(registration != null);
                }
            }
        }
        private void EmitLanguageBlockNode(ImperativeNode node, ref ProtoCore.Type inferedType)
        {
            if (IsParsingGlobal() || IsParsingGlobalFunctionBody())
            {
                LanguageBlockNode langblock = node as LanguageBlockNode;
                //(Fuqiang, Ayush) : Throwing an assert stops NUnit. Negative tests expect to catch a
                // CompilerException, so we throw that instead.
                //Debug.Assert(ProtoCore.Language.kInvalid != langblock.codeblock.language);

                if (ProtoCore.Language.kInvalid == langblock.codeblock.language)
                {
                    throw new ProtoCore.Exceptions.CompileErrorsOccured("Invalid language block");
                }

                ProtoCore.CompileTime.Context context = new ProtoCore.CompileTime.Context();

                int blockId = ProtoCore.DSASM.Constants.kInvalidIndex;

                if (globalProcIndex != ProtoCore.DSASM.Constants.kInvalidIndex && compileState.ProcNode == null)
                    compileState.ProcNode = codeBlock.procedureTable.procList[globalProcIndex];

                if (langblock.codeblock.language == Language.kAssociative)
                {
                    AssociativeCodeGen codegen = new AssociativeCodeGen(compileState, codeBlock);
                    blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.AssociativeAST.CodeBlockNode);
                }
                else if (langblock.codeblock.language == Language.kImperative)
                {
                    ImperativeCodeGen codegen = new ImperativeCodeGen(compileState, codeBlock);
                    blockId = codegen.Emit(langblock.CodeBlockNode as ProtoCore.AST.ImperativeAST.CodeBlockNode);
                }

                //core.Executives[langblock.codeblock.language].Compile(out blockId, codeBlock, langblock.codeblock, context, codeBlock.EventSink, langblock.CodeBlockNode);
                inferedType = compileState.InferedType;

                ExceptionRegistration registration = compileState.ExceptionHandlingManager.ExceptionTable.GetExceptionRegistration(blockId, globalProcIndex, globalClassIndex);
                if (registration == null)
                {
                    registration = compileState.ExceptionHandlingManager.ExceptionTable.Register(blockId, globalProcIndex, globalClassIndex);
                    Debug.Assert(registration != null);
                }
            }
        }
        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;
        }