Skip to content

Commit

Permalink
Merge pull request #156 from pontem-network/resource-access-struct-inst
Browse files Browse the repository at this point in the history
Resource access address arg fix
  • Loading branch information
mkurnikov authored Jun 9, 2024
2 parents 625d3e5 + 969c57b commit 2dcd4e0
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/main/grammars/MoveParser.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ ResourceAccessItem ::= pure | (('!')? (acquires | reads | writes) AccessSpecifie
AccessSpecifierList ::= <<non_empty_comma_sep_items AccessSpecifier>>
AccessSpecifier ::= <<pathMode 'WILDCARD' Path>> AddressSpecifier?

AddressSpecifier ::= '(' AddressSpecifierArg ')'
AddressSpecifier ::= '(' AddressSpecifierArg ')' { pin = 1 }
AddressSpecifierArg ::= '*'
| (IDENTIFIER !'(')
| AddressSpecifierLit
| <<pathMode 'VALUE' (Path '(' AddressSpecifierCallParam ')')>>
| IDENTIFIER
AddressSpecifierLit ::= DIEM_ADDRESS | INTEGER_LITERAL

AddressSpecifierCallParam ::= AddressSpecifierParamPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.move.cli.settings

import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
import com.intellij.codeInsight.daemon.impl.FileStatusMap
import com.intellij.openapi.Disposable
import com.intellij.openapi.components.BaseState
import com.intellij.openapi.components.SimplePersistentStateComponent
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectFileIndex
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.PsiManager
import com.intellij.psi.search.FileTypeIndex
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.psi.stubs.StubTreeLoader
import com.intellij.util.FileContentUtil
import com.intellij.util.FileContentUtilCore
import com.intellij.util.messages.Topic
import org.jetbrains.annotations.TestOnly
import org.move.cli.settings.MvProjectSettingsServiceBase.MvProjectSettingsBase
import org.move.lang.MoveFileType
import org.move.openapiext.saveAllDocuments
import kotlin.reflect.KProperty1
import kotlin.reflect.full.findAnnotation
Expand Down Expand Up @@ -82,14 +81,14 @@ abstract class MvProjectSettingsServiceBase<T: MvProjectSettingsBase<T>>(
}

if (event.affectsParseTree) {
// REFRESH EVERYTHING (didn't find any proper way to do it)
// refresh all .move files (didn't find any proper way to do it)
saveAllDocuments()
val files = mutableListOf<VirtualFile>()
ProjectFileIndex.getInstance(project).iterateContent { files.add(it) }

val moveFiles = FileTypeIndex.getFiles(MoveFileType, GlobalSearchScope.allScope(project))

PsiManager.getInstance(project).dropPsiCaches()
FileContentUtilCore.reparseFiles(files)
files.forEach { StubTreeLoader.getInstance().rebuildStubTree(it) }
FileContentUtilCore.reparseFiles(moveFiles)
moveFiles.forEach { StubTreeLoader.getInstance().rebuildStubTree(it) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ enum class AptosExecType {
companion object {
val isPreCompiledSupportedForThePlatform: Boolean
get() {
if (Registry.`is`("org.move.aptos.bundled.force.supported")) {
if (Registry.`is`("org.move.aptos.bundled.force.supported", false)) {
return true
}
if (Registry.`is`("org.move.aptos.bundled.force.unsupported")) {
if (Registry.`is`("org.move.aptos.bundled.force.unsupported", false)) {
return false
}
return !SystemInfo.isMac
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/move/lang/MoveParserDefinition.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ class MoveParserDefinition : ParserDefinition {
/**
* Should be increased after any change of parser rules
*/
const val PARSER_VERSION: Int = LEXER_VERSION + 48
const val PARSER_VERSION: Int = LEXER_VERSION + 49
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ class ResolveResourceAccessSpecifiersTest: ResolveTestCase() {
fun make_up_address(x: u8): address { @0x1 }
}
""")

fun `test address function can be from another module`() = checkByCode("""
module 0x1::signer {
public native fun address_of(s: &signer);
//X
}
module 0x1::main {
use 0x1::signer;
struct S { field: u8 }
fun main(s: &signer) reads *(signer::address_of(s)) {}
//^
}
""")
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ module 0x1::access_control {
fun f11() !reads *(0x42), *(0x43) {}

fun f12() pure {}
}

fun ok2(s: &signer): bool reads R(signer::address_of(s)) {}

fun ok2(s: &signer): bool reads R(address_of<u8>(s)) {}
}
112 changes: 111 additions & 1 deletion src/test/resources/org/move/lang/parser/complete/access_control.txt
Original file line number Diff line number Diff line change
Expand Up @@ -447,5 +447,115 @@ FILE
MvCodeBlockImpl(CODE_BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n ')
PsiWhiteSpace('\n\n ')
MvFunctionImpl(FUNCTION)
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('ok2')
MvFunctionParameterListImpl(FUNCTION_PARAMETER_LIST)
PsiElement(()('(')
MvFunctionParameterImpl(FUNCTION_PARAMETER)
MvBindingPatImpl(BINDING_PAT)
PsiElement(IDENTIFIER)('s')
MvTypeAnnotationImpl(TYPE_ANNOTATION)
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvRefTypeImpl(REF_TYPE)
MvRefTypeStartImpl(REF_TYPE_START)
PsiElement(&)('&')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('signer')
PsiElement())(')')
MvReturnTypeImpl(RETURN_TYPE)
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('bool')
PsiWhiteSpace(' ')
MvResourceAccessItemListImpl(RESOURCE_ACCESS_ITEM_LIST)
MvResourceAccessItemImpl(RESOURCE_ACCESS_ITEM)
PsiElement(reads_kw)('reads')
PsiWhiteSpace(' ')
MvAccessSpecifierListImpl(ACCESS_SPECIFIER_LIST)
MvAccessSpecifierImpl(ACCESS_SPECIFIER)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('R')
MvAddressSpecifierImpl(ADDRESS_SPECIFIER)
PsiElement(()('(')
MvAddressSpecifierArgImpl(ADDRESS_SPECIFIER_ARG)
MvPathImpl(PATH)
MvModuleRefImpl(MODULE_REF)
PsiElement(IDENTIFIER)('signer')
PsiElement(::)('::')
PsiElement(IDENTIFIER)('address_of')
PsiElement(()('(')
MvAddressSpecifierCallParamImpl(ADDRESS_SPECIFIER_CALL_PARAM)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('s')
PsiElement())(')')
PsiElement())(')')
PsiWhiteSpace(' ')
MvCodeBlockImpl(CODE_BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n\n ')
MvFunctionImpl(FUNCTION)
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('ok2')
MvFunctionParameterListImpl(FUNCTION_PARAMETER_LIST)
PsiElement(()('(')
MvFunctionParameterImpl(FUNCTION_PARAMETER)
MvBindingPatImpl(BINDING_PAT)
PsiElement(IDENTIFIER)('s')
MvTypeAnnotationImpl(TYPE_ANNOTATION)
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvRefTypeImpl(REF_TYPE)
MvRefTypeStartImpl(REF_TYPE_START)
PsiElement(&)('&')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('signer')
PsiElement())(')')
MvReturnTypeImpl(RETURN_TYPE)
PsiElement(:)(':')
PsiWhiteSpace(' ')
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('bool')
PsiWhiteSpace(' ')
MvResourceAccessItemListImpl(RESOURCE_ACCESS_ITEM_LIST)
MvResourceAccessItemImpl(RESOURCE_ACCESS_ITEM)
PsiElement(reads_kw)('reads')
PsiWhiteSpace(' ')
MvAccessSpecifierListImpl(ACCESS_SPECIFIER_LIST)
MvAccessSpecifierImpl(ACCESS_SPECIFIER)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('R')
MvAddressSpecifierImpl(ADDRESS_SPECIFIER)
PsiElement(()('(')
MvAddressSpecifierArgImpl(ADDRESS_SPECIFIER_ARG)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('address_of')
MvTypeArgumentListImpl(TYPE_ARGUMENT_LIST)
PsiElement(<)('<')
MvTypeArgumentImpl(TYPE_ARGUMENT)
MvPathTypeImpl(PATH_TYPE)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('u8')
PsiElement(>)('>')
PsiElement(()('(')
MvAddressSpecifierCallParamImpl(ADDRESS_SPECIFIER_CALL_PARAM)
MvPathImpl(PATH)
PsiElement(IDENTIFIER)('s')
PsiElement())(')')
PsiElement())(')')
PsiWhiteSpace(' ')
MvCodeBlockImpl(CODE_BLOCK)
PsiElement({)('{')
PsiElement(})('}')
PsiWhiteSpace('\n')
PsiElement(})('}')

0 comments on commit 2dcd4e0

Please sign in to comment.