Skip to content

Wrong parsing of functions starting with #if #1

Description

@adam-sse

This code:

#ifdef LONG
	long
#else
	int
#endif
calc(
#ifdef LONG
	long
#else
	int
#endif
a) {
	return 2 * a;
}

is incorrectly parsed to this structure:

[1] File
	[LONG] #IFDEF LONG
		[LONG] Function
			[LONG] CodeList
				[LONG] long
				[LONG && !LONG] #ELSE !LONG
					[LONG && !LONG] int
				[LONG] calc (
				[LONG && LONG] #IFDEF LONG
					[LONG && LONG] long
				[LONG] 
				[LONG && !LONG] #ELSE !LONG
					[LONG && !LONG] int
				[LONG] a )

			[LONG] CompoundStatement
				[LONG] Statement:
					[LONG] return 2 * a ;

Correct would be something like this:

[1] File
	[1] Function
		[1] CodeList
			[LONG] #IFDEF LONG
				[LONG] long
			[!LONG] #ELSE !LONG
				[!LONG] int
			[1] calc (
			[LONG] #IFDEF LONG
				[LONG] long
			[!LONG] #ELSE !LONG
				[LONG] int
			[1] a )

		[1] CompoundStatement
			[1] Statement:
				[1] return 2 * a ;

The problem is, that srcML creates an <cpp:ifdef> tag before the <function> tag:

<cpp:ifdef>#<cpp:directive>ifdef</cpp:directive> <name>LONG</name></cpp:ifdef>
	<function><type><name>long</name>
<cpp:else>#<cpp:directive>else</cpp:directive></cpp:else>
	<name>int</name></type>
<cpp:endif>#<cpp:directive>endif</cpp:directive></cpp:endif>

Fixing this would require a special rewriting of the XML structure created by srcML. We currently don't plan to do this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions