Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1025200 // tok_embeddedFunctions - transpile function with JavaX keyword "embedded"

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (2766L) is out of date.

svoid tok_embeddedFunctions(L<S> tok) {
  int i;
  while ((i = jfind(tok, "embedded <id>")) >= 0) {
    int j = tok_findEndOfMethodDecl(tok, i); // points to N after function
    S functionName = tok_functionName(subList(tok, i));
    S className = makeVar("C"), varName = makeVar();
    
    // drop keyword, rewrite function to class, create object
    
    //tok.set(i, "/* make final to optimize */ class " + className + " {");
    tok.set(i, "final class " + className + " {");
    tokAppend(tok, j-1, " } " +
      " final " + className + " " + varName + " = new " + className + "();");
    
    // redirect calls to object
    
    int end = findEndOfBlock(tok, j)-1;
    for (j |= 1; j < end; j += 2)
      if (eq(tok.get(j), functionName) && eqGet(tok, j+2, "(")) tokPrepend(tok, j, varName + ".");
    reTok(tok, i, end);
  }
}

Author comment

Began life as a copy of #1013759

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1025200
Snippet name: tok_embeddedFunctions - transpile function with JavaX keyword "embedded"
Eternal ID of this version: #1025200/11
Text MD5: 4288460e4200973823d988ae28aedd6b
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-17 16:57:33
Source code size: 858 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 644 / 803
Version history: 10 change(s)
Referenced in: [show references]