Skip to content

Commit 8c1508c

Browse files
committed
fixup! Type inference draft.
1 parent d112f8e commit 8c1508c

File tree

4 files changed

+34
-26
lines changed

4 files changed

+34
-26
lines changed

Diff for: libsolidity/experimental/codegen/IRGenerationContext.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,12 @@ class Analysis;
3333

3434
struct IRGenerationContext
3535
{
36-
Analysis const& analysis;
37-
TypeEnvironment const* env = nullptr;
36+
struct QueuedFunction
37+
{
38+
FunctionDefinition const* function = nullptr;
39+
Type type = std::monostate{};
40+
};
41+
3842
void enqueueFunctionDefinition(FunctionDefinition const* _functionDefinition, Type _type)
3943
{
4044
QueuedFunction queue{_functionDefinition, env->resolve(_type)};
@@ -43,11 +47,9 @@ struct IRGenerationContext
4347
return;
4448
functionQueue.emplace_back(queue);
4549
}
46-
struct QueuedFunction
47-
{
48-
FunctionDefinition const* function = nullptr;
49-
Type type = std::monostate{};
50-
};
50+
51+
Analysis const& analysis;
52+
TypeEnvironment const* env = nullptr;
5153
std::list<QueuedFunction> functionQueue;
5254
std::map<FunctionDefinition const*, std::vector<Type>> generatedFunctions;
5355
};

Diff for: libsolidity/experimental/codegen/IRGenerator.cpp

+7-9
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ IRGenerator::IRGenerator(
5252
DebugInfoSelection const&,
5353
CharStreamProvider const*,
5454
Analysis const& _analysis
55-
)
56-
:
57-
m_evmVersion(_evmVersion),
58-
m_eofVersion(_eofVersion),
59-
// m_debugInfoSelection(_debugInfoSelection),
60-
// m_soliditySourceProvider(_soliditySourceProvider),
61-
m_env(_analysis.typeSystem().env().clone()),
62-
m_context{_analysis, &m_env, {}, {}}
55+
):
56+
m_evmVersion(_evmVersion),
57+
m_eofVersion(_eofVersion),
58+
//m_debugInfoSelection(_debugInfoSelection),
59+
//m_soliditySourceProvider(_soliditySourceProvider),
60+
m_env(_analysis.typeSystem().env().clone()),
61+
m_context{_analysis, &m_env, {}, {}}
6362
{
6463
}
6564

@@ -69,7 +68,6 @@ std::string IRGenerator::run(
6968
std::map<ContractDefinition const*, std::string_view const> const& /*_otherYulSources*/
7069
)
7170
{
72-
7371
Whiskers t(R"(
7472
object "<CreationObject>" {
7573
code {

Diff for: libsolidity/experimental/codegen/IRGeneratorForStatements.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ struct CopyTranslate: public yul::ASTCopier
5656
IRGenerationContext const& _context,
5757
yul::Dialect const& _dialect,
5858
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _references
59-
): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {}
59+
):
60+
m_context(_context),
61+
m_dialect(_dialect),
62+
m_references(std::move(_references))
63+
{}
6064

6165
using ASTCopier::operator();
6266

Diff for: libsolidity/experimental/codegen/IRGeneratorForStatements.h

+13-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ class IRGeneratorForStatements: public ASTConstVisitor
3434
IRGeneratorForStatements(IRGenerationContext& _context): m_context(_context) {}
3535

3636
std::string generate(ASTNode const& _node);
37+
3738
private:
39+
enum class Builtins
40+
{
41+
Identity,
42+
FromBool,
43+
ToBool
44+
};
45+
3846
bool visit(ExpressionStatement const& _expressionStatement) override;
3947
bool visit(Block const& _block) override;
4048
bool visit(IfStatement const& _ifStatement) override;
@@ -54,18 +62,14 @@ class IRGeneratorForStatements: public ASTConstVisitor
5462
void endVisit(Return const& _return) override;
5563
/// Default visit will reject all AST nodes that are not explicitly supported.
5664
bool visitNode(ASTNode const& _node) override;
57-
IRGenerationContext& m_context;
58-
std::stringstream m_code;
59-
enum class Builtins
60-
{
61-
Identity,
62-
FromBool,
63-
ToBool
64-
};
65-
std::map<Expression const*, std::variant<Declaration const*, Builtins>> m_expressionDeclaration;
65+
6666
Type typeAnnotation(ASTNode const& _node) const;
6767

6868
FunctionDefinition const& resolveTypeClassFunction(TypeClass _class, std::string _name, Type _type);
69+
70+
IRGenerationContext& m_context;
71+
std::stringstream m_code;
72+
std::map<Expression const*, std::variant<Declaration const*, Builtins>> m_expressionDeclaration;
6973
};
7074

7175
}

0 commit comments

Comments
 (0)