mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fixed infinite loops
This commit is contained in:
parent
eb4cff56f7
commit
644ae320a4
@ -50,7 +50,8 @@ public:
|
|||||||
* on a textual base. They utilize regular expression to search for
|
* on a textual base. They utilize regular expression to search for
|
||||||
* keywords or to determine formatting.
|
* keywords or to determine formatting.
|
||||||
*/
|
*/
|
||||||
class SourceAnalysis {
|
class SourceAnalysis
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static bool isMultilineKeyword(
|
static bool isMultilineKeyword(
|
||||||
langutil::SourceLocation const& _location,
|
langutil::SourceLocation const& _location,
|
||||||
@ -103,6 +104,7 @@ public:
|
|||||||
for (auto inheritedContract: _contracts)
|
for (auto inheritedContract: _contracts)
|
||||||
overrideList += inheritedContract->name() + ",";
|
overrideList += inheritedContract->name() + ",";
|
||||||
|
|
||||||
|
// Note: Can create incorrect replacements
|
||||||
return "override(" + overrideList.substr(0, overrideList.size() - 1) + ")";
|
return "override(" + overrideList.substr(0, overrideList.size() - 1) + ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -123,11 +125,21 @@ public:
|
|||||||
std::string const& _expression
|
std::string const& _expression
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return regex_replace(
|
auto _regex = std::regex{"(\\b" + _keyword + "\\b)"};
|
||||||
_location.text(),
|
if (regex_search(_location.text(), _regex))
|
||||||
std::regex{"(\\b" + _keyword + "\\b)"},
|
return regex_replace(
|
||||||
_expression + " " + _keyword
|
_location.text(),
|
||||||
);
|
_regex,
|
||||||
|
_expression + " " + _keyword
|
||||||
|
);
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
false,
|
||||||
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
|
"\nNeeds to be fixed manually."
|
||||||
|
);
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches for the keyword given and appends the expression.
|
/// Searches for the keyword given and appends the expression.
|
||||||
@ -142,7 +154,17 @@ public:
|
|||||||
std::string toAppend = isMultiline ? ("\n " + _expression) : (" " + _expression);
|
std::string toAppend = isMultiline ? ("\n " + _expression) : (" " + _expression);
|
||||||
std::regex keyword{"(\\b" + _keyword + "\\b)"};
|
std::regex keyword{"(\\b" + _keyword + "\\b)"};
|
||||||
|
|
||||||
return regex_replace(_location.text(), keyword, _keyword + toAppend);
|
if (regex_search(_location.text(), keyword))
|
||||||
|
return regex_replace(_location.text(), keyword, _keyword + toAppend);
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
false,
|
||||||
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
|
"\nNeeds to be fixed manually."
|
||||||
|
);
|
||||||
|
|
||||||
|
return "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches for the first right parenthesis and appends the expression
|
/// Searches for the first right parenthesis and appends the expression
|
||||||
@ -153,11 +175,21 @@ public:
|
|||||||
std::string const& _expression
|
std::string const& _expression
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return regex_replace(
|
auto _regex = std::regex{"(\\))"};
|
||||||
_location.text(),
|
if (regex_search(_location.text(), _regex))
|
||||||
std::regex{"(\\))"},
|
return regex_replace(
|
||||||
") " + _expression
|
_location.text(),
|
||||||
);
|
std::regex{"(\\))"},
|
||||||
|
") " + _expression
|
||||||
|
);
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
false,
|
||||||
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
|
"\nNeeds to be fixed manually."
|
||||||
|
);
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Searches for the `function` keyword and its identifier and replaces
|
/// Searches for the `function` keyword and its identifier and replaces
|
||||||
@ -169,11 +201,21 @@ public:
|
|||||||
std::string const& _expression
|
std::string const& _expression
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
return regex_replace(
|
auto _regex = std::regex{ "(\\bfunction\\s*" + _name + "\\b)"};
|
||||||
_location.text(),
|
if (regex_search(_location.text(), _regex))
|
||||||
std::regex{"(\\bfunction\\s*" + _name + "\\b)"},
|
return regex_replace(
|
||||||
_expression
|
_location.text(),
|
||||||
);
|
_regex,
|
||||||
|
_expression
|
||||||
|
);
|
||||||
|
else
|
||||||
|
solAssert(
|
||||||
|
false,
|
||||||
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
|
"\nNeeds to be fixed manually."
|
||||||
|
);
|
||||||
|
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string gasUpdate(langutil::SourceLocation const& _location)
|
static std::string gasUpdate(langutil::SourceLocation const& _location)
|
||||||
@ -194,12 +236,10 @@ public:
|
|||||||
else
|
else
|
||||||
solAssert(
|
solAssert(
|
||||||
false,
|
false,
|
||||||
LocationHelper()
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
<< "Regex count not match: " << _location.text() << " at " << _location
|
"\nNeeds to be fixed manually."
|
||||||
<< "\nNeeds to be fixed manually."
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,9 +261,8 @@ public:
|
|||||||
else
|
else
|
||||||
solAssert(
|
solAssert(
|
||||||
false,
|
false,
|
||||||
LocationHelper()
|
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
|
||||||
<< "Regex count not match: " << _location.text() << " at " << _location
|
"\nNeeds to be fixed manually."
|
||||||
<< "\nNeeds to be fixed manually"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
|
Loading…
Reference in New Issue
Block a user