Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 367827 - CDT Parser gives invalid comment positions when the comment is after a null statement macro in same line.
Summary: CDT Parser gives invalid comment positions when the comment is after a null s...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 8.1.0   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Markus Schorn CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-04 05:59 EST by Hyukmin Kwon CLA
Modified: 2012-02-29 13:21 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hyukmin Kwon CLA 2012-01-04 05:59:57 EST
Build Identifier: Version: 3.7.1 Build id: M20110909-1335

Get tu (an IASTTranslationUnit) by parsing following code with CDT C parser.

#define NULL_STATEMENT_MACRO ;
void macro_test()
{
	int x = 1;

	NULL_STATEMENT_MACRO //comment1

	x; //comment2
}

The obtained position of 'comment1' by using tu.getComments() is incorrect.
The character at the position is not '/' but ' ' (space before '/').
For the 'comment2' the obtained position is correct.
Only comments after the NULL_STATEMENT_MACRO at the same line give incorrect positions.

Same phenomenon is occurred for "#define NULL_BLOCK_MACRO {}".

Reproducible: Always

Steps to Reproduce:
1.Parse following code with CDT C parser and get an IASTTranslationUnit 'tu'.
#define NULL_STATEMENT_MACRO ;
void macro_test()
{
	int x = 1;

	NULL_STATEMENT_MACRO //comment1

	x; //comment2
}

2.Get comment list from tu.getComments()
IASTComment[] cl = tu.getComments();

3.Get node offset of comments by folowing code
commentOffset[i] = cl[i].getFileLocation().getNodeOffset();

4.If we get the character at commentOffset[i] by using IDocument.getChar() method, then commentOffset[1] is '/' but commentOffset[0] is ' ' (space) (i.e. incorrect offset). The difference with correct offset is 1.
Comment 1 Markus Schorn CLA 2012-01-09 04:57:12 EST
Thanks!
Added testcase and fix.
Comment 2 CDT Genie CLA 2012-02-29 13:21:04 EST
*** cdt git genie on behalf of Markus Schorn ***

    Bug 367827: Wrong offset for comment directly after macro expansion.

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=7d0d64393c2da5cac378162fffb8dd0314cb0aac