vehre / aspa_cscc

Convert ASP pages to "pure" html/JS/PHP pages. Based on ASPA with conversion of client side VBscript to Javascript
Other
5 stars 1 forks source link

Unexpected AST node error (Unknown object members in For Loops) #15

Closed jhiswin closed 10 years ago

jhiswin commented 10 years ago

Some files throw an AST node error, unknown AST node

ERROR AspParser - Failed to produce code from vb : 

<AST>:0:0: unexpected AST node: ubound
    at gr.omadak.leviathan.asp.VbsJsGenerator.expression(VbsJsGenerator.java:1325)
    at gr.omadak.leviathan.asp.VbsJsGenerator.expression(VbsJsGenerator.java:989)
    at gr.omadak.leviathan.asp.VbsJsGenerator.expr(VbsJsGenerator.java:822)
    at gr.omadak.leviathan.asp.VbsJsGenerator.nested(VbsJsGenerator.java:710)
    at gr.omadak.leviathan.asp.VbsJsGenerator.statement(VbsJsGenerator.java:187)
    at gr.omadak.leviathan.asp.VbsJsGenerator.statements(VbsJsGenerator.java:103)
    at gr.omadak.leviathan.asp.VbsJsGenerator.function(VbsJsGenerator.java:515)
    at gr.omadak.leviathan.asp.VbsJsGenerator.nested(VbsJsGenerator.java:633)
    at gr.omadak.leviathan.asp.VbsJsGenerator.statement(VbsJsGenerator.java:187)
    at gr.omadak.leviathan.asp.VbsJsGenerator.statements(VbsJsGenerator.java:103)
    at gr.omadak.leviathan.asp.VbsJsGenerator.generate(VbsJsGenerator.java:60)
    at gr.omadak.leviathan.asp.AspParser.produceCode(AspParser.java:424)
    at gr.omadak.leviathan.asp.AspParser.parseFile(AspParser.java:378)
    at gr.omadak.leviathan.asp.AspParser.parseFile(AspParser.java:493)
    at gr.omadak.leviathan.asp.AspParser.parseDir(AspParser.java:568)
    at gr.omadak.leviathan.asp.AspParser.main(AspParser.java:666)
jhiswin commented 10 years ago

This appears to happen only with unknown objects inside of for loops. Work around is to extract the unknown object and set it outside of the for loop declaration.
Eg:

    dim rNode
    set rNode=g_objDom.documentElement
        for nI = 0 to rNode.selectNodes("Word").length -1

Note that rNode's type cannot be inferred here yet, because g_objDom isn't locatable. Workaround; Change

        for nI = 0 to rNode.selectNodes("Word").length -1

to

    dim forMax        
    forMax = rNode.selectNodes("Word").length -1 
    for nI =  0 to forMax
vehre commented 10 years ago

Fixed with commit 950802ff41431402bb1ef03749b4a0dfad417b61.

This was actually a bug in the antlr code generation, where the original ast was used in the tree parser and not the parsed one. This fixed by using a temporary in the grammar.