aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authormingchuan <mingc@skymizer.com>2018-05-23 12:31:20 +0800
committermingchuan <mingc@skymizer.com>2018-05-30 18:05:55 +0800
commitb7cafcbdf95c807f46fc07f4788d82981b7112b4 (patch)
tree5714a463da64eaf75a3ec56732165ec89e77d677 /libsolidity/analysis
parent9d5064d04d178474b95d67e87aaa32d0e5e03b0f (diff)
downloaddexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar.gz
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar.bz2
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar.lz
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar.xz
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.tar.zst
dexon-solidity-b7cafcbdf95c807f46fc07f4788d82981b7112b4.zip
Allow using `calldata` keyword to specify data location
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/ReferencesResolver.cpp38
-rw-r--r--libsolidity/analysis/TypeChecker.cpp2
2 files changed, 32 insertions, 8 deletions
diff --git a/libsolidity/analysis/ReferencesResolver.cpp b/libsolidity/analysis/ReferencesResolver.cpp
index f91eaf6e..a051d7f9 100644
--- a/libsolidity/analysis/ReferencesResolver.cpp
+++ b/libsolidity/analysis/ReferencesResolver.cpp
@@ -327,7 +327,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
else
{
// force location of external function parameters (not return) to calldata
- if (varLoc != Location::Default)
+ if (varLoc != Location::CallData && varLoc != Location::Default)
fatalTypeError(_variable.location(),
"Location has to be calldata for external functions "
"(remove the \"memory\" or \"storage\" keyword)."
@@ -344,15 +344,22 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
*dynamic_cast<Declaration const&>(*_variable.scope()).scope()
);
// force locations of public or external function (return) parameters to memory
- if (varLoc == Location::Storage && !contract.isLibrary())
+ if (varLoc != Location::Memory && varLoc != Location::Default && !contract.isLibrary())
fatalTypeError(_variable.location(),
"Location has to be memory for publicly visible functions "
- "(remove the \"storage\" keyword)."
+ "(remove the \"storage\" or \"calldata\" keyword)."
);
if (varLoc == Location::Default || !contract.isLibrary())
typeLoc = DataLocation::Memory;
else
+ {
+ if (varLoc == Location::CallData)
+ fatalTypeError(_variable.location(),
+ "Location cannot be calldata for non-external functions "
+ "(remove the \"calldata\" keyword)."
+ );
typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
+ }
}
else
{
@@ -361,7 +368,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
if (varLoc != Location::Default && varLoc != Location::Memory)
fatalTypeError(
_variable.location(),
- "Storage location has to be \"memory\" (or unspecified) for constants."
+ "Data location has to be \"memory\" (or unspecified) for constants."
);
typeLoc = DataLocation::Memory;
}
@@ -377,7 +384,7 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
typeError(
_variable.location(),
- "Storage location must be specified as either \"memory\" or \"storage\"."
+ "Data location must be specified as either \"memory\" or \"storage\"."
);
else
m_errorReporter.warning(
@@ -389,14 +396,31 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
}
}
else
- typeLoc = varLoc == Location::Memory ? DataLocation::Memory : DataLocation::Storage;
+ {
+ switch (varLoc)
+ {
+ case Location::Memory:
+ typeLoc = DataLocation::Memory;
+ break;
+ case Location::Storage:
+ typeLoc = DataLocation::Storage;
+ break;
+ case Location::CallData:
+ fatalTypeError(_variable.location(),
+ "Variable cannot be declared as \"calldata\" (remove the \"calldata\" keyword)."
+ );
+ break;
+ default:
+ solAssert(false, "Unknown data location");
+ }
+ }
isPointer = !_variable.isStateVariable();
}
type = ref->copyForLocation(typeLoc, isPointer);
}
else if (varLoc != Location::Default && !ref)
- typeError(_variable.location(), "Storage location can only be given for array or struct types.");
+ typeError(_variable.location(), "Data location can only be given for array or struct types.");
_variable.annotation().type = type;
}
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 30302908..60cde33c 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -351,7 +351,7 @@ void TypeChecker::annotateBaseConstructorArguments(
SourceLocation const* mainLocation = nullptr;
SecondarySourceLocation ssl;
-
+
if (
_currentContract.location().contains(previousNode->location()) ||
_currentContract.location().contains(_argumentNode->location())