Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_library(cxx-parser
cxx/control.cc
cxx/cxx.cc
cxx/decl_specs.cc
cxx/decl.cc
cxx/diagnostic.cc
cxx/diagnostics_client.cc
cxx/external_name_encoder.cc
Expand Down
14 changes: 8 additions & 6 deletions src/parser/cxx/const_expression_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@

namespace cxx {

ConstExpressionEvaluator::ConstExpressionEvaluator(TranslationUnit* unit)
: unit_(unit) {}

auto ConstExpressionEvaluator::control() const -> Control* {
return unit_->control();
}

auto ConstExpressionEvaluator::evaluate(ExpressionAST* ast)
-> std::optional<ConstValue> {
if (!ast) return std::nullopt;
return visit(*this, ast);
}

auto ConstExpressionEvaluator::control() const -> Control* {
return parser.control();
}

auto ConstExpressionEvaluator::operator()(GeneratedLiteralExpressionAST* ast)
-> std::optional<ConstValue> {
return ast->value;
Expand Down Expand Up @@ -522,8 +525,7 @@ auto ConstExpressionEvaluator::operator()(BinaryExpressionAST* ast)
return right;

default:
parser.translationUnit()->warning(ast->opLoc,
"invalid binary expression");
unit_->warning(ast->opLoc, "invalid binary expression");
break;
} // switch

Expand Down
9 changes: 5 additions & 4 deletions src/parser/cxx/const_expression_evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@

namespace cxx {

class Parser;
class Control;
class TranslationUnit;

class ConstExpressionEvaluator {
Parser& parser;

public:
explicit ConstExpressionEvaluator(Parser& parser) : parser(parser) {}
explicit ConstExpressionEvaluator(TranslationUnit* unit);

auto evaluate(ExpressionAST* ast) -> std::optional<ConstValue>;

Expand Down Expand Up @@ -108,6 +106,9 @@ class ConstExpressionEvaluator {
auto operator()(EqualInitializerAST* ast) -> std::optional<ConstValue>;
auto operator()(BracedInitListAST* ast) -> std::optional<ConstValue>;
auto operator()(ParenInitializerAST* ast) -> std::optional<ConstValue>;

private:
TranslationUnit* unit_;
};

} // namespace cxx
Loading