mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
fixup! Type inference draft.
This commit is contained in:
parent
319a6c4999
commit
761f5b342f
@ -2500,6 +2500,7 @@ private:
|
||||
ASTPointer<VariableDeclaration> m_typeVariable;
|
||||
std::vector<ASTPointer<ASTNode>> m_subNodes;
|
||||
};
|
||||
|
||||
class TypeClassInstantiation: public ASTNode, public ScopeOpener
|
||||
{
|
||||
public:
|
||||
@ -2590,6 +2591,7 @@ public:
|
||||
bool experimentalSolidityOnly() const override { return true; }
|
||||
|
||||
std::variant<Token, ASTPointer<IdentifierPath>> name() const { return m_name; }
|
||||
|
||||
private:
|
||||
std::variant<Token, ASTPointer<IdentifierPath>> m_name;
|
||||
};
|
||||
|
@ -63,6 +63,7 @@ class Analysis
|
||||
{
|
||||
struct AnnotationContainer;
|
||||
struct GlobalAnnotationContainer;
|
||||
|
||||
public:
|
||||
Analysis(langutil::ErrorReporter& _errorReporter, uint64_t _maxAstId);
|
||||
Analysis(Analysis const&) = delete;
|
||||
@ -73,30 +74,36 @@ public:
|
||||
uint64_t maxAstId() const { return m_maxAstId; }
|
||||
TypeSystem& typeSystem() { return m_typeSystem; }
|
||||
TypeSystem const& typeSystem() const { return m_typeSystem; }
|
||||
|
||||
template<typename Step>
|
||||
typename Step::Annotation& annotation(ASTNode const& _node)
|
||||
{
|
||||
return detail::AnnotationFetcher<Step>{*this}.get(_node);
|
||||
}
|
||||
|
||||
template<typename Step>
|
||||
typename Step::Annotation const& annotation(ASTNode const& _node) const
|
||||
{
|
||||
return detail::ConstAnnotationFetcher<Step>{*this}.get(_node);
|
||||
}
|
||||
|
||||
template<typename Step>
|
||||
typename Step::GlobalAnnotation& annotation()
|
||||
{
|
||||
return detail::AnnotationFetcher<Step>{*this}.get();
|
||||
}
|
||||
|
||||
template<typename Step>
|
||||
typename Step::GlobalAnnotation const& annotation() const
|
||||
{
|
||||
return detail::ConstAnnotationFetcher<Step>{*this}.get();
|
||||
}
|
||||
|
||||
AnnotationContainer& annotationContainer(ASTNode const& _node);
|
||||
AnnotationContainer const& annotationContainer(ASTNode const& _node) const;
|
||||
GlobalAnnotationContainer& annotationContainer() { return *m_globalAnnotation; }
|
||||
GlobalAnnotationContainer const& annotationContainer() const { return *m_globalAnnotation; }
|
||||
|
||||
private:
|
||||
langutil::ErrorReporter& m_errorReporter;
|
||||
TypeSystem m_typeSystem;
|
||||
|
@ -39,9 +39,9 @@ using namespace solidity::frontend::experimental;
|
||||
using namespace solidity::langutil;
|
||||
|
||||
TypeInference::TypeInference(Analysis& _analysis):
|
||||
m_analysis(_analysis),
|
||||
m_errorReporter(_analysis.errorReporter()),
|
||||
m_typeSystem(_analysis.typeSystem())
|
||||
m_analysis(_analysis),
|
||||
m_errorReporter(_analysis.errorReporter()),
|
||||
m_typeSystem(_analysis.typeSystem())
|
||||
{
|
||||
auto declareBuiltinClass = [&](std::string _name, BuiltinClass _class, auto _memberCreator, Sort _sort = {}) -> TypeClass {
|
||||
Type type = m_typeSystem.freshTypeVariable(std::move(_sort));
|
||||
@ -195,6 +195,7 @@ bool TypeInference::visit(TypeClassDefinition const& _typeClassDefinition)
|
||||
auto& typeClassAnnotation = annotation(_typeClassDefinition);
|
||||
if (typeClassAnnotation.type)
|
||||
return false;
|
||||
|
||||
typeClassAnnotation.type = type(&_typeClassDefinition, {});
|
||||
{
|
||||
ScopedSaveAndRestore expressionContext{m_expressionContext, ExpressionContext::Type};
|
||||
|
@ -31,9 +31,9 @@ using namespace solidity::frontend::experimental;
|
||||
using namespace solidity::langutil;
|
||||
|
||||
TypeRegistration::TypeRegistration(Analysis& _analysis):
|
||||
m_analysis(_analysis),
|
||||
m_errorReporter(_analysis.errorReporter()),
|
||||
m_typeSystem(_analysis.typeSystem())
|
||||
m_analysis(_analysis),
|
||||
m_errorReporter(_analysis.errorReporter()),
|
||||
m_typeSystem(_analysis.typeSystem())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -60,29 +60,29 @@ function g(x:uint256) -> uint256
|
||||
}
|
||||
|
||||
contract C {
|
||||
fallback() external {
|
||||
let arg;
|
||||
assembly {
|
||||
arg := calldataload(0)
|
||||
}
|
||||
let x : word;
|
||||
if (bool.abs(arg)) {
|
||||
assembly {
|
||||
x := 0x10
|
||||
}
|
||||
}
|
||||
fallback() external {
|
||||
let arg;
|
||||
assembly {
|
||||
arg := calldataload(0)
|
||||
}
|
||||
let x : word;
|
||||
if (bool.abs(arg)) {
|
||||
assembly {
|
||||
x := 0x10
|
||||
}
|
||||
}
|
||||
let w = uint256.abs(x);
|
||||
// w = f(g, w);
|
||||
w = w * w + w;
|
||||
let y : word;
|
||||
let z : (uint256,uint256);
|
||||
let y : word;
|
||||
let z : (uint256,uint256);
|
||||
assembly { y := 2 }
|
||||
y = uint256.rep(w) * y;
|
||||
assembly {
|
||||
mstore(0, y)
|
||||
return(0, 32)
|
||||
}
|
||||
}
|
||||
assembly {
|
||||
mstore(0, y)
|
||||
return(0, 32)
|
||||
}
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// EVMVersion: >=constantinople
|
||||
|
Loading…
Reference in New Issue
Block a user