From: Ted Kremenek Date: Thu, 4 Feb 2010 07:27:39 +0000 (+0000) Subject: Convert flags in FormatSpecifier to be bitfields instead of doing X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=03db470ec53315368f200a2382590e41ef9ff8d4;p=clang Convert flags in FormatSpecifier to be bitfields instead of doing direct bit manipulation. This is is less error prone, and fixes a bug in the handling of the LeadingZeroes flag as pointed out by Cristian Draghici. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95298 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/Analyses/PrintfFormatString.h b/include/clang/Analysis/Analyses/PrintfFormatString.h index 0431be143e..46f23ce3e2 100644 --- a/include/clang/Analysis/Analyses/PrintfFormatString.h +++ b/include/clang/Analysis/Analyses/PrintfFormatString.h @@ -112,14 +112,6 @@ enum LengthModifier { AsLongDouble // 'L' }; -enum Flags { - LeftJustified = 0x1, - PlusPrefix = 0x2, - SpacePrefix = 0x4, - AlternativeForm = 0x8, - LeadingZeroes = 0x16 -}; - class OptionalAmount { public: enum HowSpecified { NotSpecified, Constant, Arg }; @@ -174,12 +166,19 @@ public: class FormatSpecifier { LengthModifier LM; + unsigned IsLeftJustified : 1; + unsigned HasPlusPrefix : 1; + unsigned HasSpacePrefix : 1; + unsigned HasAlternativeForm : 1; + unsigned HasLeadingZeroes : 1; unsigned flags : 5; ConversionSpecifier CS; OptionalAmount FieldWidth; OptionalAmount Precision; public: - FormatSpecifier() : LM(None), flags(0) {} + FormatSpecifier() : LM(None), + IsLeftJustified(0), HasPlusPrefix(0), HasSpacePrefix(0), + HasAlternativeForm(0), HasLeadingZeroes(0) {} static FormatSpecifier Parse(const char *beg, const char *end); @@ -190,11 +189,11 @@ public: void setLengthModifier(LengthModifier lm) { LM = lm; } - void setIsLeftJustified() { flags |= LeftJustified; } - void setHasPlusPrefix() { flags |= PlusPrefix; } - void setHasSpacePrefix() { flags |= SpacePrefix; } - void setHasAlternativeForm() { flags |= AlternativeForm; } - void setHasLeadingZeros() { flags |= LeadingZeroes; } + void setIsLeftJustified() { IsLeftJustified = 1; } + void setHasPlusPrefix() { HasPlusPrefix = 1; } + void setHasSpacePrefix() { HasSpacePrefix = 1; } + void setHasAlternativeForm() { HasAlternativeForm = 1; } + void setHasLeadingZeros() { HasLeadingZeroes = 1; } // Methods for querying the format specifier. @@ -229,10 +228,10 @@ public: /// more than one type. ArgTypeResult getArgType(ASTContext &Ctx) const; - bool isLeftJustified() const { return flags & LeftJustified; } - bool hasPlusPrefix() const { return flags & PlusPrefix; } - bool hasAlternativeForm() const { return flags & AlternativeForm; } - bool hasLeadingZeros() const { return flags & LeadingZeroes; } + bool isLeftJustified() const { return (bool) IsLeftJustified; } + bool hasPlusPrefix() const { return (bool) HasPlusPrefix; } + bool hasAlternativeForm() const { return (bool) HasAlternativeForm; } + bool hasLeadingZeros() const { return (bool) HasLeadingZeroes; } }; } // end printf namespace