eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RBProgramNode':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RBProgramNode


Inheritance:

   Object
   |
   +--RBProgramNode
      |
      +--RBMethodNode
      |
      +--RBPragmaNode
      |
      +--RBSequenceNode
      |
      +--RBStatementNode

Package:
stx:goodies/refactoryBrowser/parser
Category:
Refactory-AST-Nodes
Version:
rev: 1.131 date: 2024/03/05 19:02:39
user: cg
file: RBProgramNode.st directory: goodies/refactoryBrowser/parser
module: stx stc-classLibrary: parser

Description:


BRProgramNode is an abstract class that represents an abstract syntax tree node in a Smalltalk program.

Subclasses must implement the following messages:
        accessing
                start
                stop
        visitor
                acceptVisitor:

The #start and #stop methods are used to find the source that corresponds to this node. "source copyFrom: self start to: self stop" should return the source for this node.

The #acceptVisitor: method is used by BRProgramNodeVisitors (the visitor pattern). This will also require updating all the BRProgramNodeVisitors so that they know of the new node.

Subclasses might also want to redefine match:inContext: and copyInContext: to do parse tree searching and replacing.

Subclasses that contain other nodes should override equalTo:withMapping: to compare nodes while ignoring renaming temporary variables, and children that returns a collection of our children nodes.

Instance Variables:
        comments        <Collection of: Interval>       the intervals in the source that have comments for this node
        parent  <BRProgramNode> the node we're contained in


Class protocol:

accessing
o  formatterClass
(comment from inherited method)
return a class to use for formatting (prettyPrinting) this class -
this can be redefined in special classes, to format classes with
JavaScript, Ruby, Lisp, Prolog, ASN1, Basic :-) or whatever syntax.

o  formatterClass: aClass

o  optimizedSelectors
answer the selectors, that are inlined by the compiler

initialization
o  initialize


Instance protocol:

accessing
o  asReturn
Change the current node to a return node.

o  blockScope

o  children

o  comments

o  comments: aCollection

o  commentsAfter

o  commentsAfter: aCollectionOfComments

o  commentsBefore

o  commentsBefore: aCollectionOfComments
'oops - loosing comments before'.

o  endPosition

o  formattedCode

o  formatterClass

o  lineNumber
lineNumber isNil ifTrue:[

o  lineNumber: anInteger
Modified (format): / 06-03-2012 / 11:13:19 / cg

o  methodScope

o  newSource

o  originalCode

o  originalFormattedCode
same as formattedCode, but does not rewrite '_' to ':='

o  parent

o  parent: anObject

o  parents

o  precedence

o  removeCommentsAfter
occasionally someone wants to move comments from one node to another;
this is a helper to clear the comments in the old node.
(see senders of why this is done)

o  source

o  sourceInterval

o  start

** This method must be redefined in concrete classes (subclassResponsibility) **

o  startWithoutParentheses

o  stop

** This method must be redefined in concrete classes (subclassResponsibility) **

o  stopPosition

o  topNode

o  typeInfo
this is a hook for the type inferer;
it may attach additional info to a node with this

o  typeInfo: someArbitraryThingy
this is a hook for the type inferer;
it may attach additional info to a node with this

comparing
o  equalTo: aNode exceptForVariables: variableNameCollection

o  equalTo: aNode withMapping: aDictionary
return true, if I am equal to another node, with a given variable name mapping.

o  equalTo: aNode withSelectorMapping: aDictionary
return true, if I am equal to another node, with a given selector name mapping.
Side effect: update the mapping dictionary as required to reflect a matching mapping (if possible)

o  semanticallyEqualTo: aNode withMapping: aDictionary
return true, if I am semantically equal to another node, with a given variable name mapping.
Semantical equalTo: is defined slightly less strict, than equalTo:.
Both check the parsetree, ignoring formatting and comments.
However, in some situations, semanticallyEqualTo: detects the same intention,
(which is mostly heuristic and builtin knowledge).
For example:
foo isNil ifTrue:e1 ifFalse:e2
is semantcallyEqualTo:
foo notNil ifTrue:e2 ifFalse:e1
and also to:
foo isNil ifFalse:e2 ifTrue:e1
The fallback implemented here is to ask for the regular equality.
Side effect: update the mapping dictionary as required to reflect a matching mapping (if possible)

copying
o  copy
This is redefined for IBM Smalltalk which doesn't have postCopy.

o  copyCommentsFrom: aNode
Add all comments from aNode to us. If we already have the comment, then don't add it.

copying-private
o  postCopy

enumeration
o  allAssignmentNodesDo: aBlock

o  allBlockNodesDo: aBlock

o  allLiteralNodesDo: aBlock

o  allMessageNodesDo: aBlock

o  allNonPatternMessageNodesDo: aBlock

o  allReturnNodesDo: aBlock

o  collect: aBlock
Hacked to fit collection protocols

o  detectParentForWhich: aBlock

o  do: aBlock
Hacked to fit collection protocols

o  size
Hacked to fit collection protocols

o  variableNodesDo: aBlock
evaluate a Block for all variable nodes

iteration
o  nodesDo: aBlock

matching
o  copyInContext: aDictionary

o  copyList: matchNodes inContext: aDictionary

o  match: aNode inContext: aDictionary

o  matchList: matchNodes against: programNodes inContext: aDictionary
Modified (format): / 05-03-2024 / 12:11:43 / cg

o  matchList: matchNodes index: matchIndex against: programNodes index: programIndex inContext: aDictionary

meta variable-accessing
o  cascadeListCharacter

o  ignoreInMatchCharacter

o  listCharacter

o  literalCharacter

o  recurseIntoCharacter

o  statementCharacter

printing
o  printOn: aStream
(comment from inherited method)
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

The default here is to output the receiver's class name.
BUT: this method is heavily redefined for objects which
can print prettier.

querying
o  allAssignmentNodes

o  allMessageNodes

o  assigns: aVariableName

o  bestNodeFor: anInterval

o  containedBy: anInterval
true if the interval contains me completely

o  containsReturn

o  defines: aName

o  directlyUses: aNode

o  evaluatedFirst: aNode

o  firstLineNumber

o  hasAssignmentNodes

o  hasBlockNodes

o  hasFalseValue

o  hasReturnNodes

o  hasTrueValue

o  intersectsInterval: anInterval
^(anInterval first between:myStart and:myStop)

o  isChildOf: anotherNode

o  isDirectlyUsed
This node is directly used as an argument, receiver, or part of an assignment.

o  isEvaluatedFirst
Return true if we are the first thing evaluated in this statement.

o  isInsidePatternNode

o  isInsideSyntheticMessage

o  isLast: aNode

o  isLoop

o  isReferringToAnExceptionInContext: aSearchDictionary
true iff:
(node contains a ref to a global variable or node is a class variable)
and the variable refers to an Exception class (but not a Notification)

o  isSynthetic
true if I am a synthetic node (generated from embedded expression strings)

o  lastIsLoop

o  lastIsReturn

o  lastLineNumber
lineNumber isNil ifTrue:[self halt:'should always be non-nil'].

o  reads: aVariableName

o  references: aVariableName
(comment from inherited method)
return true if the receiver refers to the argument, anObject.
- for debugging only

o  selfMessages
warning: returns a string collection because we avoid creating symbols when parsing

o  sentMessages

o  statementNode
Return your topmost node that is contained by a sequence node.

o  superMessages
warning: returns a string collection because we avoid creating symbols when parsing

o  uses: aNode

replacing
o  removeDeadCode

o  replaceNode: aNode withNode: anotherNode

o  replaceWith: aNode

searching
o  whichNodeIntersects: anInterval
I intersect

o  whichNodeIsContainedBy: anInterval

o  whoDefines: aName
return the node (blockNode) in which this variable is defined.
(nil if instvar, classvar or global)

special queries
o  addAllCommentsTo: aCollection

o  addReferencedVariablesTo: aCollection

o  addUsedLiteralsTo: aCollection
adds the values of all literals to aCollection

o  addUsedSymbolsTo: aCollection

o  allArgumentVariables

o  allArgumentVariablesInto: aCollection

o  allComments

o  allDefinedVariables

o  allTemporaryVariables

o  allVariablesOnScope

o  blockVariables

o  detectNodeForWhich: aBlock
top level first

o  referencedVariables

o  temporaryVariables

o  usedLiterals
returns a set of the literal values (i.e. not the nodes)

o  usedSymbols
returns a set of the symbols used (i.e. not the nodes)

stx:libtool support
o  highlightInCodeView: aCodeView

o  leftClickMenuInCodeView: aCodeView

o  middleClickMenuInCodeView: aCodeView

o  rightClickMenuInCodeView: aCodeView

testing
o  isAssignment

o  isBlock

o  isCascade

o  isClassVariableInContext: aSearchDictionary

o  isGlobal
Return true if the variable node is for
a non-local (not really global), false otherwise.
Actually wrong: also returns true for inst- and class variables
(i.e. anything that is not a block- or method local)

o  isGlobalVariable
Return true if the variable node is for
a non-local (not really global), false otherwise.
Actually wrong: also returns true for inst- and class variables
(i.e. anything that is not a block- or method local)

o  isImmediate

o  isInstanceVariable

o  isKeywordMessage

o  isLiteral

o  isLiteralArray

o  isLiteralByteArray

o  isLiteralCharacter

o  isLiteralFloat

o  isLiteralInteger

o  isLiteralNil

o  isLiteralNode

o  isLiteralNumber

o  isLiteralString

o  isLiteralSymbol

o  isMessage

o  isMessageWithSelector: aStringOrSymbol

o  isMethod

o  isPragma

o  isReturn

o  isSTXPrimitiveCCode

o  isSelf
true if I am the self-variable node

o  isSequence

o  isSqueakArray

o  isSuper

o  isSyntheticMessage

o  isTemporary
Return true if the variable node is for
a temporary variable, false otherwise

o  isUsed
Answer true if this node could be used as part of another expression.
For example, you could use the result of this node as a receiver of a message,
an argument, the right part of an assignment, or the return value of a block.
This differs from isDirectlyUsed in that it is conservative since it also includes
return values of blocks.

o  isValue

o  isVariable

o  isVariableNotInLeftHandSideOfAssignment
Returns true iff receiver is variable node but not
in left-hand side of assignment

testing-matching
o  canMatchMethod: aCompiledMethod
the original code below iterates over the literals for each tested;

o  isList

o  isPatternNode

o  recurseInto

visitor
o  acceptCommentsAfterVisitor: aVisitor

o  acceptCommentsBeforeVisitor: aVisitor

o  acceptVisitor: aProgramNodeVisitor
(comment from inherited method)
double-dispatch onto a Visitor.

** This method must be redefined in concrete classes (subclassResponsibility) **


Private classes:

    AuxInfo


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 19 May 2024 18:25:07 GMT