Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / build / clang-plugin / VariableUsageHelpers.h
blobd498857eea44bd3f093d54563283803f68f619b3
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef VariableUsageHelpers_h__
6 #define VariableUsageHelpers_h__
8 #include "plugin.h"
10 /// Returns a list of the statements where the given declaration is used as an
11 /// rvalue (within the provided function).
12 ///
13 /// WARNING: incomplete behaviour/implementation for general-purpose use outside
14 /// of escapesFunction(). This only detects very basic usages (see
15 /// implementation for more details).
16 std::vector<const Stmt *> getUsageAsRvalue(const ValueDecl *ValueDeclaration,
17 const FunctionDecl *FuncDecl);
19 /// This is the error enumeration for escapesFunction(), describing all the
20 /// possible error cases.
21 enum class EscapesFunctionError {
22 ConstructorDeclNotFound = 1,
23 FunctionDeclNotFound,
24 FunctionIsBuiltin,
25 FunctionIsVariadic,
26 ExprNotInCall,
27 NoParamForArg,
28 ArgAndParamNotPointers
31 /// Required by the std::error_code system to convert our enum into a general
32 /// error code.
33 std::error_code make_error_code(EscapesFunctionError);
35 /// Returns a (statement, decl) tuple if an argument from an argument list
36 /// escapes the function scope through globals/statics/other things. The
37 /// statement is where the value escapes the function, while the declaration
38 /// points to what it escapes through. If the argument doesn't escape the
39 /// function, the tuple will only contain nullptrs.
40 /// If the analysis runs into an unexpected error or into an unimplemented
41 /// configuration, it will return an error_code of type EscapesFunctionError
42 /// representing the precise issue.
43 ///
44 /// WARNING: incomplete behaviour/implementation for general-purpose use outside
45 /// of DanglingOnTemporaryChecker. This only covers a limited set of cases,
46 /// mainly in terms of arguments and parameter types.
47 ErrorOr<std::tuple<const Stmt *, const Decl *>>
48 escapesFunction(const Expr *Arg, const FunctionDecl *FuncDecl,
49 const Expr *const *Arguments, unsigned NumArgs);
51 /// Helper function taking a call expression.
52 ErrorOr<std::tuple<const Stmt *, const Decl *>>
53 escapesFunction(const Expr *Arg, const CallExpr *Call);
55 /// Helper function taking a construct expression.
56 ErrorOr<std::tuple<const Stmt *, const Decl *>>
57 escapesFunction(const Expr *Arg, const CXXConstructExpr *Construct);
59 /// Helper function taking an operator call expression.
60 ErrorOr<std::tuple<const Stmt *, const Decl *>>
61 escapesFunction(const Expr *Arg, const CXXOperatorCallExpr *OpCall);
63 #endif