25 #include "../common/consts.h" 26 #include "../common/utils/FormatableString.h" 81 virtual std::wstring
toWString()
const = 0;
85 virtual void dump(std::wostream& dest,
unsigned& indent)
const;
114 virtual std::wstring
toWString()
const {
return L
"Block"; }
127 virtual std::wstring
toWString()
const {
return L
"ProgramBlock"; }
128 virtual std::wstring
toNodeName()
const {
return L
"program block"; }
146 virtual std::wstring
toWString()
const {
return L
"Assign"; }
147 virtual std::wstring
toNodeName()
const {
return L
"assignment"; }
168 virtual std::wstring
toNodeName()
const {
return L
"if/when"; }
191 virtual std::wstring
toNodeName()
const {
return L
"folded if/when"; }
228 virtual std::wstring
toNodeName()
const {
return L
"folded while"; }
244 virtual std::wstring
toNodeName()
const {
return L
"event declaration"; }
279 virtual std::wstring
toNodeName()
const {
return L
"subroutine declaration"; }
287 unsigned subroutineId;
296 virtual std::wstring
toNodeName()
const {
return L
"subroutine call"; }
310 void deMorganNotRemoval();
317 virtual std::wstring
toNodeName()
const {
return L
"binary function"; }
341 virtual std::wstring
toNodeName()
const {
return L
"unary function"; }
362 virtual std::wstring
toNodeName()
const {
return L
"constant"; }
381 virtual std::wstring
toNodeName()
const {
return L
"variable access (write)"; }
402 virtual std::wstring
toNodeName()
const {
return L
"variable access (read)"; }
423 virtual std::wstring
toNodeName()
const {
return L
"array access (write)"; }
444 virtual std::wstring
toNodeName()
const {
return L
"array access (read)"; }
467 virtual std::wstring
toNodeName()
const {
return L
"load native arg"; }
485 virtual std::wstring
toNodeName()
const {
return L
"native function call"; }
499 virtual std::wstring
toWString()
const {
return L
"Return"; }
500 virtual std::wstring
toNodeName()
const {
return L
"return"; }
534 virtual std::wstring
toNodeName()
const {
return L
"array of constants"; }
535 virtual void dump(std::wostream& dest,
unsigned& indent)
const;
539 virtual bool isImmediateVector()
const;
540 virtual int getImmediateValue(
unsigned index)
const;
541 virtual void addImmediateValue(
int value) {
children.push_back(
new ImmediateNode(sourcePos, value)); }
565 virtual std::wstring
toNodeName()
const {
return L
"vector access"; }
569 bool isAddressStatic()
const;
571 virtual void setWrite(
bool write) { this->write = write; }
590 virtual std::wstring
toNodeName()
const {
return L
"arithmetic assignment"; }
613 virtual std::wstring
toNodeName()
const {
return L
"unary arithmetic assignment"; }
virtual EmitNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:257
virtual CallNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:478
unsigned eventId
id of event to emit
Definition: tree.h:251
Node for unary arithmetic children[0] is the expression to negate.
Definition: tree.h:328
void expectType(const Node::ReturnType &expected, const Node::ReturnType &type) const
Check for a specific type, throw an exception otherwise.
Definition: tree-typecheck.cpp:41
unsigned arraySize
size of the array, might be used to assert compile-time access checks
Definition: tree.h:555
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:259
virtual unsigned getVectorAddr() const
return the address of the left-most operand, or E_NOVAL if none
Definition: tree.h:425
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:296
Node for L"if" and L"when" with operator folded inside.
Definition: tree.h:176
An abstract node of syntax tree.
Definition: tree.h:47
Node for writing to an array.
Definition: tree.h:410
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:317
AsebaBinaryOperator op
operator
Definition: tree.h:580
Node for reading from an array.
Definition: tree.h:431
std::wstring binaryOperatorToString(AsebaBinaryOperator op)
Return the string corresponding to the binary operator.
Definition: tree-dump.cpp:30
std::wstring arrayName
name of the array (for debug)
Definition: tree.h:457
unsigned endLine
line of end keyword
Definition: tree.h:180
virtual UnaryArithmeticNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:335
virtual Node * expandVectorialNodes(std::wostream *dump, Compiler *compiler=0, unsigned int index=0)
Third pass to expand vectorial operations into mutliple scalar ones.
Definition: tree.h:588
AsebaBinaryOperator op
operator
Definition: tree.h:304
virtual MemoryVectorNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:560
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:168
AsebaUnaryOperator
List of unary operators.
Definition: consts.h:105
virtual EventDeclNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:238
unsigned subroutineId
the associated subroutine
Definition: tree.h:270
unsigned varAddr
address of variable to load from
Definition: tree.h:391
virtual Node * optimize(std::wostream *dump)=0
Optimize this node, return the optimized node.
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:147
AsebaBinaryOperator op
operator
Definition: tree.h:217
std::wstring unaryOperatorToString(AsebaUnaryOperator op)
Return the string corresponding to the unary operator.
Definition: tree-dump.cpp:60
virtual Node * expandVectorialNodes(std::wostream *dump, Compiler *compiler=0, unsigned int index=0)
Third pass to expand vectorial operations into mutliple scalar ones.
Definition: tree-expand.cpp:197
Node for L"while" with operator folded inside.
Definition: tree.h:215
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree-typecheck.cpp:47
virtual unsigned getVectorSize() const
return the children's size, check for equal size, or E_NOVAL if no child
Definition: tree.h:405
unsigned arrayAddr
address of the first element of the array
Definition: tree.h:433
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:480
virtual unsigned getVectorSize() const
return the children's size, check for equal size, or E_NOVAL if no child
Definition: tree.h:426
virtual void dump(std::wostream &dest, unsigned &indent) const
Dump this node and the rest of the tree.
Definition: tree-dump.cpp:73
virtual void emit(PreLinkBytecode &bytecodes) const =0
Generate bytecode.
virtual void checkVectorSize() const
Check the consistency in vectors' size.
Definition: tree-expand.cpp:338
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:495
virtual ~Node()
Destructor, delete all children.
Definition: tree-build.cpp:45
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:381
Node for L"while".
Definition: tree.h:197
virtual std::wstring toWString() const =0
Return a string representation of this node.
FoldedWhileNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:220
IfWhenNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:160
EmitNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:256
unsigned arrayAddr
address of the first element of the array to send
Definition: tree.h:252
std::wstring arrayName
name of the array (for debug)
Definition: tree.h:414
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:516
unsigned arrayAddr
address of the first element of the array
Definition: tree.h:554
virtual std::wstring toWString() const
Return a string representation of this node.
Definition: tree.h:127
UnaryArithmeticNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:333
virtual SubDeclNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:273
virtual unsigned getStackDepth() const
Return the stack depth requirement for this node and its children.
Definition: tree.h:518
Definition: analysis.cpp:26
virtual Node * optimize(std::wostream *dump)
Optimize this node, return the optimized node.
Definition: tree.h:517
virtual ArrayWriteNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:417
virtual unsigned getStackDepth() const
Return the stack depth requirement for this node and its children.
Definition: tree-emit.cpp:94
WhileNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:200
Node for L"callsub" no children.
Definition: tree.h:284
Node for calling a native function may have children for pushing constants somewhere.
Definition: tree.h:472
Node for accessing a memory as a vector, in read or write operations If write == true, will expand to StoreNode or ArrayWriteNode If write == false, will expand to LoadNode or ArrayReadNode children[0] is an optional index If children[0] is a TupleVectorNode of one elements (int), it will be foo[x] If children[0] is a TupleVectorNode of two elements (int), it will be foo[x:y] If children[0] is another type of node, it will be foo[whatever] If children[0] doesn't exist, access to the full array is considered.
Definition: tree.h:552
virtual ArrayReadNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:438
virtual unsigned getVectorAddr() const
return the address of the left-most operand, or E_NOVAL if none
Definition: tree.h:383
virtual ArithmeticAssignmentNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:584
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:419
virtual Node * optimize(std::wostream *dump)
Optimize this node, return the optimized node.
Definition: tree.h:496
virtual std::wstring toWString() const
Return a string representation of this node.
Definition: tree.h:146
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:467
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:191
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:485
virtual UnaryArithmeticAssignmentNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:608
std::wstring typeName(const Node::ReturnType &type) const
Return the name of a type.
Definition: tree-typecheck.cpp:30
Node for L"program", i.e. a block node with some special behaviour later on.
Definition: tree.h:119
virtual IfWhenNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:161
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:263
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:128
std::wstring arrayName
name of the array (for debug)
Definition: tree.h:435
Aseba Event Scripting Language compiler.
Definition: compiler.h:258
unsigned eventId
the event id associated with this context
Definition: tree.h:235
Node for storing a variable from stack.
Definition: tree.h:369
virtual void emit(PreLinkBytecode &bytecodes) const
Generate bytecode.
Definition: tree.h:519
unsigned arraySize
size of the array to send.
Definition: tree.h:253
std::vector< Node * > NodesVector
Vector for children of a node.
Definition: tree.h:100
Node for returning from an event or subroutine has no children, just a jump of 0 offset that will be ...
Definition: tree.h:490
virtual LoadNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:395
virtual Node * expandVectorialNodes(std::wostream *dump, Compiler *compiler=0, unsigned int index=0)
Third pass to expand vectorial operations into mutliple scalar ones.
Definition: tree.h:611
bool edgeSensitive
if true, true block is triggered only if previous comparison was false ("when" block).
Definition: tree.h:179
SourcePos sourcePos
position is source
Definition: tree.h:102
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:377
Node for L"onevent" no children.
Definition: tree.h:233
virtual unsigned getVectorAddr() const
return the address of the left-most operand, or E_NOVAL if none
Definition: tree.h:446
AsebaUnaryOperator op
operator
Definition: tree.h:330
virtual unsigned getVectorSize() const
return the children's size, check for equal size, or E_NOVAL if no child
Definition: tree.h:447
NodesVector children
children of this node
Definition: tree.h:101
unsigned funcId
identifier of the function to be called
Definition: tree.h:474
unsigned arrayAddr
address of the first element of the array
Definition: tree.h:455
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:228
Node for assignation.
Definition: tree.h:134
AbstractTreeNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:511
Node for binary arithmetic.
Definition: tree.h:302
bool write
expand to a node for storing or loading data?
Definition: tree.h:557
Node for L"emit".
Definition: tree.h:249
virtual std::wstring toWString() const
Return a string representation of this node.
Definition: tree.h:114
virtual ReturnNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:493
std::wstring arrayName
name of the array (for debug)
Definition: tree.h:556
Node(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:58
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:341
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:397
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:115
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:500
virtual StoreNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:375
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:590
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:423
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:534
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:444
Node for L"sub" no children.
Definition: tree.h:268
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:208
AssignmentNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:137
bool edgeSensitive
if true, true block is triggered only if previous comparison was false ("when" block).
Definition: tree.h:156
AsebaBinaryOperator op
operator
Definition: tree.h:178
virtual AssignmentNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:139
AsebaBinaryOperator
List of binary operators.
Definition: consts.h:75
StoreNode(const SourcePos &sourcePos, unsigned varAddr)
Constructor.
Definition: tree.h:374
virtual std::wstring toNodeName() const =0
Return a string representation of the name of this node.
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:440
unsigned arraySize
size of the array, might be used to assert compile-time access checks
Definition: tree.h:434
Node for assembling values into an array children[x] is the x-th Node to be assembled.
Definition: tree.h:524
unsigned arraySize
size of the array, might be used to assert compile-time access checks
Definition: tree.h:456
Node for L"block", i.e. a vector of statements.
Definition: tree.h:106
Node for L"if" and L"when".
Definition: tree.h:154
std::wstring subroutineName
the subroutine to call
Definition: tree.h:286
ProgramNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:122
std::vector< unsigned > templateArgs
sizes of templated arguments
Definition: tree.h:475
virtual BinaryArithmeticNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:308
virtual FoldedIfWhenNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:184
Node for operations like "vector (op)= something" Will expand to "vector = vector (op) something" chi...
Definition: tree.h:578
virtual CallSubNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:290
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:613
virtual unsigned getVectorSize() const
return the children's size, check for equal size, or E_NOVAL if no child
Definition: tree-expand.cpp:448
virtual ProgramNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:123
virtual unsigned getVectorAddr() const
return the address of the left-most operand, or E_NOVAL if none
Definition: tree-expand.cpp:438
virtual Node * shallowCopy()=0
Return a shallow copy of the object (children point to the same objects)
Node for loading a variable on stack.
Definition: tree.h:389
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:462
virtual FoldedWhileNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:221
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:279
LoadNode(const SourcePos &sourcePos, unsigned varAddr)
Constructor.
Definition: tree.h:394
virtual Node * expandAbstractNodes(std::wostream *dump)
Second pass to expand "abstract" nodes into more concrete ones.
Definition: tree-expand.cpp:59
virtual unsigned getVectorSize() const
return the children's size, check for equal size, or E_NOVAL if no child
Definition: tree.h:384
unsigned varAddr
address of variable to store to
Definition: tree.h:371
BlockNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:109
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:402
unsigned arraySize
size of the array, might be used to assert compile-time access checks
Definition: tree.h:413
Node for loading the address of the argument of a native function that is not known at compile time...
Definition: tree.h:452
TupleVectorNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:527
virtual Node * deepCopy()
Return a deep copy of the object (children are also copied)
Definition: tree-build.cpp:55
virtual unsigned getVectorAddr() const
return the address of the left-most operand, or E_NOVAL if none
Definition: tree.h:404
Virtual class for abstraction nodes abort() if you try to typeCheck(), optimize() or emit() to force ...
Definition: tree.h:508
ReturnType
A type a node can return.
Definition: tree.h:50
Bytecode use for compilation previous to linking.
Definition: compiler.h:483
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:275
Node for operations like "vector(op)", may be ++ or – Will expand to "vector (op)= [1...
Definition: tree.h:602
FoldedIfWhenNode(const SourcePos &sourcePos)
Constructor.
Definition: tree.h:183
virtual TupleVectorNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:529
virtual unsigned getStackDepth() const
Return the stack depth requirement for this node and its children.
Definition: tree.h:497
virtual WhileNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:201
unsigned arrayAddr
address of the first element of the array
Definition: tree.h:412
virtual std::wstring toWString() const
Return a string representation of this node.
Definition: tree.h:499
virtual BlockNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:110
Position in a source file or string. First is line, second is column.
Definition: compiler.h:156
virtual LoadNativeArgNode * shallowCopy()
Return a shallow copy of the object (children point to the same objects)
Definition: tree.h:460
virtual ReturnType typeCheck(Compiler *compiler)
Typecheck this node, throw an exception if there is any type violation.
Definition: tree.h:240
unsigned endLine
line of end keyword
Definition: tree.h:157
AsebaBinaryOperator arithmeticOp
operator
Definition: tree.h:604
unsigned tempAddr
address of temporary (end of memory) for stack value duplication
Definition: tree.h:454
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:244
virtual std::wstring toNodeName() const
Return a string representation of the name of this node.
Definition: tree.h:565