Skip to content

Commit 54b5f3e

Browse files
committed
Throw custom error exception for preprocessor #error statements
1 parent 0e9ffca commit 54b5f3e

3 files changed

Lines changed: 67 additions & 3 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//#Unafe
2+
/*-----------------------------------------------------------------------------
3+
* C program with preprocessor error statement
4+
*-----------------------------------------------------------------------------
5+
* Author: Manuel Bentele
6+
* Date: 2025-01-17
7+
*---------------------------------------------------------------------------*/
8+
9+
#error This is an preprocessor error in the program
10+
11+
int main(void)
12+
{
13+
return 0;
14+
}

trunk/source/CACSL2BoogieTranslator/src/de/uni_freiburg/informatik/ultimate/cdt/translation/implementation/base/PreprocessorHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorUndefStatement;
4747

4848
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.LocationFactory;
49-
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.exception.IncorrectSyntaxException;
49+
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.exception.PreprocessorErrorException;
5050
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.exception.UnsupportedSyntaxException;
5151
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.result.Result;
5252
import de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.result.SkipResult;
@@ -92,9 +92,9 @@ public Result visit(final IDispatcher main, final IASTPreprocessorEndifStatement
9292

9393
@Override
9494
public Result visit(final IDispatcher main, final IASTPreprocessorErrorStatement node) {
95-
final String msg = "PreprocessorHandler: There was an error while parsing the preprocessor statements!";
95+
final String msg = "PreprocessorHandler: " + node.toString();
9696
final ILocation loc = mLocationFactory.createCLocation(node);
97-
throw new IncorrectSyntaxException(loc, msg);
97+
throw new PreprocessorErrorException(loc, msg);
9898
}
9999

100100
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2025 Manuel Bentele (bentele@informatik.uni-freiburg.de)
3+
*
4+
* This file is part of the ULTIMATE CACSL2BoogieTranslator plug-in.
5+
*
6+
* The ULTIMATE CACSL2BoogieTranslator plug-in is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Lesser General Public License as published
8+
* by the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* The ULTIMATE CACSL2BoogieTranslator plug-in is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public License
17+
* along with the ULTIMATE CACSL2BoogieTranslator plug-in. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* Additional permission under GNU GPL version 3 section 7:
20+
* If you modify the ULTIMATE CACSL2BoogieTranslator plug-in, or any covered work, by linking
21+
* or combining it with Eclipse RCP (or a modified version of Eclipse RCP),
22+
* containing parts covered by the terms of the Eclipse Public License, the
23+
* licensors of the ULTIMATE CACSL2BoogieTranslator plug-in grant you additional permission
24+
* to convey the resulting work.
25+
*/
26+
package de.uni_freiburg.informatik.ultimate.cdt.translation.implementation.exception;
27+
28+
import de.uni_freiburg.informatik.ultimate.core.model.models.ILocation;
29+
30+
/**
31+
* Exception for a preprocessor #error statement.
32+
*
33+
* @author Manuel Bentele (bentele@informatik.uni-freiburg.de)
34+
*/
35+
public class PreprocessorErrorException extends CACSL2BoogieTranslationException {
36+
37+
private static final long serialVersionUID = 1L;
38+
39+
/**
40+
* Create a new exception for a preprocessor #error statement.
41+
*
42+
* @param location
43+
* Location of the preprocessor statement.
44+
* @param msg
45+
* Detailed error message.
46+
*/
47+
public PreprocessorErrorException(final ILocation location, final String msg) {
48+
super(location, msg);
49+
}
50+
}

0 commit comments

Comments
 (0)