-
Notifications
You must be signed in to change notification settings - Fork 61
Implement DIP1009 correctly (#303) #304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
df18083
Implement DIP1009 correctly, close #303
LaurentTreguier e531024
Handle expression-based contracts in formatter
LaurentTreguier f0e70bc
Introduce AssertArguments
LaurentTreguier 3d0017c
Add missing trace calls
LaurentTreguier 1601983
Better follow DIP1009 syntax changes
LaurentTreguier 7a7be30
Remove obsolete BodyStatement
LaurentTreguier c97d121
Use moreToken() to prevent RangeError's
LaurentTreguier 6d828b4
Use currentIs instead of current.type
LaurentTreguier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,7 @@ abstract class ASTVisitor | |
| /** */ void visit(const AsmTypePrefix asmTypePrefix) { asmTypePrefix.accept(this); } | ||
| /** */ void visit(const AsmUnaExp asmUnaExp) { asmUnaExp.accept(this); } | ||
| /** */ void visit(const AsmXorExp asmXorExp) { asmXorExp.accept(this); } | ||
| /** */ void visit(const AssertArguments assertArguments) { assertArguments.accept(this); } | ||
| /** */ void visit(const AssertExpression assertExpression) { assertExpression.accept(this); } | ||
| /** */ void visit(const AssignExpression assignExpression) { assignExpression.accept(this); } | ||
| /** */ void visit(const AssocArrayLiteral assocArrayLiteral) { assocArrayLiteral.accept(this); } | ||
|
|
@@ -179,7 +180,6 @@ abstract class ASTVisitor | |
| /** */ void visit(const AutoDeclaration autoDeclaration) { autoDeclaration.accept(this); } | ||
| /** */ void visit(const AutoDeclarationPart autoDeclarationPart) { autoDeclarationPart.accept(this); } | ||
| /** */ void visit(const BlockStatement blockStatement) { blockStatement.accept(this); } | ||
| /** */ void visit(const BodyStatement bodyStatement) { bodyStatement.accept(this); } | ||
| /** */ void visit(const BreakStatement breakStatement) { breakStatement.accept(this); } | ||
| /** */ void visit(const BaseClass baseClass) { baseClass.accept(this); } | ||
| /** */ void visit(const BaseClassList baseClassList) { baseClassList.accept(this); } | ||
|
|
@@ -228,6 +228,7 @@ abstract class ASTVisitor | |
| /** */ void visit(const FunctionAttribute functionAttribute) { functionAttribute.accept(this); } | ||
| /** */ void visit(const FunctionBody functionBody) { functionBody.accept(this); } | ||
| /** */ void visit(const FunctionCallExpression functionCallExpression) { functionCallExpression.accept(this); } | ||
| /** */ void visit(const FunctionContract functionContract) { functionContract.accept(this); } | ||
| /** */ void visit(const FunctionDeclaration functionDeclaration) { functionDeclaration.accept(this); } | ||
| /** */ void visit(const FunctionLiteralExpression functionLiteralExpression) { functionLiteralExpression.accept(this); } | ||
| /** */ void visit(const GotoStatement gotoStatement) { gotoStatement.accept(this); } | ||
|
|
@@ -242,7 +243,10 @@ abstract class ASTVisitor | |
| /** */ void visit(const ImportDeclaration importDeclaration) { importDeclaration.accept(this); } | ||
| /** */ void visit(const ImportExpression importExpression) { importExpression.accept(this); } | ||
| /** */ void visit(const IndexExpression indexExpression) { indexExpression.accept(this); } | ||
| /** */ void visit(const InContractExpression inContractExpression) { inContractExpression.accept(this); } | ||
| /** */ void visit(const InExpression inExpression) { inExpression.accept(this); } | ||
| /** */ void visit(const InOutContractExpression inOutContractExpression) { inOutContractExpression.accept(this); } | ||
| /** */ void visit(const InOutStatement inOutStatement) { inOutStatement.accept(this); } | ||
| /** */ void visit(const InStatement inStatement) { inStatement.accept(this); } | ||
| /** */ void visit(const Initialize initialize) { initialize.accept(this); } | ||
| /** */ void visit(const Initializer initializer) { initializer.accept(this); } | ||
|
|
@@ -255,6 +259,7 @@ abstract class ASTVisitor | |
| /** */ void visit(const LastCatch lastCatch) { lastCatch.accept(this); } | ||
| /** */ void visit(const LinkageAttribute linkageAttribute) { linkageAttribute.accept(this); } | ||
| /** */ void visit(const MemberFunctionAttribute memberFunctionAttribute) { memberFunctionAttribute.accept(this); } | ||
| /** */ void visit(const MissingFunctionBody missingFunctionBody) { missingFunctionBody.accept(this); } | ||
| /** */ void visit(const MixinDeclaration mixinDeclaration) { mixinDeclaration.accept(this); } | ||
| /** */ void visit(const MixinExpression mixinExpression) { mixinExpression.accept(this); } | ||
| /** */ void visit(const MixinTemplateDeclaration mixinTemplateDeclaration) { mixinTemplateDeclaration.accept(this); } | ||
|
|
@@ -268,6 +273,7 @@ abstract class ASTVisitor | |
| /** */ void visit(const Operands operands) { operands.accept(this); } | ||
| /** */ void visit(const OrExpression orExpression) { orExpression.accept(this); } | ||
| /** */ void visit(const OrOrExpression orOrExpression) { orOrExpression.accept(this); } | ||
| /** */ void visit(const OutContractExpression outContractExpression) { outContractExpression.accept(this); } | ||
| /** */ void visit(const OutStatement outStatement) { outStatement.accept(this); } | ||
| /** */ void visit(const ParameterAttribute parameterAttribute) { parameterAttribute.accept(this); } | ||
| /** */ void visit(const Parameter parameter) { parameter.accept(this); } | ||
|
|
@@ -287,6 +293,7 @@ abstract class ASTVisitor | |
| /** */ void visit(const ShiftExpression shiftExpression) { shiftExpression.accept(this); } | ||
| /** */ void visit(const SingleImport singleImport) { singleImport.accept(this); } | ||
| /** */ void visit(const Index index) { index.accept(this); } | ||
| /** */ void visit(const SpecifiedFunctionBody specifiedFunctionBody) { specifiedFunctionBody.accept(this); } | ||
| /** */ void visit(const Statement statement) { statement.accept(this); } | ||
| /** */ void visit(const StatementNoCaseNoDefault statementNoCaseNoDefault) { statementNoCaseNoDefault.accept(this); } | ||
| /** */ void visit(const StaticAssertDeclaration staticAssertDeclaration) { staticAssertDeclaration.accept(this); } | ||
|
|
@@ -817,19 +824,30 @@ final class AsmXorExp : ExpressionNode | |
| } | ||
|
|
||
| /// | ||
| final class AssertExpression : ExpressionNode | ||
| final class AssertArguments : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(assertion, message)); | ||
| } | ||
| /** */ size_t line; | ||
| /** */ size_t column; | ||
| /** */ ExpressionNode assertion; | ||
| /** */ ExpressionNode message; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class AssertExpression : ExpressionNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(assertArguments)); | ||
| } | ||
| /** */ size_t line; | ||
| /** */ size_t column; | ||
| /** */ AssertArguments assertArguments; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class AssignExpression : ExpressionNode | ||
| { | ||
|
|
@@ -953,17 +971,6 @@ final class BlockStatement : ASTNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class BodyStatement : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(blockStatement)); | ||
| } | ||
| /** */ BlockStatement blockStatement; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class BreakStatement : ASTNode | ||
| { | ||
|
|
@@ -1671,14 +1678,11 @@ final class FunctionBody : ASTNode | |
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(inStatements, outStatements, bodyStatement, | ||
| blockStatement)); | ||
| mixin (visitIfNotNull!(specifiedFunctionBody, missingFunctionBody)); | ||
| } | ||
|
|
||
| /** */ BlockStatement blockStatement; | ||
| /** */ BodyStatement bodyStatement; | ||
| /** */ OutStatement[] outStatements; | ||
| /** */ InStatement[] inStatements; | ||
| /** */ SpecifiedFunctionBody specifiedFunctionBody; | ||
| /** */ MissingFunctionBody missingFunctionBody; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
|
|
@@ -1696,6 +1700,18 @@ final class FunctionCallExpression : ExpressionNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class FunctionContract : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(inOutContractExpression, inOutStatement)); | ||
| } | ||
| /** */ InOutContractExpression inOutContractExpression; | ||
| /** */ InOutStatement inOutStatement; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class FunctionDeclaration : ASTNode | ||
| { | ||
|
|
@@ -1726,11 +1742,11 @@ final class FunctionLiteralExpression : ExpressionNode | |
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(returnType, parameters, functionAttributes, | ||
| memberFunctionAttributes, functionBody, assignExpression)); | ||
| memberFunctionAttributes, specifiedFunctionBody, assignExpression)); | ||
| } | ||
| /** */ ExpressionNode assignExpression; | ||
| /** */ FunctionAttribute[] functionAttributes; | ||
| /** */ FunctionBody functionBody; | ||
| /** */ SpecifiedFunctionBody specifiedFunctionBody; | ||
| /** */ IdType functionOrDelegate; | ||
| /** */ MemberFunctionAttribute[] memberFunctionAttributes; | ||
| /** */ Parameters parameters; | ||
|
|
@@ -1909,6 +1925,18 @@ final class IndexExpression : ExpressionNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class InContractExpression : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(assertArguments)); | ||
| } | ||
| /** */ size_t inTokenLocation; | ||
| /** */ AssertArguments assertArguments; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class InExpression : ExpressionNode | ||
| { | ||
|
|
@@ -1921,6 +1949,30 @@ final class InExpression : ExpressionNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class InOutContractExpression : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(inContractExpression, outContractExpression)); | ||
| } | ||
| /** */ InContractExpression inContractExpression; | ||
| /** */ OutContractExpression outContractExpression; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class InOutStatement : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(inStatement, outStatement)); | ||
| } | ||
| /** */ InStatement inStatement; | ||
| /** */ OutStatement outStatement; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class InStatement : ASTNode | ||
| { | ||
|
|
@@ -1977,9 +2029,10 @@ final class Invariant : ASTNode | |
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(blockStatement)); | ||
| mixin (visitIfNotNull!(blockStatement, assertArguments)); | ||
| } | ||
| /** */ BlockStatement blockStatement; | ||
| /** */ AssertArguments assertArguments; | ||
| /** */ string comment; | ||
| size_t line; | ||
| size_t index; | ||
|
|
@@ -2076,6 +2129,17 @@ final class MemberFunctionAttribute : ASTNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class MissingFunctionBody : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(functionContracts)); | ||
| } | ||
| /** */ FunctionContract[] functionContracts; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class MixinDeclaration : ASTNode | ||
| { | ||
|
|
@@ -2288,6 +2352,19 @@ final class OrOrExpression : ExpressionNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class OutContractExpression : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(parameter, assertArguments)); | ||
| } | ||
| /** */ size_t outTokenLocation; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as comment related to InContractExpression |
||
| /** */ Token parameter; | ||
| /** */ AssertArguments assertArguments; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class OutStatement : ASTNode | ||
| { | ||
|
|
@@ -2542,6 +2619,18 @@ final class SingleImport : ASTNode | |
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class SpecifiedFunctionBody : ASTNode | ||
| { | ||
| override void accept(ASTVisitor visitor) const | ||
| { | ||
| mixin (visitIfNotNull!(functionContracts, blockStatement)); | ||
| } | ||
| /** */ FunctionContract[] functionContracts; | ||
| /** */ BlockStatement blockStatement; | ||
| mixin OpEquals; | ||
| } | ||
|
|
||
| /// | ||
| final class Statement : ASTNode | ||
| { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is required. IIRC you wanted this for DFMT but with the official grammar FunctionContract gives the information if it's a expression style contract (its InOutStatement is null) or a statement style contract (its InOutContractExpression) is null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inTokenLocationandoutTokenLocationwere already used for detecting classic contract statements; the problem with them was simply that they weren't filled for expression-based contracts, so DFMT didn't consider them as contracts.But
inTokenLocationandoutTokenLocationare used to distinguish contracts from other usages ofinandout, and not to distinguish expression-based ones from statement ones, so I think it's probably better to leave them thereUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok then. since my comment i just remembered too that DFMT is based on the tokens and only very partially on the AST.