Skip to content

Commit

Permalink
Merge pull request #139 from moosetechnology/resolving-intrinsic-rout…
Browse files Browse the repository at this point in the history
…ines

Introduced list of "intrinsic routines" and resolve invocation of these
  • Loading branch information
NicolasAnquetil committed Jun 15, 2024
2 parents 2b24bac + c5fe05d commit 6f58af4
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 21 deletions.
40 changes: 40 additions & 0 deletions src/EsopeImporter-Tests/FamixEsopeResolverTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,46 @@ FamixEsopeResolverTest >> testResolveIncludeDirective [
self assert: sub inclusions anyOne includedBy equals: main
]

{ #category : #tests }
FamixEsopeResolverTest >> testResolveInvocationToIntrinsic [
| invocation callee caller |

caller := (self defaultMain: 'main')
addOutgoingInvocation: (self defaultInvocation: 'cos');
yourself.

resolver resolve.

self assert: caller outgoingInvocations size equals: 1.
invocation := caller outgoingInvocations first.

self assert: invocation class equals: FamixF77Invocation.
self assert: invocation sender equals: caller.

self assert: invocation candidates size equals: 1.
self assert: invocation candidates first class equals: FamixF77IntrinsicRoutine.
]

{ #category : #tests }
FamixEsopeResolverTest >> testResolveInvocationToWrite [
| invocation caller |

caller := (self defaultMain: 'main')
addOutgoingInvocation: (self defaultInvocation: 'write');
yourself.

resolver resolve.

self assert: caller outgoingInvocations size equals: 1.
invocation := caller outgoingInvocations first.

self assert: invocation class equals: FamixF77Invocation.
self assert: invocation sender equals: caller.

self assert: invocation candidates size equals: 1.
self assert: invocation candidates first class equals: FamixF77IntrinsicRoutine.
]

{ #category : #tests }
FamixEsopeResolverTest >> testResolveInvocations [
| invocation callee caller |
Expand Down
39 changes: 20 additions & 19 deletions src/EsopeImporter/FamixEsopeResolver.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Class {
#category : #'EsopeImporter-Importer'
}

{ #category : #'as yet unclassified' }
FamixEsopeResolver class >> intrinsicRoutines [

^#( abort . abs . access . achar . acos . adjustl . adjustr . aimag . aint . alarm . all . allocated . alog . alog10 . amax0 . amax1 . amin0 . amin1 . amod . and . anint . any . asin . associated . atan . atan2 . besj0 . besj1 . besjn . besy0 . besy1 . besyn . bit_size . btest . cabs . ccos . ceiling . cexp . char . chdir . chmod . clog . cmplx . complex . conjg . cos . cosh . count . cpu_time . cshift . csin . csqrt . ctime . ctime . dabs . dacos . dasin . datan . datan2 . date_and_time . dbesj0 . dbesj1 . dbesjn . dbesy0 . dbesy1 . dbesyn . dble . dcos . dcosh . ddim . derf . derfc . dexp . digits . dim . dint . dlog . dlog10 . dmax1 . dmin1 . dmod . dnint . dot_product . dprod . dsign . dsin . dsinh . dsqrt . dtan . dtanh . dtime . eoshift . epsilon . erf . erfc . etime . etime . exit . exp . exponent . fdate . fdate . fget . fgetc . float . floor . flush . fnum . fput . fputc . fraction . fseek . fstat . fstat . ftell . ftell . gerror . getarg . getcwd . getcwd . getenv . getgid . getlog . getpid . getuid . gmtime . hostnm . hostnm . huge . iabs . iachar . iand . iargc . ibclr . ibits . ibset . ichar . idate . idim . idint . idnint . ieor . ierrno . ifix . imag . imagpart . index . int . int2 . int8 . ior . irand . isatty . ishft . ishftc . isign . itime . kill . kind . lbound . len . len_trim . lge . lgt . link . lle . llt . lnblnk . loc . log . log10 . logical . long . lshift . lstat . lstat . ltime . matmul . max . max0 . max1 . maxexponent . maxloc . maxval . mclock . mclock8 . merge . min . min0 . min1 . minexponent . minloc . minval . mod . modulo . mvbits . nearest . nint . not . or . pack . perror . precision . present . product . radix . rand . random_number . random_seed . range . real . realpart . rename . repeat . reshape . rrspacing . rshift . scale . scan . second . second . selected_int_kind . selected_real_kind . set_exponent . shape . short . sign . signal . sin . sinh . sleep . sngl . spacing . spread . sqrt . srand . stat . stat . sum . symlnk . system . system_clock . tan . tanh . time . time8 . tiny . transfer . transpose . trim . ttynam . ttynam . ubound . umask . unlink . unpack . verify . write . xor . zabs . zcos . zexp . zlog . zsin . zsqrt )
]

{ #category : #'private-helper' }
FamixEsopeResolver class >> on: aMooseModel [
"Answer an instance with same model as aMooseModel."
Expand All @@ -31,14 +37,20 @@ FamixEsopeResolver >> errorHandler: anErrorHandler [
errorHandler := anErrorHandler
]

{ #category : #'private - utility' }
{ #category : #private }
FamixEsopeResolver >> implicitTypeFor: name inProgramUnit: programUnit [
"find a type according to the first letter of the variable's name"

^ programUnit implicitDictionary at: name first ifAbsent: [ FamixF77TypeUnknown defaultName ]
]

{ #category : #'private - import' }
{ #category : #private }
FamixEsopeResolver >> isIntrinsicRoutine: invocated [

^self class intrinsicRoutines includes: invocated entityName
]

{ #category : #private }
FamixEsopeResolver >> mergeVariable: variableToRemove into: variableToKeep [
"merge meaningfull properties from variableToRemove into variableToKeep
then remove links between variableToRemove and other entities (associations are
Expand Down Expand Up @@ -80,7 +92,7 @@ FamixEsopeResolver >> model: anObject [
model := anObject
]

{ #category : #'private-creation' }
{ #category : #private }
FamixEsopeResolver >> newEntity: aFamixClass [
^aFamixClass new
mooseModel: model;
Expand Down Expand Up @@ -138,19 +150,6 @@ FamixEsopeResolver >> registerImplicitsForPU: programUnit [
]
]

{ #category : #'private - utility' }
FamixEsopeResolver >> removeAttribute: aSymbol fromEntity: anEntity [

| entity |
entity := anEntity
attributeAt: aSymbol
ifAbsent: [ nil ].

anEntity attributeAt: aSymbol put: nil.

^entity
]

{ #category : #'symbols resolution' }
FamixEsopeResolver >> requalifyFunctionDeclaration: external [
"external declaration of function followed by a VariableDeclaration of the same function
Expand Down Expand Up @@ -400,7 +399,8 @@ FamixEsopeResolver >> resolveInvocables: invocable [

(model allWithSubTypesOf: FamixF77PUProcedure)
do: [ :entity |
((entity name = invocable entityName) and: [ entity parameters size = (invocable arguments ifNil: [ #() ]) size ])
((entity name = invocable entityName) and:
[ entity parameters size = (invocable arguments ifNil: [ #() ]) size ])
ifTrue: [ ^ entity ]
].

Expand All @@ -415,8 +415,9 @@ FamixEsopeResolver >> resolveInvocation: anInvocation [
invocated := anInvocation getAndRemoveAttribute: #entity .

(self resolveInvocables: invocated)
ifNotNil: [ :invocatedFound |
anInvocation addCandidate: invocatedFound ]
ifNotNil: [ :invocatedFound | anInvocation addCandidate: invocatedFound ]
ifNil: [ (self isIntrinsicRoutine: invocated)
ifTrue: [ anInvocation addCandidate: (model newIntrinsicRoutine name: invocated entityName) ] ]
]

{ #category : #run }
Expand Down
10 changes: 10 additions & 0 deletions src/EsopeImporter/FamixF77IntrinsicRoutine.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Extension { #name : #FamixF77IntrinsicRoutine }

{ #category : #'*EsopeImporter' }
FamixF77IntrinsicRoutine >> famixImportSanityCheck [
"not calling super because does not have a parent Programfile"

self
assert: self incomingInvocations isNotEmpty
description: name , ' without invocations'.
]
7 changes: 7 additions & 0 deletions src/EsopeImporter/FamixF77PUComment.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : #FamixF77PUComment }

{ #category : #'*EsopeImporter' }
FamixF77PUComment >> famixImportSanityCheck [
"same check, but PUComment does not have a name"
self assert: programFile isNotNil description: 'PUComment without parent ProgramFile'
]
2 changes: 1 addition & 1 deletion src/EsopeImporter/FamixF77PUFunction.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ FamixF77PUFunction >> famixImportSanityCheck [

super famixImportSanityCheck.

self assert: declaredType isNotNil description: 'Function without declaredType'.
self assert: declaredType isNotNil description: name , ' without declaredType'.
]
2 changes: 1 addition & 1 deletion src/EsopeImporter/FamixF77ProgramUnit.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ FamixF77ProgramUnit >> defaultImplicit [
{ #category : #'*EsopeImporter' }
FamixF77ProgramUnit >> famixImportSanityCheck [

self assert: programFile isNotNil description: 'ProgramUnit without parent ProgramFile'.
self assert: programFile isNotNil description: name , ' without parent ProgramFile'.
]

{ #category : #'*EsopeImporter' }
Expand Down

0 comments on commit 6f58af4

Please sign in to comment.