35
35
36
36
namespace cxx {
37
37
38
- static auto getFunctionDeclaratorHelper (DeclaratorAST* declarator)
38
+ namespace {
39
+
40
+ class RecordingDiagnosticsClient : public DiagnosticsClient {
41
+ public:
42
+ void reset () { messages_.clear (); }
43
+
44
+ void reportTo (DiagnosticsClient* client) {
45
+ for (const auto & message : messages_) {
46
+ client->report (message);
47
+ }
48
+ }
49
+
50
+ auto messages () const -> const std::vector<Diagnostic>& { return messages_; }
51
+
52
+ void report (const Diagnostic& message) override {
53
+ messages_.push_back (message);
54
+ }
55
+
56
+ private:
57
+ std::vector<Diagnostic> messages_;
58
+ };
59
+
60
+ auto getFunctionDeclaratorHelper (DeclaratorAST* declarator)
39
61
-> std::pair<FunctionDeclaratorAST*, bool> {
40
62
if (!declarator) return std::make_pair (nullptr , false );
41
63
@@ -64,11 +86,13 @@ static auto getFunctionDeclaratorHelper(DeclaratorAST* declarator)
64
86
return std::make_pair (nullptr , false );
65
87
}
66
88
67
- static auto getFunctionDeclarator (DeclaratorAST* declarator)
89
+ auto getFunctionDeclarator (DeclaratorAST* declarator)
68
90
-> FunctionDeclaratorAST* {
69
91
return get<0 >(getFunctionDeclaratorHelper (declarator));
70
92
}
71
93
94
+ } // namespace
95
+
72
96
Parser::Parser (TranslationUnit* unit) : unit(unit) {
73
97
control = unit->control ();
74
98
cursor_ = 1 ;
@@ -1945,6 +1969,8 @@ auto Parser::parse_unop_expression(ExpressionAST*& yyast) -> bool {
1945
1969
1946
1970
if (!parse_cast_expression (ast->expression )) {
1947
1971
parse_error (" expected an expression" );
1972
+ rewind (opLoc);
1973
+ return false ;
1948
1974
}
1949
1975
1950
1976
return true ;
@@ -2289,7 +2315,18 @@ auto Parser::parse_delete_expression(ExpressionAST*& yyast) -> bool {
2289
2315
auto Parser::parse_cast_expression (ExpressionAST*& yyast) -> bool {
2290
2316
const auto start = currentLocation ();
2291
2317
2292
- if (parse_cast_expression_helper (yyast)) return true ;
2318
+ RecordingDiagnosticsClient diags;
2319
+
2320
+ auto savedDiagnosticClient = unit->changeDiagnosticsClient (&diags);
2321
+
2322
+ auto parsedCastExpression = parse_cast_expression_helper (yyast);
2323
+
2324
+ unit->changeDiagnosticsClient (savedDiagnosticClient);
2325
+
2326
+ if (parsedCastExpression) {
2327
+ diags.reportTo (unit->diagnosticsClient ());
2328
+ return true ;
2329
+ }
2293
2330
2294
2331
rewind (start);
2295
2332
@@ -2311,7 +2348,9 @@ auto Parser::parse_cast_expression_helper(ExpressionAST*& yyast) -> bool {
2311
2348
2312
2349
ExpressionAST* expression = nullptr ;
2313
2350
2314
- if (!parse_cast_expression (expression)) return false ;
2351
+ if (!parse_cast_expression (expression)) {
2352
+ return false ;
2353
+ }
2315
2354
2316
2355
auto ast = new (pool) CastExpressionAST ();
2317
2356
yyast = ast;
0 commit comments