Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Does ASTParser process goto statements?
Does ASTParser process goto statements? [message #1707980] Fri, 11 September 2015 07:55 Go to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Hi,
I see that ASTParser processes not corrent gotos. Here is example, I just set breakpoint in debugger when parsing MethodDeclaration.
Real body:

    	Object attributeset;
        if(attributeset == null)
        	goto _L2;
        else
        	goto _L1
_L1:
        System.out.println();
_L2:
	int i = 0, j = 5;
        if(i >= j)
        	System.out.println();


Here is parsed code:
Object attributeset;
  if (attributeset == null)   throw _L2;
 else {
    _L1 _L1;
    System.out.println();
    _L2: {
      int i=0, j=5;
      if (i >= j)       System.out.println();
 else       ;
    }
  }


I see that it complitely doesn't understand gotos, and generate incorrect AST. Maybe I'm doing something wrong? If that so, please advise a solution, else please help me to edit AST parser core

[Updated on: Fri, 11 September 2015 08:15]

Report message to a moderator

Re: Does ASTParser process goto statements? [message #1708005 is a reply to message #1707980] Fri, 11 September 2015 11:58 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Maybe this sentence from JLS 14.7. helps: "Unlike C and C++, the Java programming language has no goto statement; identifier statement labels are used with break or continue statements (§14.15, §14.16) appearing anywhere within the labeled statement."

The strange part is (JLS 3.9): "The keywords const and goto are reserved, even though they are not currently used. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in programs."

HTH
Stephan
Re: Does ASTParser process goto statements? [message #1708141 is a reply to message #1708005] Mon, 14 September 2015 08:25 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Yes, I know. But I'm using ASTParser for analyzing decompiled JARs. Usually the output code contains a lot of goto statements and labels (because decompiler was unable to produce correct code, yes). So, if ASTParser doesn't generate a correct output for code with gotos (and here's no way to do it), I have to search its sources and make my own version of ASTParser with labels and gotos.

Maybe here is a chance to contact with developers and ask them to create new class "GotoStatement" which object reffers to ExpressionStatement (next node)?
Re: Does ASTParser process goto statements? [message #1708202 is a reply to message #1708141] Mon, 14 September 2015 15:33 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Sorry, but parsing pseudo code generated by some tool is outside the scope of ASTParser. ASTParser requires legal Java source code, which your example is not.
Also be warned that ASTParser is not designed to be easily hacked. You would have to learn extending a JikesPG grammar, generating the Parser, making adjustments in the hand-coded parts of the internal Parser and much more like that. In short: not an easy task.

Stephan

PS: You might be much better off by directly processing the byte code with one of the available byte code libraries. Better use a matching pair of tool and input rather than forcing wrong input into a tool that was not designed for that task.
Re: Does ASTParser process goto statements? [message #1708302 is a reply to message #1708202] Tue, 15 September 2015 10:28 Go to previous messageGo to next message
Sergey Toshin is currently offline Sergey ToshinFriend
Messages: 56
Registered: May 2015
Member
Is there a way to ignore unused keywords in this case? In the shown example invalid code isn't ignored, but replaced by wrong operations (throw and declaration of a variable)
Re: Does ASTParser process goto statements? [message #1708320 is a reply to message #1708302] Tue, 15 September 2015 13:25 Go to previous message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
Ivan Ivan wrote on Tue, 15 September 2015 12:28
Is there a way to ignore unused keywords in this case? In the shown example invalid code isn't ignored, but replaced by wrong operations (throw and declaration of a variable)


That's called error recovery, and works by "guessing" a minimal change that results in syntactically legal code. In some situations error recovery indeed just ignores one or more tokens, but the parser would have to first understand the goto syntax (with its label argument) in order to know how much text should be ignored. This could be filed as an RFE (bugzilla), but I wouldn't give high priority to this.

Stephan
Previous Topic:Unable to update eclipse
Next Topic:From scratch Elipse-Mars openjdk-7-jdk on Ubunut 14.04.2 build path problems
Goto Forum:
  


Current Time: Fri Apr 19 23:30:09 GMT 2024

Powered by FUDForum. Page generated in 0.03440 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top