mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6003 from ethereum/moreStyleChecks
Even more style checks.
This commit is contained in:
commit
0408130338
@ -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
|
||||
|
@ -240,7 +240,7 @@ bool contains(T const& _t, V const& _v)
|
||||
/// place at the end, but already visited elements might be invalidated.
|
||||
/// If nothing is replaced, no copy is performed.
|
||||
template <typename T, typename F>
|
||||
void iterateReplacing(std::vector<T>& _vector, const F& _f)
|
||||
void iterateReplacing(std::vector<T>& _vector, F const& _f)
|
||||
{
|
||||
// Concept: _f must be Callable, must accept param T&, must return optional<vector<T>>
|
||||
bool useModified = false;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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) +
|
||||
|
@ -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.
|
||||
|
@ -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 } },
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ Error::Error(Type _type, SourceLocation const& _location, string const& _descrip
|
||||
*this << errinfo_comment(_description);
|
||||
}
|
||||
|
||||
Error::Error(Error::Type _type, const std::string& _description, const SourceLocation& _location):
|
||||
Error::Error(Error::Type _type, std::string const& _description, SourceLocation const& _location):
|
||||
Error(_type)
|
||||
{
|
||||
if (!_location.isEmpty())
|
||||
|
@ -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);
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
ReadCallback m_readFile;
|
||||
};
|
||||
|
||||
static const CodeFragment NullCodeFragment;
|
||||
static CodeFragment const NullCodeFragment;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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))))))))"
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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 },
|
||||
|
@ -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.");
|
||||
@ -652,7 +652,7 @@ void CompilerUtils::convertType(
|
||||
bool chopSignBitsPending = _chopSignBits && targetTypeCategory == Type::Category::Integer;
|
||||
if (chopSignBitsPending)
|
||||
{
|
||||
const IntegerType& targetIntegerType = dynamic_cast<const IntegerType &>(_targetType);
|
||||
IntegerType const& targetIntegerType = dynamic_cast<IntegerType const&>(_targetType);
|
||||
chopSignBitsPending = targetIntegerType.isSigned();
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -355,7 +355,7 @@ bool hasPayableFunctions(ContractDefinition const& _contract)
|
||||
void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contract)
|
||||
{
|
||||
map<FixedHash<4>, FunctionTypePointer> interfaceFunctions = _contract.interfaceFunctions();
|
||||
map<FixedHash<4>, const eth::AssemblyItem> callDataUnpackerEntryPoints;
|
||||
map<FixedHash<4>, eth::AssemblyItem const> callDataUnpackerEntryPoints;
|
||||
|
||||
if (_contract.isLibrary())
|
||||
{
|
||||
|
@ -473,7 +473,7 @@ void StorageByteArrayElement::setToZero(SourceLocation const&, bool _removeRefer
|
||||
m_context << Instruction::SWAP1 << Instruction::SSTORE;
|
||||
}
|
||||
|
||||
StorageArrayLength::StorageArrayLength(CompilerContext& _compilerContext, const ArrayType& _arrayType):
|
||||
StorageArrayLength::StorageArrayLength(CompilerContext& _compilerContext, ArrayType const& _arrayType):
|
||||
LValue(_compilerContext, _arrayType.memberType("length").get()),
|
||||
m_arrayType(_arrayType)
|
||||
{
|
||||
|
@ -19,9 +19,13 @@ 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 "\(const " -- '*.h' '*.cpp' # const on left side of type
|
||||
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
|
||||
) | egrep -v "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" | egrep -v "^test/"
|
||||
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)
|
||||
git grep -nIE "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" -- '*.h' '*.cpp' | egrep -v -e "return [*]" -e "^* [*]" -e "^*//.*"
|
||||
) | egrep -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/"
|
||||
)
|
||||
|
||||
if [[ "$FORMATERROR" != "" ]]
|
||||
|
Loading…
Reference in New Issue
Block a user