Type Checker for try/catch.

This commit is contained in:
chriseth
2019-09-23 17:22:56 +02:00
parent b5bc52f2a7
commit 8e736a9f49
9 changed files with 166 additions and 18 deletions
+13 -12
View File
@@ -452,12 +452,9 @@ bool VariableDeclaration::isLocalVariable() const
dynamic_cast<ForStatement const*>(s);
}
bool VariableDeclaration::isCallableParameter() const
bool VariableDeclaration::isCallableOrCatchParameter() const
{
// TODO Adjust for catch params.
// I think catch params should return true here.
// some of the error strings would need to be adjusted.
if (isReturnParameter() || dynamic_cast<TryCatchClause const*>(scope()))
if (isReturnParameter() || isTryCatchParameter())
return true;
vector<ASTPointer<VariableDeclaration>> const* parameters = nullptr;
@@ -476,8 +473,7 @@ bool VariableDeclaration::isCallableParameter() const
bool VariableDeclaration::isLocalOrReturn() const
{
// TODO adjust for catch params
return isReturnParameter() || (isLocalVariable() && !isCallableParameter());
return isReturnParameter() || (isLocalVariable() && !isCallableOrCatchParameter());
}
bool VariableDeclaration::isReturnParameter() const
@@ -497,9 +493,14 @@ bool VariableDeclaration::isReturnParameter() const
return false;
}
bool VariableDeclaration::isTryCatchParameter() const
{
return dynamic_cast<TryCatchClause const*>(scope());
}
bool VariableDeclaration::isExternalCallableParameter() const
{
if (!isCallableParameter())
if (!isCallableOrCatchParameter())
return false;
if (auto const* callable = dynamic_cast<CallableDeclaration const*>(scope()))
@@ -511,7 +512,7 @@ bool VariableDeclaration::isExternalCallableParameter() const
bool VariableDeclaration::isInternalCallableParameter() const
{
if (!isCallableParameter())
if (!isCallableOrCatchParameter())
return false;
if (auto const* funTypeName = dynamic_cast<FunctionTypeName const*>(scope()))
@@ -523,7 +524,7 @@ bool VariableDeclaration::isInternalCallableParameter() const
bool VariableDeclaration::isLibraryFunctionParameter() const
{
if (!isCallableParameter())
if (!isCallableOrCatchParameter())
return false;
if (auto const* funDef = dynamic_cast<FunctionDefinition const*>(scope()))
return dynamic_cast<ContractDefinition const&>(*funDef->scope()).isLibrary();
@@ -559,10 +560,10 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
locations.insert(Location::Storage);
return locations;
}
else if (isCallableParameter())
else if (isCallableOrCatchParameter())
{
set<Location> locations{ Location::Memory };
if (isInternalCallableParameter() || isLibraryFunctionParameter())
if (isInternalCallableParameter() || isLibraryFunctionParameter() || isTryCatchParameter())
locations.insert(Location::Storage);
return locations;
}
+4 -1
View File
@@ -738,9 +738,12 @@ public:
/// (or function type name or event) or declared inside a function body.
bool isLocalVariable() const;
/// @returns true if this variable is a parameter or return parameter of a function.
bool isCallableParameter() const;
bool isCallableOrCatchParameter() const;
/// @returns true if this variable is a return parameter of a function.
bool isReturnParameter() const;
/// @returns true if this variable is a parameter of the success or failure clausse
/// of a try/catch statement.
bool isTryCatchParameter() const;
/// @returns true if this variable is a local variable or return parameter.
bool isLocalOrReturn() const;
/// @returns true if this variable is a parameter (not return parameter) of an external function.