Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
#261 allow solidity version ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
flantony committed Jul 2, 2019
1 parent 1a99aef commit 903a0c6
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SolidityLabelProvider extends DefaultEObjectLabelProvider {
}

def dispatch String text(PragmaSolidityDirective it) {
'''pragma solidity «version»'''.toString
'''pragma solidity «minVersion»'''.toString
}

def dispatch String text(PragmaExperimentalDirective it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import com.yakindu.solidity.solidity.IfStatement
import com.yakindu.solidity.solidity.MappingTypeSpecifier
import com.yakindu.solidity.solidity.Modifier
import com.yakindu.solidity.solidity.Parameter
import com.yakindu.solidity.solidity.PragmaSolidityDirective
import com.yakindu.solidity.solidity.SolidityFactory
import com.yakindu.solidity.solidity.SourceUnit
import com.yakindu.solidity.solidity.StorageLocation
Expand Down Expand Up @@ -77,18 +76,6 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider {
@Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion
ExpressionsFactory factory = ExpressionsFactory.eINSTANCE

@Fix(WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT)
def changeToDefaultPragma(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Change version to ' + solcVersion, 'solidity version', null,
new ISemanticModification() {
override apply(EObject element, IModificationContext context) throws Exception {
if (element instanceof PragmaSolidityDirective) {
element.version = solcVersion
}
}
})
}

@Fix(ERROR_STATE_MUTABILITY_ONLY_ALLOWED_FOR_ADDRESS)
def removePayableToNonAddressDeclaration(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove payable declaration', 'Remove payable declaration', null,
Expand Down Expand Up @@ -394,8 +381,9 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider {
@Fix(ERROR_NO_VISIBILITY_SPECIFIED))
def makeVisibilityExplicit(Issue issue, IssueResolutionAcceptor acceptor) {
val operation = (new ResourceSetImpl().getEObject(issue.uriToProblem, true) as Operation);
val contract = (operation.eContainer as ContractDefinition)
if (contract.type != ContractType.INTERFACE && !operation.name.nullOrEmpty) {
val contract = (operation?.eContainer as ContractDefinition)

if (contract.type != ContractType.INTERFACE && (!operation.name.nullOrEmpty || operation instanceof ConstructorDefinition)) {
if (!(operation instanceof ConstructorDefinition)) {

acceptor.accept(issue, 'Make this function private', 'Private function.', null,
Expand Down Expand Up @@ -456,7 +444,7 @@ class SolidityQuickfixProvider extends ExpressionsQuickfixProvider {
if (element.eContainer instanceof SourceUnit) {
val sourceUnit = element.eContainer as SourceUnit
val pragma = createPragmaSolidityDirective => [
version = "^" + solcVersion
minVersion = solcVersion
]
sourceUnit.pragma += pragma
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/com.yakindu.solidity/model/generated/Solidity.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="PragmaSolidityDirective" eSuperTypes="#//PragmaDirective">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="version" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="minVersion" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="maxVersion" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="PragmaExperimentalDirective" eSuperTypes="#//PragmaDirective">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="value" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference Solidity.ecore#//SourceUnit/imports"/>
</genClasses>
<genClasses ecoreClass="Solidity.ecore#//PragmaSolidityDirective">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Solidity.ecore#//PragmaSolidityDirective/version"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Solidity.ecore#//PragmaSolidityDirective/minVersion"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Solidity.ecore#//PragmaSolidityDirective/maxVersion"/>
</genClasses>
<genClasses ecoreClass="Solidity.ecore#//PragmaExperimentalDirective">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute Solidity.ecore#//PragmaExperimentalDirective/value"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ PragmaDirective returns types::PackageMember:
PragmaSolidityDirective | PragmaExperimentalDirective;

PragmaSolidityDirective returns PragmaDirective:
{PragmaSolidityDirective} 'pragma' 'solidity' version=VERSION ';';
{PragmaSolidityDirective} 'pragma' 'solidity' ('^'|'>'|'>='|'='|'<='|'<') minVersion=VERSION (('<='|'<') maxVersion=VERSION)?';';

PragmaExperimentalDirective returns PragmaDirective:
{PragmaExperimentalDirective} 'pragma' 'experimental' value=STRING ';';
Expand Down Expand Up @@ -405,7 +405,7 @@ terminal DECIMAL returns EBigDecimal:
('0'..'9')+ ('.' ('0'..'9')*)? (('e' | 'E') ('0'..'9')+)?;

terminal VERSION:
'^' INT . INT . INT;
INT . INT . INT;

terminal BOOL returns EBoolean:
'true' | 'false';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,11 @@ class SolidityFormatter extends AbstractFormatter2 {
}

protected def int getLengthOfFunctionSignature(FunctionDefinition it) {
val int functionKeywordLength = regionFor.keyword("function").length + 1
val functionKeyWord = regionFor?.keyword("function")
if (functionKeyWord === null) {
return 0
}
val int functionKeywordLength = regionFor?.keyword("function").length + 1
val int nameLength = name.length
var int parametersLength = 0
for (parameter : parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,14 @@
*/
package com.yakindu.solidity.validation

import com.google.inject.name.Named
import com.yakindu.solidity.SolidityVersion
import com.yakindu.solidity.solidity.PragmaSolidityDirective
import com.yakindu.solidity.solidity.SolidityPackage
import java.util.List
import javax.inject.Inject
import org.eclipse.xtext.validation.Check
import org.yakindu.base.expressions.expressions.AssignmentExpression
import org.yakindu.base.expressions.expressions.Expression
import org.yakindu.base.expressions.validation.ExpressionsJavaValidator
import org.yakindu.base.types.Operation

class SolidityValidator extends ExpressionsJavaValidator {
val public SOLIDITY_VERSION_NOT_DEFAULT = "Solidity version does not match the default version"

@Inject @Named(SolidityVersion.SOLIDITY_VERSION) String solcVersion

override protected assertOperationArguments(Operation operation, List<Expression> args) {
// TODO Disabled, doesn't work with extension operations
Expand All @@ -39,14 +31,6 @@ class SolidityValidator extends ExpressionsJavaValidator {
// TODO Disables, doesn't work with Parameters
}

@Check
def protected checkPragmaVersion(PragmaSolidityDirective pragma) {
if (!( solcVersion).equals(pragma.version)) {
warning(SOLIDITY_VERSION_NOT_DEFAULT + " (" + solcVersion + ")", pragma,
SolidityPackage.Literals.PRAGMA_SOLIDITY_DIRECTIVE__VERSION,
IssueCodes.WARNING_SOLIDITY_VERSION_NOT_THE_DEFAULT)
}
}

override getEPackages() {
val superPackages = super.EPackages
Expand Down

0 comments on commit 903a0c6

Please sign in to comment.