Skip to content

Commit

Permalink
Merge pull request #1810 from ethereum/compactJson
Browse files Browse the repository at this point in the history
Compact format for AST-Json.
  • Loading branch information
chriseth committed May 22, 2017
2 parents e3af064 + e82df07 commit 8eead55
Show file tree
Hide file tree
Showing 15 changed files with 579 additions and 495 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### 0.4.12 (unreleased)
* AST: export all attributes to Json format

### 0.4.11 (2017-05-03)

Expand Down
16 changes: 10 additions & 6 deletions libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,13 +1238,17 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)

if (auto const* typeType = dynamic_cast<TypeType const*>(expressionType.get()))
{
_functionCall.annotation().isStructConstructorCall = (typeType->actualType()->category() == Type::Category::Struct);
_functionCall.annotation().isTypeConversion = !_functionCall.annotation().isStructConstructorCall;
if (typeType->actualType()->category() == Type::Category::Struct)
_functionCall.annotation().kind = FunctionCallKind::StructConstructorCall;
else
_functionCall.annotation().kind = FunctionCallKind::TypeConversion;

}
else
_functionCall.annotation().isStructConstructorCall = _functionCall.annotation().isTypeConversion = false;
_functionCall.annotation().kind = FunctionCallKind::FunctionCall;
solAssert(_functionCall.annotation().kind != FunctionCallKind::Unset, "");

if (_functionCall.annotation().isTypeConversion)
if (_functionCall.annotation().kind == FunctionCallKind::TypeConversion)
{
TypeType const& t = dynamic_cast<TypeType const&>(*expressionType);
TypePointer resultType = t.actualType();
Expand Down Expand Up @@ -1274,7 +1278,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)

/// For error message: Struct members that were removed during conversion to memory.
set<string> membersRemovedForStructConstructor;
if (_functionCall.annotation().isStructConstructorCall)
if (_functionCall.annotation().kind == FunctionCallKind::StructConstructorCall)
{
TypeType const& t = dynamic_cast<TypeType const&>(*expressionType);
auto const& structType = dynamic_cast<StructType const&>(*t.actualType());
Expand Down Expand Up @@ -1312,7 +1316,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
toString(parameterTypes.size()) +
".";
// Extend error message in case we try to construct a struct with mapping member.
if (_functionCall.annotation().isStructConstructorCall && !membersRemovedForStructConstructor.empty())
if (_functionCall.annotation().kind == FunctionCallKind::StructConstructorCall && !membersRemovedForStructConstructor.empty())
{
msg += " Members that have to be skipped in memory:";
for (auto const& member: membersRemovedForStructConstructor)
Expand Down
9 changes: 4 additions & 5 deletions libsolidity/ast/AST.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,7 @@ class FunctionDefinition: public CallableDeclaration, public Documented, public
bool isPayable() const { return m_isPayable; }
std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; }
std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); }
Block const& body() const { return *m_body; }

Block const& body() const { solAssert(m_body, ""); return *m_body; }
virtual bool isVisibleInContract() const override
{
return Declaration::isVisibleInContract() && !isConstructor() && !name().empty();
Expand Down Expand Up @@ -1314,7 +1313,7 @@ class Assignment: public Expression

/**
* Tuple, parenthesized expression, or bracketed expression.
* Examples: (1, 2), (x,), (x), (), [1, 2],
* Examples: (1, 2), (x,), (x), (), [1, 2],
* Individual components might be empty shared pointers (as in the second example).
* The respective types in lvalue context are: 2-tuple, 2-tuple (with wildcard), type of x, 0-tuple
* Not in lvalue context: 2-tuple, _1_-tuple, type of x, 0-tuple.
Expand All @@ -1327,8 +1326,8 @@ class TupleExpression: public Expression
std::vector<ASTPointer<Expression>> const& _components,
bool _isArray
):
Expression(_location),
m_components(_components),
Expression(_location),
m_components(_components),
m_isArray(_isArray) {}
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
Expand Down
13 changes: 9 additions & 4 deletions libsolidity/ast/ASTAnnotations.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,17 @@ struct BinaryOperationAnnotation: ExpressionAnnotation
TypePointer commonType;
};

enum class FunctionCallKind
{
Unset,
FunctionCall,
TypeConversion,
StructConstructorCall
};

struct FunctionCallAnnotation: ExpressionAnnotation
{
/// Whether this is an explicit type conversion.
bool isTypeConversion = false;
/// Whether this is a struct constructor call.
bool isStructConstructorCall = false;
FunctionCallKind kind = FunctionCallKind::Unset;
};

}
Expand Down
Loading

0 comments on commit 8eead55

Please sign in to comment.