Exemple #1
0
        /// <summary>
        /// Returns DEEP COPY of a 'real' compiled constant.
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        public Expression GetCompiledConstValue(Expression exp)
        {
            Expression content = (Expression)exp.CreateCopy();
            MoveInfo   expTree = new MoveInfo(content, SearchTree.ContentTree, 0, _sf);
            IElement   curElem = expTree.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (curElem is FuncCall)
                {
                    ((FuncCall)curElem).Compile_SpecifyPath(this);
                }
                else if (curElem is DelegateDef)
                {
                    ((DelegateDef)curElem).Compile_SpecifyPath(this);
                }
                else if (curElem is ConstName)
                {
                    ConstName constName = (ConstName)curElem;
                    IElement  finalExp  = null;

                    OverwriteConstDef overwriteConst = OverwriteConstDefList.Find(a => a.ConstInfo.Compare(constName.ConstInfo));
                    if (overwriteConst != null)
                    {
                        finalExp = overwriteConst.OriginalContent;
                    }
                    else
                    {
                        ConstInfo targetConstInfo = constName.ConstInfo;
                        if (targetConstInfo.SF.SI.IsGlobal)
                        {
                            finalExp = GetGlobalConstContent(constName);
                        }
                        else
                        {
                            finalExp = GetCompiledConstValue(targetConstInfo);
                        }
                    }

                    expTree.ReplaceCurrent(finalExp);
                }
                else if (curElem is UsingName)
                {
                    UsingName usingName   = (UsingName)curElem;
                    string    finalSFPath = GetActualSFPath(usingName.UsingInfo.SFPath);
                    expTree.ReplaceCurrent(new Path(usingName.UsingInfo.SFPath, finalSFPath));
                }
                else if (curElem is Path)
                {
                    string originalPath = ((Path)curElem).OriginalPath;
                    string finalSFPath  = GetActualSFPath(originalPath);
                    ((Path)curElem).Update(finalSFPath);
                }

                curElem = expTree.FindNextBlack(SearchDirection.LeftToRight);
            }
            return(content);
        }
Exemple #2
0
        public bool CompileMembers()
        {
            // replace usings & paths & constants & specify paths in constants
            foreach (ConstDef c in ConstDefList)
            {
                c.ReplaceMembersInContent(this);
            }

            foreach (OverwriteConstDef c in OverwriteConstDefList)
            {
                c.ReplaceMembersInContent(this);
            }

            // replace path in includes
            foreach (PreProcessorInclude i in IncludeDefList)
            {
                string originalPath = i.Path.OriginalPath;
                string finalPath    = GetActualSFPath(originalPath);
                i.Path.Update(finalPath);
            }

            // update constants in overwritten SFs
            foreach (OverwriteConstDef c in OverwriteConstDefList)
            {
                ScriptFile overwriteSF    = _overwriteSFList[c.ConstInfo.SF];
                ConstInfo  cInOverwriteSF = overwriteSF.SI.FindLocalConst(c.ConstInfo.Name);
                cInOverwriteSF.ConstDef.OriginalContent = c.CompiledContent;
            }

            // compile overwritten SFs
            foreach (ScriptFile originalSF in _overwriteSFList.Keys)
            {
                ScriptFile sf = _overwriteSFList[originalSF];
                if (sf == _sf) // ignore itself
                {
                    continue;
                }

                if (!sf.PrepareCompileSC())
                {
                    return(false);
                }

                if (!sf.CompileMembersSC())
                {
                    return(false);
                }

                sf.CompileCodeSC();
                sf.CompileOutputSC();
            }

            // replace usings & paths & constants in code
            MoveInfo treeInfo = new MoveInfo(this, SearchTree.ChildrenTree, 0, this._sf);
            IElement curElem  = treeInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible);

            while (curElem != null)
            {
                if (curElem is UsingName)
                {
                    UsingName usingName   = (UsingName)curElem;
                    string    finalSFPath = GetActualSFPath(usingName.UsingInfo.SFPath);
                    treeInfo.ReplaceCurrent(new Path(usingName.UsingInfo.SFPath, finalSFPath));
                }
                else if (curElem is Path)
                {
                    string originalPath = ((Path)curElem).OriginalPath;
                    string finalSFPath  = GetActualSFPath(originalPath);
                    ((Path)curElem).Update(finalSFPath);
                }
                else if (curElem is ConstName)
                {
                    ConstName constName = (ConstName)curElem;
                    IElement  finalExp  = null;

                    OverwriteConstDef overwriteConst = OverwriteConstDefList.Find(a => a.ConstInfo.Compare(constName.ConstInfo));
                    if (overwriteConst != null)
                    {
                        finalExp = overwriteConst.OriginalContent;
                    }
                    else
                    {
                        ConstInfo targetConstInfo = constName.ConstInfo;
                        if (targetConstInfo.SF.SI.IsGlobal)
                        {
                            finalExp = GetGlobalConstContent(constName);
                        }
                        else
                        {
                            finalExp = GetCompiledConstValue(targetConstInfo);
                        }
                    }

                    treeInfo.ReplaceCurrent(finalExp);
                }

                curElem = treeInfo.FindNextBlack(SearchDirection.LeftToRight);
            }
            return(true);
        }