Even more style checks.

This commit is contained in:
Daniel Kirchner 2019-02-14 11:53:00 +01:00
parent 8ca6715e18
commit 809b9a95f9
15 changed files with 35 additions and 34 deletions

View File

@ -74,7 +74,7 @@ using strings = std::vector<std::string>;
/// Interprets @a _u as a two's complement signed number and returns the resulting s256.
inline s256 u2s(u256 _u)
{
static const bigint c_end = bigint(1) << 256;
static bigint const c_end = bigint(1) << 256;
if (boost::multiprecision::bit_test(_u, 255))
return s256(-(c_end - _u));
else
@ -84,7 +84,7 @@ inline s256 u2s(u256 _u)
/// @returns the two's complement signed representation of the signed number _u.
inline u256 s2u(s256 _u)
{
static const bigint c_end = bigint(1) << 256;
static bigint const c_end = bigint(1) << 256;
if (_u >= 0)
return u256(_u);
else

View File

@ -31,7 +31,7 @@ namespace dev
/// Base class for all exceptions.
struct Exception: virtual std::exception, virtual boost::exception
{
const char* what() const noexcept override;
char const* what() const noexcept override;
/// @returns "FileName:LineNumber" referring to the point where the exception was thrown.
std::string lineInfo() const;

View File

@ -47,17 +47,17 @@ namespace
/******** The Keccak-f[1600] permutation ********/
/*** Constants. ***/
static const uint8_t rho[24] = \
static uint8_t const rho[24] = \
{ 1, 3, 6, 10, 15, 21,
28, 36, 45, 55, 2, 14,
27, 41, 56, 8, 25, 43,
62, 18, 39, 61, 20, 44};
static const uint8_t pi[24] = \
static uint8_t const pi[24] = \
{10, 7, 11, 17, 18, 3,
5, 16, 8, 21, 24, 4,
15, 23, 19, 13, 12, 2,
20, 14, 22, 9, 6, 1};
static const uint64_t RC[24] = \
static uint64_t const RC[24] = \
{1ULL, 0x8082ULL, 0x800000000000808aULL, 0x8000000080008000ULL,
0x808bULL, 0x80000001ULL, 0x8000000080008081ULL, 0x8000000000008009ULL,
0x8aULL, 0x88ULL, 0x80008009ULL, 0x8000000aULL,
@ -118,7 +118,7 @@ static inline void keccakf(void* state) {
_(for (size_t i = 0; i < L; i += ST) { S; })
#define mkapply_ds(NAME, S) \
static inline void NAME(uint8_t* dst, \
const uint8_t* src, \
uint8_t const* src, \
size_t len) { \
FOR(i, 1, len, S); \
}
@ -148,7 +148,7 @@ mkapply_sd(setout, dst[i] = src[i]) // setout
inline void hash(
uint8_t* out,
size_t outlen,
const uint8_t* in,
uint8_t const* in,
size_t inlen,
size_t rate,
uint8_t delim

View File

@ -139,8 +139,8 @@ inline std::string formatNumberReadable(
if (len < 24)
return str;
const int initialChars = (prefix == HexPrefix::Add) ? 6 : 4;
const int finalChars = 4;
int const initialChars = (prefix == HexPrefix::Add) ? 6 : 4;
int const finalChars = 4;
int numSkipped = len - initialChars - finalChars;
return str.substr(0, initialChars) +

View File

@ -149,7 +149,7 @@ private:
/// Appends the given assembly item.
void appendItem(AssemblyItem const& _item);
static const int c_invalidPosition = -0x7fffffff;
static int const c_invalidPosition = -0x7fffffff;
AssemblyItems m_generatedItems;
/// Current height of the stack relative to the start.

View File

@ -29,7 +29,7 @@ using namespace std;
using namespace dev;
using namespace dev::solidity;
const std::map<std::string, Instruction> dev::solidity::c_instructions =
std::map<std::string, Instruction> const dev::solidity::c_instructions =
{
{ "STOP", Instruction::STOP },
{ "ADD", Instruction::ADD },
@ -173,7 +173,7 @@ const std::map<std::string, Instruction> dev::solidity::c_instructions =
{ "SELFDESTRUCT", Instruction::SELFDESTRUCT }
};
static const std::map<Instruction, InstructionInfo> c_instructionInfo =
static std::map<Instruction, InstructionInfo> const c_instructionInfo =
{ // Add, Args, Ret, SideEffects, GasPriceTier
{ Instruction::STOP, { "STOP", 0, 0, 0, true, Tier::Zero } },
{ Instruction::ADD, { "ADD", 0, 2, 1, false, Tier::VeryLow } },

View File

@ -119,8 +119,8 @@ private:
unsigned m_errorCount = 0;
unsigned m_warningCount = 0;
const unsigned c_maxWarningsAllowed = 256;
const unsigned c_maxErrorsAllowed = 256;
unsigned const c_maxWarningsAllowed = 256;
unsigned const c_maxErrorsAllowed = 256;
};
}

View File

@ -143,7 +143,7 @@ static Token keywordByName(string const& _name)
// and keywords to be put inside the keywords variable.
#define KEYWORD(name, string, precedence) {string, Token::name},
#define TOKEN(name, string, precedence)
static const map<string, Token> keywords({TOKEN_LIST(TOKEN, KEYWORD)});
static map<string, Token> const keywords({TOKEN_LIST(TOKEN, KEYWORD)});
#undef KEYWORD
#undef TOKEN
auto it = keywords.find(_name);

View File

@ -65,7 +65,7 @@ private:
ReadCallback m_readFile;
};
static const CodeFragment NullCodeFragment;
static CodeFragment const NullCodeFragment;
}
}

View File

@ -44,7 +44,7 @@ CodeFragment const& CompilerState::getDef(std::string const& _s) const
void CompilerState::populateStandard()
{
static const string s = "{"
static string const s = "{"
"(def 'panic () (asm INVALID))"
// Alternative macro version of alloc, which is currently implemented in the parser
// "(def 'alloc (n) (raw (msize) (when n (pop (mload (+ (msize) (& (- n 1) (~ 0x1f))))))))"

View File

@ -42,7 +42,7 @@ bool DocStringAnalyser::analyseDocStrings(SourceUnit const& _sourceUnit)
bool DocStringAnalyser::visit(ContractDefinition const& _contract)
{
static const set<string> validTags = set<string>{"author", "title", "dev", "notice"};
static set<string> const validTags = set<string>{"author", "title", "dev", "notice"};
parseDocStrings(_contract, _contract.annotation(), validTags, "contracts");
return true;
@ -99,7 +99,7 @@ void DocStringAnalyser::handleConstructor(
DocumentedAnnotation& _annotation
)
{
static const set<string> validTags = set<string>{"author", "dev", "notice", "param"};
static set<string> const validTags = set<string>{"author", "dev", "notice", "param"};
parseDocStrings(_node, _annotation, validTags, "constructor");
checkParameters(_callable, _annotation);
}
@ -110,7 +110,7 @@ void DocStringAnalyser::handleCallable(
DocumentedAnnotation& _annotation
)
{
static const set<string> validTags = set<string>{"author", "dev", "notice", "return", "param"};
static set<string> const validTags = set<string>{"author", "dev", "notice", "return", "param"};
parseDocStrings(_node, _annotation, validTags, "functions");
checkParameters(_callable, _annotation);
}

View File

@ -35,13 +35,13 @@ enum class ExperimentalFeature
TestOnlyAnalysis
};
static const std::map<ExperimentalFeature, bool> ExperimentalFeatureOnlyAnalysis =
static std::map<ExperimentalFeature, bool> const ExperimentalFeatureOnlyAnalysis =
{
{ ExperimentalFeature::SMTChecker, true },
{ ExperimentalFeature::TestOnlyAnalysis, true },
};
static const std::map<std::string, ExperimentalFeature> ExperimentalFeatureNames =
static std::map<std::string, ExperimentalFeature> const ExperimentalFeatureNames =
{
{ "ABIEncoderV2", ExperimentalFeature::ABIEncoderV2 },
{ "SMTChecker", ExperimentalFeature::SMTChecker },

View File

@ -37,11 +37,11 @@ namespace dev
namespace solidity
{
const unsigned CompilerUtils::dataStartOffset = 4;
const size_t CompilerUtils::freeMemoryPointer = 64;
const size_t CompilerUtils::zeroPointer = CompilerUtils::freeMemoryPointer + 32;
const size_t CompilerUtils::generalPurposeMemoryStart = CompilerUtils::zeroPointer + 32;
const unsigned CompilerUtils::identityContractAddress = 4;
unsigned const CompilerUtils::dataStartOffset = 4;
size_t const CompilerUtils::freeMemoryPointer = 64;
size_t const CompilerUtils::zeroPointer = CompilerUtils::freeMemoryPointer + 32;
size_t const CompilerUtils::generalPurposeMemoryStart = CompilerUtils::zeroPointer + 32;
unsigned const CompilerUtils::identityContractAddress = 4;
static_assert(CompilerUtils::freeMemoryPointer >= 64, "Free memory pointer must not overlap with scratch area.");
static_assert(CompilerUtils::zeroPointer >= CompilerUtils::freeMemoryPointer + 32, "Zero pointer must not overlap with free memory pointer.");
@ -653,7 +653,7 @@ void CompilerUtils::convertType(
bool chopSignBitsPending = _chopSignBits && targetTypeCategory == Type::Category::Integer;
if (chopSignBitsPending)
{
const IntegerType& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
chopSignBitsPending = targetIntegerType.isSigned();
}

View File

@ -273,18 +273,18 @@ public:
/// Bytes we need to the start of call data.
/// - The size in bytes of the function (hash) identifier.
static const unsigned dataStartOffset;
static unsigned const dataStartOffset;
/// Position of the free-memory-pointer in memory;
static const size_t freeMemoryPointer;
static size_t const freeMemoryPointer;
/// Position of the memory slot that is always zero.
static const size_t zeroPointer;
static size_t const zeroPointer;
/// Starting offset for memory available to the user (aka the contract).
static const size_t generalPurposeMemoryStart;
static size_t const generalPurposeMemoryStart;
private:
/// Address of the precompiled identity contract.
static const unsigned identityContractAddress;
static unsigned const identityContractAddress;
/// Stores the given string in memory.
/// Stack pre: mempos

View File

@ -20,6 +20,7 @@ FORMATERROR=$(
git grep -nIE "\<(if|for)\(" -- '*.h' '*.cpp' # no space after "if" or "for"
git grep -nIE "\<if\>\s*\(.*\)\s*\{\s*$" -- '*.h' '*.cpp' # "{\n" on same line as "if" / "for"
git grep -nIE "[,\(<]\s*const " -- '*.h' '*.cpp' # const on left side of type
git grep -nIE "^\s*(static)?\s*const " -- '*.h' '*.cpp' # const on left side of type (beginning of line)
git grep -nIE "^ [^*]|[^*] | [^*]" -- '*.h' '*.cpp' # uses spaces for indentation or mixes spaces and tabs
git grep -nIE "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" -- '*.h' '*.cpp' | egrep -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
# right-aligned reference pointer star (needs to exclude return and comments)