Skip to content

Commit

Permalink
Handle sr <type> <unqualified-name> expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuey committed Nov 6, 2017
1 parent b148eb0 commit f6bcf4c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3916,6 +3916,8 @@ where
/// ::= sZ <function-param> # sizeof...(parameter), size of a function parameter pack
/// ::= sP <template-arg>* E # sizeof...(T), size of a captured template parameter pack from an alias template
/// ::= sp <expression> # expression..., pack expansion
/// ::= sr <type> <unqualified-name>
/// ::= sr <type> <unqualified-name> <template-args>
/// ::= tw <expression> # throw expression
/// ::= tr # throw with no operand (rethrow)
/// ::= <unresolved-name> # f(p), N::f(p), ::f(p),
Expand Down Expand Up @@ -4045,6 +4047,12 @@ pub enum Expression {
/// `expression...`, pack expansion.
PackExpansion(Box<Expression>),

/// `type` `unqualified_name` expression.
TypeUnqualifiedName(TypeHandle, UnqualifiedName),

/// `type` `unqualified_name` `template-args` expression.
TypeUnqualifiedNameTemplateArgs(TypeHandle, UnqualifiedName, TemplateArgs),

/// `throw expression`
Throw(Box<Expression>),

Expand Down Expand Up @@ -4225,6 +4233,17 @@ impl Parse for Expression {
b"gs" => {
return can_be_global(true, ctx, subs, tail);
}
b"sr" => {
let (ty, tail) = TypeHandle::parse(ctx, subs, tail)?;
let (name, tail) = UnqualifiedName::parse(ctx, subs, tail)?;
let (expr, tail) = if tail.peek() == Some(b'I') {
let (template_args, tail) = TemplateArgs::parse(ctx, subs, tail)?;
(Expression::TypeUnqualifiedNameTemplateArgs(ty, name, template_args), tail)
} else {
(Expression::TypeUnqualifiedName(ty, name), tail)
};
return Ok((expr, tail));
}
_ => {}
}
}
Expand Down Expand Up @@ -4684,6 +4703,19 @@ where
write!(ctx, "...")?;
Ok(())
}
Expression::TypeUnqualifiedName(ref ty, ref name) => {
ty.demangle(ctx, stack)?;
write!(ctx, "::")?;
name.demangle(ctx, stack)
}
Expression::TypeUnqualifiedNameTemplateArgs(ref ty,
ref name,
ref template_args) => {
ty.demangle(ctx, stack)?;
write!(ctx, "::")?;
name.demangle(ctx, stack)?;
template_args.demangle(ctx, stack)
}
Expression::Throw(ref expr) => {
write!(ctx, "throw ")?;
expr.demangle(ctx, stack)
Expand Down Expand Up @@ -7227,6 +7259,35 @@ mod tests {
b"...",
[]
}
b"XsrS_1QE..." => {
TemplateArg::Expression(
Expression::TypeUnqualifiedName(
TypeHandle::BackReference(0),
UnqualifiedName::Source(
SourceName(Identifier {
start: 6,
end: 7,
})))),
b"...",
[]
}
b"XsrS_1QIlEE..." => {
TemplateArg::Expression(
Expression::TypeUnqualifiedNameTemplateArgs(
TypeHandle::BackReference(0),
UnqualifiedName::Source(
SourceName(Identifier {
start: 6,
end: 7,
})),
TemplateArgs(vec![
TemplateArg::Type(
TypeHandle::Builtin(
BuiltinType::Standard(StandardBuiltinType::Long))),
]))),
b"...",
[]
}
b"LS_E..." => {
TemplateArg::SimpleExpression(
ExprPrimary::Literal(TypeHandle::BackReference(0), 3, 3)),
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ demangles!(
"void Ty::method<Ty>(void (Ty::*)(char const*), void (Ty::*)(char const*))"
);
demangles!(_ZNK1fB5cxx11Ev,"f[abi:cxx11]() const");
demangles!(
_ZN4base8internal14CheckedSubImplIlEENSt9enable_ifIXsrSt14numeric_limitsIT_E10is_integerEbE4typeES4_S4_PS4_,
"std::enable_if<std::numeric_limits<long>::is_integer, bool>::type base::internal::CheckedSubImpl<long>(long, long, long*)"
);

// Test cases found via differential testing against `c++filt` with `cargo-fuzz`
// and `libFuzzer`.
Expand Down

0 comments on commit f6bcf4c

Please sign in to comment.