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

21
LINES

< > TinyBrain | #1008911 - ctxSimplifyIfs [OUTDATED]

JavaX fragment (include)

static void ctxSimplifyIfs(L<S> tok) {
  int i;
  while ((i = jfind(tok, "if (")) >= 0) {
    int iEnd = findEndOfBracketPart(tok, i+2)-1;
    S cond = join(subList(tok, i+4, iEnd-1));
    bool yes = ctxEvalCondition(cond);
    assertEquals("{", tok.get(iEnd+2));
    int iEndYes = findEndOfBlock(tok, iEnd+2)-1;
    S yesCode = join(subList(tok, iEnd+4, iEndYes-1));
    int j = iEndYes+2;
    S noCode = "";
    if (eqGet(tok, iEndYes+2, "else")) {
      int iNo = iEndYes+4;
      assertEquals("{", tok.get(iNo));
      int iEndNo = findEndOfBlock(tok, iNo)-1;
      j = iEndNo+2;
      noCode = join(subList(tok, iNo+2, iEndNo-1));
    }
    replaceTokens_reTok(tok, i, j, yes ? yesCode : noCode);
  }
}

download  show line numbers  debug dex   

Travelled to 2 computer(s): cfunsshuasjs, tvejysmllsmz

No comments. add comment

Snippet ID: #1008911
Snippet name: ctxSimplifyIfs [OUTDATED]
Eternal ID of this version: #1008911/6
Text MD5: 1c5a32b55859e2acdd79a907e14ff890
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-01 19:07:34
Source code size: 727 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 32 / 53
Version history: 5 change(s)
Referenced in: [show]