This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG1630e50874a9: [Syntax] Tablegen literal expressions. (authored by sammccall).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D91277/new/ https://reviews.llvm.org/D91277 Files: clang/include/clang/Tooling/Syntax/Nodes.h clang/include/clang/Tooling/Syntax/Nodes.td clang/lib/Tooling/Syntax/Nodes.cpp
Index: clang/lib/Tooling/Syntax/Nodes.cpp =================================================================== --- clang/lib/Tooling/Syntax/Nodes.cpp +++ clang/lib/Tooling/Syntax/Nodes.cpp @@ -196,10 +196,6 @@ return Children; } -syntax::Leaf *syntax::LiteralExpression::getLiteralToken() { - return cast_or_null<syntax::Leaf>(findChild(syntax::NodeRole::LiteralToken)); -} - syntax::Expression *syntax::BinaryOperatorExpression::getLhs() { return cast_or_null<syntax::Expression>( findChild(syntax::NodeRole::LeftHandSide)); Index: clang/include/clang/Tooling/Syntax/Nodes.td =================================================================== --- clang/include/clang/Tooling/Syntax/Nodes.td +++ clang/include/clang/Tooling/Syntax/Nodes.td @@ -54,18 +54,112 @@ Role<"CloseParen", Token<"r_paren">>, ]; } -def LiteralExpression : External<Expression> {} -def IntegerLiteralExpression : External<LiteralExpression> {} -def CharacterLiteralExpression : External<LiteralExpression> {} -def FloatingLiteralExpression : External<LiteralExpression> {} -def StringLiteralExpression : External<LiteralExpression> {} -def BoolLiteralExpression : External<LiteralExpression> {} -def CxxNullPtrExpression : External<LiteralExpression> {} -def UserDefinedLiteralExpression : External<LiteralExpression> {} -def IntegerUserDefinedLiteralExpression : External<UserDefinedLiteralExpression> {} -def FloatUserDefinedLiteralExpression : External<UserDefinedLiteralExpression> {} -def CharUserDefinedLiteralExpression : External<UserDefinedLiteralExpression> {} -def StringUserDefinedLiteralExpression : External<UserDefinedLiteralExpression> {} +def LiteralExpression : Alternatives<Expression> { + let documentation = [{ + Expression for literals. C++ [lex.literal] + }]; +} +def IntegerLiteralExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for integer literals. C++ [lex.icon] + }]; + let children = [ + Role<"LiteralToken", Token<"numeric_constant">>, + ]; +} +defvar AnyCharacterLiteral = AnyToken<[ + "char_constant", "wide_char_constant", "utf8_char_constant", + "utf16_char_constant", "utf32_char_constant" +]>; +def CharacterLiteralExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for character literals. C++ [lex.ccon] + }]; + let children = [ + Role<"LiteralToken", AnyCharacterLiteral>, + ]; +} +def FloatingLiteralExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for floating-point literals. C++ [lex.fcon] + }]; + let children = [ + Role<"LiteralToken", Token<"numeric_constant">>, + ]; +} +defvar AnyStringLiteral = AnyToken<[ + "string_literal", "wide_string_literal", "utf8_string_literal", + "utf16_string_literal", "utf32_string_literal" +]>; +def StringLiteralExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for string-literals. C++ [lex.string] + }]; + // FIXME: string literals may consist of multiple tokens. + // These are merged in phase 6, but tokens are captured after phase 4. + // The child here should be a list of literal tokens instead. + let children = [ + Role<"LiteralToken", AnyStringLiteral>, + ]; +} +def BoolLiteralExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for boolean literals. C++ [lex.bool] + }]; + let children = [ + Role<"LiteralToken", AnyToken<["kw_false","kw_true"]>>, + ]; +} +def CxxNullPtrExpression : Sequence<LiteralExpression> { + let documentation = [{ + Expression for the `nullptr` literal. C++ [lex.nullptr] + }]; + let children = [ + Role<"LiteralToken", Keyword<"nullptr">>, + ]; +} +def UserDefinedLiteralExpression : Alternatives<LiteralExpression> { + let documentation = [{ + Expression for user-defined literal. C++ [lex.ext] + user-defined-literal: + user-defined-integer-literal + user-defined-floating-point-literal + user-defined-string-literal + user-defined-character-literal + }]; +} +def IntegerUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> { + let documentation = [{ + Expression for user-defined-integer-literal. C++ [lex.ext] + }]; + let children = [ + Role<"LiteralToken", Keyword<"numeric_constant">>, + ]; +} +def FloatUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> { + let documentation = [{ + Expression for user-defined-floating-point-literal. C++ [lex.ext] + }]; + let children = [ + Role<"LiteralToken", Keyword<"numeric_constant">>, + ]; +} +def CharUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> { + let documentation = [{ + Expression for user-defined-character-literal. C++ [lex.ext] + }]; + let children = [ + Role<"LiteralToken", AnyCharacterLiteral>, + ]; +} +def StringUserDefinedLiteralExpression : Sequence<UserDefinedLiteralExpression> { + let documentation = [{ + Expression for user-defined-string-literal. C++ [lex.ext] + }]; + let children = [ + Role<"LiteralToken", AnyStringLiteral>, + ]; +} def IdExpression : Sequence<Expression> { let documentation = [{ Models an `id-expression`, e.g. `std::vector<int>::size`. Index: clang/include/clang/Tooling/Syntax/Nodes.h =================================================================== --- clang/include/clang/Tooling/Syntax/Nodes.h +++ clang/include/clang/Tooling/Syntax/Nodes.h @@ -156,113 +156,6 @@ std::vector<List::ElementAndDelimiter<Expression>> getArgumentsAndCommas(); }; -/// Expression for literals. C++ [lex.literal] -class LiteralExpression : public Expression { -public: - LiteralExpression(NodeKind K) : Expression(K) {} - static bool classof(const Node *N); - Leaf *getLiteralToken(); -}; - -/// Expression for integer literals. C++ [lex.icon] -class IntegerLiteralExpression final : public LiteralExpression { -public: - IntegerLiteralExpression() - : LiteralExpression(NodeKind::IntegerLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for character literals. C++ [lex.ccon] -class CharacterLiteralExpression final : public LiteralExpression { -public: - CharacterLiteralExpression() - : LiteralExpression(NodeKind::CharacterLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for floating-point literals. C++ [lex.fcon] -class FloatingLiteralExpression final : public LiteralExpression { -public: - FloatingLiteralExpression() - : LiteralExpression(NodeKind::FloatingLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for string-literals. C++ [lex.string] -class StringLiteralExpression final : public LiteralExpression { -public: - StringLiteralExpression() - : LiteralExpression(NodeKind::StringLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for boolean literals. C++ [lex.bool] -class BoolLiteralExpression final : public LiteralExpression { -public: - BoolLiteralExpression() - : LiteralExpression(NodeKind::BoolLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for the `nullptr` literal. C++ [lex.nullptr] -class CxxNullPtrExpression final : public LiteralExpression { -public: - CxxNullPtrExpression() : LiteralExpression(NodeKind::CxxNullPtrExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for user-defined literal. C++ [lex.ext] -/// user-defined-literal: -/// user-defined-integer-literal -/// user-defined-floating-point-literal -/// user-defined-string-literal -/// user-defined-character-literal -class UserDefinedLiteralExpression : public LiteralExpression { -public: - UserDefinedLiteralExpression(NodeKind K) : LiteralExpression(K) {} - static bool classof(const Node *N); -}; - -/// Expression for user-defined-integer-literal. C++ [lex.ext] -class IntegerUserDefinedLiteralExpression final - : public UserDefinedLiteralExpression { -public: - IntegerUserDefinedLiteralExpression() - : UserDefinedLiteralExpression( - NodeKind::IntegerUserDefinedLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for user-defined-floating-point-literal. C++ [lex.ext] -class FloatUserDefinedLiteralExpression final - : public UserDefinedLiteralExpression { -public: - FloatUserDefinedLiteralExpression() - : UserDefinedLiteralExpression( - NodeKind::FloatUserDefinedLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for user-defined-character-literal. C++ [lex.ext] -class CharUserDefinedLiteralExpression final - : public UserDefinedLiteralExpression { -public: - CharUserDefinedLiteralExpression() - : UserDefinedLiteralExpression( - NodeKind::CharUserDefinedLiteralExpression) {} - static bool classof(const Node *N); -}; - -/// Expression for user-defined-string-literal. C++ [lex.ext] -class StringUserDefinedLiteralExpression final - : public UserDefinedLiteralExpression { -public: - StringUserDefinedLiteralExpression() - : UserDefinedLiteralExpression( - NodeKind::StringUserDefinedLiteralExpression) {} - static bool classof(const Node *N); -}; - /// An abstract class for prefix and postfix unary operators. class UnaryOperatorExpression : public Expression { public:
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits