home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
vbgentor.tcl
< prev
next >
Wrap
Text File
|
1997-05-02
|
33KB
|
888 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 : vbgentor.tcl
# Author :
# Original date : May 1997
# Description : Classes for code generation
#
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
# File: @(#)vbfilehand.tcl /main/hindenburg/7
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "filehandle.tcl"
Class VBFileHandler : {FileHandler} {
constructor
method destructor
method getFileName
method getSpecialFiles
method getFileTypes
method getProjectFileName
attribute VBPType
attribute FRMType
attribute BASType
attribute CLSType
attribute OLDType
}
constructor VBFileHandler {class this} {
set this [FileHandler::constructor $class $this]
$this VBPType "vbp"
$this FRMType "frm"
$this BASType "bas"
$this CLSType "cls"
$this OLDType "old"
# Start constructor user section
# End constructor user section
return $this
}
method VBFileHandler::destructor {this} {
# Start destructor user section
# End destructor user section
$this FileHandler::destructor
}
method VBFileHandler::getFileName {this class fileType} {
if {$fileType == [$this BASType]} {
return "[$class getName]Extras.$fileType"
} else {
return "[$class getName].$fileType"
}
}
method VBFileHandler::getSpecialFiles {this} {
set list [List new]
$list append [$this getProjectFileName]
return $list
}
method VBFileHandler::getFileTypes {this} {
set list [List new]
$list append [$this VBPType]
$list append [$this FRMType]
$list append [$this BASType]
$list append [$this CLSType]
$list append [$this OLDType]
return $list
}
method VBFileHandler::getProjectFileName {this} {
return "[getCurrentSystemName].[$this VBPType]"
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)vbgenadapt.tcl /main/hindenburg/4
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
Class VBGenAdapter : {GCObject} {
constructor
method destructor
method generate
}
constructor VBGenAdapter {class this} {
set this [GCObject::constructor $class $this]
# Start constructor user section
# End constructor user section
return $this
}
method VBGenAdapter::destructor {this} {
# Start destructor user section
# End destructor user section
}
method VBGenAdapter::generate {this} {
# Source stolen from STGenAdapter::generate
set fileHandler [VBFileHandler new]
$fileHandler sourceTclFiles
set ooplModel [$oomodel ooplModel]
set selectedClasses [List new]
foreach class [getSelectedOoplClasses $ooplModel] {
if [$class isExternal] {
continue
}
if {[$class getName] == ""} {
m4_error $E_NONAMECLASS
continue
}
set externalSource [List new]
$externalSource contents [string trim [$class getPropertyValue class_source]]
if { ![$externalSource empty] } {
$externalSource foreach fileName {
$fileHandler importExternal $class [$fileHandler c
ppType] $fileName
}
continue
}
$selectedClasses append $class
}
$fileHandler checkUniqueFiles $selectedClasses
set vbgenerator [VBGenerator new]
$selectedClasses foreach class {
set l [List new]
$l append $class
set generatedSections [$vbgenerator generate $l]
$generatedSections foreach class classToSection {
$classToSection foreach type section {
#TODO: fileTypes
$fileHandler writeSectionToFile $section $class $type
}
set classToSection ""
}
set generatedSections ""
}
# special files
if $import_new {
set specialFileList [$fileHandler getSpecialFiles]
} else {
set specialFileList [List new]
set selectedFiles [get_tgt_objs]
[$fileHandler getSpecialFiles] foreach specialFile {
if { [lsearch $selectedFiles $specialFile] != -1 } {
$specialFileList append $specialFile
}
}
}
if { ![$specialFileList empty] } {
if {[M4CheckManager::getErrorCount] > 0} {
m4_error $E_NOSPECFILES
} else {
$vbgenerator generateSpecialFiles $specialFileList
}
}
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)vbgenerato.tcl /main/hindenburg/16
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "generator.tcl"
Class VBGenerator : {Generator} {
constructor
method destructor
method generate
method generateSpecialFiles
attribute fileHandler
}
constructor VBGenerator {class this} {
set this [Generator::constructor $class $this]
# Start constructor user section
$this fileHandler [VBFileHandler new]
# End constructor user section
return $this
}
method VBGenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Generator::destructor
}
method VBGenerator::generate {this classList} {
set typeToClassDict [Dictionary new]
set project [VBProject new]
$classList foreach cl {
if {[$cl baseType] != "NodeControl" && [$cl baseType] != "LeafControl"} {
$cl generate $project
set tempDict [Dictionary new]
$typeToClassDict set $cl $tempDict
}
}
[$project form] foreach formkey formval {
$formval configur
}
if {[$project mdiform] != ""} {
[$project mdiform] configur
}
set regenerator [VBRegenerator new [$this fileHandler]]
$regenerator regenerate $classList $project
$project generate $typeToClassDict
return $typeToClassDict
}
method VBGenerator::generateSpecialFiles {this fileList} {
$fileList foreach specialFile {
set fileName [[$this fileHandler] getProjectFileName]
set project [TextSection new]
set startup "(None)"
set hasstartup 1
foreach class [[$oomodel ooplModel] ooplClassSet] {
if {[$class isExternal]} {
continue
}
if {[$class hasMain]} {
switch [$class baseClass] {
"Form" {
$project append "Form="
$project append [[$this fileHandler] getFileName $class "frm"]
$project append "\n"
if {[$class getPropertyValue "is_startup"] == 1} {
if {$startup == "(None)"} {
set startup [$class getName]
set hasstartup 1
} else {
m4_error $E_DOUBLESTARTUP [$class getName] $startup
set hasstartup 0
}
}
}
"Class" {
$project append "Class="
$project append [$class getName]
$project append "; "
$project append [[$this fileHandler] getFileName $class "cls"]
$project append "\n"
if {[$class getPropertyValue "is_startup"] == 1} {
m4_warning $W_CANTBESTARTUP [$class getName]
}
}
"MDIForm" {
$project append "Form="
$project append [[$this fileHandler] getFileName $class "frm"]
$project append "\n"
if {[$class getPropertyValue "is_startup"] == 1} {
if {$startup == "(None)"} {
set startup [$class getName]
set hasstartup 1
} else {
m4_error $E_DOUBLESTARTUP [$class getName] $startup
set hasstartup 0
}
}
}
default {
if {[$class getPropertyValue "is_startup"] == 1} {
m4_warning $W_CANTBESTARTUP [$class getName]
}
continue
}
}
}
if {[$class hasExtras]} {
$project append "Module="
$project append [$class getName]
if {[$class baseClass] != "Enum"} {
$project append "Extras"
}
$project append "; "
$project append [[$this fileHandler] getFileName $class "bas"]
$project append "\n"
}
}
set cc [ClientContext::global]
$project append "Class=ClassSet; ..\\src\\ClassSet.cls\n"
$project append [$cc getCustomFileContents "auto32ld" "vbp" etc]
$project append "Name=\"[getCurrentSystemName]\"\n"
if {$startup == "(None)"} {
m4_warning $W_NOSTARTUP $fileName
};
if {$hasstartup} {
$project append "Startup=\"$startup\"\n"
m4_message $M_CREATINGSPEC $fileName
[$this fileHandler] writeSectionToNamedFile $project $fileName
} else {
m4_message $M_ERSTARTUP $fileName
}
}
}
# Do not delete this line -- regeneration end marker
#---------------------------------------------------------------------------
# File: @(#)vbregenera.tcl /main/hindenburg/16
#---------------------------------------------------------------------------
# Start user added include file section
# End user added include file section
require "regenerato.tcl"
Class VBRegenerator : {Regenerator} {
constructor
method destructor
method regenerate
method checkClassFiles
method processGUIClassDef
method processGUIForm
method processGUIControl
method processGUIMenu
method processGUIFormDef
method processCodeDef
method grabMethodBody
method putMethodUserCode
attribute fileHandler
}
constructor VBRegenerator {class this fileHandler} {
set this [Regenerator::constructor $class $this]
$this fileHandler $fileHandler
# Start constructor user section
# End constructor user section
return $this
}
method VBRegenerator::destructor {this} {
# Start destructor user section
# End destructor user section
$this Regenerator::destructor
}
method VBRegenerator::regenerate {this classList project} {
$classList foreach cl {
set obscls 0
set obsfrm 0
set obsbas 0
set rmvcls 0
set rmvfrm 0
set rmvbas 0
if {[$cl baseType] != "NodeControl" && [$cl baseType] != "LeafControl" && [$cl baseClass] != "Enum"} {
if {[$this checkClassFiles $cl]} {
set fileDesc [[$this fileHandler] openFile $cl "cls"]
if {$fileDesc != ""} {
if {[$cl baseType] == "Class"} {
if {[$this processGUIClassDef $cl $project $fileDesc]} {
set obscls 1
}
if {[$this processCodeDef $cl $project $fileDesc]} {
set obscls 1
}
} else {
m4_warning $W_OBSOL [[$this fileHandler] getFileName $cl "cls"]
set obscls 1
set rmvcls 1
}
[$this fileHandler] closeFile $fileDesc
}
set fileDesc [[$this fileHandler] openFile $cl "frm"]
if {$fileDesc != ""} {
if {[$cl baseType] != "Class"} {
if {[$this processGUIFormDef $cl $project $fileDesc]} {
set obsfrm 1
}
if {[$this processCodeDef $cl $project $fileDesc]} {
set obsfrm 1
}
} else {
m4_warning $W_OBSOL [[$this fileHandler] getFileName $cl "frm"]
set obsfrm 1
set rmvfrm 1
}
[$this fileHandler] closeFile $fileDesc
}
set fileDesc [[$this fileHandler] openFile $cl "bas"]
if {$fileDesc != ""} {
if {[$cl hasExtras]} {
if {[$this processCodeDef $cl $project $fileDesc]} {
set obsbas 1
}
} else {
m4_warning $W_OBSOL [[$this fileHandler] getFileName $cl "bas"]
set obsbas 1
set rmvbas 1
}
[$this fileHandler] closeFile $fileDesc
}
}
}
if {$obscls} {
set fileDesc [[$this fileHandler] openFile $cl "cls"]
set cont [TextSection new]
while {![eof $fileDesc]} {
$cont append "[gets $fileDesc]\n"
}
[$this fileHandler] closeFile $fileDesc
[$this fileHandler] writeSectionToFile $cont $cl "old"
if {$rmvcls} {
if {[M4CheckManager::getErrorCount] > 0} {
puts "Not removing [[$this fileHandler] getFileName $cl "cls"] because of previous errors"
} else {
fstorage::remove [[$this fileHandler] getFileName $cl "cls"]
}
}
}
if {$obsfrm} {
set fileDesc [[$this fileHandler] openFile $cl "frm"]
set cont [TextSection new]
while {![eof $fileDesc]} {
$cont append "[gets $fileDesc]\n"
}
[$this fileHandler] closeFile $fileDesc
[$this fileHandler] writeSectionToFile $cont $cl "old"
if {$rmvfrm} {
fstorage::remove [[$this fileHandler] getFileName $cl "frm"]
}
}
if {$obsbas} {
set fileDesc [[$this fileHandler] openFile $cl "bas"]
set cont [TextSection new]
while {![eof $fileDesc]} {
$cont append "[gets $fileDesc]\n"
}
[$this fileHandler] closeFile $fileDesc
puts stdout "Creating [$cl getName]Extras.old"
[$this fileHandler] writeSectionToNamedFile $cont "[$cl getName]Extras.old"
if {$rmvbas} {
fstorage::remove [[$this fileHandler] getFileName $cl "bas"]
}
}
}
}
method VBRegenerator::checkClassFiles {this class} {
set files [fstorage::dir]
if {[regexp "[$class getName].old" $files]} {
m4_error $E_HASOLD [$class getName]
return 0
} else {
return 1
}
}
method VBRegenerator::processGUIClassDef {this class project fileDesc} {
set done 0
set start 0
set cont [TextSection new]
set cl [$project getClassmodule [$class getName]]
set line [gets $fileDesc]
set line [gets $fileDesc]
set line [gets $fileDesc]
set line [gets $fileDesc]
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp ${VBCookie::regenMarker} $line]} {
set done 1
} else {
if {![regexp {Attribute[ ]*VB_Name=} $line]} {
$cont append "$line\n"
} else {
$cont append "Attribute VB_Name = \"[$cl name]\"\n"
}
}
}
$cl attribs $cont
return 0
}
method VBRegenerator::processGUIForm {this form fileDesc} {
set done 0
set obs 0
set specs [TextSection new]
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {End[ ]*} $line]} {
set done 1
} else {
if {[regexp {Begin[ ]*([^\.]*)\.([^ ^ ]*)[ ]*([^ ^ ]*)} $line total guilib guitype name]} {
if {$guitype == "Menu"} {
set contr ""
[$form menuSet] foreach menu {
if {[$menu name] == $name} {
set contr $menu
$form removeMenu $menu
$form addSortedmenu $menu
break
}
}
if {$contr == ""} {
m4_warning $W_OBSOLCONTROL $name
set obs 1
}
if {[$this processGUIMenu $contr $fileDesc]} {
set obs 1
}
} else {
set contr ""
[$form controlSet] foreach cont {
if {[$cont name] == $name && [$cont specs] == ""} {
set contr $cont
break
}
}
if {$contr == ""} {
m4_warning $W_OBSOLCONTROL $name
set obs 1
}
if {[$this processGUIControl $contr $fileDesc]} {
set obs 1
}
}
} else {
$specs append "$line\n"
}
}
}
if {![regexp {End[ ]*} $line]} {
if {[eof $fileDesc]} {
m4_error $E_SYNTAX "End" "end of file"
} else {
m4_error $E_SYNTAX "End" $line
}
}
$form specs $specs
return $obs
}
method VBRegenerator::processGUIControl {this control fileDesc} {
set obs 0
if {$control == ""} {
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {End[ ]*} $line]} {
set done 1
} else {
if {[regexp {Begin[ ]*([^\.]*)\.([^ ^ ]*)[ ]*([^ ^ ]*)} $line total guilib guitype name]} {
set contr ""
m4_warning $W_OBSOLCONTROL $name
set obs 1
$this processGUIControl $contr $fileDesc
}
}
}
} else {
set specs [TextSection new]
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {End[ ]*} $line]} {
set done 1
} else {
if {[regexp {Begin[ ]*([^\.]*)\.([^ ^ ]*)[ ]*([^ ^ ]*)} $line total guilib guitype name]} {
set contr ""
[$control subcontrolSet] foreach cont {
if {[$cont name] == $name && [$cont specs] == ""} {
set contr $cont
break
}
}
if {$contr == ""} {
m4_warning $W_OBSOLCONTROL $name
set obs 1
}
if {[$this processGUIControl $contr $fileDesc]} {
set obs 1
}
} else {
if {[regexp {[ ]*Index[ ]*=[ ]*([^ ^ ])*} $line total indx]} {
if {[$control hasIndex]} {
$specs append "$line\n"
$control index $indx
$control indexInSpecs 1
}
} else {
$specs append "$line\n"
}
}
}
}
$control specs $specs
}
if {![regexp {End[ ]*} $line]} {
if {[eof $fileDesc]} {
m4_error $E_SYNTAX "End" "end of file"
} else {
m4_error $E_SYNTAX "End" $line
}
}
return $obs
}
method VBRegenerator::processGUIMenu {this menu fileDesc} {
set obs 0
if {$menu == ""} {
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {End[ ]*} $line]} {
set done 1
} else {
if {[regexp {Begin[ ]*([^\.]*)\.([^ ^ ]*)[ ]*([^ ^ ]*)} $line total guilib guitype name]} {
set contr ""
m4_warning $W_OBSOLCONTROL $name
set obs 1
$this processGUIMenu $contr $fileDesc
}
}
}
} else {
set specs [TextSection new]
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {End[ ]*} $line]} {
set done 1
} else {
if {[regexp {Begin[ ]*([^\.]*)\.([^ ^ ]*)[ ]*([^ ^ ]*)} $line total guilib guitype name]} {
set contr ""
[$menu submenuSet] foreach mnu {
if {[$mnu name] == $name} {
set contr $mnu
$menu removeSubmenu $mnu
$menu addSortedsubmenu $mnu
break
}
}
if {$contr == ""} {
m4_warning $W_OBSOLCONTROL $name
set obs 1
}
if {[$this processGUIMenu $contr $fileDesc]} {
set obs 1
}
} else {
if {[regexp {[ ]*Index[ ]*=[ ]*([^ ^ ])*} $line total indx]} {
if {[$menu hasIndex]} {
$specs append "$line\n"
$menu index $indx
$menu indexInSpecs 1
}
} else {
$specs append "$line\n"
}
}
}
}
$menu specs $specs
}
if {![regexp {End[ ]*} $line]} {
if {[eof $fileDesc]} {
m4_error $E_SYNTAX "End" "end of file"
} else {
m4_error $E_SYNTAX "End" $line
}
}
return $obs
}
method VBRegenerator::processGUIFormDef {this class project fileDesc} {
set obs 0
set start 0
set cont [TextSection new]
set cl [$project getForm [$class getName]]
if {$cl == ""} {
if {[[$project mdiform] name] == [$class getName]} {
set cl [$project mdiform]
}
}
$cl objects [TextSection new]
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp {Begin[ ]*VB\.(Form|MDIForm)} $line]} {
set done 1
} else {
if {[regexp {^[ ]*Object[ ]*=[ ]*} $line]} {
[$cl objects] append "$line\n"
}
}
}
if {[regexp {Begin[ ]*VB\.(Form|MDIForm)} $line]} {
$this processGUIForm $cl $fileDesc
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp ${VBCookie::regenMarker} $line]} {
set done 1
} else {
if {[regexp {Attribute[ ]*VB_([^ ^ ]*)[ ]*=} $line]} {
if {![regexp {Attribute[ ]*VB_Name[ ]*=} $line]} {
$cont append "$line\n"
} else {
$cont append "Attribute VB_Name = \"[$cl name]\"\n"
}
} else {
set done 1
}
}
}
if {[regexp ${VBCookie::regenMarker} $line]} {
$cl attribs $cont
} else {
m4_error $E_SYNTAX ${VBCookie::regenMarker} $line
}
} else {
m4_error $E_SYNTAX "Beginning of Form" "end of file"
}
return $obs
}
method VBRegenerator::processCodeDef {this class project fileDesc} {
set done 0
set obs 0
set exp_method {^[ ]*(Public|Private)[ ]*(Static)?[ ]*(Sub|Function)[ ]*([^(]*)\(([^)]*)\)[ ]*(As[ ]*([^ ]*))?}
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp ${VBCookie::regenMarker} $line]} {
set done 1
} else {
if {[regexp $exp_method $line total access dummy1 procType totalname params dummy2 returnvalue]} {
if {![regexp {([^_]*)_([^ ^ ]*)} $totalname total refname name]} {
set refname ""
set name $totalname
}
if {[$this putMethodUserCode $class $project [$this grabMethodBody $fileDesc] $refname $name]} {
set obs 1
}
}
}
}
if {![regexp ${VBCookie::regenMarker} $line]} {
m4_error $E_SYNTAX ${VBCookie::regenMarker} "end of file"
}
return $obs
}
method VBRegenerator::grabMethodBody {this fileDesc} {
set usercode [TextSection new]
set done 0
while {![eof $fileDesc] && !$done} {
set line [gets $fileDesc]
if {[regexp ${VBCookie::endUserSection} $line] || [regexp {^[ ]*(End)[ ]*(Sub|Function)} $line]} {
set done 1
} else {
if {[regexp ${VBCookie::startUserSection} $line]} {
set usercode [TextSection new]
} else {
$usercode append "$line\n"
}
}
}
return $usercode
}
method VBRegenerator::putMethodUserCode {this class project userCode refname name} {
set cl [$project getClassmodule [$class getName]]
if {$cl == ""} {
set cl [$project getForm [$class getName]]
if {$cl == ""} {
if {[[$project mdiform] name] == [$class getName]} {
set cl [$project mdiform]
}
}
}
set proc ""
if {$proc == "" && $refname == ""} {
set proc [$cl getUserproc $name]
}
if {$proc == "" && $refname == [$cl name]} {
set proc [$cl getGlobproc $name]
}
if {$proc == "" && [$class baseType] == "Window" && $refname == [$cl type]} {
set proc [$cl getEvent $name]
}
if {$proc == "" && [$class baseType] == "Window"} {
[$cl containerSet] foreach container {
if {[$container name] == $refname} {
set proc [$container getEvent $name]
if {$proc != ""} {
break
}
}
}
}
if {$proc == "" && $refname == [$cl type] && $name == [[$cl terminate] name]} {
set proc [$cl terminate]
}
if {[$cl constructor] != ""} {
if {$proc == "" && $refname == [$cl name] && $name == [[$cl constructor] name]} {
set proc [$cl constructor]
}
}
if {$proc != ""} {
$proc usercode $userCode
} else {
if {$refname != ""} {
m4_warning $W_OBSOLPROC "${refname}_$name"
} else {
m4_warning $W_OBSOLPROC "$name"
}
return 1
}
return 0
}
# Do not delete this line -- regeneration end marker