/// <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); }
/// <summary> /// Create a deep copy of all children and attributes. /// </summary> /// <param name="sf"></param> /// <returns></returns> public BaseTree CreateCopy(ScriptFile sf) { List <IElement> newChildren = new List <IElement>(children.Count); foreach (IElement e in children) { newChildren.Add(e.CreateCopy()); } BaseTree bt = new BaseTree(newChildren); bt._sf = sf; bt.IncludeDefList = new List <PreProcessorInclude>(); bt.FuncDefList = new List <FuncDef>(); bt.ConstDefList = new List <ConstDef>(); bt.UsingDefList = new List <UsingDef>(); bt.OverwriteConstDefList = new List <OverwriteConstDef>(); // find defs... MoveInfo btInfo = new MoveInfo(bt, SearchTree.ChildrenBlock, 0, sf); IElement curElem = btInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); while (curElem != null) { if (curElem is PreProcessorInclude) { bt.IncludeDefList.Add((PreProcessorInclude)curElem); } if (curElem is FuncDef) { bt.FuncDefList.Add((FuncDef)curElem); } else if (curElem is ConstDef) { bt.ConstDefList.Add((ConstDef)curElem); // update SI def ConstInfo cInfo = sf.SI.FindLocalConst(((ConstDef)curElem).ConstInfo.Name); cInfo.ConstDef = (ConstDef)curElem; } else if (curElem is UsingDef) { bt.UsingDefList.Add((UsingDef)curElem); } else if (curElem is OverwriteConstDef) { bt.OverwriteConstDefList.Add((OverwriteConstDef)curElem); } curElem = btInfo.FindNextBlack(SearchDirection.LeftToRight); } return(bt); }
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); }
public static BaseTree Parse(List <IElement> sourceTokens, ScriptFile sf, ScriptInfo scriptInfo) { BaseTree tree = new BaseTree(sourceTokens); tree._sf = sf; MoveInfo parser = new MoveInfo(tree, SearchTree.ChildrenBlock, 0, sf); ParsingInfo parsingInfo = new ParsingInfo(sf); // parse all groups MoveInfo groupInfo = new MoveInfo(tree, SearchTree.ContentTree, 0, sf); IElement cur = groupInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); while (cur != null) { Group.Check(groupInfo, parsingInfo, scriptInfo); cur = groupInfo.FindNextBlack(SearchDirection.LeftToRight); } // parse delegate call [[delegate]] MoveInfo delegateInfo = new MoveInfo(tree, SearchTree.ContentTree, 0, sf); cur = delegateInfo.Find(SearchDirection.LeftToRight, SearchVisibility.Visible); while (cur != null) { DelegateCallGroup.Check(delegateInfo, parsingInfo, scriptInfo); cur = delegateInfo.FindNextBlack(SearchDirection.LeftToRight); } // create parse tree MoveInfo contentInfo = new MoveInfo(parser); cur = contentInfo.Current; while (cur != null) { if (!cur.Visible) { XMLBlock.Check(contentInfo, parsingInfo, scriptInfo); cur = contentInfo.Move(SearchDirection.LeftToRight); } else { if (DevCode.Check(contentInfo, parsingInfo, scriptInfo) || PreProcessorInclude.Check(contentInfo, parsingInfo, scriptInfo) || PreProcessorRegion.Check(contentInfo, parsingInfo, scriptInfo) || AccessModifier.Check(contentInfo, parsingInfo, scriptInfo) || SealedModifier.Check(contentInfo, parsingInfo, scriptInfo) || UsingDef.Check(contentInfo, parsingInfo, scriptInfo) || OverwriteConstDef.Check(contentInfo, parsingInfo, scriptInfo) || FuncDef.Check(contentInfo, parsingInfo, scriptInfo) || ConstDef.Check(contentInfo, parsingInfo, scriptInfo) ) { cur = contentInfo.Move(SearchDirection.LeftToRight); } else { throw new SyntaxException("Unknown token", contentInfo.GetErrorInfo()); } } } tree.IncludeDefList = parsingInfo.IncludeDefList; tree.FuncDefList = parsingInfo.FuncDefList; tree.ConstDefList = parsingInfo.ConstDefList; tree.UsingDefList = parsingInfo.UsingDefList; tree.OverwriteConstDefList = parsingInfo.OverwriteConstDefList; return(tree); }