home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / stgrammar.tcl < prev    next >
Text File  |  1997-01-27  |  25KB  |  904 lines

  1. #--------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1997
  4. #
  5. #      File:           %W%
  6. #      Author:         <generated>
  7. #
  8. #--------------------------------------------------------------------------
  9.  
  10. #      File:           @(#)stclassimp.tcl    /main/1
  11.  
  12.  
  13. # This class represents all code generated to implement one class.
  14. # It is also responsible for method and category management:
  15. # keeping names unique and creating and assigning categories.
  16.  
  17. Class STClassImplementation : {GCObject} {
  18.     method destructor
  19.     method generate
  20.     method getInstanceMethodImplementation
  21.     method getClassMethodImplementation
  22.     method getMethodImplementation
  23.     method methodExists
  24.     method classMethodExists
  25.     constructor
  26.     method addExpression
  27.     method addCommentLine
  28.     method addInstanceVariable
  29.     method addClassVariable
  30.     method addPoolDictionary
  31.  
  32.     # Name of the class.
  33.     #
  34.     attribute name
  35.  
  36.     # The comment for this implementation.
  37.     #
  38.     attribute comment
  39.  
  40.     # List of instance variables of the class.
  41.     #
  42.     attribute instanceVars
  43.  
  44.     # List of class variables of the class.
  45.     #
  46.     attribute classVars
  47.  
  48.     # List of pool dictionaries of the class.
  49.     #
  50.     attribute poolDicts
  51.  
  52.     # The name of the super class of this class.
  53.     #
  54.     attribute super
  55.  
  56.     # Category of this class.
  57.     #
  58.     attribute category
  59.  
  60.     # Type of inheritance, empty for normal, or variable or variableByte.
  61.     #
  62.     attribute inheritanceType
  63.     attribute initialize
  64.     attribute release
  65.     attribute printOn
  66.     attribute printVars
  67.     attribute expressionSet
  68.     attribute classMethodCategory
  69.     attribute instanceMethodCategory
  70.     attribute instanceMethodImplementation
  71.     attribute classMethodImplementation
  72. }
  73.  
  74. method STClassImplementation::destructor {this} {
  75.     # Start destructor user section
  76.     # End destructor user section
  77. }
  78.  
  79.  
  80. # Generates all the code to implement one class on section stSection.
  81. # Order: Class declaration, class comment, class message categories, instance message categories,
  82. # expressions.
  83. #
  84. method STClassImplementation::generate {this stSection} {
  85.     # if there is no superclass no code was generated for this class
  86.     if { [$this super] == "" } {
  87.     return
  88.     }
  89.  
  90.     $stSection append "[$this super] [$this inheritanceType]"
  91.  
  92.     if {[$this inheritanceType] == "" } {
  93.     $stSection append "subclass"
  94.     } else {
  95.     $stSection append "Subclass"
  96.     }
  97.  
  98.     $stSection append ": #[$this name]\n"
  99.     $stSection indent +
  100.  
  101.     $stSection append "instanceVariableNames: \'"
  102.     $stSection append "[[$this instanceVars] contents]\'\n"
  103.  
  104.     $stSection append "classVariableNames: \'"
  105.     $stSection append "[[$this classVars] contents]\'\n"
  106.  
  107.     $stSection append "poolDictionaries: \'"
  108.     $stSection append "[[$this poolDicts] contents]\'\n"
  109.  
  110.     $stSection append "category: \'[$this category]\'!\n"
  111.     $stSection indent -
  112.     
  113.     if {[$this comment] != "" } {
  114.     $stSection append "\n"
  115.     $stSection append "[$this name] comment: \'"
  116.     $stSection append "[$this comment]\'!\n"
  117.     }
  118.  
  119.     foreach category [[$this classMethodCategory] values] {
  120.     $stSection append "\n"
  121.     $category generate $stSection
  122.     }
  123.  
  124.     foreach category [[$this instanceMethodCategory] values] {
  125.     $stSection append "\n"
  126.     $category generate $stSection
  127.     }
  128.  
  129.     [$this expressionSet] foreach expression {
  130.     $stSection append "\n"
  131.     $expression generate $stSection
  132.     $stSection append "!"
  133.     }
  134. }
  135.  
  136.  
  137. # Gets a method implementation object for <selector>;
  138. # creates it in category <category> if it didn't exist yet. If it existed already
  139. # the category is updated.
  140. # The old category is deleted if it is empty.
  141. # The category <category> is created if it didn't exist yet.
  142. # if <category> is empty, the implementation object is returned if it existed already.
  143. #
  144. method STClassImplementation::getInstanceMethodImplementation {this selector category} {
  145.     set selDict [$this instanceMethodImplementation]
  146.     set catDict [$this instanceMethodCategory]
  147.     return [$this getMethodImplementation $selector $category $selDict $catDict ""]
  148. }
  149.  
  150. method STClassImplementation::getClassMethodImplementation {this selector category} {
  151.     set selDict [$this classMethodImplementation]
  152.     set catDict [$this classMethodCategory]
  153.     return [$this getMethodImplementation $selector $category $selDict $catDict "class"]
  154. }
  155.  
  156.  
  157. # Shared code for getInstanceMethodImplementation and
  158. # getClassMethodImplementation.
  159. #
  160. method STClassImplementation::getMethodImplementation {this selector category selectorDict categoryDict type} {
  161.     # if category is "" return implementation if it exists
  162.     if { $category == "" } {
  163.     return [$selectorDict set $selector]
  164.     }
  165.  
  166.     # create category if needed
  167.     if [$categoryDict exists $category] {
  168.     set methodCategory [$categoryDict set $category]
  169.     } else {
  170.     set methodCategory [STMethodCategory new [$this name] $category $type]
  171.     $categoryDict set $category $methodCategory
  172.     }
  173.  
  174.     # If selector existed: check if old category gets empty:
  175.     # and delete if this is the case
  176.     if [$selectorDict exists $selector] {
  177.     set implementation [$selectorDict set $selector]
  178.     set oldCategory [$implementation methodCategory]
  179.     $implementation methodCategory $methodCategory
  180.     if [$oldCategory isEmpty] {
  181.         $categoryDict unset [$oldCategory categoryName]
  182.     }
  183.     # trash prevention: remove arguments in case method is both
  184.     # generated and defined by user.
  185.     if { ![[$implementation arguments] empty] } {
  186.         [$implementation arguments] remove 0 end
  187.     }
  188.     } else {
  189.     set implementation [STMethodImplementation new $selector $methodCategory]
  190.     $selectorDict set $selector $implementation
  191.     }  
  192.     return $implementation
  193. }
  194.  
  195.  
  196. # Returns 1 if the there is a method implementation object with the specified selector
  197. # in the instanceMethodImplementation association.
  198. #
  199. method STClassImplementation::methodExists {this selector} {
  200.     return [[$this instanceMethodImplementation] exists $selector]
  201. }
  202.  
  203.  
  204. # Returns 1 if there is a class method object with the specified selector
  205. # in the classMethodImplementation association.
  206. #
  207. method STClassImplementation::classMethodExists {this selector} {
  208.     return [[$this classMethodImplementation] exists $selector]
  209. }
  210.  
  211.  
  212. # Initializes all attributes to their specified types (lists and dictionaries)
  213. # and stores <name> in name.
  214. #
  215. constructor STClassImplementation {class this name} {
  216.     set this [GCObject::constructor $class $this]
  217.     $this instanceVars [List new]
  218.     $this classVars [List new]
  219.     $this poolDicts [List new]
  220.     $this expressionSet [List new]
  221.     $this classMethodCategory [Dictionary new]
  222.     $this instanceMethodCategory [Dictionary new]
  223.     $this instanceMethodImplementation [Dictionary new]
  224.     $this classMethodImplementation [Dictionary new]
  225.     $this name $name
  226.     # Start constructor user section
  227.     # End constructor user section
  228.     return $this
  229. }
  230.  
  231.  
  232. # Creates a new expression with contents <contents>, add it to the expression association and return it.
  233. #
  234. method STClassImplementation::addExpression {this contents} {
  235.     set expression [STExpression new $contents]
  236.     [$this expressionSet] append $expression
  237.     return $expression
  238. }
  239.  
  240.  
  241. # Add a new comment line with contents commentText to instance variable comment.
  242. #
  243. method STClassImplementation::addCommentLine {this commentText} {
  244.     if { [$this comment] != "" } {
  245.     $this comment "[$this comment]\n$commentText"
  246.     } else {
  247.     $this comment $commentText
  248.     }
  249. }
  250.  
  251.  
  252. # Adds name to instance variable list.
  253. #
  254. method STClassImplementation::addInstanceVariable {this name} {
  255.     [$this instanceVars] append $name
  256. }
  257.  
  258.  
  259. # Add name to class variable list.
  260. #
  261. method STClassImplementation::addClassVariable {this name} {
  262.     [$this classVars] append $name
  263. }
  264.  
  265.  
  266. # Add name to pool dictionary list.
  267. #
  268. method STClassImplementation::addPoolDictionary {this name} {
  269.     [$this poolDicts] append $name
  270. }
  271.  
  272. # Do not delete this line -- regeneration end marker
  273.  
  274.  
  275. #      File:           @(#)stexprpart.tcl    /main/1
  276.  
  277.  
  278. # Part of a smalltalk expression. Objects of this class are additional parts,
  279. # objects of subclass Expression are first parts.
  280.  
  281. Class STExprPart : {GCObject} {
  282.     method destructor
  283.     constructor
  284.     method generate
  285.     method generateExpressions
  286.     method addExpression
  287.     method addArgument
  288.  
  289.     # Contents of expression part.
  290.     #
  291.     attribute contents
  292.  
  293.     # Used to store block arguments.
  294.     #
  295.     attribute arguments
  296.     attribute expressionSet
  297. }
  298.  
  299. method STExprPart::destructor {this} {
  300.     # Start destructor user section
  301.     # End destructor user section
  302. }
  303.  
  304.  
  305. # Initializes the expression association, 
  306. # the arguments list and sets contents to <contents>.
  307. #
  308. constructor STExprPart {class this contents} {
  309.     set this [GCObject::constructor $class $this]
  310.     $this contents $contents
  311.     $this expressionSet [List new]
  312.     $this arguments [List new]
  313.     return $this
  314. }
  315.  
  316.  
  317. # Generates on stSection.
  318. #
  319. method STExprPart::generate {this stSection} {
  320.     # put it on same line if one line, on new lines otherwise
  321.     $stSection append [$this contents]
  322.     $stSection indent +
  323.     $this generateExpressions $stSection    
  324.     $stSection indent -
  325. }
  326.  
  327.  
  328. # Generates the subexpressions and block arguments of this expression on stSection.
  329. #
  330. method STExprPart::generateExpressions {this stSection} {
  331.     # Do block argument if it exists
  332.     set blockArgument ""
  333.     if { ![[$this arguments] empty] } {
  334.     [$this arguments] foreach argument {
  335.         set blockArgument "$blockArgument :$argument"
  336.     }
  337.     set blockArgument "$blockArgument | "
  338.     }
  339.  
  340.     # put on new line if multiple lines or line too long.
  341.     if {![[$this expressionSet] empty]} {
  342.     if {[[$this expressionSet] length] > 1 } {
  343.         set newLine 1
  344.     } else {
  345.         set contentsLength [string length [$this contents]]
  346.         set contentsLength [expr $contentsLength+[string length $blockArgument]]
  347.         set expression [[$this expressionSet] index 0]
  348.         set expressionLength [string length [$expression contents]]
  349.         if {[expr $contentsLength+$expressionLength+4] > 70 } {
  350.         set newLine 1
  351.         } else {
  352.         set newLine 0
  353.         }
  354.     }
  355.  
  356.     if $newLine {
  357.         $stSection append "\n\[$blockArgument"
  358.     } else {
  359.         $stSection append " \[$blockArgument"
  360.     }
  361.  
  362.     set first 1
  363.     [$this expressionSet] foreach expression {
  364.         if $first {
  365.         set first 0
  366.         } else {
  367.         $stSection append ".\n"
  368.         }
  369.         $expression generate $stSection
  370.     }
  371.  
  372.     $stSection append "\]"
  373.     }
  374. }
  375.  
  376.  
  377. # Create a new expression object, add it to the expression association and return it.
  378. #
  379. method STExprPart::addExpression {this contents} {
  380.     set expression [STExpression new $contents]
  381.     [$this expressionSet] append $expression
  382.     return $expression
  383. }
  384.  
  385.  
  386. # Add argument to arguments list.
  387. #
  388. method STExprPart::addArgument {this name} {
  389.     [$this arguments] append $name
  390. }
  391.  
  392. # Do not delete this line -- regeneration end marker
  393.  
  394.  
  395. #      File:           @(#)stmethodca.tcl    /main/1
  396.  
  397.  
  398. # This class represents the code generated for a method category.
  399.  
  400. Class STMethodCategory : {GCObject} {
  401.     method destructor
  402.     constructor
  403.     method generate
  404.     method isEmpty
  405.     method methodImplementationSet
  406.  
  407.     # Name of the category.
  408.     #
  409.     attribute categoryName
  410.  
  411.     # Class to which this category belongs.
  412.     #
  413.     attribute className
  414.  
  415.     # Type of this category: class or instance.
  416.     #
  417.     attribute categoryType
  418.     attribute _methodImplementationSet
  419. }
  420.  
  421. method STMethodCategory::destructor {this} {
  422.     # Start destructor user section
  423.     # End destructor user section
  424. }
  425.  
  426.  
  427. # Sets className to <className>, categoryName to <categoryName>,
  428. # categoryType to <categoryType> and initialize methodImplementation.
  429. #
  430. constructor STMethodCategory {class this className categoryName categoryType} {
  431.     set this [GCObject::constructor $class $this]
  432.     $this className $className
  433.     $this categoryName $categoryName
  434.     $this categoryType $categoryType
  435.     $this _methodImplementationSet [List new]
  436.     return $this
  437. }
  438.  
  439.  
  440. # This method generates the method category on stSection.
  441. #
  442. method STMethodCategory::generate {this stSection} {
  443.     # category header
  444.     $stSection append "![$this className] "
  445.     if { [$this categoryType] == "class" } {
  446.     $stSection append "class "
  447.     }
  448.     $stSection append "methodsFor: \'[$this categoryName]\'!\n\n"
  449.  
  450.     # methods in this category
  451.     set first 1
  452.     [$this methodImplementationSet] foreach implementation {
  453.     if  !$first {
  454.         $stSection append "\n\n"
  455.     } else {
  456.         set first 0
  457.     }
  458.     $implementation generate $stSection
  459.     }
  460.  
  461.     # closing !
  462.     $stSection append " !\n"
  463. }
  464.  
  465.  
  466. # Returns whether this category is empty
  467. # e.g. the methodImplementation association is empty.
  468. #
  469. method STMethodCategory::isEmpty {this} {
  470.     return [[$this methodImplementationSet] empty]
  471. }
  472.  
  473. # Do not delete this line -- regeneration end marker
  474.  
  475. method STMethodCategory::methodImplementationSet {this} {
  476.     return [$this _methodImplementationSet]
  477. }
  478.  
  479.  
  480. #      File:           @(#)stfile.tcl    /main/1
  481.  
  482.  
  483. # This class represents the contents of a Smalltalk file.
  484.  
  485. Class STFile : {GCObject} {
  486.     constructor
  487.     method destructor
  488.     method generate
  489.     method getImplementation
  490.     method setImplementation
  491.     method removeImplementation
  492.     attribute implementation
  493. }
  494.  
  495. constructor STFile {class this} {
  496.     set this [GCObject::constructor $class $this]
  497.     $this implementation [Dictionary new]
  498.     # Start constructor user section
  499.     # End constructor user section
  500.     return $this
  501. }
  502.  
  503. method STFile::destructor {this} {
  504.     # Start destructor user section
  505.     # End destructor user section
  506. }
  507.  
  508.  
  509. # Generates the contents of all associated objects in stSection.
  510. #
  511. method STFile::generate {this stSection} {
  512.     set first 1    
  513.     foreach implementation [[$this implementation] values] {
  514.     if $first {
  515.         set first 0
  516.     } else {
  517.         $stSection append "\n\n\n"
  518.     }
  519.     $implementation generate $stSection
  520.     } 
  521. }
  522.  
  523.  
  524. # Gets a STClassImplementation object for class 'name' and creates it if it didn't exist yet.
  525. #
  526. method STFile::getImplementation {this name} {
  527.     if [[$this implementation] exists $name] {
  528.     return [[$this implementation] set $name]
  529.     }
  530.  
  531.     set newImplementation [STClassImplementation new $name]
  532.     [[$this implementation] set $name $newImplementation
  533.     return $newImplementation
  534. }
  535.  
  536. # Do not delete this line -- regeneration end marker
  537.  
  538. method STFile::setImplementation {this name newImplementation} {
  539.     [$this implementation] set $name $newImplementation
  540. }
  541.  
  542. method STFile::removeImplementation {this name} {
  543.     [$this implementation] unset $name
  544. }
  545.  
  546.  
  547. #      File:           @(#)stmethodim.tcl    /main/1
  548.  
  549.  
  550. # This class represents a method implementation: the header, the temporary variables and the 
  551. # expressions in the body. It is also responsible for creating unique argument names.
  552.  
  553. Class STMethodImplementation : {GCObject} {
  554.     method destructor
  555.     constructor
  556.     method generate
  557.     method getNewUniqueArgumentName
  558.     method getUniqueArgumentName
  559.     method addExpression
  560.     method insertExpression
  561.     method addCommentLine
  562.     method addArgument
  563.     method addTemporary
  564.     method getArguments
  565.     method isEmpty
  566.     method methodCategory
  567.  
  568.     # The message selector of this implementation.
  569.     #
  570.     attribute selector
  571.  
  572.     # Stores argument name for each part of the selector.
  573.     # Needed for initialize.
  574.     #
  575.     attribute selectorpartToArgument
  576.  
  577.     # Used to store the non unique argument names and number of occurrences.
  578.     # Needed for efficient generation of unique names.
  579.     #
  580.     attribute argumentToFrequency
  581.  
  582.     # The argument names of this method.
  583.     #
  584.     attribute arguments
  585.  
  586.     # Temporary variables of this method.
  587.     #
  588.     attribute temporaries
  589.  
  590.     # The method comment (appears between method header and method implementation).
  591.     #
  592.     attribute comment
  593.  
  594.     # Indicates whether this method has a user code part. 
  595.     # Is considered to be 1 if isUserDefined is set.
  596.     #
  597.     attribute hasUserCodePart
  598.  
  599.     # Set if user code was found during
  600.     # regeneration.
  601.     #
  602.     attribute hasUserCode
  603.  
  604.     # Indicates whether this is a user defined method implementation.
  605.     #
  606.     attribute isUserDefined
  607.     attribute _methodCategory
  608.     attribute expressionSet
  609. }
  610.  
  611. method STMethodImplementation::destructor {this} {
  612.     # Start destructor user section
  613.     # End destructor user section
  614. }
  615.  
  616.  
  617. # Initializes the dictionaries, the associations
  618. # comment to the empty string, the *User* attributes to
  619. # 0 and the lists and sets selector to <selector>
  620. # and methodCategory to <category>.
  621. #
  622. constructor STMethodImplementation {class this selector category} {
  623.     set this [GCObject::constructor $class $this]
  624.     $this selector $selector
  625.     $this methodCategory $category
  626.     $this selectorpartToArgument [Dictionary new]
  627.     $this argumentToFrequency [Dictionary new]
  628.     $this arguments [List new]
  629.     $this temporaries [List new]
  630.     $this expressionSet [List new]
  631.     $this comment ""
  632.     $this isUserDefined 0
  633.     $this hasUserCodePart 0
  634.     $this hasUserCode 0
  635.     return $this
  636. }
  637.  
  638.  
  639. # Generates the method implementation on section stSection.
  640. # Insert regeneration markers if required.
  641. # Generate a not implemented comment if the implementation
  642. # has no expressions.
  643. #
  644. method STMethodImplementation::generate {this stSection} {
  645.     # method header
  646.     if [[$this arguments] empty] {
  647.     $stSection append "[$this selector]"
  648.     } elseif { [[$this arguments] length] == 1 } {
  649.     # Workaround for operator- as mentioned in STGOperation
  650.     if { [$this selector] == "operator-" } {
  651.         $stSection append "- [[$this arguments] index 0]"
  652.     } else {
  653.         $stSection append "[$this selector] [[$this arguments] index 0]"
  654.     }
  655.     } else {
  656.     set index 0
  657.     set selectorPartList [split [$this selector] ':']
  658.     [$this arguments] foreach argument { 
  659.         if { $index > 0 } {
  660.         $stSection append " "
  661.         }
  662.         set selectorPart [lindex $selectorPartList $index]
  663.         # trash prevention: should go away once qualifier initializer bug
  664.         # is fixed.
  665.         if { $selectorPart == "" } {
  666.         break
  667.         }
  668.         $stSection append "$selectorPart: $argument"
  669.         set index [expr $index+1]
  670.     }
  671.     }
  672.  
  673.     # comment,     temporaries, "Generated" comment
  674.     # This comment is put in methods without user code
  675.     $stSection indent +
  676.     if {[$this comment] != ""} {
  677.     $stSection append "\n\"[$this comment]\""
  678.     }
  679.     if { (![$this isUserDefined]) && ![$this hasUserCodePart] } {
  680.     $stSection append "\n\"Generated\""
  681.     }
  682.     if {![[$this temporaries] empty]} {
  683.     $stSection append "\n| [[$this temporaries] contents] |"
  684.     }
  685.  
  686.     # expressions
  687.     set index 0
  688.     set exprCnt [[$this expressionSet] length]
  689.     [$this expressionSet] foreach expression {
  690.     if { $index > 0 } {
  691.         $stSection append ".\n"
  692.     } else {
  693.         $stSection append "\n"
  694.     }
  695.  
  696.     # if there was user added code it is in the last expression
  697.     # generate this without indent and place a separator if necessary
  698.     if  { [$this hasUserCode] && ($index == [expr $exprCnt-1]) } {
  699.         if { $index > 0 } {
  700.         $stSection append "[$globals startUserCodeMarker]\n"
  701.         }
  702.         $stSection indent -
  703.     }
  704.  
  705.     $expression generate $stSection
  706.  
  707.     set index [expr $index+1]
  708.     }
  709.  
  710.     if  ![$this hasUserCode] {
  711.     if [$this isUserDefined] {
  712.         if { $exprCnt > 0 } {
  713.         $stSection append ".\n[$globals startUserCodeMarker]"
  714.         }
  715.         $stSection append "\n\"Not yet implemented\""
  716.     } elseif [$this hasUserCodePart] {
  717.         if { $exprCnt > 0 } {
  718.         $stSection append "."
  719.         }
  720.         $stSection append "\n[$globals startUserCodeMarker]"
  721.     }
  722.     $stSection indent -
  723.     }
  724.     # closing !
  725.     $stSection append "!"
  726. }
  727.  
  728.  
  729. # Gets a new unique argument name and adds it to argument list.
  730. #
  731. method STMethodImplementation::getNewUniqueArgumentName {this name} {
  732.     if [[$this argumentToFrequency] exists $name] {
  733.     set frequency [[$this argumentToFrequency] set $name]
  734.     set uniqueName "$name$frequency"
  735.     [$this argumentToFrequency] set $name [expr $frequency+1]
  736.     } else {
  737.     set uniqueName $name
  738.     [$this argumentToFrequency] set $name 1
  739.     }
  740.     
  741.     [$this arguments] append $uniqueName
  742.     return $uniqueName
  743. }
  744.  
  745.  
  746. # If selectorpart existed in selectorpartToArgument, return argument.
  747. # If not get unique argument name for this selector part and store it in selectorPartToArgument.
  748. #
  749. method STMethodImplementation::getUniqueArgumentName {this selectorpart {name ""}} {
  750.     if [[$this selectorpartToArgument] exists $selectorpart] {
  751.     return [[$this selectorpartToArgument] set $selectorpart]
  752.     }
  753.  
  754.     set uniqueName [$this getNewUniqueArgumentName $name]
  755.     [$this selectorpartToArgument] set $selectorpart $uniqueName
  756.     return $uniqueName
  757. }
  758.  
  759.  
  760. # Create new expression object with contents <contents>, add it to the expression association and return it.
  761. #
  762. method STMethodImplementation::addExpression {this contents} {
  763.     set expression [STExpression new $contents]
  764.     [$this expressionSet] append $expression
  765.     return $expression
  766. }
  767.  
  768.  
  769. # Create new expression with contents contents, insert in the expression association and return it.
  770. #
  771. method STMethodImplementation::insertExpression {this contents} {
  772.     set expression [STExpression new $contents]
  773.     [$this expressionSet] insert $expression
  774.     return $expression
  775. }
  776.  
  777.  
  778. # Add new line with <commentText> to comment.
  779. #
  780. method STMethodImplementation::addCommentLine {this commentText} {
  781.     if { [$this comment] != "" } {
  782.     $this comment "[$this comment]\n$commentText"
  783.     } else {
  784.     $this comment $commentText
  785.     }
  786. }
  787.  
  788.  
  789. # Add argument name to argument list.
  790. #
  791. method STMethodImplementation::addArgument {this name} {
  792.     [$this arguments] append $name
  793. }
  794.  
  795.  
  796. # Add temporary name to temporaries list.
  797. #
  798. method STMethodImplementation::addTemporary {this name} {
  799.     [$this temporaries] append $name
  800. }
  801.  
  802.  
  803. # Return list of argument names.
  804. #
  805. method STMethodImplementation::getArguments {this} {
  806.     return [$this arguments]
  807. }
  808.  
  809.  
  810. # Returns 1 if the expression association is empty, 0 otherwise.
  811. #
  812. method STMethodImplementation::isEmpty {this} {
  813.     return [[$this expressionSet] empty]
  814. }
  815.  
  816. # Do not delete this line -- regeneration end marker
  817.  
  818. method STMethodImplementation::methodCategory {this args} {
  819.     if {$args == ""} {
  820.         return [$this _methodCategory]
  821.     }
  822.     set ref [$this _methodCategory]
  823.     if {$ref != ""} {
  824.         [$ref _methodImplementationSet] removeValue $this
  825.     }
  826.     set obj [lindex $args 0]
  827.     if {$obj != ""} {
  828.         [$obj _methodImplementationSet] append $this
  829.     }
  830.     $this _methodCategory $obj
  831. }
  832.  
  833.  
  834. #      File:           @(#)stexpressi.tcl    /main/1
  835.  
  836.  
  837. # This class represents one Smalltalk expression.
  838. # It always contains the first part of an expression. If there are more
  839. # parts, these are stored in STExprPart objects.
  840. # This is an optimization compared to the syntax,
  841. # suggested by the fact that additional parts are not very often used by the code generator.
  842. # For regeneration the user added expressions are considered as one expression.
  843.  
  844. Class STExpression : {STExprPart} {
  845.     constructor
  846.     method destructor
  847.     method generate
  848.     method addExpressionPart
  849.     attribute expressionPartSet
  850. }
  851.  
  852. constructor STExpression {class this contents} {
  853.     set this [STExprPart::constructor $class $this $contents]
  854.     $this expressionPartSet [List new]
  855.     # Start constructor user section
  856.     # End constructor user section
  857.     return $this
  858. }
  859.  
  860. method STExpression::destructor {this} {
  861.     # Start destructor user section
  862.     # End destructor user section
  863.     $this STExprPart::destructor
  864. }
  865.  
  866.  
  867. # Generates expression contents on stSection.
  868. #
  869. method STExpression::generate {this stSection} {
  870.     $stSection append [$this contents]
  871.     $stSection indent +
  872.  
  873.     # if there are xpression parts use extra indent
  874.     set numberParts [[$this expressionPartSet] length]
  875.     if $numberParts {
  876.     $stSection indent +
  877.     }
  878.  
  879.     $this generateExpressions $stSection
  880.  
  881.     $stSection indent -
  882.     
  883.     # now the other expression parts    
  884.     if $numberParts {
  885.     [$this expressionPartSet] foreach expressionPart {
  886.         $stSection append "\n"
  887.         $expressionPart generate $stSection
  888.     }
  889.     $stSection indent -
  890.     }    
  891. }
  892.  
  893.  
  894. # Creates an ExprPart object, adds it to the expressionPart association and returns it.
  895. #
  896. method STExpression::addExpressionPart {this contents} {
  897.     set expressionPart [STExprPart new $contents]
  898.     [$this expressionPartSet] append $expressionPart
  899.     return $expressionPart
  900. }
  901.  
  902. # Do not delete this line -- regeneration end marker
  903.  
  904.