コード例 #1
0
        public static bool GenRDTemplates(string outputtemplatefilename, string basenamespace, out string code, params string[] inputfiles)
        {
            code = string.Empty;
            // tokenize data
            bool tokok = true;

            for (int i = 0; i < inputfiles.Length; i++)
            {
                var source    = inputfiles[i];
                var inputcode = h.getfile(source, null);
                tokok &= createstream(source, inputcode, i == 0);
            }

            if (!tokok)
            {
                return(false);
            }

            // generate constants
            GenericTracker <Token[]> const2consttoks = getcodeconstants();

            // generate helpers

            GenericTracker <List <Token> > function2ftoks = new GenericTracker <List <Token> >();
            bool helperok = transform_assist_helpers(getallsourcetypes(basenamespace, inputfiles), const2consttoks, ref function2ftoks);


            // generate classes
            string        assistcode;
            List <string> typenames;
            var           assistok = transform_assist_calls(outputtemplatefilename, getsourcetype(basenamespace, inputfiles[0]),
                                                            function2ftoks, const2consttoks, out assistcode, out typenames);

            if (helperok && assistok)
            {
                // generate method to get all the types as params
                var getallmethod = gencode_gettypes_fromnames(outputtemplatefilename, typenames);

                // add to global RD listing class
                var rdlisting_class = TargetMap.GetClass(outputtemplatefilename, string.Empty, getallmethod);

                // wrap it all together
                code = RD_AssistTemplate.GetTemplateFile(rdlisting_class + assistcode);

                // save class if required
                bool savefile = !string.IsNullOrWhiteSpace(outputtemplatefilename);
                //var folder = h.gf();
                var folder = Environment.CurrentDirectory + "\\";
                var fn     = folder + outputtemplatefilename + ".cs";
                if (savefile && !string.IsNullOrWhiteSpace(code) && h.setfile(fn, code))
                {
                }


                return(true);
            }

            return(false);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        internal static bool transform_assist_calls(string groupname, string sourcetype, GenericTracker <List <Token> > symbolname2functiontoks, GenericTracker <Token[]> const2code, out string code, out List <string> typenames)
        {
            code = string.Empty;
            // get all assists in question
            var masterlist = AssistHelper.getavailableassists_names();
            var mastercopy = masterlist.ToArray();

            for (int i = 0; i < masterlist.Count; i++)
            {
                masterlist[i] = masterlist[i].Replace(sourcetype + ":", string.Empty);
            }
            // strip out their location

            int okcount = 0;
            int classes = 0;

            typenames = new List <string>();
            // process every primary source token
            for (int i = 0; i < primarytokencount; i++)
            {
                // get our building blocks
                var tok = tokstream[i];
                // see if we want it
                if (!tok.isSymbol)
                {
                    continue;
                }
                if (sourcetype.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 voidarguments = issymbolvoidargumentmethod(tok);
                var  masteridx     = masterlist.IndexOf(tok.data);
                bool userfacing    = (masteridx >= 0);
                bool hasname       = userfacing && (AssistHelper.getassist(mastercopy[masteridx], null).AssistName != "GleanCommon.Assist");
                // verify our current token is a void method that is user-facing
                if (voidarguments && userfacing && hasname)
                {
                    // get name
                    var fname = tok.data;
                    // get any helper code which might be called by our function
                    var helpercode = gethelpercode(fname, symbolname2functiontoks);
                    // get new class name (that will inherit from RD_AssistTemplate)
                    var classname = getclassname(fname);
                    // get the pretty name
                    var prettyname = GleanHelper.getsafevarname(AssistHelper.getassist(mastercopy[masteridx], null).AssistName);
                    // insert assist code RD class of the same name (eg GetOffsetTracker or taBollinger)
                    var classdefinition = RD_AssistTemplate.GetTemplateClass(classname, prettyname, "return " + fname + "();", helpercode, false, false);
                    code += classdefinition;
                    // count it
                    classes++;
                    okcount++;
                    typenames.Add(classname);
                }
            }



            return(true);
        }
コード例 #4
0
        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);
        }