From cad0de646620dc2d32896673b7dba5724a383b2e Mon Sep 17 00:00:00 2001 From: Gabriel Darbord Date: Fri, 5 Jul 2024 08:33:41 +0200 Subject: [PATCH] `Closure` entity with bound variable association --- .../FamixValueUnknownType.extension.st | 6 ++ .../FamixValueOfClosure.class.st | 41 ++++++--- .../FamixValueOfClosureVariable.class.st | 85 +++++++++++++++++++ .../FamixValueOfType.class.st | 50 +++++------ .../FamixValueTEntityCreator.trait.st | 7 ++ .../FamixValueUnknownType.class.st | 6 -- .../FamixValueGenerator.class.st | 20 ++++- 7 files changed, 170 insertions(+), 45 deletions(-) create mode 100644 src/Famix-Value-Entities/FamixValueOfClosureVariable.class.st diff --git a/src/Famix-Value-Entities-Extensions/FamixValueUnknownType.extension.st b/src/Famix-Value-Entities-Extensions/FamixValueUnknownType.extension.st index 6bfb87c..85d6b3e 100644 --- a/src/Famix-Value-Entities-Extensions/FamixValueUnknownType.extension.st +++ b/src/Famix-Value-Entities-Extensions/FamixValueUnknownType.extension.st @@ -1,5 +1,11 @@ Extension { #name : #FamixValueUnknownType } +{ #category : #'*Famix-Value-Entities-Extensions' } +FamixValueUnknownType >> acceptValueVisitor: visitor forObject: object [ + + self error: 'Exporting an unknown type is not (yet?) supported.' +] + { #category : #'*Famix-Value-Entities-Extensions' } FamixValueUnknownType >> baseName [ diff --git a/src/Famix-Value-Entities/FamixValueOfClosure.class.st b/src/Famix-Value-Entities/FamixValueOfClosure.class.st index 0eaa932..4f9aa56 100644 --- a/src/Famix-Value-Entities/FamixValueOfClosure.class.st +++ b/src/Famix-Value-Entities/FamixValueOfClosure.class.st @@ -7,7 +7,7 @@ A lexical closure. ### Other | Relation | Origin | Opposite | Type | Comment | |---| -| `value` | `FamixValueOfClosure` | `closure` | `FamixValueOfType` | | +| `variables` | `FamixValueOfClosure` | `closure` | `FamixValueOfClosureVariable` | | ## Properties @@ -15,16 +15,15 @@ A lexical closure. | Name | Type | Default value | Comment | |---| -| `value` | `Object` | nil | Value data represented as a native Smalltalk object.| +| `sourceCode` | `String` | nil | The source code of the lexical closure.| " Class { #name : #FamixValueOfClosure, #superclass : #FamixValueOfType, - #traits : 'FamixValueTWithValueProperty', - #classTraits : 'FamixValueTWithValueProperty classTrait', #instVars : [ - '#value => FMOne type: #FamixValueOfType opposite: #closure' + '#sourceCode => FMProperty', + '#variables => FMMany type: #FamixValueOfClosureVariable opposite: #closure' ], #category : #'Famix-Value-Entities-Entities' } @@ -38,17 +37,39 @@ FamixValueOfClosure class >> annotation [ ^ self ] +{ #category : #adding } +FamixValueOfClosure >> addVariable: anObject [ + + ^ self variables add: anObject +] + +{ #category : #accessing } +FamixValueOfClosure >> sourceCode [ + + + + + ^ sourceCode +] + +{ #category : #accessing } +FamixValueOfClosure >> sourceCode: anObject [ + + sourceCode := anObject +] + { #category : #accessing } -FamixValueOfClosure >> value [ - "Relation named: #value type: #FamixValueOfType opposite: #closure" +FamixValueOfClosure >> variables [ + "Relation named: #variables type: #FamixValueOfClosureVariable opposite: #closure" - ^ value + + ^ variables ] { #category : #accessing } -FamixValueOfClosure >> value: anObject [ +FamixValueOfClosure >> variables: anObject [ - value := anObject + variables value: anObject ] diff --git a/src/Famix-Value-Entities/FamixValueOfClosureVariable.class.st b/src/Famix-Value-Entities/FamixValueOfClosureVariable.class.st new file mode 100644 index 0000000..6fe4698 --- /dev/null +++ b/src/Famix-Value-Entities/FamixValueOfClosureVariable.class.st @@ -0,0 +1,85 @@ +" +A variable binding in a lexical closure. + +## Relations +====================== + +### Other +| Relation | Origin | Opposite | Type | Comment | +|---| +| `closure` | `FamixValueOfClosureVariable` | `variables` | `FamixValueOfClosure` | | +| `value` | `FamixValueOfClosureVariable` | `variableInClosures` | `FamixValueOfType` | | + + +## Properties +====================== + +| Name | Type | Default value | Comment | +|---| +| `name` | `String` | nil | Name of the variable bound to the closure.| + +" +Class { + #name : #FamixValueOfClosureVariable, + #superclass : #FamixValueEntity, + #instVars : [ + '#name => FMProperty', + '#closure => FMOne type: #FamixValueOfClosure opposite: #variables', + '#value => FMOne type: #FamixValueOfType opposite: #variableInClosures' + ], + #category : #'Famix-Value-Entities-Entities' +} + +{ #category : #meta } +FamixValueOfClosureVariable class >> annotation [ + + + + + ^ self +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> closure [ + "Relation named: #closure type: #FamixValueOfClosure opposite: #variables" + + + ^ closure +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> closure: anObject [ + + + closure := anObject +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> name [ + + + + + ^ name +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> name: anObject [ + + name := anObject +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> value [ + "Relation named: #value type: #FamixValueOfType opposite: #variableInClosures" + + + ^ value +] + +{ #category : #accessing } +FamixValueOfClosureVariable >> value: anObject [ + + + value := anObject +] diff --git a/src/Famix-Value-Entities/FamixValueOfType.class.st b/src/Famix-Value-Entities/FamixValueOfType.class.st index 5871ad4..290670a 100644 --- a/src/Famix-Value-Entities/FamixValueOfType.class.st +++ b/src/Famix-Value-Entities/FamixValueOfType.class.st @@ -8,12 +8,12 @@ Abstract superclass of all ValueOf_Type_ entities. | Relation | Origin | Opposite | Type | Comment | |---| | `attributeInObjects` | `FamixValueOfType` | `value` | `FamixValueOfObjectAttribute` | | -| `closure` | `FamixValueOfType` | `value` | `FamixValueOfClosure` | | | `elementInCollections` | `FamixValueOfType` | `value` | `FamixValueOfCollectionElement` | | | `keyInDictionaries` | `FamixValueOfType` | `key` | `FamixValueOfDictionaryAssociation` | | | `type` | `FamixValueOfType` | `values` | `FamixTType` | | | `typedEntity` | `FamixValueOfType` | `values` | `FamixTTypedEntity` | | | `valueInDictionaries` | `FamixValueOfType` | `value` | `FamixValueOfDictionaryAssociation` | | +| `variableInClosures` | `FamixValueOfType` | `value` | `FamixValueOfClosureVariable` | | @@ -23,10 +23,10 @@ Class { #superclass : #FamixValueEntity, #instVars : [ '#attributeInObjects => FMMany type: #FamixValueOfObjectAttribute opposite: #value', - '#closure => FMMany type: #FamixValueOfClosure opposite: #value', '#elementInCollections => FMMany type: #FamixValueOfCollectionElement opposite: #value', '#keyInDictionaries => FMMany type: #FamixValueOfDictionaryAssociation opposite: #key', - '#valueInDictionaries => FMMany type: #FamixValueOfDictionaryAssociation opposite: #value' + '#valueInDictionaries => FMMany type: #FamixValueOfDictionaryAssociation opposite: #value', + '#variableInClosures => FMMany type: #FamixValueOfClosureVariable opposite: #value' ], #category : #'Famix-Value-Entities-Entities' } @@ -54,12 +54,6 @@ FamixValueOfType >> addAttributeInObject: anObject [ ^ self attributeInObjects add: anObject ] -{ #category : #adding } -FamixValueOfType >> addClosure: anObject [ - - ^ self closure add: anObject -] - { #category : #adding } FamixValueOfType >> addElementInCollection: anObject [ @@ -78,6 +72,12 @@ FamixValueOfType >> addValueInDictionary: anObject [ ^ self valueInDictionaries add: anObject ] +{ #category : #adding } +FamixValueOfType >> addVariableInClosure: anObject [ + + ^ self variableInClosures add: anObject +] + { #category : #accessing } FamixValueOfType >> attributeInObjects [ "Relation named: #attributeInObjects type: #FamixValueOfObjectAttribute opposite: #value" @@ -94,22 +94,6 @@ FamixValueOfType >> attributeInObjects: anObject [ attributeInObjects value: anObject ] -{ #category : #accessing } -FamixValueOfType >> closure [ - "Relation named: #closure type: #FamixValueOfClosure opposite: #value" - - - - ^ closure -] - -{ #category : #accessing } -FamixValueOfType >> closure: anObject [ - - - closure value: anObject -] - { #category : #accessing } FamixValueOfType >> elementInCollections [ "Relation named: #elementInCollections type: #FamixValueOfCollectionElement opposite: #value" @@ -196,3 +180,19 @@ FamixValueOfType >> valueInDictionaries: anObject [ valueInDictionaries value: anObject ] + +{ #category : #accessing } +FamixValueOfType >> variableInClosures [ + "Relation named: #variableInClosures type: #FamixValueOfClosureVariable opposite: #value" + + + + ^ variableInClosures +] + +{ #category : #accessing } +FamixValueOfType >> variableInClosures: anObject [ + + + variableInClosures value: anObject +] diff --git a/src/Famix-Value-Entities/FamixValueTEntityCreator.trait.st b/src/Famix-Value-Entities/FamixValueTEntityCreator.trait.st index 85b0e79..b875965 100644 --- a/src/Famix-Value-Entities/FamixValueTEntityCreator.trait.st +++ b/src/Famix-Value-Entities/FamixValueTEntityCreator.trait.st @@ -32,6 +32,13 @@ FamixValueTEntityCreator >> newOfClosure [ ^ self add: FamixValueOfClosure new ] +{ #category : #'entity creation' } +FamixValueTEntityCreator >> newOfClosureVariable [ + + + ^ self add: FamixValueOfClosureVariable new +] + { #category : #'entity creation' } FamixValueTEntityCreator >> newOfCollection [ diff --git a/src/Famix-Value-Entities/FamixValueUnknownType.class.st b/src/Famix-Value-Entities/FamixValueUnknownType.class.st index 3fcd93f..b4f1bd9 100644 --- a/src/Famix-Value-Entities/FamixValueUnknownType.class.st +++ b/src/Famix-Value-Entities/FamixValueUnknownType.class.st @@ -48,12 +48,6 @@ FamixValueUnknownType class >> annotation [ ^ self ] -{ #category : #visiting } -FamixValueUnknownType >> acceptValueVisitor: visitor forObject: object [ - - self error: 'Exporting an unknown type is not (yet?) supported.' -] - { #category : #testing } FamixValueUnknownType >> isUnknownType [ diff --git a/src/Famix-Value-Generator/FamixValueGenerator.class.st b/src/Famix-Value-Generator/FamixValueGenerator.class.st index 4cb8255..5000786 100644 --- a/src/Famix-Value-Generator/FamixValueGenerator.class.st +++ b/src/Famix-Value-Generator/FamixValueGenerator.class.st @@ -24,7 +24,8 @@ Class { 'collectionElement', 'objectAttribute', 'classReference', - 'closure' + 'closure', + 'closureVariable' ], #category : #'Famix-Value-Generator' } @@ -90,6 +91,10 @@ FamixValueGenerator >> defineClasses [ closure := builder newClassNamed: #OfClosure comment: 'A lexical closure.'. + closureVariable := builder + newClassNamed: #OfClosureVariable + comment: + 'A variable binding in a lexical closure.'. ofUnknownType := (builder newClassNamed: #OfUnknownType comment: 'A value of an unknwon type.') @@ -112,7 +117,6 @@ FamixValueGenerator >> defineHierarchy [ classReference --|> value. dictionaryAssociation --|> value. - closure --|> tWithValueProperty. "for the code" primitive --|> tWithValueProperty. ofUnknownType --|> tWithValueProperty. @@ -123,7 +127,12 @@ FamixValueGenerator >> defineHierarchy [ FamixValueGenerator >> defineProperties [ (tWithValueProperty property: #value type: #Object) comment: - 'Value data represented as a native Smalltalk object.' + 'Value data represented as a native Smalltalk object.'. + + (closure property: #sourceCode type: #String) comment: + 'The source code of the lexical closure.'. + (closureVariable property: #name type: #String) comment: + 'Name of the variable bound to the closure.' ] { #category : #definition } @@ -161,7 +170,10 @@ FamixValueGenerator >> defineRelations [ *- ((self remoteTrait: #TClass withPrefix: #Famix) property: #valueReferences). - (closure property: #value) *- (value property: #closure) + (closure property: #variables) + -* (closureVariable property: #closure). + (closureVariable property: #value) + *- (value property: #variableInClosures) ] { #category : #definition }