PluggableParseNodeVisitor.st
author HG Automerge
Thu, 12 Jan 2017 09:44:22 +0000
branchjv
changeset 4088 529963173d68
parent 3841 a22f33410bdf
child 4723 524785227024
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3841
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     1
"
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     2
 COPYRIGHT (c) 2006 by eXept Software AG
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     3
              All Rights Reserved
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     4
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     5
 This software is furnished under a license and may be used
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     6
 only in accordance with the terms of that license and with the
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
     9
 other person.  No title to or ownership of the software is
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    10
 hereby transferred.
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    11
"
3782
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
"{ Package: 'stx:libcomp' }"
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    14
"{ NameSpace: Smalltalk }"
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    15
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    16
ParseNodeVisitor subclass:#PluggableParseNodeVisitor
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    17
	instanceVariableNames:'actionsPerNodeType'
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
	classVariableNames:''
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    19
	poolDictionaries:''
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    20
	category:'System-Compiler-Support'
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    21
!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    22
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!PluggableParseNodeVisitor class methodsFor:'documentation'!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
3841
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    25
copyright
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    26
"
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    27
 COPYRIGHT (c) 2006 by eXept Software AG
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    28
              All Rights Reserved
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    29
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    30
 This software is furnished under a license and may be used
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    31
 only in accordance with the terms of that license and with the
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    33
 be provided or otherwise made available to, or used by, any
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    34
 other person.  No title to or ownership of the software is
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    35
 hereby transferred.
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    36
"
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    37
!
a22f33410bdf Reduced dependencies
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3794
diff changeset
    38
3782
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
documentation
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
"
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
    a pluggable node visitor.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
    setup with:
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
        actionForNodeClass:aClass put:aBlock
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
        
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
    for example, if you are only interested in assignments,
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
    use the following code:
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
        |v|
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
        v := PluggableParseNodeVisitor new.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
        v actionForNodeClass:AssignmentNode put:[:node | Transcript showCR:node. true].
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
        v visit:(Parser parse:code in:someClass.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
"
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
! !
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
!PluggableParseNodeVisitor methodsFor:'setup'!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
actionForNodeClass:aNodeClass put:aBlock
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    "setup so that for nodes of type aNodeClass, aBlock is invoked.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
     If the block returns true, subnodes (eg. right side of assignments, etc.)
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
     will be enumerated as well.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
     Otherwise, no subnodes are visited."
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
    actionsPerNodeType isNil ifTrue:[
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
         actionsPerNodeType := Dictionary new.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    ].
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
    actionsPerNodeType at:aNodeClass put:aBlock
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
! !
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
!PluggableParseNodeVisitor methodsFor:'visiting'!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
visit:aNodeObject
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
    "redefined to look for an action for this node's class.
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
     If there is one, it can specify if subnodes are to be visited too"
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
     
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    |action|
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
3794
ea706f2a101f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3782
diff changeset
    76
    action := actionsPerNodeType at:aNodeObject class ifAbsent:[nil].
3782
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
    action notNil ifTrue:[ 
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
        (action value:aNodeObject) ifFalse:[^ self].
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
    ].
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
    super visit:aNodeObject
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
! !
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
!PluggableParseNodeVisitor class methodsFor:'documentation'!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
version
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
    ^ '$Header$'
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
!
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
version_CVS
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    90
    ^ '$Header$'
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    91
! !
226f62e32424 initial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    92