Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CDT parser include file handling and support recursion for includes #639

Draft
wants to merge 8 commits into
base: dev
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//#Safe
/*-----------------------------------------------------------------------------
* C program with preprocessor macros to test macro parsing and substitution
*-----------------------------------------------------------------------------
* Author: Manuel Bentele
* Date: 2023-09-25
*---------------------------------------------------------------------------*/

#undef SELECT_FUNC_ONE

#define VALUE 100

int compute_one(int num)
{
return num - VALUE;
}

int compute_two(int num)
{
return num + VALUE;
}

#ifdef SELECT_FUNC_ONE
#define FUNC(VAL) compute_one(VAL)
#else
#define FUNC(VAL) compute_two(VAL)
#endif

int main(void)
{
int ret = FUNC(VALUE);
//@ assert(ret == 100 + 100);
return ret;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//#Unafe
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//#Unsafe

Copy link
Member Author

@bahnwaerter bahnwaerter Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out the invalid program correctness specifier.

/*-----------------------------------------------------------------------------
* C program with preprocessor macros to test macro parsing and substitution
*-----------------------------------------------------------------------------
* Author: Manuel Bentele
* Date: 2023-09-25
*---------------------------------------------------------------------------*/

#define SELECT_FUNC_ONE

#define VALUE 100

int compute_one(int num)
{
return num - VALUE;
}

int compute_two(int num)
{
return num + VALUE;
}

#ifdef SELECT_FUNC_ONE
#define FUNC(VAL) compute_one(VAL)
#else
#define FUNC(VAL) compute_two(VAL)
#endif

int main(void)
{
int ret = FUNC(VALUE);
//@ assert(ret == 100 + 100);
return ret;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//#Safe
/*-----------------------------------------------------------------------------
* C program with preprocessor macro to test macro parsing and substitution
*-----------------------------------------------------------------------------
* Author: Manuel Bentele
* Date: 2023-09-25
*---------------------------------------------------------------------------*/

#define VALUE 100

int main(void)
{
int ret = VALUE;
//@ assert(ret == 100);
return ret;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//#Unsafe
/*-----------------------------------------------------------------------------
* C program with preprocessor macro to test macro parsing and substitution
*-----------------------------------------------------------------------------
* Author: Manuel Bentele
* Date: 2023-09-25
*---------------------------------------------------------------------------*/

#define VALUE 100

int main(void)
{
int ret = VALUE;
//@ assert(ret == 200);
return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorElseStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorEndifStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorErrorStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorFunctionStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorObjectStyleMacroDefinition;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorPragmaStatement;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;

Expand Down Expand Up @@ -78,25 +80,16 @@ public Result visit(final IDispatcher main, final IASTNode node) {

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorElifStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorElseStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorEndifStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

Expand All @@ -109,25 +102,16 @@ public Result visit(final IDispatcher main, final IASTPreprocessorErrorStatement

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorIfdefStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorIfndefStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorIfStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

Expand All @@ -139,25 +123,34 @@ public Result visit(final IDispatcher main, final IASTPreprocessorIncludeStateme
@Override
public Result visit(final IDispatcher main, final IASTPreprocessorMacroDefinition node) {
// this was already handled by the CDT parser...

if (node instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
return visit(main, (IASTPreprocessorFunctionStyleMacroDefinition) node);
} else if (node instanceof IASTPreprocessorObjectStyleMacroDefinition) {
return visit(main, (IASTPreprocessorObjectStyleMacroDefinition) node);
}

return new SkipResult();
}

public Result visit(final IDispatcher main, final IASTPreprocessorFunctionStyleMacroDefinition node) {
return new SkipResult();
}

public Result visit(final IDispatcher main, final IASTPreprocessorObjectStyleMacroDefinition node) {
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorPragmaStatement node) {
if (mIgnorePreprocessorPragmas) {
return new SkipResult();
}
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final String msg = "Ignoring preprocessor pragma";
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
mReporter.warn(loc, msg);
return new SkipResult();
}

@Override
public Result visit(final IDispatcher main, final IASTPreprocessorUndefStatement node) {
final String msg = "PreprocessorHandler: Not yet implemented: " + node.toString();
final ILocation loc = mLocationFactory.createCLocation(node);
mReporter.unsupportedSyntax(loc, msg);
return new SkipResult();
}

Expand Down