[clang] 860cbbd - [SyntaxTree] Add support for `LiteralExpression`
Eduardo Caldas via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 4 07:05:34 PDT 2020
Author: Eduardo Caldas
Date: 2020-08-04T14:05:09Z
New Revision: 860cbbdd6b84017e6d37e1752b0358a05da6b115
URL: https://github.com/llvm/llvm-project/commit/860cbbdd6b84017e6d37e1752b0358a05da6b115
DIFF: https://github.com/llvm/llvm-project/commit/860cbbdd6b84017e6d37e1752b0358a05da6b115.diff
LOG: [SyntaxTree] Add support for `LiteralExpression`
We use inheritance to model the grammar's disjunction rule:
literal:
integer-literal
character-literal
floating-point-literal
string-literal
boolean-literal
pointer-literal
user-defined-literal
Differential Revision: https://reviews.llvm.org/D85186
Added:
Modified:
clang/include/clang/Tooling/Syntax/Nodes.h
clang/lib/Tooling/Syntax/Nodes.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Tooling/Syntax/Nodes.h b/clang/include/clang/Tooling/Syntax/Nodes.h
index d97b127638bb..8a873f9d5273 100644
--- a/clang/include/clang/Tooling/Syntax/Nodes.h
+++ b/clang/include/clang/Tooling/Syntax/Nodes.h
@@ -267,66 +267,82 @@ class ParenExpression final : public Expression {
syntax::Leaf *closeParen();
};
+/// Expression for literals. C++ [lex.literal]
+class LiteralExpression : public Expression {
+public:
+ LiteralExpression(NodeKind K) : Expression(K) {}
+ static bool classof(const Node *N) {
+ return N->kind() == NodeKind::IntegerLiteralExpression ||
+ N->kind() == NodeKind::CharacterLiteralExpression ||
+ N->kind() == NodeKind::FloatingLiteralExpression ||
+ N->kind() == NodeKind::StringLiteralExpression ||
+ N->kind() == NodeKind::BoolLiteralExpression ||
+ N->kind() == NodeKind::CxxNullPtrExpression ||
+ N->kind() == NodeKind::IntegerUserDefinedLiteralExpression ||
+ N->kind() == NodeKind::FloatUserDefinedLiteralExpression ||
+ N->kind() == NodeKind::CharUserDefinedLiteralExpression ||
+ N->kind() == NodeKind::StringUserDefinedLiteralExpression;
+ }
+ syntax::Leaf *literalToken();
+};
+
/// Expression for integer literals. C++ [lex.icon]
-class IntegerLiteralExpression final : public Expression {
+class IntegerLiteralExpression final : public LiteralExpression {
public:
- IntegerLiteralExpression() : Expression(NodeKind::IntegerLiteralExpression) {}
+ IntegerLiteralExpression()
+ : LiteralExpression(NodeKind::IntegerLiteralExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::IntegerLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for character literals. C++ [lex.ccon]
-class CharacterLiteralExpression final : public Expression {
+class CharacterLiteralExpression final : public LiteralExpression {
public:
CharacterLiteralExpression()
- : Expression(NodeKind::CharacterLiteralExpression) {}
+ : LiteralExpression(NodeKind::CharacterLiteralExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::CharacterLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for floating-point literals. C++ [lex.fcon]
-class FloatingLiteralExpression final : public Expression {
+class FloatingLiteralExpression final : public LiteralExpression {
public:
FloatingLiteralExpression()
- : Expression(NodeKind::FloatingLiteralExpression) {}
+ : LiteralExpression(NodeKind::FloatingLiteralExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::FloatingLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for string-literals. C++ [lex.string]
-class StringLiteralExpression final : public Expression {
+class StringLiteralExpression final : public LiteralExpression {
public:
- StringLiteralExpression() : Expression(NodeKind::StringLiteralExpression) {}
+ StringLiteralExpression()
+ : LiteralExpression(NodeKind::StringLiteralExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::StringLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for boolean literals. C++ [lex.bool]
-class BoolLiteralExpression final : public Expression {
+class BoolLiteralExpression final : public LiteralExpression {
public:
- BoolLiteralExpression() : Expression(NodeKind::BoolLiteralExpression) {}
+ BoolLiteralExpression()
+ : LiteralExpression(NodeKind::BoolLiteralExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::BoolLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for the `nullptr` literal. C++ [lex.nullptr]
-class CxxNullPtrExpression final : public Expression {
+class CxxNullPtrExpression final : public LiteralExpression {
public:
- CxxNullPtrExpression() : Expression(NodeKind::CxxNullPtrExpression) {}
+ CxxNullPtrExpression() : LiteralExpression(NodeKind::CxxNullPtrExpression) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::CxxNullPtrExpression;
}
- syntax::Leaf *nullPtrKeyword();
};
/// Expression for user-defined literal. C++ [lex.ext]
@@ -335,16 +351,15 @@ class CxxNullPtrExpression final : public Expression {
/// user-defined-floating-point-literal
/// user-defined-string-literal
/// user-defined-character-literal
-class UserDefinedLiteralExpression : public Expression {
+class UserDefinedLiteralExpression : public LiteralExpression {
public:
- UserDefinedLiteralExpression(NodeKind K) : Expression(K) {}
+ UserDefinedLiteralExpression(NodeKind K) : LiteralExpression(K) {}
static bool classof(const Node *N) {
return N->kind() == NodeKind::IntegerUserDefinedLiteralExpression ||
N->kind() == NodeKind::FloatUserDefinedLiteralExpression ||
N->kind() == NodeKind::CharUserDefinedLiteralExpression ||
N->kind() == NodeKind::StringUserDefinedLiteralExpression;
}
- syntax::Leaf *literalToken();
};
/// Expression for user-defined-integer-literal. C++ [lex.ext]
diff --git a/clang/lib/Tooling/Syntax/Nodes.cpp b/clang/lib/Tooling/Syntax/Nodes.cpp
index 2435ae0a91dd..eced68fa2443 100644
--- a/clang/lib/Tooling/Syntax/Nodes.cpp
+++ b/clang/lib/Tooling/Syntax/Nodes.cpp
@@ -230,37 +230,7 @@ syntax::Leaf *syntax::ParenExpression::closeParen() {
findChild(syntax::NodeRole::CloseParen));
}
-syntax::Leaf *syntax::IntegerLiteralExpression::literalToken() {
- return llvm::cast_or_null<syntax::Leaf>(
- findChild(syntax::NodeRole::LiteralToken));
-}
-
-syntax::Leaf *syntax::CharacterLiteralExpression::literalToken() {
- return llvm::cast_or_null<syntax::Leaf>(
- findChild(syntax::NodeRole::LiteralToken));
-}
-
-syntax::Leaf *syntax::FloatingLiteralExpression::literalToken() {
- return llvm::cast_or_null<syntax::Leaf>(
- findChild(syntax::NodeRole::LiteralToken));
-}
-
-syntax::Leaf *syntax::StringLiteralExpression::literalToken() {
- return llvm::cast_or_null<syntax::Leaf>(
- 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));
-}
-
-syntax::Leaf *syntax::UserDefinedLiteralExpression::literalToken() {
+syntax::Leaf *syntax::LiteralExpression::literalToken() {
return llvm::cast_or_null<syntax::Leaf>(
findChild(syntax::NodeRole::LiteralToken));
}
More information about the cfe-commits
mailing list