home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
pbgentor.tcl
< prev
next >
Wrap
Text File
|
1997-05-30
|
44KB
|
1,469 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1997 by Cayenne Software, Inc.
#
# This software is furnished under a license and may be used only in
# accordance with the terms of such license and with the inclusion of
# the above copyright notice. This software or any other copies thereof
# may not be provided or otherwise made available to any other person.
# No title to and ownership of the software is hereby transferred.
#
# The information in this software is subject to change without notice
# and should not be construed as a commitment by Cayenne Software, Inc.
#
#---------------------------------------------------------------------------
#
# File : pbgentor.tcl
# Author :
# Original date : May 1997
# Description : Classes for code generation
#
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# File: @(#)pbfilehand.tcl /main/hindenburg/1
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "filehandle.tcl"
Class PBFileHandler : {FileHandler} {
constructor
method destructor
method getFileTypes
method getSpecialFiles
method setImpFrom
attribute srwType
attribute srmType
attribute srsType
attribute sruType
}
constructor PBFileHandler {class this} {
set this [FileHandler::constructor $class $this]
$this srwType "window"
$this srmType "menu"
$this srsType "structure"
$this sruType "userobject"
# Start constructor user section
# End constructor user section
return $this
}
method PBFileHandler::destructor {this} {
# Start destructor user section
# End destructor user section
$this FileHandler::destructor
}
method PBFileHandler::getFileTypes {this} {
set list [List new]
$list append [$this srwType]
$list append [$this srmType]
$list append [$this srsType]
$list append [$this sruType]
return $list
}
method PBFileHandler::getSpecialFiles {this} {
return [List new]
}
method PBFileHandler::setImpFrom {this fileName class} {
$this FileHandler::setImpFrom $fileName $class
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)pbgenerato.tcl /main/hindenburg/2
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "generator.tcl"
Class PBGenerator : {Generator} {
constructor
method destructor
method generate
}
constructor PBGenerator {class this} {
set this [Generator::constructor $class $this]
# Start constructor user section
# End constructor user section
return $this
}
method PBGenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Generator::destructor
}
method PBGenerator::generate {this classList} {
set typeToClassDictionary [Dictionary new]
set pbModel [PBModel new]
set regenerator [PBRegenerator new]
set fileHandler [PBFileHandler new]
$classList foreach class {
if ![$class isGlobalType] {
continue
}
set pbdefinition [$class generate $pbModel]
if {$pbdefinition == ""} {
continue
}
set entry [$pbdefinition libraryEntry]
if {$entry == ""} {
continue
}
set fileType [$entry getFileType]
set fileDesc [$fileHandler openFile $class $fileType]
if {$fileDesc != ""} {
$regenerator regenerate $entry $fileDesc
$fileHandler closeFile $fileDesc
}
}
$pbModel generate $typeToClassDictionary
return $typeToClassDictionary
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)pbregenera.tcl /main/hindenburg/31
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "regenerato.tcl"
Class PBRegenerator : {Regenerator} {
constructor
method destructor
method regenerate
method checkEntryFiles
method processFile
method processForward
method processType
method skipType
method processVariables
method skipVariables
method processPrototypes
method processStructure
method processEntryStructure
method processEvent
method skipEvent
method processFunction
method skipFunction
method processSubroutine
method skipSubroutine
method processBinaryData
method skipBinaryData
method processOn
method skipOn
method processOnCreate
method processOnDestroy
method processParameter
attribute currentClass
attribute currentEntry
attribute obsolete
attribute pbdebug
}
constructor PBRegenerator {class this} {
set this [Regenerator::constructor $class $this]
# Start constructor user section
$this pbdebug 0
# End constructor user section
return $this
}
method PBRegenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Regenerator::destructor
}
method PBRegenerator::regenerate {this entry fileDesc} {
$this currentEntry $entry
$this obsolete 0
set oldFileDesc $fileDesc
$this currentClass [[$this currentEntry] globalDefinition]
# All functions return True (!= 0) if syntax is correctly ended.
# This allows checking of an not correctly terminated file.
# if obsolete code is present then stop
if { ![$this checkEntryFiles $entry $fileDesc]} {
return 0
}
# process file:
set line [gets $fileDesc]
if { [regexp {^(| *)\$PBExportHeader\$(.*)} $line total dummy entryFileName] } {
set line [gets $fileDesc]
}
if { [regexp {^(| *)\$PBExportComments\$(.*)} $line total dummy entryComment] } {
[$this currentEntry] exportComments $entryComment
set line [gets $fileDesc]
}
if { [regexp {^(| *)forward(.*|)} $line total] } {
$this processForward [$this currentEntry] $fileDesc
}
while { ![eof $fileDesc] } {
set line [gets $fileDesc]
if { [regexp {^(| *)global type ([^ ]*) from ([^ ]*) *}\
$line total dummy type from] } {
# when called correctly the type corresponds with currentEntry!
# if unsure a name comparison CAN be done
$this currentClass [[$this currentEntry] globalDefinition]
[$this currentClass] isRegenerated 1
if {[string tolower $from] == "structure"} {
# process type body and add variables to body of entry
set ret [$this processStructure [$this currentClass] $fileDesc]
} else {
# process type body and add variables to body of entry
set ret [$this processType [$this currentClass] $fileDesc]
}
} elseif { [regexp {^(| *)global ([^ ]*) ([^ ]*) *}\
$line total dummy type name] } {
# just to be on the save side
$this currentClass [[$this currentEntry] globalDefinition]
[$this currentClass] isRegenerated 1
} elseif { [regexp {^(| *)type variables[ ]*} $line total] } {
# first get vars TextSection
if { [[$this currentClass] isA "PBClass"] } {
if { [[$this currentClass] nonModeledInstanceVars] != "" } {
set vars [[$this currentClass] nonModeledInstanceVars]
} else {
set vars [TextSection new]
[$this currentClass] nonModeledInstanceVars $vars
}
if { [[$this currentClass] nonModeledInstanceVars] == "" } {
}
set ret [$this processVariables $vars $fileDesc]
} else {
# currentClass cannot contain instance vars though it is present
m4_warning $W_OBSOLVARS [[$this currentClass] name]
$this obsolete 1
set ret [$this skipVariables $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECT "instance variables" [[$this currentClass] name]
}
}
} elseif { [regexp {^(| *)shared variables.*} $line total] } {
# shared variables are part of entry, so set currentClass to given entry:
$this currentClass [[$this currentEntry] globalDefinition]
# first get vars TextSection
if { [[$this currentClass] isA "PBClass"] } {
if { [[$this currentClass] nonModeledSharedVars] != "" } {
set vars [[$this currentClass] nonModeledSharedVars]
} else {
set vars [TextSection new]
[$this currentClass] nonModeledSharedVars $vars
}
if { [[$this currentClass] nonModeledSharedVars] == "" } {
}
set ret [$this processVariables $vars $fileDesc]
} else {
# currentClass cannot contain instance vars though it is present
m4_warning $W_OBSOLVARS [[$this currentClass] name]
$this obsolete 1
set ret [$this skipVariables $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECT "variables" [[$this currentClass] name]
}
}
} elseif { [regexp {^(| *)forward prototypes.*} $line total] } {
set ret [$this processPrototypes [$this currentClass] $fileDesc]
} elseif { [regexp {^(| *)type ([^ ]*) from ([^ ]*) within ([^ ]*)(| | .*)}\
$line total dummy name from within] } {
# first find corresponding class (recursively)
if { [[[$this currentEntry] globalDefinition] isA "PBVisualContainer"] } {
$this currentClass [[[$this currentEntry] globalDefinition] \
findContainedClass $name 1]
if {[$this currentClass] != ""} {
[$this currentClass] isRegenerated 1
set ret [$this processType [$this currentClass] $fileDesc]
} else {
# object is gone
m4_warning $W_OBSOLPROPS $name
$this obsolete 1
set ret [$this skipType $fileDesc]
}
} else {
# a contained class is found but cannot be inserted
m4_warning $W_OBSOLCLASSENTRY $name [[$this currentEntry] getName]
$this obsolete 1
set ret [$this skipType $fileDesc]
}
} elseif { [regexp {^ *type ([^ ]*) *from *([^ ]*)(| | .*)}\
$line total name from] } {
if { [string tolower $from] == "structure" } {
# if a structure then do nothing, inserted by generator
set ret [$this skipType $fileDesc]
} elseif { [[[$this currentEntry] globalDefinition] isA "PBVisualContainer"] } {
# first find corresponding class (recursively)
$this currentClass [[[$this currentEntry] globalDefinition] \
findContainedClass $name 1]
if {[$this currentClass] != ""} {
[$this currentClass] isRegenerated 1
set ret [$this processType [$this currentClass] $fileDesc]
} else {
# object is gone
m4_warning $W_OBSOLPROPS $name
$this obsolete 1
set ret [$this skipType $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECT "type" $name
}
}
} else {
# a contained class is found but cannot be inserted
m4_warning $W_OBSOLCLASSENTRY $name [[$this currentEntry] getName]
$this obsolete 1
set ret [$this skipType $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECT "type" [[$this currentClass] name]
}
}
} elseif { [regexp {^ *event *([^ ]*) *; *(call[^;]*;|)(.*)$}\
$line total name callSuper methLine e1 e2] } {
# first check for association method
if { [regexp "^ *${PBCookie::associationAccessorMethod}" $methLine] } {
# association
set ret [$this skipEvent $fileDesc]
} elseif { [$this currentClass] == "" } {
$this obsolete 1
set ret [$this skipEvent $fileDesc]
} else {
set body ""
# first find corresponding function
# so check whether it can have functions:
if { ![[$this currentClass] isA "PBClass"] } {
# currentClass cannot contain events though it is present
m4_warning $W_OBSOLEVENTCLASS $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipEvent $fileDesc]
} else {
set event [[$this currentClass] findEvent $name]
if { $event != "" } {
# perfect matching method, if it has a body then move this body to
# another method (check function, not the events (no event overloading))
if { [$event body] != ""} {
# body is already filled, although this was perfect match, so find
# other and move body to other matching function (by name only)
set body [$event body]
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
$func body $body
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLEVENT $name [[$this currentClass] name]
$this obsolete 1
}
}
set body [TextSection new]
$event body $body
if { $callSuper != "" } {
$event extendAncestorScript 1
}
} else {
# find a matching function and store code in this body preceding a comment line
# not find a event (no overloading)
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
set body [TextSection new]
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
$func body $body
$body append {// Old code section}
$body append "\n"
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLEVENT $name [[$this currentClass] name]
$this obsolete 1
}
}
# if a body set then there was some match, and now fill body.
if { $body != "" } {
# processEvent checks association methods (and skip those)
set ret [$this processEvent $body $fileDesc $methLine]
} else {
# obsolete code user defined
m4_warning $W_OBSOLEVENT $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipEvent $fileDesc]
}
}
}
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "event" $name [[$this currentClass] name]
}
} elseif { [regexp {^ *(|[^ ]* )function ([^ ]*) ([^ ]*) (\([^);]*\)) *; *(.*)$}\
$line total access type name args methLine] } {
# obsolete code when not a association
if { [regexp "^ *${PBCookie::associationAccessorMethod}" $methLine] } {
# association
set ret [$this skipFunction $fileDesc]
} elseif { [$this currentClass] == "" } {
$this obsolete 1
set ret [$this skipFunction $fileDesc]
} else {
set body ""
# first find corresponding function
# so check whether it can have functions:
if { ![[$this currentClass] isA "PBClass"] } {
# currentEntry cannot contain functions though it is present
m4_warning $W_OBSOLFUNCTCLASS $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipFunction $fileDesc]
} else {
# generate parameter list for finding correct function (overloading)
set paramList [$this processParameter $args]
set function [[$this currentClass] findObjectFunction $name $paramList]
if { $function != "" } {
# perfect matching method, if it has a body then move this body to
# another method (first check function then events
if { [$function body] != ""} {
# body is already filled, although this was perfect match, so find
# other and move body to other matching function (by name only)
set body [$function body]
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
$func body $body
} else {
set event [[$this currentClass] matchEvent $name]
if {$event != ""} {
# matchE already checks for empty bodies
$event body $body
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLMETHOD $name [[$this currentClass] name]
$this obsolete 1
}
}
}
set body [TextSection new]
$function body $body
} else {
# find a matching and store code in this body preceding a comment line
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
set body [TextSection new]
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
$func body $body
$body append {// Old code section}
$body append "\n"
} else {
set event [[$this currentClass] matchEvent $name]
if {$event != ""} {
# matchE already checks for empty bodies
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
set body [TextSection new]
$event body $body
$body append {// Old code section}
$body append "\n"
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLFUNCT $name [[$this currentClass] name]
$this obsolete 1
}
}
}
# if a body set then there was some match, and now fill body.
if { $body != "" } {
# processFunction checks association methods (and skip those)
set ret [$this processFunction $body $fileDesc $methLine]
} else {
# obsolete code, user defined
$this obsolete 1
set ret [$this skipFunction $fileDesc]
}
}
}
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "function" $name [[$this currentClass] name]
}
} elseif { [regexp {^ *(|[^ ]* )subroutine ([^ ]*) (\([^);]*\)) *; *(.*)$}\
$line total access name args methLine] } {
# first check for association method
if { [regexp "^ *${PBCookie::associationAccessorMethod}" $methLine] } {
# association
set ret [$this skipSubroutine $fileDesc]
} elseif { [$this currentClass] == "" } {
$this obsolete 1
set ret [$this skipSubroutine $fileDesc]
} else {
set body ""
# first find corresponding function
# so check whether it can have functions:
if { ![[$this currentClass] isA "PBClass"] } {
# currentEntry cannot contain functions though it is present
m4_warning $W_OBSOLSUBRTCLASS $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipSubroutine $fileDesc]
} else {
# generate parameter list for finding correct function (overloading)
set paramList [$this processParameter $args]
set function [[$this currentClass] findObjectFunction $name $paramList]
if { $function != "" } {
# perfect matching method, if it has a body then move this body to
# another method (first check function then events
if { [$function body] != ""} {
# body is already filled, although this was perfect match, so find
# other and move body to other matching function (by name only)
set body [$function body]
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
$func body $body
} else {
set event [[$this currentClass] matchEvent $name]
if {$event != ""} {
# matchE already checks for empty bodies
$event body $body
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLMETHOD $name [[$this currentClass] name]
$this obsolete 1
}
}
}
set body [TextSection new]
$function body $body
} else {
# find a matching and store code in this body preceding a comment line
set func [[$this currentClass] matchObjectFunction $name]
if {$func != ""} {
# matchOF already checks for empty bodies
set body [TextSection new]
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
$func body $body
$body append {// Old code section}
$body append "\n"
} else {
set event [[$this currentClass] matchEvent $name]
if {$event != ""} {
# matchE already checks for empty bodies
m4_warning $W_OLDMETHOD $name [[$this currentClass] name]
set body [TextSection new]
$event body $body
$body append {// Old code section}
$body append "\n"
} else {
# nothing suitable found: all already filled, or no
# matching names
m4_warning $W_OBSOLSUBRT $name [[$this currentClass] name]
$this obsolete 1
}
}
}
# if a body set then there was some match, and now fill body.
if { $body != "" } {
# processSubroutine checks association methods (and skip those)
set ret [$this processSubroutine $body $fileDesc $methLine]
} else {
# obsolete code user defined
$this obsolete 1
set ret [$this skipSubroutine $fileDesc]
}
}
}
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "subroutine" $name [[$this currentClass] name]
}
} elseif { [regexp {^(| *)on ([^ .]*)\.([^ ]*) *$} $line total dummy class name ] } {
# first find corresponding class as defined by class in on
if { [$this currentClass] != "" } {
if { [[$this currentClass] name] == $class } {
set onClass [$this currentClass]
} else {
set onClass [[[$this currentEntry] globalDefinition] findContainedClass $name 1]
}
} else {
set onClass [[[$this currentEntry] globalDefinition] findContainedClass $name 1]
}
if { $onClass == "" } {
# onClass not present
m4_warning $W_OBSOLMETHCONTR $name $class
$this obsolete 1
set ret [$this skipOn $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name $class
}
} else {
# first find corresponding function
# so check whether it can have functions:
if { [$onClass isA "PBClass"] } {
if { [string tolower $name] == "destroy" } {
set methLine ""
if { [$onClass isA "PBVisual"] } {
# only Visual class has an extensive destroy section
set ret [$this processOnDestroy $onClass $fileDesc $methLine]
} else {
set ret [$this skipOn $fileDesc]
}
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [$onClass name]
}
} elseif { [string tolower $name] == "create" } {
set methLine ""
if { [$onClass isA "PBVisual"] } {
# only Visual class has an extensive create section
set ret [$this processOnCreate $onClass $fileDesc $methLine]
} else {
set ret [$this skipOn $fileDesc]
}
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [$onClass name]
}
} else {
# this is a on event (hopefully)
set event [onClass findEvent $name]
if { $event != "" } {
if { [$event body] } {
set body [$event body]
} else {
set body [TextSection new]
$event body $body
}
set ret [$this processOn $body $fileDesc $methLine ]
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [$onClass name]
}
} else {
# obsolete code
m4_warning $W_OBSOLON $name [$onClass name]
$this obsolete 1
set ret [$this skipOn $fileDesc]
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [$onClass name]
}
}
}
} else {
# currentClass cannot contain events though it is present
m4_warning $W_OBSOLONCLASS $name [$onClass name]
$this obsolete 1
set ret [$this skipOn $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [$onClass name]
}
}
}
} elseif { [regexp {^ *on ([^ ;]*) *;(.*)$} $line total name methLine] } {
# first find corresponding event
# so check whether it can have functions:
if { [$this currentClass] == "" } {
$this obsolete 1
set ret [$this skipOn $fileDesc]
} elseif { [[$this currentClass] isA "PBClass"] } {
set event [[$this currentClass] findEvent $name]
if { $event != "" } {
if { [$event body] != ""} {
set body [$event body]
} else {
set body [TextSection new]
$event body $body
}
set ret [$this processOn $body $fileDesc $methLine]
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [[$this currentClass] name]
}
} else {
# obsolete code
m4_warning $W_OBSOLON $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipOn $fileDesc]
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name [[$this currentClass] name]
}
}
} else {
# currentClass cannot contain events though it is present
m4_warning $W_OBSOLONCLASS $name [[$this currentClass] name]
$this obsolete 1
set ret [$this skipOn $fileDesc]
}
# generate syntax error if ret is false
if { [$this currentClass] == "" } {
set $tmp ""
} else {
set $tmp [[$this currentClass] name]
}
if { ! $ret } {
m4_error $E_ENDEXPECTMETHOD "on" $name $tmp
}
} elseif { [regexp "^ *${PBCookie::startBinaryDataSection}.*"\
$line total name methLine] } {
# first find corresponding event
# so check whether it can have functions:
$this currentClass [[$this currentEntry] globalDefinition]
if { [[$this currentClass] isA "PBVisualContainer"] } {
if { [$this currentClass] binaryData != "" } {
set binaryData [[$this currentClass] binaryData]
} else {
set binaryData [TextSection new]
[$this currentClass] binaryData $body
}
set ret [$this processBinaryData $binaryData $fileDesc]
# generate syntax error if ret is false
if { ! $ret } {
m4_error $E_ENDEXPECTBINARY [[$this currentClass] name]
}
} else {
# currentClass cannot contain events though it is present
m4_warning $W_OBSOLBINARY [[$this currentClass] name]
$this obsolete 1
set ret [$this skipBinaryData $fileDesc]
if { ! $ret } {
m4_error $E_ENDEXPECTBINARY [[$this currentClass] name]
}
}
} elseif { [regexp {^ *$} $line] } {
set ret 1
} else {
puts "Unexpected syntax: $line"
puts " Must be a begin-line of a section (eg. method, type declaration)"
puts " Possibly a wrong end-line (eg. end-line inside comment)"
set ret 0
}
# end parser
if { ! $ret } {
# something went wrong
m4_error $E_STOP [[$this currentEntry] getName]
return
# return 0
}
}
if { [$this obsolete] == 1 } {
# read file pointed by setting pointer back and reread it
seek $fileDesc 0
set cont [TextSection new]
while { ![eof $fileDesc] } {
$cont append "[gets $fileDesc]\n"
}
# write old file
set oldFileHandler [PBFileHandler new]
$oldFileHandler writeSectionToFile $cont [[[$this currentEntry] globalDefinition] ooplClass]\
"old.[[$this currentEntry] getFileType]"
}
# everthing went succesfully (maybe some obsolete code)
return
# return 1
}
method PBRegenerator::checkEntryFiles {this entry fileDesc} {
# if any .old file is present stop regenerating!
set files [fstorage::dir]
if {[regexp {\.old} $files]} {
m4_error $E_HASOLD
return 0
} else {
return 1
}
}
method PBRegenerator::processFile {this entry fileDesc} {
# !! Implement this function !!
}
method PBRegenerator::processForward {this entry fileDesc} {
# read and skip all lines until a "end forward"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end forward[ \t]*$} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processType {this class fileDesc} {
# read and parse all lines until a "end type"
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
set type ""
set typename ""
set eventname ""
set value ""
if { [regexp {^end type[ \t]*$} $line ] } {
set done 1
break
}
if { [regexp {^ *([^ ]*) ([^ =]*) *=[ ]*([^\{ ].*)$}\
$line total type typename value] } {
} elseif { [regexp {^ *([^ ]*) ([^ =]*) *=[ ]*(\{[^\{\}]*\})}\
$line total type typename value] } {
} elseif { [regexp {^ *([^ ]*) ([^ =]*) *=[ ]*(\{[^\}]*)$}\
$line total type typename value] } {
# append value until closing brace is read
set end 0
while {![eof $fileDesc] && !$end } {
set line [gets $fileDesc]
if { [regexp {[^\}]*\}} $line] } {
set end 1
set value "$value\n$line"
} else {
set value "$value\n$line"
}
}
} elseif { [regexp {^ *event ([^ ]*) ([^ ]*)}\
$line total eventname eventid] } {
} elseif { [regexp {^ *event type ([^ ]*) ([^ ]*) \( \)} \
$line total type eventname] } {
} elseif { [regexp {^ *event ([^ ]*) (\([^\)]*\))} \
$line total eventname] } {
} elseif { [regexp {([^ ]*) ([^ ]*)} $line total type name] } {
if { $type == $name } {
# equals so probable a contained element
} else {
# a declared something
set typename $name
}
} else {
}
# if there is a typename add a builtin property to the class
if { [$class isA "PBVisual"] } {
if { $typename != "" && \
[string tolower $typename] != "menuname" && \
[string tolower $typename] != "windowtype"} {
$class setBuiltinProperty $typename \
[PBBuiltinProperty new $typename $type $value \
-where ${PBBuiltinProperty::InTypeDef} ]
}
}
}
# generate syntax error because done not set
if { !$done } {
m4_error $E_ENDEXPECT "type" [$class name]
}
set ret $done
return $ret
}
method PBRegenerator::skipType {this fileDesc} {
# read and skip all lines until a "end type"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end type[ \t]*} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processVariables {this vars fileDesc} {
# read and skip all lines (= variables) except those after
# the non-modelled user defined attributes (and Declare ... ;) )
set done 0
# process variable section
# return false if eof
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end variables[ \t]*$} $line ] } {
# exit all
set done 1
} elseif { [regexp {^ *DECLARE.*} [string toupper $line] ] } {
# declared SQL query/function, non-object-team support so user defined:
$vars append $line
$vars append "\n"
# read all lines until a line ends with ";"
set declare 0
while { ![eof $fileDesc] && !$declare } {
set line [gets $fileDesc]
if { [regexp {[^;]*;.*} $line ] } {
$vars append $line
$vars append "\n"
set declare 1
} elseif { [regexp {^end variables[ \t]*} $line ] } {
# exit all
set done 1
set declare 1
m4_error $E_DECLARESYNTAX [[$this currentClass] name]
} else {
$vars append $line
$vars append "\n"
}
}
} elseif { [regexp "${PBCookie::nonModeledAttributeSection}" $line ] } {
# read all lines until next section (or "end variables" or EOF)
set next 0
set emptyLine 0
set emptyLineStr ""
while { ![eof $fileDesc] && !$next } {
set line [gets $fileDesc]
if { [regexp {^end variables[ \t]*$} $line ] } {
# exit all
set done 1
set next 1
} elseif { [regexp {^[ \t]*$} $line] } {
# some special empty line handling
# when empty line remember this and
# only store this line when NOT end of section
if { $emptyLine == 1 } {
# when already an empty line in buffer store this one
$vars append $emptyLineStr
$vars append "\n"
} else {
set emptyLine 1
set emptyLineStr $line
}
} elseif { ![regexp "${PBCookie::dataAttributeSection}" $line] && \
![regexp "${PBCookie::associationAttributeSection}" $line] && \
![regexp "${PBCookie::controlClassMapSection}" $line] } {
if { $emptyLine == 1 } {
# there is an empty line waiting to be stored first
$vars append $emptyLineStr
$vars append "\n"
set emptyLine 0
set emptyLineStr ""
}
$vars append $line
$vars append "\n"
} else {
# exit this section
set next 1
}
}
} else {
}
#end while
}
set ret $done
return $ret
}
method PBRegenerator::skipVariables {this fileDesc} {
# read and skip all lines until a "end type"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end variables[ \t]*$} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processPrototypes {this class fileDesc} {
# read and skip all lines until a "end prototypes"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end prototypes[ \t]*$} $line ] } {
set done 1
break
}
}
# generate syntax error because done not set
if { !$done } {
m4_error $E_ENDEXPECT "prototypes" [$class name]
}
set ret $done
return $ret
}
method PBRegenerator::processStructure {this class fileDesc} {
# read and skip all lines until a "end type"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end type[ \t]*$} $line ] } {
set done 1
break
}
}
# generate syntax error because done not set
if { !$done } {
m4_error $E_ENDEXPECTMETHOD "type" "(structure)" [$class name]
}
set ret $done
return $ret
}
method PBRegenerator::processEntryStructure {this class fileDesc} {
# read and skip all lines until a "end type"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end type[ \t]*$} $line ] } {
set done 1
break
}
}
# generate syntax error because done not set
if { !$done } {
m4_error $E_ENDEXPECTMETHOD "type" "(structure)" [$class name]
}
set ret $done
return $ret
}
method PBRegenerator::processEvent {this body fileDesc line} {
# read and add all lines until a "end type"
# return false if eof
# if there is a start and end marker only get code between those
# eg constructor and destructor events
# deletes added code before any startmarker!
# stops adding after end marker!
set done 0
set skip 0
set bodyTmp [TextSection new]
while { ![eof $fileDesc] && !$done } {
if { [regexp {^end event[ \t]*$} $line ] } {
set done 1
break
} elseif { [regexp "^ *${PBCookie::endUserSection}" $line ] } {
set skip 1
# nothing
} elseif { [regexp "^ *${PBCookie::startUserSection}" $line ] } {
set skip 0
set bodyTmp [TextSection new]
# nothing
} else {
# add line to body
if {$skip == 0} {
$bodyTmp append $line
$bodyTmp append "\n"
}
}
# read next line
set line [gets $fileDesc]
}
$body appendSect $bodyTmp
set ret $done
return $ret
}
method PBRegenerator::skipEvent {this fileDesc} {
# read and skip all lines until a "end event"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end event[ \t]*$} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processFunction {this body fileDesc line} {
# read and add all lines until a "end type"
# return false if eof
set done 0
# set to false:
set skip 0
set bodyTmp [TextSection new]
while { ![eof $fileDesc] && !$done } {
if { [regexp {^end function[ \t]*$} $line ] } {
set done 1
break
} elseif { [regexp "^ *${PBCookie::associationAccessorMethod}" $line] } {
set skip 1
# nothing
} elseif { [regexp {^ *// User defined method.*} $line] } {
set skip 0
# nothing
} else {
# add line to body
$bodyTmp append $line
$bodyTmp append "\n"
}
# read next line
set line [gets $fileDesc]
}
if { $skip == 0} {
$body appendSect $bodyTmp
}
set ret $done
return $ret
}
method PBRegenerator::skipFunction {this fileDesc} {
# read and skip all lines until a "end function"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end function[ \t]*$} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processSubroutine {this body fileDesc line} {
# read and add all lines until a "end type"
# return false if eof
set done 0
# set to false:
set skip 0
set bodyTmp [TextSection new]
while { ![eof $fileDesc] && !$done } {
if { [regexp {^end subroutine[ \t]*$} $line ] } {
set done 1
break
} elseif { [regexp "^ *${PBCookie::associationAccessorMethod}" $line ] } {
set skip 1
# nothing
} elseif { [regexp {^ *// User defined method.*} $line ] } {
set skip 0
# nothing
} else {
# add line to body
$bodyTmp append $line
$bodyTmp append "\n"
}
# read next line
set line [gets $fileDesc]
}
if { $skip == 0} {
$body appendSect $bodyTmp
}
set ret $done
return $ret
}
method PBRegenerator::skipSubroutine {this fileDesc} {
# read and skip all lines until a "end function"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end subroutine[ \t]*} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processBinaryData {this body fileDesc} {
# read and add all lines until a "End of PowerBuilder Binary Data Section : No Source Expected After This Point"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
if { [regexp {^ *End of PowerBuilder Binary Data Section : No Source Expected After This Point.*} $line ] } {
set done 1
break
} else {
# add line to body
$body append $line
$body append "\n"
}
# read next line
set line [gets $fileDesc]
}
set ret $done
return $ret
}
method PBRegenerator::skipBinaryData {this fileDesc} {
# read and skip all lines until a "End of PowerBuilder Binary Data Section : No Source Expected After This Point"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp "^ *${PBCookie::endBinaryDataSection}.*" $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processOn {this body fileDesc line} {
# read and add all lines until a "end type"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
if { [regexp {^end on[ \t]*$} $line ] } {
set done 1
break
} elseif { [regexp "^ *${PBCookie::associationAccessorMethod}.*" $line ] } {
# nothing
} elseif { [regexp {// User defined method.*} $line ] } {
# nothing
} else {
# add line to body
$body append $line
$body append "\n"
}
# read next line
set line [gets $fileDesc]
}
set ret $done
return $ret
}
method PBRegenerator::skipOn {this fileDesc} {
# read and skip all lines until a "end on"
# return false if eof
set done 0
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end on[ \t]*$} $line ] } {
set done 1
break
}
}
set ret $done
return $ret
}
method PBRegenerator::processOnCreate {this class fileDesc line} {
# scan on-body for property initializations
set done 0
if { [$class onCreateResidue] != "" } {
set body [$class onCreateResidue]
} else {
set body [TextSection new]
$class onCreateResidue $body
}
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
set type ""
set name ""
set value ""
if { [regexp {^end on[ \t]*$} $line ] } {
set done 1
break
}
if { [regexp {^ *this\.([^ =]*) *= *create .*} $line total ] } {
} elseif { [regexp {^ *this\.([^ =]*) *= *([^\{ ].*)$} $line total name value] } {
} elseif { [regexp {^ *this\.([^ =]*) *= *(\{[^\}]*\})} $line total name value] } {
} elseif { [regexp {^ *if.*} $line] } {
} elseif { [regexp {^ *this\.([^ =]*) *= *(\{[^\}]*\})$} $line total name value] } {
} elseif { [regexp {^ *this\.([^ =]*) *= *(\{[^\}]*)$} $line total name value] } {
# append value until closing brace is read
set end 0
while {![eof $fileDesc] && !$end } {
set line [gets $fileDesc]
if { [regexp {[^\}]*\}.*} $line] } {
set end 1
set value "$value\n$line"
} else {
set value "$value\n$line"
}
}
} elseif { [regexp {^ *call ([^:]*)::create *} $line total callname] } {
if { $callname != [$class superClassName] } {
# add unknown line to crappy section.
$body append $line
$body append "\n"
}
} else {
# add unknown lines to crappy section.
$body append $line
$body append "\n"
}
# these exceptions may not be added:
set tmpname [string tolower $name]
if {($tmpname == "item\[\]") || \
($tmpname == "control\[\]") } {
set name ""
}
# if there is a name add a builtin property to the class
if { $name != "" } {
$class setBuiltinProperty $name \
[PBBuiltinProperty new $name $type $value \
-where ${PBBuiltinProperty::InOnCreate} ]
}
}
set ret $done
return $ret
}
method PBRegenerator::processOnDestroy {this class fileDesc line} {
# skip on body and return false when eof
set done 0
if { [$class onDestroyResidue] != "" } {
set body [$class onDestroyResidue]
} else {
set body [TextSection new]
$class onDestroyResidue $body
}
while { ![eof $fileDesc] && !$done } {
set line [gets $fileDesc]
if { [regexp {^end on[ \t]*$} $line ] } {
set done 1
break
} else {
# add unknown lines to crappy section.
$body append $line
$body append "\n"
}
}
set ret $done
return $ret
}
method PBRegenerator::processParameter {this line} {
# create list of argument/parameter types from string given by line
set lst [List new]
# strip parentheses
if { [regexp {^ *\(([^)]*)\) *$} $line total params] } {
set params [string tolower $params]
} else {
set params [string tolower $line]
}
while { [regexp {^ *(reference |ref |readonly |value |)([^ ]*) ([^ ,]*) *,(.*)} $params total passBy type name params_] } {
set params $params_
$lst append $type
}
if { [regexp {^ *(reference |ref |readonly |value |)([^ ]*) ([^ ]*) *} $params total passBy type name] } {
$lst append $type
}
set i 0
$lst foreach arg {
incr i 1
}
return $lst
}
# Do not delete this line -- regeneration end marker