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

21
LINES

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

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

Libraryless. Click here for Pure Java version (2766L/18K).

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  
    tokAppend(tok, j-1, " } " +
12  
      " final " + className + " " + varName + " = new " + className + "();");
13  
    
14  
    // redirect calls to object
15  
    
16  
    int end = findEndOfBlock(tok, j)-1;
17  
    for (j |= 1; j < end; j += 2)
18  
      if (eq(tok.get(j), functionName) && eqGet(tok, j+2, "(")) tokPrepend(tok, j, varName + ".");
19  
    reTok(tok, i, end);
20  
  }
21  
}

Author comment

Began life as a copy of #1013759

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025200
Snippet name: tok_embeddedFunctions - transpile function with JavaX keyword "embedded"
Eternal ID of this version: #1025200/10
Text MD5: b925493c0f68333b00cbe29b0002bdac
Transpilation MD5: d8f000e729f3df05d3b4104717eb612a
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-13 13:40:44
Source code size: 804 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 86 / 146
Version history: 9 change(s)
Referenced in: [show references]

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