diff options
author | Dino Radakovic <dinor@google.com> | 2024-02-08 13:52:58 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-02-08 13:54:16 -0800 |
commit | 8eadbbac42ead8b516ed0b802d2668650d9218ec (patch) | |
tree | 5e54e6d2068dae39cc96e077913499e948e1c7c7 /absl/debugging/internal/demangle.cc | |
parent | 36442dd87ed5f568f483f702252c6c5e6028aeb3 (diff) | |
download | abseil-8eadbbac42ead8b516ed0b802d2668650d9218ec.tar.gz abseil-8eadbbac42ead8b516ed0b802d2668650d9218ec.tar.bz2 abseil-8eadbbac42ead8b516ed0b802d2668650d9218ec.zip |
`demangle`: Parse C++20-compatible template param declarations, except those with `requires` expressions
Support for `requires` expressions will be added in a follow-up.
PiperOrigin-RevId: 605418370
Change-Id: I2c84cdf0c4599e36683b3c94dcbb173ab4fc3ee8
Diffstat (limited to 'absl/debugging/internal/demangle.cc')
-rw-r--r-- | absl/debugging/internal/demangle.cc | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/absl/debugging/internal/demangle.cc b/absl/debugging/internal/demangle.cc index 3ef21581..fd3aef70 100644 --- a/absl/debugging/internal/demangle.cc +++ b/absl/debugging/internal/demangle.cc @@ -570,6 +570,7 @@ static bool ParseClassEnumType(State *state); static bool ParseArrayType(State *state); static bool ParsePointerToMemberType(State *state); static bool ParseTemplateParam(State *state); +static bool ParseTemplateParamDecl(State *state); static bool ParseTemplateTemplateParam(State *state); static bool ParseTemplateArgs(State *state); static bool ParseTemplateArg(State *state); @@ -624,6 +625,9 @@ static bool ParseMangledName(State *state) { // <encoding> ::= <(function) name> <bare-function-type> // ::= <(data) name> // ::= <special-name> +// +// NOTE: Based on http://shortn/_Hoq9qG83rx +// TODO(b/324066279): Add support for [Q <requires-clause expression>]. static bool ParseEncoding(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; @@ -1431,6 +1435,52 @@ static bool ParseTemplateParam(State *state) { return false; } +// <template-param-decl> +// ::= Ty # template type parameter +// ::= Tk <concept name> [<template-args>] # constrained type parameter +// ::= Tn <type> # template non-type parameter +// ::= Tt <template-param-decl>* E # template template parameter +// ::= Tp <template-param-decl> # template parameter pack +// +// NOTE: <concept name> is just a <name>: http://shortn/_MqJVyr0fc1 +// TODO(b/324066279): Implement optional suffix for `Tt`: +// [Q <requires-clause expr>] +static bool ParseTemplateParamDecl(State *state) { + ComplexityGuard guard(state); + if (guard.IsTooComplex()) return false; + ParseState copy = state->parse_state; + + if (ParseTwoCharToken(state, "Ty")) { + return true; + } + state->parse_state = copy; + + if (ParseTwoCharToken(state, "Tk") && ParseName(state) && + Optional(ParseTemplateArgs(state))) { + return true; + } + state->parse_state = copy; + + if (ParseTwoCharToken(state, "Tn") && ParseType(state)) { + return true; + } + state->parse_state = copy; + + if (ParseTwoCharToken(state, "Tt") && + ZeroOrMore(ParseTemplateParamDecl, state) && + ParseOneCharToken(state, 'E')) { + return true; + } + state->parse_state = copy; + + if (ParseTwoCharToken(state, "Tp") && ParseTemplateParamDecl(state)) { + return true; + } + state->parse_state = copy; + + return false; +} + // <template-template-param> ::= <template-param> // ::= <substitution> static bool ParseTemplateTemplateParam(State *state) { @@ -1442,6 +1492,9 @@ static bool ParseTemplateTemplateParam(State *state) { } // <template-args> ::= I <template-arg>+ E +// +// TODO(b/324066279): Implement optional [Q <requires-clause expr>] before E. +// See: http://shortn/_Z7yM7PonSD static bool ParseTemplateArgs(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; @@ -1457,13 +1510,11 @@ static bool ParseTemplateArgs(State *state) { return false; } -// <template-arg> ::= <type> +// <template-arg> ::= <template-param-decl> <template-arg> +// ::= <type> // ::= <expr-primary> // ::= J <template-arg>* E # argument pack // ::= X <expression> E -// ::= Tk <type> <type> # constraint -// -// TODO(b/323420445): Support templated constraints. static bool ParseTemplateArg(State *state) { ComplexityGuard guard(state); if (guard.IsTooComplex()) return false; @@ -1564,7 +1615,7 @@ static bool ParseTemplateArg(State *state) { } state->parse_state = copy; - if (ParseTwoCharToken(state, "Tk") && ParseType(state) && ParseType(state)) { + if (ParseTemplateParamDecl(state) && ParseTemplateArg(state)) { return true; } state->parse_state = copy; |