diff options
author | dim <dim@FreeBSD.org> | 2012-08-15 20:02:54 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2012-08-15 20:02:54 +0000 |
commit | 554bcb69c2d785a011a30e7db87a36a87fe7db10 (patch) | |
tree | 9abb1a658a297776086f4e0dfa6ca533de02104e /include/clang/Analysis/Analyses/FormatString.h | |
parent | bb67ca86b31f67faee50bd10c3b036d65751745a (diff) | |
download | FreeBSD-src-554bcb69c2d785a011a30e7db87a36a87fe7db10.zip FreeBSD-src-554bcb69c2d785a011a30e7db87a36a87fe7db10.tar.gz |
Vendor import of clang trunk r161861:
http://llvm.org/svn/llvm-project/cfe/trunk@161861
Diffstat (limited to 'include/clang/Analysis/Analyses/FormatString.h')
-rw-r--r-- | include/clang/Analysis/Analyses/FormatString.h | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/include/clang/Analysis/Analyses/FormatString.h b/include/clang/Analysis/Analyses/FormatString.h index 9ec27ce..7f50ee3 100644 --- a/include/clang/Analysis/Analyses/FormatString.h +++ b/include/clang/Analysis/Analyses/FormatString.h @@ -175,6 +175,7 @@ public: switch (kind) { case PrintErrno: assert(IsPrintf); + return false; case PercentArg: return false; default: @@ -200,7 +201,7 @@ protected: Kind kind; }; -class ArgTypeResult { +class ArgType { public: enum Kind { UnknownTy, InvalidTy, SpecificTy, ObjCPointerTy, CPointerTy, AnyCharTy, CStrTy, WCStrTy, WIntTy }; @@ -208,26 +209,26 @@ private: const Kind K; QualType T; const char *Name; - ArgTypeResult(bool) : K(InvalidTy), Name(0) {} + bool Ptr; public: - ArgTypeResult(Kind k = UnknownTy) : K(k), Name(0) {} - ArgTypeResult(Kind k, const char *n) : K(k), Name(n) {} - ArgTypeResult(QualType t) : K(SpecificTy), T(t), Name(0) {} - ArgTypeResult(QualType t, const char *n) : K(SpecificTy), T(t), Name(n) {} - ArgTypeResult(CanQualType t) : K(SpecificTy), T(t), Name(0) {} - - static ArgTypeResult Invalid() { return ArgTypeResult(true); } + ArgType(Kind k = UnknownTy, const char *n = 0) : K(k), Name(n), Ptr(false) {} + ArgType(QualType t, const char *n = 0) + : K(SpecificTy), T(t), Name(n), Ptr(false) {} + ArgType(CanQualType t) : K(SpecificTy), T(t), Name(0), Ptr(false) {} + static ArgType Invalid() { return ArgType(InvalidTy); } bool isValid() const { return K != InvalidTy; } - const QualType *getSpecificType() const { - return K == SpecificTy ? &T : 0; + /// Create an ArgType which corresponds to the type pointer to A. + static ArgType PtrTo(const ArgType& A) { + assert(A.K >= InvalidTy && "ArgType cannot be pointer to invalid/unknown"); + ArgType Res = A; + Res.Ptr = true; + return Res; } bool matchesType(ASTContext &C, QualType argTy) const; - bool matchesAnyObjCObjectRef() const { return K == ObjCPointerTy; } - QualType getRepresentativeType(ASTContext &C) const; std::string getRepresentativeTypeName(ASTContext &C) const; @@ -278,7 +279,7 @@ public: return length + UsesDotPrefix; } - ArgTypeResult getArgType(ASTContext &Ctx) const; + ArgType getArgType(ASTContext &Ctx) const; void toString(raw_ostream &os) const; @@ -354,6 +355,10 @@ public: bool hasStandardConversionSpecifier(const LangOptions &LangOpt) const; bool hasStandardLengthConversionCombination() const; + + /// For a TypedefType QT, if it is a named integer type such as size_t, + /// assign the appropriate value to LM and return true. + static bool namedTypeToLengthModifier(QualType QT, LengthModifier &LM); }; } // end analyze_format_string namespace @@ -387,7 +392,7 @@ public: } }; -using analyze_format_string::ArgTypeResult; +using analyze_format_string::ArgType; using analyze_format_string::LengthModifier; using analyze_format_string::OptionalAmount; using analyze_format_string::OptionalFlag; @@ -462,7 +467,7 @@ public: /// will return null if the format specifier does not have /// a matching data argument or the matching argument matches /// more than one type. - ArgTypeResult getArgType(ASTContext &Ctx, bool IsObjCLiteral) const; + ArgType getArgType(ASTContext &Ctx, bool IsObjCLiteral) const; const OptionalFlag &hasThousandsGrouping() const { return HasThousandsGrouping; @@ -516,35 +521,11 @@ public: } }; -using analyze_format_string::ArgTypeResult; +using analyze_format_string::ArgType; using analyze_format_string::LengthModifier; using analyze_format_string::OptionalAmount; using analyze_format_string::OptionalFlag; -class ScanfArgTypeResult : public ArgTypeResult { -public: - enum Kind { UnknownTy, InvalidTy, CStrTy, WCStrTy, PtrToArgTypeResultTy }; -private: - Kind K; - ArgTypeResult A; - const char *Name; - QualType getRepresentativeType(ASTContext &C) const; -public: - ScanfArgTypeResult(Kind k = UnknownTy, const char* n = 0) : K(k), Name(n) {} - ScanfArgTypeResult(ArgTypeResult a, const char *n = 0) - : K(PtrToArgTypeResultTy), A(a), Name(n) { - assert(A.isValid()); - } - - static ScanfArgTypeResult Invalid() { return ScanfArgTypeResult(InvalidTy); } - - bool isValid() const { return K != InvalidTy; } - - bool matchesType(ASTContext& C, QualType argTy) const; - - std::string getRepresentativeTypeName(ASTContext& C) const; -}; - class ScanfSpecifier : public analyze_format_string::FormatSpecifier { OptionalFlag SuppressAssignment; // '*' public: @@ -573,7 +554,7 @@ public: return CS.consumesDataArgument() && !SuppressAssignment; } - ScanfArgTypeResult getArgType(ASTContext &Ctx) const; + ArgType getArgType(ASTContext &Ctx) const; bool fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx); |