mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-12 02:47:10 +00:00
Add BoolLiteralExpression
to SyntaxTree
Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82310
This commit is contained in:
parent
c9e8c9e3ea
commit
7f7f856480
@ -45,6 +45,7 @@ enum class NodeKind : uint16_t {
|
||||
BinaryOperatorExpression,
|
||||
CxxNullPtrExpression,
|
||||
IntegerLiteralExpression,
|
||||
BoolLiteralExpression,
|
||||
IdExpression,
|
||||
|
||||
// Statements.
|
||||
@ -264,6 +265,16 @@ public:
|
||||
syntax::Leaf *literalToken();
|
||||
};
|
||||
|
||||
/// Expression for boolean literals. C++ [lex.bool]
|
||||
class BoolLiteralExpression final : public Expression {
|
||||
public:
|
||||
BoolLiteralExpression() : Expression(NodeKind::BoolLiteralExpression) {}
|
||||
static bool classof(const Node *N) {
|
||||
return N->kind() == NodeKind::BoolLiteralExpression;
|
||||
}
|
||||
syntax::Leaf *literalToken();
|
||||
};
|
||||
|
||||
/// An abstract class for prefix and postfix unary operators.
|
||||
class UnaryOperatorExpression : public Expression {
|
||||
public:
|
||||
|
@ -654,6 +654,13 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalkUpFromCXXBoolLiteralExpr(CXXBoolLiteralExpr *S) {
|
||||
Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
|
||||
Builder.foldNode(Builder.getExprRange(S),
|
||||
new (allocator()) syntax::BoolLiteralExpression, S);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WalkUpFromCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *S) {
|
||||
Builder.markChildToken(S->getLocation(), syntax::NodeRole::LiteralToken);
|
||||
Builder.foldNode(Builder.getExprRange(S),
|
||||
|
@ -22,6 +22,8 @@ llvm::raw_ostream &syntax::operator<<(llvm::raw_ostream &OS, NodeKind K) {
|
||||
return OS << "CxxNullPtrExpression";
|
||||
case NodeKind::IntegerLiteralExpression:
|
||||
return OS << "IntegerLiteralExpression";
|
||||
case NodeKind::BoolLiteralExpression:
|
||||
return OS << "BoolLiteralExpression";
|
||||
case NodeKind::PrefixUnaryOperatorExpression:
|
||||
return OS << "PrefixUnaryOperatorExpression";
|
||||
case NodeKind::PostfixUnaryOperatorExpression:
|
||||
@ -200,6 +202,11 @@ syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
|
||||
findChild(syntax::NodeRole::LiteralToken));
|
||||
}
|
||||
|
||||
syntax::Leaf *syntax::BoolLiteralExpression::literalToken() {
|
||||
return llvm::cast_or_null<syntax::Leaf>(
|
||||
findChild(syntax::NodeRole::LiteralToken));
|
||||
}
|
||||
|
||||
syntax::Leaf *syntax::CxxNullPtrExpression::nullPtrKeyword() {
|
||||
return llvm::cast_or_null<syntax::Leaf>(
|
||||
findChild(syntax::NodeRole::LiteralToken));
|
||||
|
@ -69,6 +69,10 @@ struct TestClangConfig {
|
||||
Language == Lang_CXX20;
|
||||
}
|
||||
|
||||
bool hasBoolType() const {
|
||||
return Language == Lang_C89 || Language == Lang_C99;
|
||||
}
|
||||
|
||||
bool supportsCXXDynamicExceptionSpecification() const {
|
||||
return Language == Lang_CXX03 || Language == Lang_CXX11 ||
|
||||
Language == Lang_CXX14;
|
||||
@ -1228,6 +1232,40 @@ void test() {
|
||||
)txt"));
|
||||
}
|
||||
|
||||
TEST_P(SyntaxTreeTest, BoolLiteral) {
|
||||
if (GetParam().hasBoolType()) {
|
||||
return;
|
||||
}
|
||||
EXPECT_TRUE(treeDumpEqual(
|
||||
R"cpp(
|
||||
void test() {
|
||||
true;
|
||||
false;
|
||||
}
|
||||
)cpp",
|
||||
R"txt(
|
||||
*: TranslationUnit
|
||||
`-SimpleDeclaration
|
||||
|-void
|
||||
|-SimpleDeclarator
|
||||
| |-test
|
||||
| `-ParametersAndQualifiers
|
||||
| |-(
|
||||
| `-)
|
||||
`-CompoundStatement
|
||||
|-{
|
||||
|-ExpressionStatement
|
||||
| |-BoolLiteralExpression
|
||||
| | `-true
|
||||
| `-;
|
||||
|-ExpressionStatement
|
||||
| |-BoolLiteralExpression
|
||||
| | `-false
|
||||
| `-;
|
||||
`-}
|
||||
)txt"));
|
||||
}
|
||||
|
||||
TEST_P(SyntaxTreeTest, IntegerLiteral) {
|
||||
EXPECT_TRUE(treeDumpEqual(
|
||||
R"cpp(
|
||||
@ -1691,18 +1729,18 @@ void test(int a) {
|
||||
|-{
|
||||
|-ExpressionStatement
|
||||
| |-BinaryOperatorExpression
|
||||
| | |-UnknownExpression
|
||||
| | |-BoolLiteralExpression
|
||||
| | | `-true
|
||||
| | |-||
|
||||
| | `-UnknownExpression
|
||||
| | `-BoolLiteralExpression
|
||||
| | `-false
|
||||
| `-;
|
||||
|-ExpressionStatement
|
||||
| |-BinaryOperatorExpression
|
||||
| | |-UnknownExpression
|
||||
| | |-BoolLiteralExpression
|
||||
| | | `-true
|
||||
| | |-or
|
||||
| | `-UnknownExpression
|
||||
| | `-BoolLiteralExpression
|
||||
| | `-false
|
||||
| `-;
|
||||
|-ExpressionStatement
|
||||
@ -2556,7 +2594,7 @@ static_assert(true);
|
||||
|-StaticAssertDeclaration
|
||||
| |-static_assert
|
||||
| |-(
|
||||
| |-UnknownExpression
|
||||
| |-BoolLiteralExpression
|
||||
| | `-true
|
||||
| |-,
|
||||
| |-UnknownExpression
|
||||
@ -2566,7 +2604,7 @@ static_assert(true);
|
||||
`-StaticAssertDeclaration
|
||||
|-static_assert
|
||||
|-(
|
||||
|-UnknownExpression
|
||||
|-BoolLiteralExpression
|
||||
| `-true
|
||||
|-)
|
||||
`-;
|
||||
@ -3186,7 +3224,7 @@ int b() noexcept(true);
|
||||
| |-)
|
||||
| |-noexcept
|
||||
| |-(
|
||||
| |-UnknownExpression
|
||||
| |-BoolLiteralExpression
|
||||
| | `-true
|
||||
| `-)
|
||||
`-;
|
||||
|
Loading…
x
Reference in New Issue
Block a user