The OCL AST¶
The classes in besser.BUML.metamodel.ocl.ocl define the abstract
syntax tree produced by parse_ocl().
A tool that translates OCL into another language (e.g. evaluating
constraints, encoding them into a proof assistant, emitting them as
target-specific assertions) walks this tree.
Inheritance¶
Element
└── NamedElement
└── TypedElement
└── OCLExpression ◄── base class for every node
├── OperationCallExpression
├── PropertyCallExpression
├── VariableExp
├── TypeExp
├── IfExp
├── LoopExp
├── IteratorExp
└── LiteralExpression
├── IntegerLiteralExpression
├── RealLiteralExpression
├── BooleanLiteralExpression
├── StringLiteralExpression
└── DateLiteralExpression
Major node types¶
OperationCallExpressionA binary or unary operation. Notable shape:
argumentsis a list of operands plus the operator marker. For a binary op, the layout is[lhs, InfixOperator, rhs]. TheInfixOperatorentry is not anOCLExpression; consumers walkingargumentsshould filter onisinstance(child, OCLExpression)when they only want operands.The operator name is also exposed on the call as
operation(e.g.'>=','and','+').PropertyCallExpressionA property access. The
sourceattribute is the receiver (typically anotherOCLExpression, e.g.self); thereferredPropertyis the resolvedPropertyfrom the domain model.For chained access like
self.account.balance, parsing produces a nested chain ofPropertyCallExpressionnodes via thesourcelink.VariableExpA reference to a name introduced by a quantifier (
forAll(e | ...)) or aletbinding. ThereferredVariablepoints at theVariablethat introduces the name.TypeExpA type reference, used by
oclIsTypeOf(T)/oclAsType(T)/oclIsKindOf(T). ThereferredTypeis the targetType.IfExpA conditional. Children:
ifCondition,thenExpression,elseExpression— allOCLExpression.LoopExpandIteratorExpQuantifiers and bulk operations over collections.
IteratorExpcoversforAll/exists/select/reject/collect; itsbodyis the expression evaluated for each element, anditeratorsare the boundVariableinstances.- Literals
The literal subclasses (
IntegerLiteralExpression,RealLiteralExpression,BooleanLiteralExpression,StringLiteralExpression,DateLiteralExpression) hold the parsed value on avalueattribute. Booleans are coerced to Pythonboolby the wrapping visitor.
The wrapping visitor¶
parse_ocl uses besser.BUML.notations.ocl.wrapping_visitor.WrappingVisitor,
which post-processes the raw ANTLR-derived AST to:
Reconstruct property chains so that
self.account.balanceis a clean chain ofPropertyCallExpressionnodes (rather than a flat list of names).Coerce boolean literals from ANTLR strings to Python
bool.Resolve property and type references against the supplied
DomainModel.
A consumer walking the AST should expect the wrapped shape, not the raw
ANTLR shape. The non-wrapping BOCLVisitorImpl is an internal
helper used for source-location population during parsing — direct use
is rarely needed.