diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index ec703d3b7b25..163743cdc9db 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -229,6 +229,31 @@ Example matches a +
Same as nestedNameSpecifier but matches NestedNameSpecifierLoc. +
Matches nested name specifiers. + +Given + namespace ns { + struct A { static void f(); }; + void A::f() {} + void g() { A::f(); } + } + ns::A a; +nestedNameSpecifier() + matches "ns::" and both "A::" +
Matches QualTypes in the clang AST. +
Matches array subscript expressions. @@ -791,15 +816,363 @@ whileStmt()
Matches all kinds of arrays. + +Given + int a[] = { 2, 3 }; + int b[4]; + void f() { int c[a[0]]; } +arrayType() + matches "int a[]", "int b[4]" and "int c[a[0]]"; +
Matches atomic types. + +Given + _Atomic(int) i; +atomicType() + matches "_Atomic(int) i" +
Matches types nodes representing C++11 auto types. + +Given: + auto n = 4; + int v[] = { 2, 3 } + for (auto i : v) { } +autoType() + matches "auto n" and "auto i" +
Matches block pointer types, i.e. types syntactically represented as +"void (^)(int)". + +The pointee is always required to be a FunctionType. +
Matches builtin Types. + +Given + struct A {}; + A a; + int b; + float c; + bool d; +builtinType() + matches "int b", "float c" and "bool d" +
Matches C99 complex types. + +Given + _Complex float f; +complexType() + matches "_Complex float f" +
Matches C arrays with a specified constant size. + +Given + void() { + int a[2]; + int b[] = { 2, 3 }; + int c[b[0]]; + } +constantArrayType() + matches "int a[2]" +
Matches C++ arrays whose size is a value-dependent expression. + +Given + template<typename T, int Size> + class array { + T data[Size]; + }; +dependentSizedArrayType + matches "T data[Size]" +
Matches FunctionType nodes. + +Given + int (*f)(int); + void g(); +functionType() + matches "int (*f)(int)" and the type of "g". +
Matches C arrays with unspecified size. + +Given + int a[] = { 2, 3 }; + int b[42]; + void f(int c[]) { int d[a[0]]; }; +incompleteArrayType() + matches "int a[]" and "int c[]" +
Matches member pointer types. +Given + struct A { int i; } + A::* ptr = A::i; +memberPointerType() + matches "A::* ptr" +
Matches pointer types. + +Given + int *a; + int &b = *a; + int c = 5; +pointerType() + matches "int *a" +
Matches reference types. + +Given + int *a; + int &b = *a; + int c = 5; +pointerType() + matches "int &b" +
Matches TypeLocs in the clang AST.
Matches typedef types. + +Given + typedef int X; +typedefType() + matches "typedef int X" +
Matches C arrays with a specified size that is not an +integer-constant-expression. + +Given + void f() { + int a[] = { 2, 3 } + int b[42]; + int c[a[0]]; +variableArrayType() + matches "int c[a[0]]" +
Matches all kinds of arrays. + +Given + int a[] = { 2, 3 }; + int b[4]; + void f() { int c[a[0]]; } +arrayType() + matches "int a[]", "int b[4]" and "int c[a[0]]"; +
Matches atomic types. + +Given + _Atomic(int) i; +atomicType() + matches "_Atomic(int) i" +
Matches types nodes representing C++11 auto types. + +Given: + auto n = 4; + int v[] = { 2, 3 } + for (auto i : v) { } +autoType() + matches "auto n" and "auto i" +
Matches block pointer types, i.e. types syntactically represented as +"void (^)(int)". + +The pointee is always required to be a FunctionType. +
Matches builtin Types. + +Given + struct A {}; + A a; + int b; + float c; + bool d; +builtinType() + matches "int b", "float c" and "bool d" +
Matches C99 complex types. + +Given + _Complex float f; +complexType() + matches "_Complex float f" +
Matches C arrays with a specified constant size. + +Given + void() { + int a[2]; + int b[] = { 2, 3 }; + int c[b[0]]; + } +constantArrayType() + matches "int a[2]" +
Matches C++ arrays whose size is a value-dependent expression. + +Given + template<typename T, int Size> + class array { + T data[Size]; + }; +dependentSizedArrayType + matches "T data[Size]" +
Matches FunctionType nodes. + +Given + int (*f)(int); + void g(); +functionType() + matches "int (*f)(int)" and the type of "g". +
Matches C arrays with unspecified size. + +Given + int a[] = { 2, 3 }; + int b[42]; + void f(int c[]) { int d[a[0]]; }; +incompleteArrayType() + matches "int a[]" and "int c[]" +
Matches member pointer types. +Given + struct A { int i; } + A::* ptr = A::i; +memberPointerType() + matches "A::* ptr" +
Matches pointer types. + +Given + int *a; + int &b = *a; + int c = 5; +pointerType() + matches "int *a" +
Matches reference types. + +Given + int *a; + int &b = *a; + int c = 5; +pointerType() + matches "int &b" +
Matches Types in the clang AST.
Matches typedef types. + +Given + typedef int X; +typedefType() + matches "typedef int X" +
Matches C arrays with a specified size that is not an +integer-constant-expression. + +Given + void f() { + int a[] = { 2, 3 } + int b[42]; + int c[a[0]]; +variableArrayType() + matches "int c[a[0]]" +
Matches NamedDecl nodes whose full names partially match the -given RegExp. ++ Matches NamedDecl nodes whose fully qualified names contain +a substring matched by the given RegExp. Supports specifying enclosing namespaces or classes by prefixing the name with '<enclosing>::'. Does not match typedefs @@ -1423,6 +1796,78 @@ arraySubscriptExpression(hasIndex(integerLiteral()))+ Matcher<ArrayTypeLoc> hasElementTypeLoc Matcher<TypeLoc> + + + Matches arrays and C99 complex types that have a specific element +type. + +Given + struct A {}; + A a[7]; + int b[7]; +arrayType(hasElementType(builtinType())) + matches "int b[7]" + +Usable as: Matcher<ArrayType>, Matcher<ComplexType> ++ Matcher<ArrayType> hasElementType Matcher<Type> + + + Matches arrays and C99 complex types that have a specific element +type. + +Given + struct A {}; + A a[7]; + int b[7]; +arrayType(hasElementType(builtinType())) + matches "int b[7]" + +Usable as: Matcher<ArrayType>, Matcher<ComplexType> ++ Matcher<AtomicTypeLoc> hasValueTypeLoc Matcher<TypeLoc> + + + Matches atomic types with a specific value type. + +Given + _Atomic(int) i; + _Atomic(float) f; +atomicType(hasValueType(isInteger())) + matches "_Atomic(int) i" + +Usable as: Matcher<AtomicType> ++ Matcher<AtomicType> hasValueType Matcher<Type> + + + Matches atomic types with a specific value type. + +Given + _Atomic(int) i; + _Atomic(float) f; +atomicType(hasValueType(isInteger())) + matches "_Atomic(int) i" + +Usable as: Matcher<AtomicType> ++ Matcher<AutoType> hasDeducedType Matcher<Type> + + Matches AutoType nodes where the deduced type is a specific type. + +Note: There is no TypeLoc for the deduced type and thus no +getDeducedLoc() matcher. + +Given + auto a = 1; + auto b = 2.0; +autoType(hasDeducedType(isInteger())) + matches "auto a" + +Usable as: Matcher<AutoType> +Matcher<BinaryOperator> hasEitherOperand Matcher<Expr> InnerMatcher + Matches if either the left hand side or the right hand side of a binary operator matches. @@ -1445,6 +1890,38 @@ Example matches b (matcher = binaryOperator(hasRHS()))+ Matcher<BlockPointerTypeLoc> pointeeLoc Matcher<TypeLoc> + + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> ++ Matcher<BlockPointerType> pointee Matcher<Type> + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> +Matcher<CXXConstructExpr> hasDeclaration Matcher<Decl> InnerMatcher + Matches a type if the declaration of the type matches the given matcher. @@ -1643,6 +2120,36 @@ classTemplateSpecializationDecl(hasTemplateArgument(+ Matcher<ComplexTypeLoc> hasElementTypeLoc Matcher<TypeLoc> + + + Matches arrays and C99 complex types that have a specific element +type. + +Given + struct A {}; + A a[7]; + int b[7]; +arrayType(hasElementType(builtinType())) + matches "int b[7]" + +Usable as: Matcher<ArrayType>, Matcher<ComplexType> ++ Matcher<ComplexType> hasElementType Matcher<Type> + + Matches arrays and C99 complex types that have a specific element +type. + +Given + struct A {}; + A a[7]; + int b[7]; +arrayType(hasElementType(builtinType())) + matches "int b[7]" + +Usable as: Matcher<ArrayType>, Matcher<ComplexType> +Matcher<CompoundStmt> hasAnySubstatement Matcher<Stmt> InnerMatcher + Matches compound statements where at least one substatement matches a given matcher. @@ -1996,6 +2503,38 @@ memberExpr(member(hasName("first")))+ Matcher<MemberPointerTypeLoc> pointeeLoc Matcher<TypeLoc> + + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> ++ Matcher<MemberPointerType> pointee Matcher<Type> + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> +Matcher<NestedNameSpecifierLoc> hasPrefix Matcher<NestedNameSpecifierLoc> InnerMatcher + Matches on the prefix of a NestedNameSpecifierLoc. @@ -2007,6 +2546,12 @@ nestedNameSpecifierLoc(hasPrefix(loc(specifiesType(asString("struct A")))))+ Matcher<NestedNameSpecifierLoc> loc Matcher<NestedNameSpecifier> InnerMatcher + + Matches NestedNameSpecifierLocs for which the given inner +NestedNameSpecifier-matcher matches. +Matcher<NestedNameSpecifierLoc> specifiesTypeLoc Matcher<TypeLoc> InnerMatcher + Matches nested name specifier locs that specify a type matching the given TypeLoc. @@ -2055,6 +2600,38 @@ nestedNameSpecifier(specifiesType(hasDeclaration(recordDecl(hasName("A")))))+ Matcher<PointerTypeLoc> pointeeLoc Matcher<TypeLoc> + + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> ++ Matcher<PointerType> pointee Matcher<Type> + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> +Matcher<QualType> hasDeclaration Matcher<Decl> InnerMatcher + Matches a type if the declaration of the type matches the given matcher. @@ -2074,6 +2651,38 @@ Usable as: Matcher<ReferenceTypeLoc>pointeeLoc Matcher<TypeLoc> + + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> ++ Matcher<ReferenceType> pointee Matcher<Type> + + Narrows PointerType (and similar) matchers to those where the +pointee matches a given matcher. + +Given + int *a; + int const *b; + float const *f; +pointerType(pointee(isConstQualified(), isInteger())) + matches "int const *b" + +Usable as: Matcher<BlockPointerType>, Matcher<MemberPointerType>, + Matcher<PointerType>, Matcher<ReferenceType> +Matcher<Stmt> alignOfExpr Matcher<UnaryExprOrTypeTraitExpr> InnerMatcher + Same as unaryExprOrTypeTraitExpr, but only matching alignof. @@ -2113,6 +2722,12 @@ classTemplateSpecializationDecl(hasAnyTemplateArgument(+ Matcher<TypeLoc> loc Matcher<QualType> InnerMatcher + + Matches TypeLocs for which the given inner +QualType-matcher matches. +Matcher<TypedefType> hasDecl Matcher<TypedefNameDecl> InnerMatcher Matches TypedefTypes referring to a specific TypedefNameDecl. diff --git a/clang/docs/tools/dump_ast_matchers.py b/clang/docs/tools/dump_ast_matchers.py index bc5f1a64a5c6..cd7ab0b74f1e 100644 --- a/clang/docs/tools/dump_ast_matchers.py +++ b/clang/docs/tools/dump_ast_matchers.py @@ -133,17 +133,48 @@ def act_on_decl(declaration, comment, allowed_types): if declaration.strip(): # Node matchers are defined by writing: # VariadicDynCastAllOfMatchername; - m = re.match(r""".*VariadicDynCastAllOfMatcher\s*< - \s*([^\s,]+)\s*, - \s*([^\s>]+)\s*> + m = re.match(r""".*Variadic(?:DynCast)?AllOfMatcher\s*< + \s*([^\s,]+)\s*(?:, + \s*([^\s>]+)\s*)?> \s*([^\s;]+)\s*;\s*$""", declaration, flags=re.X) if m: result, inner, name = m.groups() + if not inner: + inner = result add_matcher(result, name, 'Matcher<%s>...' % inner, comment, is_dyncast=True) return # Parse the various matcher definition macros. + m = re.match(""".*AST_TYPE_MATCHER\( + \s*([^\s,]+\s*), + \s*([^\s,]+\s*) + \)\s*;\s*$""", declaration, flags=re.X) + if m: + inner, name = m.groups() + add_matcher('Type', name, 'Matcher<%s>...' % inner, + comment, is_dyncast=True) + add_matcher('TypeLoc', '%sLoc' % name, 'Matcher<%sLoc>...' % inner, + comment, is_dyncast=True) + return + + m = re.match(""".*AST_TYPE(LOC)?_TRAVERSE_MATCHER\( + \s*([^\s,]+\s*), + \s*(?:[^\s,]+\s*) + \)\s*;\s*$""", declaration, flags=re.X) + if m: + loc = m.group(1) + name = m.group(2) + result_types = extract_result_types(comment) + if not result_types: + raise Exception('Did not find allowed result types for: %s' % name) + for result_type in result_types: + add_matcher(result_type, name, 'Matcher ', comment) + if loc: + add_matcher('%sLoc' % result_type, '%sLoc' % name, 'Matcher ', + comment) + return + m = re.match(r"""^\s*AST_(POLYMORPHIC_)?MATCHER(_P)?(.?)\( (?:\s*([^\s,]+)\s*,)? \s*([^\s,]+)\s* @@ -178,9 +209,9 @@ def act_on_decl(declaration, comment, allowed_types): if m: result, name, args = m.groups() args = ', '.join(p.strip() for p in args.split(',')) - m = re.match(r'.*\s+internal::Matcher<([^>]+)>$', result) + m = re.match(r'.*\s+internal::(Bindable)?Matcher<([^>]+)>$', result) if m: - result_types = [m.group(1)] + result_types = [m.group(2)] else: result_types = extract_result_types(comment) if not result_types: