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.

1  
svoid tok_embeddedFunctions(L<S> tok) {
2  
  int i;
3  
  while ((i = jfind(tok, "embedded <id>")) >= 0) {
4  
    int j = tok_findEndOfMethodDecl(tok, i); // points to N after function
5  
    S functionName = tok_functionName(subList(tok, i));
6  
    S className = makeVar("C"), varName = makeVar();
7  
    
8  
    // drop keyword, rewrite function to class, create object
9  
    
10  
    //tok.set(i, "/* make final to optimize */ class " + className + " {");
11  
    tok.set(i, "final class " + className + " {");
12  
    tokAppend(tok, j-1, " } " +
13  
      " final " + className + " " + varName + " = new " + className + "();");
14  
    
15  
    // redirect calls to object
16  
    
17  
    int end = findEndOfBlock(tok, j)-1;
18  
    for (j |= 1; j < end; j += 2)
19  
      if (eq(tok.get(j), functionName) && eqGet(tok, j+2, "(")) tokPrepend(tok, j, varName + ".");
20  
    reTok(tok, i, end);
21  
  }
22  
}

Author comment

Began life as a copy of #1013759

download  show line numbers  debug dex   

Travelled to 3 computer(s): mqqgnosmbjvj, tvejysmllsmz, 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: 147 / 218
Version history: 10 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1025200 & http://1025200.tinybrain.de