OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Static Private Member Functions | Private Attributes | List of all members
TokenizerData::TokenTreeNode Class Reference

#include <OperationDAGLanguageParser.hh>

Collaboration diagram for TokenizerData::TokenTreeNode:
Collaboration graph

Public Member Functions

 TokenTreeNode ()
 
 TokenTreeNode (Token &token)
 
bool isFunctionCall () const
 
bool isAssignment () const
 
bool isInteger () const
 
long intValue () const
 
void addToTokenTree (Token &token)
 
const Tokentoken () const
 
int leafCount () const
 
TokenTreeNodeleaf (int index) const
 
std::string toStr () const
 

Static Private Member Functions

static void addToTokenTree (TokenTreeNode *currNode, TokenTreeNode *newToken)
 

Private Attributes

Tokendata_
 Token of token tree node.
 
std::vector< TokenTreeNode * > leafs_
 Leafs of this node.
 

Detailed Description

One node of tree of tokens.

Each node contains reference to it's token and it's sub-token-nodes..

root \ function / \ name postfix / | name name

Definition at line 397 of file OperationDAGLanguageParser.hh.

Constructor & Destructor Documentation

◆ TokenTreeNode() [1/2]

TokenizerData::TokenTreeNode::TokenTreeNode ( )
inline

Definition at line 399 of file OperationDAGLanguageParser.hh.

399: data_(NULL) {}
Token * data_
Token of token tree node.

Referenced by addToTokenTree().

◆ TokenTreeNode() [2/2]

TokenizerData::TokenTreeNode::TokenTreeNode ( Token token)
inline

Definition at line 400 of file OperationDAGLanguageParser.hh.

400: data_(&token) {}

Member Function Documentation

◆ addToTokenTree() [1/2]

void TokenizerData::TokenTreeNode::addToTokenTree ( Token token)
inline

Adds newly parsed token to tree under this token tree node.

Parameters
tokenToken to add token tree.

Definition at line 485 of file OperationDAGLanguageParser.hh.

References addToTokenTree(), token(), and TokenTreeNode().

Referenced by TokenizerData::addToken(), addToTokenTree(), and addToTokenTree().

Here is the call graph for this function:

◆ addToTokenTree() [2/2]

static void TokenizerData::TokenTreeNode::addToTokenTree ( TokenTreeNode currNode,
TokenTreeNode newToken 
)
inlinestaticprivate

Adds token tree node to under other token tree node.

Parameters
currNodeNode where to add new node.
newTokenToken tree node to add to currNode.

Definition at line 561 of file OperationDAGLanguageParser.hh.

562 {
563
564 // check if token should be part of one of the leafs
565 for (std::vector<TokenTreeNode*>::iterator i =
566 currNode->leafs_.begin() ;
567 i != currNode->leafs_.end();i++) {
568 TokenTreeNode *currLeaf = *i;
569
570 // if this token should be part of current leaf
571 if (newToken->data_->start_ >= currLeaf->data_->start_ &&
572 newToken->data_->end_ <= currLeaf->data_->end_) {
573
574 addToTokenTree(currLeaf, newToken);
575 return;
576 }
577
578 // move current leafs to inside this token
579 // if necessary
580 if (newToken->data_->start_ <= currLeaf->data_->start_ &&
581 newToken->data_->end_ >= currLeaf->data_->end_) {
582
583 // remove from original
584 std::vector<TokenTreeNode*>::iterator temp = i;
585 i--;
586 currNode->leafs_.erase(temp);
587
588 // add to new...
589 newToken->leafs_.push_back(currLeaf);
590 }
591
592 // if start of current leaf is after end of this..
593 // add token to this point.
594 if (newToken->data_->end_ <= currLeaf->data_->start_) {
595 currNode->leafs_.insert(i, newToken);
596 return;
597 }
598 }
599
600 // if there wasn't any sub nodes where value could go, add it to
601 // end of current node
602 currNode->leafs_.push_back(newToken);
603 return;
604 }

References addToTokenTree(), data_, TokenizerData::Token::end_, leafs_, and TokenizerData::Token::start_.

Here is the call graph for this function:

◆ intValue()

long TokenizerData::TokenTreeNode::intValue ( ) const
inline

Definition at line 460 of file OperationDAGLanguageParser.hh.

460 {
461 if (!isInteger()) {
462 // TODO: throw exception
463 assert(false && "Node is not integer.");
464 }
465
466 long retVal = 0;
467
468 if (leafCount() == 2) {
469 retVal = leaf(1).token().intValue();
470 if (leaf(0).token().isMinusOperator()) {
471 retVal = -retVal;
472 }
473 } else {
474 retVal = token().intValue();
475 }
476
477 return retVal;
478 }
#define assert(condition)
TokenTreeNode & leaf(int index) const

References assert, TokenizerData::Token::intValue(), isInteger(), leaf(), leafCount(), and token().

Referenced by OperationDAGBuilder::getBinding().

Here is the call graph for this function:

◆ isAssignment()

bool TokenizerData::TokenTreeNode::isAssignment ( ) const
inline

Returns true if node contain tokens of assignment

leafs must be: ANY, ASSIGNMENT_OPERATOR, ANY

Returns
true if node is assginment.

Definition at line 427 of file OperationDAGLanguageParser.hh.

427 {
428 if (leafCount() == 3 &&
429 leaf(1).token().type_ == ASSIGNMENT_OPERATOR) {
430 return true;
431 }
432 return false;
433 }

References TokenizerData::ASSIGNMENT_OPERATOR, leaf(), leafCount(), and token().

Referenced by OperationDAGBuilder::parseNode().

Here is the call graph for this function:

◆ isFunctionCall()

bool TokenizerData::TokenTreeNode::isFunctionCall ( ) const
inline

Returns true if node contain tokens of function call.

leafs must be: PRIMARY_EXPRESSION, POSTFIX_EXPRESSION

Returns
true if node is function call.

Definition at line 410 of file OperationDAGLanguageParser.hh.

410 {
411 if (leafCount() == 2 &&
412 leaf(0).token().type_ == PRIMARY_EXPRESSION &&
413 leaf(1).token().type_ == POSTFIX_EXPRESSION) {
414 return true;
415 }
416 return false;
417 }

References leaf(), leafCount(), TokenizerData::POSTFIX_EXPRESSION, TokenizerData::PRIMARY_EXPRESSION, and token().

Referenced by OperationDAGBuilder::getBinding(), OperationDAGBuilder::getVariableName(), and OperationDAGBuilder::parseNode().

Here is the call graph for this function:

◆ isInteger()

bool TokenizerData::TokenTreeNode::isInteger ( ) const
inline

Returns true if node contain integer value.

leafs must be: none, or (+|-, isIntegerLiteral)

Returns
true if node is integer value.

Definition at line 442 of file OperationDAGLanguageParser.hh.

442 {
443 if (
444 // if two part integer e.g. -1 or +1
445 (leafCount() == 2 &&
446 leaf(1).token().isIntegerLiteral() &&
447 (leaf(0).token().isPlusOperator() ||
448 leaf(0).token().isMinusOperator())) ||
449
450 // or if just number without prefix
451 (leafCount() == 0 && token().isIntegerLiteral())
452 ) {
453
454 return true;
455 }
456
457 return false;
458 }

References leaf(), leafCount(), and token().

Referenced by OperationDAGBuilder::getBinding(), and intValue().

Here is the call graph for this function:

◆ leaf()

TokenTreeNode & TokenizerData::TokenTreeNode::leaf ( int  index) const
inline

Returns leaf of requested index.

Parameters
indexIndex of leaf to return.
Returns
leaf of requested index.

Definition at line 513 of file OperationDAGLanguageParser.hh.

513 {
514 assert(index < leafCount());
515 return *leafs_[index];
516 }
std::vector< TokenTreeNode * > leafs_
Leafs of this node.

References assert, leafCount(), and leafs_.

Referenced by OperationDAGBuilder::getIOOperand(), intValue(), isAssignment(), isFunctionCall(), isInteger(), OperationDAGBuilder::parse(), OperationDAGBuilder::parseNode(), and toStr().

Here is the call graph for this function:

◆ leafCount()

int TokenizerData::TokenTreeNode::leafCount ( ) const
inline

Returns number of leafs that this token tree node has.

Returns
Number of leafs that this token tree node has.

Definition at line 503 of file OperationDAGLanguageParser.hh.

503 {
504 return leafs_.size();
505 }

References leafs_.

Referenced by OperationDAGBuilder::getIOOperand(), intValue(), isAssignment(), isFunctionCall(), isInteger(), leaf(), OperationDAGBuilder::parse(), OperationDAGBuilder::parseNode(), and toStr().

◆ token()

const Token & TokenizerData::TokenTreeNode::token ( ) const
inline

◆ toStr()

std::string TokenizerData::TokenTreeNode::toStr ( ) const
inline

Returns node and its sub nodes as a string.

Returns
Node and its sub nodes as a string.

Definition at line 524 of file OperationDAGLanguageParser.hh.

524 {
525 static int recursioLevel = 0;
526
527 recursioLevel++;
528 std::stringstream retVal;
529
530 if (data_ == NULL) {
531 retVal << "Root node" << std::endl;
532 } else {
533 retVal << setw(5) << data_->start_ << ":"
534 << setw(5) << std::left << data_->end_ << std::right
535 << setw(30) << TokenizerData::idString(data_->type_)
536 << " ";
537
538 for (int fill = 0; fill < (recursioLevel-2)*2; fill++) {
539 retVal << "*";
540 }
541
542 retVal << " " << data_->strValue_ << std::endl;
543 }
544
545 for (int i = 0; i < leafCount(); i++) {
546 retVal << " " << leaf(i).toStr();
547 }
548
549 recursioLevel--;
550 return retVal.str();
551 }
static std::string idString(OperationID id)

References data_, TokenizerData::Token::end_, TokenizerData::idString(), leaf(), leafCount(), TokenizerData::Token::start_, TokenizerData::Token::strValue_, toStr(), and TokenizerData::Token::type_.

Referenced by OperationDAGBuilder::parseNode(), and toStr().

Here is the call graph for this function:

Member Data Documentation

◆ data_

Token* TokenizerData::TokenTreeNode::data_
private

Token of token tree node.

Definition at line 607 of file OperationDAGLanguageParser.hh.

Referenced by addToTokenTree(), token(), and toStr().

◆ leafs_

std::vector<TokenTreeNode*> TokenizerData::TokenTreeNode::leafs_
private

Leafs of this node.

Definition at line 610 of file OperationDAGLanguageParser.hh.

Referenced by addToTokenTree(), leaf(), and leafCount().


The documentation for this class was generated from the following file: