Fixed infinite loops

This commit is contained in:
hrkrshnn 2020-04-24 15:40:04 +05:30
parent eb4cff56f7
commit 644ae320a4

View File

@ -50,7 +50,8 @@ public:
* on a textual base. They utilize regular expression to search for
* keywords or to determine formatting.
*/
class SourceAnalysis {
class SourceAnalysis
{
public:
static bool isMultilineKeyword(
langutil::SourceLocation const& _location,
@ -103,6 +104,7 @@ public:
for (auto inheritedContract: _contracts)
overrideList += inheritedContract->name() + ",";
// Note: Can create incorrect replacements
return "override(" + overrideList.substr(0, overrideList.size() - 1) + ")";
}
};
@ -123,11 +125,21 @@ public:
std::string const& _expression
)
{
return regex_replace(
_location.text(),
std::regex{"(\\b" + _keyword + "\\b)"},
_expression + " " + _keyword
);
auto _regex = std::regex{"(\\b" + _keyword + "\\b)"};
if (regex_search(_location.text(), _regex))
return regex_replace(
_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.
@ -142,7 +154,17 @@ public:
std::string toAppend = isMultiline ? ("\n " + _expression) : (" " + _expression);
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
@ -153,11 +175,21 @@ public:
std::string const& _expression
)
{
return regex_replace(
_location.text(),
std::regex{"(\\))"},
") " + _expression
);
auto _regex = std::regex{"(\\))"};
if (regex_search(_location.text(), _regex))
return regex_replace(
_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
@ -169,11 +201,21 @@ public:
std::string const& _expression
)
{
return regex_replace(
_location.text(),
std::regex{"(\\bfunction\\s*" + _name + "\\b)"},
_expression
);
auto _regex = std::regex{ "(\\bfunction\\s*" + _name + "\\b)"};
if (regex_search(_location.text(), _regex))
return regex_replace(
_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)
@ -194,12 +236,10 @@ public:
else
solAssert(
false,
LocationHelper()
<< "Regex count not match: " << _location.text() << " at " << _location
<< "\nNeeds to be fixed manually."
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
"\nNeeds to be fixed manually."
);
return "";
}
@ -221,9 +261,8 @@ public:
else
solAssert(
false,
LocationHelper()
<< "Regex count not match: " << _location.text() << " at " << _location
<< "\nNeeds to be fixed manually"
LocationHelper() << "Could not fix: " << _location.text() << " at " << _location <<
"\nNeeds to be fixed manually."
);
return "";