internal static Token[] rewrite_nonlocalsymbols(Token[] sourcetokens, string originalsymbol_location, string finallocation) { // get destination class symbols var classsym = RD_AssistTemplate.GetClassSymbols(); // get source symbols var sourcesym = GetSourceSymbols(originalsymbol_location); // process every source symbol for (int i = 0; i < sourcetokens.Length; i++) { var t = sourcetokens[i]; if (!t.isSymbol) { continue; } // get symbol var sym = t.data; // ignore reserved words if (isreservedsymbol(sym)) { continue; } // ignore if symbol is local to class if (classsym.Contains(sym)) { continue; } // re-write any from sourceclass if (sourcesym.Contains(sym)) { t.data = finallocation + "." + t.data; sourcetokens[i] = t; continue; } // other symbols should be already defined as local } return(sourcetokens); }
internal static bool transform_assist_helpers(List <string> sourcetypes, GenericTracker <Token[]> const2tokens, ref GenericTracker <List <Token> > function2functoks) { // get destination class symbols var templateclasssym = RD_AssistTemplate.GetClassSymbols(); // process every token for (int i = 0; i < tokstream.Count; i++) { // get our building blocks var tok = tokstream[i]; // look for symbols if (!tok.isSymbol) { continue; } // ignore constructors if (sourcetypes.Contains(tok.data)) { continue; } // skip methods we have overridden in destination class (eg GetSymbolDecimal) if (templateclasssym.Contains(tok.data)) { continue; } // get previous token symbol var ptok = getprevioussymbol(tok); // verify we return an assist if (ptok.data != "AssistI") { continue; } // update other states //bool isvoidmethod = issymbolvoidargumentmethod(tok); //if (isvoidmethod) // continue; bool ismethod = issymbolmethod(tok); // take the non-void static methods which return assists and place them as helpers if (ismethod) { // get name of function var fname = tok.data; // get function tokens including the argument list (but not the static token) var allfunction = new List <Token>(); // save this name var ftokens = getfunctiontokens(i); // get the constants used by this helper var consttoks = gethelperconstants(ftokens, const2tokens); // build entire function starting with return arguments allfunction.Add(new Token(tokentype.symbol, "AssistI")); allfunction.Add(new Token(tokentype.space, " ")); // name allfunction.Add(tok); // arguments allfunction.AddRange(getfunctionarguments(i)); // re-write any functions not present in destination //var rewrittenbody = rewrite_nonlocalsymbols(ftokens, sourcetype); // body allfunction.Add(new Token(tokentype.line, h.line())); allfunction.Add(new Token(tokentype.block_start, "{")); allfunction.Add(new Token(tokentype.line, h.line())); // constants allfunction.AddRange(consttoks); // code allfunction.AddRange(ftokens); // end body allfunction.Add(new Token(tokentype.line, h.line())); allfunction.Add(new Token(tokentype.block_end, "}")); allfunction.Add(new Token(tokentype.line, h.line())); // get code from these modified tokens //var bodycode = gettokencode(allfunction.ToArray()); // see if we have some code already int tokencodeidx = function2functoks.getindex(tok.data); // if not, save it if (tokencodeidx < 0) { tokencodeidx = function2functoks.addindex(tok.data, allfunction); } else // otherwise it's an overload, append it { function2functoks[tokencodeidx].AddRange(allfunction); } } } return(true); }