Dear list,
I am working on code generation. In this work I found a compilation problem. I try to compile conditionally a class in a namespace. If there is no class of that name in an imported namespace, there is no problem. However in the next case the class did not compile. Generated code: <?xml version="1.0" encoding="UTF-8"?> <st-source> <time-stamp> This is generated code from GIPA (Generator of Integrity Preserving Associations) GIPA is developed by Reinier van Oosten 2009 [hidden email] March 10, 2009 22:03:25.327 </time-stamp> <do-it package="Lb-domain">LbTest ifNil:[ Smalltalk defineNameSpace: 'LbTest' private: false imports: 'private Smalltalk.* private XML.* private GIPA.* ' category: 'Lb-domain' attributes: #( #(#package 'Lb-domain'))]</do-it> <do-it package="Lb-domain">Smalltalk at: 'LbTest.Event' ifAbsent: [LbTest defineClass: #Event superclass: #{Core.Object} indexedType: #none private: false instanceVariableNames: ' ' classInstanceVariableNames: ' ' imports: ' ' category: 'Lb-domain' attributes: #(#(#package 'Lb-domain'))]</do-it> </st-source> First I define, if necessary, the namespace LbTest. Then I create the class LbTest.Event. The result in the changes file shows that the namespace is created, however the class is not. I also created a class LbTest.Meet, which was created. The following piece of code and the way the system is reacting on it is more disturbing. <?xml version="1.0" encoding="UTF-8"?> <st-source> <time-stamp> This is generated code from GIPA (Generator of Integrity Preserving Associations) GIPA is developed by Reinier van Oosten 2009 [hidden email] March 10, 2009 22:03:25.327 </time-stamp> <do-it package="Lb-domain">LbTest.Event addInstVarName: 'daytime'</do-it> <methods> <class-id>LbTest.Event</class-id> <category>attribute-accessing</category> <body package="Lb-domain" selector="daytime:"> daytime: anObject "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten [hidden email] " | theObject | theObject := anObject. (theObject isKindOf: Core.Time) ifFalse:[self error: 'Wrong type for attribute daytime']. daytime := theObject</body> <body package="Lb-domain" selector="daytime"> daytime "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten [hidden email] " ^daytime</body> </methods> </st-source> I add the variable daytime to the class LbTest.Event and add some methods to that class. The log from the changes are very informative however unexpected. I show here the entries in the changeList tool Smalltalk.UI defineClass: #Event superclass: #{Core.Object} indexedType: #none private: false instanceVariableNames: 'time initiator window daytime ' classInstanceVariableNames: '' imports: '' category: 'Interface-Events' attributes: #( #(#package 'Interface-Events')) daytime: anObject "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " | theObject | theObject := anObject. (theObject isKindOf: Core.Time) ifFalse:[self error: 'Wrong type for attribute daytime']. daytime := theObject daytime "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " ^daytime Apparently the system finds the class Smalltalk.UI.Event, and instead of creating a new class LbTest.Event it works with UI.Event. This is not expected and for sure not something you want. _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Reinier,
I think your class creation do-it is incorrect. You start with the test:
Smalltalk at: ‘LbTest.Event’ ifAbsent: […]
Smalltalk won’t find the string ‘LbTest.Event’ – that is, as a name space, Smalltalk only has keys of symbols, and they are completely unqualified. Thus, the name space UI, under Smalltalk, exists with key #OS, etc.
What I think you want is a test like this instead:
#{LbTest.Event} isDefined ifFalse: […]
You want to resolve the name #Event in the context of its namespace, #LbTest, so you have to use a qualified reference. Otherwise, as it did, it will resolve the name #Event to class UI.Event.
Cheers!
From:
[hidden email] [mailto:[hidden email]] On Behalf Of reinier van oosten
Dear list,
I am working on code generation. In this work I found a compilation problem.
I try to compile conditionally a class in a namespace. If there is no class of that name in an imported namespace, there is no problem. However in the next case the class did not compile.
Generated code:
<?xml version="1.0"
encoding="UTF-8"?>
First I define, if necessary, the namespace LbTest. Then I create the class LbTest.Event. The result in the changes file shows that the namespace is created, however the class is not. I also created a class LbTest.Meet, which was created.
The following piece of code and the way the system is reacting on it is more disturbing.
<?xml version="1.0"
encoding="UTF-8"?>
I add the variable daytime to the class LbTest.Event and add some methods to that class. The log from the changes are very informative however unexpected. I show here the entries in the changeList tool
Smalltalk.UI defineClass: #Event superclass: #{Core.Object} indexedType: #none private: false instanceVariableNames: 'time initiator window daytime ' classInstanceVariableNames: '' imports: '' category: 'Interface-Events' attributes: #( #(#package 'Interface-Events'))
daytime: anObject "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " | theObject | theObject := anObject. (theObject isKindOf: Core.Time) ifFalse:[self error: 'Wrong type for attribute daytime']. daytime := theObject
daytime "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " ^daytime
Apparently the system finds the class Smalltalk.UI.Event, and instead of creating a new class LbTest.Event it works with UI.Event. This is not expected and for sure not something you want.
Reinier van Oosten Pelschans 7 2728 GV Zoetermeer
tel: 079-3437073 gsm: 0651335993 email: [hidden email]
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Hello Thomas,
Thank you for your response. I tried it, but it didn't work. The result is the same as before. I think the crux is that in namespace LbTest the class Event is imported. I will try whether the namespace of the found class is actually LbTest. Reinier van Oosten Pelschans 7 2728 GV Zoetermeer tel: 079-3437073 gsm: 0651335993 email: [hidden email] On 10 Mar 2009, at 23:06, <[hidden email]> wrote:
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by thomas.hawker
Reinier,
Actually, you could change the test to:
(LbTest localBindingFor: #Event) isNil ifTrue: […]
That check won’t look at imported definitions.
Then again, maybe you shouldn’t use the class name #Event just to avoid the ambiguity.
Cheers!
From: reinier van
oosten [mailto:[hidden email]]
Hello Thomas,
Thank you for your response. I tried it, but it didn't work. The result is the same as before.
I think the crux is that in namespace LbTest the class Event is imported. I will try whether the namespace of the found class is actually LbTest. Reinier van Oosten Pelschans 7 2728 GV Zoetermeer
tel: 079-3437073 gsm: 0651335993 email: [hidden email]
On 10 Mar 2009, at 23:06, <[hidden email]> wrote:
Reinier,
I think your class creation do-it is incorrect. You start with the test:
Smalltalk at: ‘LbTest.Event’ ifAbsent: […]
Smalltalk won’t find the string ‘LbTest.Event’ – that is, as a name space, Smalltalk only has keys of symbols, and they are completely unqualified. Thus, the name space UI, under Smalltalk, exists with key #OS, etc.
What I think you want is a test like this instead:
#{LbTest.Event} isDefined ifFalse: […]
You want to resolve the name #Event in the context of its namespace, #LbTest, so you have to use a qualified reference. Otherwise, as it did, it will resolve the name #Event to class UI.Event.
Cheers!
From: [hidden email] [[hidden email]] On
Behalf Of reinier van
oosten
Dear list,
I am working on code generation. In this work I found a compilation problem.
I try to compile conditionally a class in a namespace. If there is no class of that name in an imported namespace, there is no problem. However in the next case the class did not compile.
Generated code:
<?xml version="1.0"
encoding="UTF-8"?>
First I define, if necessary, the namespace LbTest. Then I create the class LbTest.Event. The result in the changes file shows that the namespace is created, however the class is not. I also created a class LbTest.Meet, which was created.
The following piece of code and the way the system is reacting on it is more disturbing.
<?xml version="1.0"
encoding="UTF-8"?>
I add the variable daytime to the class LbTest.Event and add some methods to that class. The log from the changes are very informative however unexpected. I show here the entries in the changeList tool
Smalltalk.UI defineClass: #Event superclass: #{Core.Object} indexedType: #none private: false instanceVariableNames: 'time initiator window daytime ' classInstanceVariableNames: '' imports: '' category: 'Interface-Events' attributes: #( #(#package 'Interface-Events'))
daytime: anObject "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " | theObject | theObject := anObject. (theObject isKindOf: Core.Time) ifFalse:[self error: 'Wrong type for attribute daytime']. daytime := theObject
daytime "This is generated code from GIPA for attribute daytime GIPA is developed by Reinier van Oosten " ^daytime
Apparently the system finds the class Smalltalk.UI.Event, and instead of creating a new class LbTest.Event it works with UI.Event. This is not expected and for sure not something you want.
Reinier van Oosten Pelschans 7 2728 GV Zoetermeer
tel: 079-3437073 gsm: 0651335993 email: [hidden email]
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Hello Thomas,
I tried it in two ways: Smalltalk at: 'LbTest.Event' ifAbsent: []. targetClass ifNotNil: [targetClass environment fullName = 'LbTest' ifFalse:[targetClass := nil]]. targetClass ifNil:[....] and (LbTest localBindingFor: #Event) ifNil: [...] Both worked. I prefer your solution. Thank you for sharing your ideas. I agree with you that you shouldn't use the class name #Event. But this is the result of code generation under development. In the end this should lead to a publishable parcel. Others may not be as prudent. In this respect I'm happy to have stumbled in this problem. On 11 Mar 2009, at 00:08, <[hidden email]> wrote:
_______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |