Skip to content

Commit a9bdf99

Browse files
committed
std.cfg: Added *experimental* support for math constants liken M_PI. These are *NOT* standard, but they are supported by GCC/Clang and VS.
1 parent 728ac6a commit a9bdf99

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

cfg/std.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@
3636
<define name="UINT_LEAST16_MAX" value="65535"/>
3737
<define name="UINT_LEAST32_MAX" value="4294967295"/>
3838
<define name="UINT_LEAST64_MAX" value="18446744073709551615"/>
39+
<define name="M_E" value="2.7182818284590452354"/>
40+
<define name="M_LOG2E" value="1.4426950408889634074"/>
41+
<define name="M_LOG10E" value="0.43429448190325182765"/>
42+
<define name="M_LN2" value="0.69314718055994530942"/>
43+
<define name="M_LN10" value="2.30258509299404568402"/>
44+
<define name="M_PI" value="3.14159265358979323846"/>
45+
<define name="M_PI_2" value="1.57079632679489661923"/>
46+
<define name="M_PI_4" value="0.78539816339744830962"/>
47+
<define name="M_1_PI" value="0.31830988618379067154"/>
48+
<define name="M_2_PI" value="0.63661977236758134308"/>
49+
<define name="M_2_SQRTPI" value="1.12837916709551257390"/>
50+
<define name="M_SQRT2" value="1.41421356237309504880"/>
51+
<define name="M_SQRT1_2" value="0.70710678118654752440"/>
3952
<!-- errno_t is a typedef for int -->
4053
<define name="errno_t" value="int"/>
4154
<!-- void abort(void); -->

lib/templatesimplifier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3381,9 +3381,9 @@ void TemplateSimplifier::simplifyTemplates(
33813381
unsigned int passCount = 0;
33823382
const unsigned int passCountMax = 10;
33833383
for (; passCount < passCountMax; ++passCount) {
3384-
for (auto tok = mTokenizer->list.front(); tok; tok = tok->next()) tok->scopeInfo(nullptr);
3385-
mTokenizer->calculateScopes();
3386-
3384+
for (auto tok = mTokenizer->list.front(); tok; tok = tok->next()) tok->scopeInfo(nullptr);
3385+
mTokenizer->calculateScopes();
3386+
33873387
if (passCount) {
33883388
// it may take more than one pass to simplify type aliases
33893389
bool usingChanged = false;

lib/token.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,7 @@ void Token::insertToken(const std::string &tokenStr, const std::string &original
10751075
} else {
10761076
if (prepend && newToken->previous()) {
10771077
newToken->mImpl->mScopeInfo = newToken->previous()->scopeInfo();
1078-
}
1079-
else {
1078+
} else {
10801079
newToken->mImpl->mScopeInfo = mImpl->mScopeInfo;
10811080
}
10821081
if (tokenStr == ";") {
@@ -1975,10 +1974,12 @@ std::string Token::typeStr(const Token* tok)
19751974
return r.first->stringifyList(r.second, false);
19761975
}
19771976

1978-
void Token::scopeInfo(std::shared_ptr<ScopeInfo2> newScopeInfo) {
1977+
void Token::scopeInfo(std::shared_ptr<ScopeInfo2> newScopeInfo)
1978+
{
19791979
mImpl->mScopeInfo = newScopeInfo;
19801980
}
1981-
std::shared_ptr<ScopeInfo2> Token::scopeInfo() const {
1981+
std::shared_ptr<ScopeInfo2> Token::scopeInfo() const
1982+
{
19821983
return mImpl->mScopeInfo;
19831984
}
19841985

lib/token.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ struct TokenImpl {
108108

109109
// Pointer to the object representing this token's scope
110110
std::shared_ptr<ScopeInfo2> mScopeInfo;
111-
111+
112112
// __cppcheck_in_range__
113113
struct CppcheckAttributes {
114114
enum Type {LOW,HIGH} type;
@@ -1200,7 +1200,7 @@ class CPPCHECKLIB Token {
12001200
void printAst(bool verbose, bool xml, std::ostream &out) const;
12011201

12021202
void printValueFlow(bool xml, std::ostream &out) const;
1203-
1203+
12041204
void scopeInfo(std::shared_ptr<ScopeInfo2> newScopeInfo);
12051205
std::shared_ptr<ScopeInfo2> scopeInfo() const;
12061206
};

lib/tokenize.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,8 +2880,7 @@ void Tokenizer::calculateScopes()
28802880
if (nextScopeNameAddition.length() > 0) nextScopeNameAddition = nextScopeNameAddition.substr(0, nextScopeNameAddition.length() - 1);
28812881
}
28822882

2883-
if (Token::simpleMatch(tok, "{"))
2884-
{
2883+
if (Token::simpleMatch(tok, "{")) {
28852884
// This might be the opening of a member function
28862885
Token *tok1 = tok;
28872886
while (Token::Match(tok1->previous(), "const|volatile|final|override|&|&&|noexcept"))

0 commit comments

Comments
 (0)