Merge pull request #10907 from ethereum/yul-fuzzer-clang-tidy-fixes

Clang tidy fixes in protoToYul.cpp.
This commit is contained in:
Bhargava Shastry 2021-02-08 10:34:18 +01:00 committed by GitHub
commit a39aae8604
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 22 deletions

View File

@ -164,12 +164,12 @@ bool ProtoConverter::varDeclAvailable()
if (m_inFunctionDef) if (m_inFunctionDef)
{ {
consolidateVarDeclsInFunctionDef(); consolidateVarDeclsInFunctionDef();
return m_currentFuncVars.size() > 0; return !m_currentFuncVars.empty();
} }
else else
{ {
consolidateGlobalVarDecls(); consolidateGlobalVarDecls();
return m_currentGlobalVars.size() > 0; return !m_currentGlobalVars.empty();
} }
} }
@ -192,13 +192,13 @@ void ProtoConverter::visit(VarRef const& _x)
if (m_inFunctionDef) if (m_inFunctionDef)
{ {
// Ensure that there is at least one variable declaration to reference in function scope. // Ensure that there is at least one variable declaration to reference in function scope.
yulAssert(m_currentFuncVars.size() > 0, "Proto fuzzer: No variables to reference."); yulAssert(!m_currentFuncVars.empty(), "Proto fuzzer: No variables to reference.");
m_output << *m_currentFuncVars[static_cast<size_t>(_x.varnum()) % m_currentFuncVars.size()]; m_output << *m_currentFuncVars[static_cast<size_t>(_x.varnum()) % m_currentFuncVars.size()];
} }
else else
{ {
// Ensure that there is at least one variable declaration to reference in nested scopes. // Ensure that there is at least one variable declaration to reference in nested scopes.
yulAssert(m_currentGlobalVars.size() > 0, "Proto fuzzer: No global variables to reference."); yulAssert(!m_currentGlobalVars.empty(), "Proto fuzzer: No global variables to reference.");
m_output << *m_currentGlobalVars[static_cast<size_t>(_x.varnum()) % m_currentGlobalVars.size()]; m_output << *m_currentGlobalVars[static_cast<size_t>(_x.varnum()) % m_currentGlobalVars.size()];
} }
} }
@ -436,7 +436,7 @@ void ProtoConverter::visit(MultiVarDecl const& _x)
// We support up to 4 variables in a single // We support up to 4 variables in a single
// declaration statement. // declaration statement.
unsigned numVars = _x.num_vars() % 3 + 2; unsigned numVars = _x.num_vars() % 3 + 2;
string delimiter = ""; string delimiter;
for (unsigned i = 0; i < numVars; i++) for (unsigned i = 0; i < numVars; i++)
{ {
string varName = newVarName(); string varName = newVarName();
@ -872,7 +872,7 @@ bool ProtoConverter::functionValid(FunctionCall_Returns _type, unsigned _numOutP
void ProtoConverter::convertFunctionCall( void ProtoConverter::convertFunctionCall(
FunctionCall const& _x, FunctionCall const& _x,
std::string _name, string const& _name,
unsigned _numInParams, unsigned _numInParams,
bool _newLine bool _newLine
) )
@ -1211,7 +1211,7 @@ void ProtoConverter::visit(CaseStmt const& _x)
// a case statement containing a case literal that has already been used in a // a case statement containing a case literal that has already been used in a
// previous case statement. If the hash (u256 value) matches a previous hash, // previous case statement. If the hash (u256 value) matches a previous hash,
// then we simply don't create a new case statement. // then we simply don't create a new case statement.
string noDoubleQuoteStr{""}; string noDoubleQuoteStr;
if (literal.size() > 2) if (literal.size() > 2)
{ {
// Ensure that all characters in the string literal except the first // Ensure that all characters in the string literal except the first
@ -1438,7 +1438,7 @@ void ProtoConverter::visit(Statement const& _x)
void ProtoConverter::openBlockScope() void ProtoConverter::openBlockScope()
{ {
m_scopeFuncs.push_back({}); m_scopeFuncs.emplace_back(vector<string>{});
// Create new block scope inside current function scope // Create new block scope inside current function scope
if (m_inFunctionDef) if (m_inFunctionDef)
@ -1459,9 +1459,9 @@ void ProtoConverter::openBlockScope()
} }
else else
{ {
m_globalVars.push_back({}); m_globalVars.emplace_back(vector<string>{});
if (m_inForInitScope && m_forInitScopeExtEnabled) if (m_inForInitScope && m_forInitScopeExtEnabled)
m_globalForLoopInitVars.push_back(vector<string>{}); m_globalForLoopInitVars.emplace_back(vector<string>{});
} }
} }
@ -1692,7 +1692,7 @@ void ProtoConverter::fillFunctionCallInput(unsigned _numInParams)
case 2: case 2:
m_output << "sload(" << slot << ")"; m_output << "sload(" << slot << ")";
break; break;
case 3: default:
// Call to dictionaryToken() automatically picks a token // Call to dictionaryToken() automatically picks a token
// at a pseudo-random location. // at a pseudo-random location.
m_output << dictionaryToken(); m_output << dictionaryToken();
@ -1721,7 +1721,7 @@ void ProtoConverter::saveFunctionCallOutput(vector<string> const& _varsVec)
} }
void ProtoConverter::createFunctionCall( void ProtoConverter::createFunctionCall(
string _funcName, string const& _funcName,
unsigned _numInParams, unsigned _numInParams,
unsigned _numOutParams unsigned _numOutParams
) )
@ -1847,7 +1847,7 @@ string ProtoConverter::getObjectIdentifier(unsigned _x)
unsigned currentId = currentObjectId(); unsigned currentId = currentObjectId();
string currentObjName = "object" + to_string(currentId); string currentObjName = "object" + to_string(currentId);
yulAssert( yulAssert(
m_objectScope.count(currentObjName) && m_objectScope.at(currentObjName).size() > 0, m_objectScope.count(currentObjName) && !m_objectScope.at(currentObjName).empty(),
"Yul proto fuzzer: Error referencing object" "Yul proto fuzzer: Error referencing object"
); );
vector<string> objectIdsInScope = m_objectScope.at(currentObjName); vector<string> objectIdsInScope = m_objectScope.at(currentObjName);
@ -1887,7 +1887,7 @@ void ProtoConverter::buildObjectScopeTree(Object const& _x)
string objectName = newObjectId(false); string objectName = newObjectId(false);
vector<string> node{objectName}; vector<string> node{objectName};
if (_x.has_data()) if (_x.has_data())
node.push_back(s_dataIdentifier); node.emplace_back(s_dataIdentifier);
for (auto const& subObj: _x.sub_obj()) for (auto const& subObj: _x.sub_obj())
{ {
// Identifies sub object whose numeric suffix is // Identifies sub object whose numeric suffix is
@ -1900,7 +1900,7 @@ void ProtoConverter::buildObjectScopeTree(Object const& _x)
yulAssert(m_objectScope.count(subObjectName), "Yul proto fuzzer: Invalid object hierarchy"); yulAssert(m_objectScope.count(subObjectName), "Yul proto fuzzer: Invalid object hierarchy");
for (string const& item: m_objectScope.at(subObjectName)) for (string const& item: m_objectScope.at(subObjectName))
if (item != subObjectName) if (item != subObjectName)
node.push_back(subObjectName + "." + item); node.emplace_back(subObjectName + "." + item);
} }
m_objectScope.emplace(objectName, node); m_objectScope.emplace(objectName, node);
} }
@ -1942,7 +1942,7 @@ string ProtoConverter::programToString(Program const& _input)
return m_output.str(); return m_output.str();
} }
std::string ProtoConverter::functionTypeToString(NumFunctionReturns _type) string ProtoConverter::functionTypeToString(NumFunctionReturns _type)
{ {
switch (_type) switch (_type)
{ {

View File

@ -133,7 +133,7 @@ private:
/// Accepts an arbitrary string, removes all characters that are neither /// Accepts an arbitrary string, removes all characters that are neither
/// alphabets nor digits from it and returns the said string. /// alphabets nor digits from it and returns the said string.
std::string createAlphaNum(std::string const& _strBytes); static std::string createAlphaNum(std::string const& _strBytes);
enum class NumFunctionReturns enum class NumFunctionReturns
{ {
@ -153,7 +153,7 @@ private:
/// None -> "n" /// None -> "n"
/// Single -> "s" /// Single -> "s"
/// Multiple -> "m" /// Multiple -> "m"
std::string functionTypeToString(NumFunctionReturns _type); static std::string functionTypeToString(NumFunctionReturns _type);
/// Builds a single vector containing variables declared in /// Builds a single vector containing variables declared in
/// function scope. /// function scope.
@ -208,7 +208,7 @@ private:
/// true. Default value for the flag is true. /// true. Default value for the flag is true.
void convertFunctionCall( void convertFunctionCall(
FunctionCall const& _x, FunctionCall const& _x,
std::string _name, std::string const& _name,
unsigned _numInParams, unsigned _numInParams,
bool _newLine = true bool _newLine = true
); );
@ -248,7 +248,7 @@ private:
/// @param _funcName Name of the function to be called /// @param _funcName Name of the function to be called
/// @param _numInParams Number of input parameters in function signature /// @param _numInParams Number of input parameters in function signature
/// @param _numOutParams Number of output parameters in function signature /// @param _numOutParams Number of output parameters in function signature
void createFunctionCall(std::string _funcName, unsigned _numInParams, unsigned _numOutParams); void createFunctionCall(std::string const& _funcName, unsigned _numInParams, unsigned _numOutParams);
/// Print the Yul syntax to pass input arguments to a function that has /// Print the Yul syntax to pass input arguments to a function that has
/// @a _numInParams number of input parameters to the output stream. /// @a _numInParams number of input parameters to the output stream.
@ -288,7 +288,7 @@ private:
/// Returns an EVMVersion object corresponding to the protobuf /// Returns an EVMVersion object corresponding to the protobuf
/// enum of type Program_Version /// enum of type Program_Version
solidity::langutil::EVMVersion evmVersionMapping(Program_Version const& _x); static solidity::langutil::EVMVersion evmVersionMapping(Program_Version const& _x);
/// Returns a monotonically increasing counter that starts from zero. /// Returns a monotonically increasing counter that starts from zero.
unsigned counter() unsigned counter()
@ -323,7 +323,7 @@ private:
/// Returns the object counter value corresponding to the object /// Returns the object counter value corresponding to the object
/// being visited. /// being visited.
unsigned currentObjectId() unsigned currentObjectId() const
{ {
return m_objectId - 1; return m_objectId - 1;
} }