Guest User

asdasdasd

a guest
May 20th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.20 KB | None | 0 0
  1. ifndef __TLL_SEMANTICS_StackCounter_H__
  2. #define __TLL_SEMANTICS_StackCounter_H__
  3.  
  4. #include "semantics/SemanticProcessor.h"
  5. #include "nodes/all.h"  // automatically generated
  6.  
  7. namespace tll {
  8.     namespace semantics {
  9.  
  10.         class StackCounter : public virtual SemanticProcessor {
  11.             int _num_bytes;
  12.         public:
  13.             StackCounter() : _num_bytes(0){}
  14.         public:
  15.             inline int num_bytes(){
  16.                 return _num_bytes;
  17.             }
  18.         public:
  19.             inline ~StackCounter(){}
  20.         public:
  21.             template<typename T> void processSimple(cdk::node::expression::Simple<T> * const node,
  22.                                       int lvl) {}
  23.             void processInteger(cdk::node::expression::Integer * const node, int lvl){}
  24.             void processDouble(cdk::node::expression::Double * const node, int lvl){}
  25.             void processString(cdk::node::expression::String * const node, int lvl){}
  26.             void processIdentifier(cdk::node::expression::Identifier * const node, int lvl){}
  27.         public:
  28.             void processUnaryExpression(cdk::node::expression::UnaryExpression * const node, int lvl){}
  29.             void processNEG(cdk::node::expression::NEG * const node, int lvl){}
  30.         public:  
  31.             void processExpressionTrash(tll::node::expression::ExpressionTrash * const node, int lvl){}
  32.         public:
  33.             void processBinaryExpression(cdk::node::expression::BinaryExpression * const node, int lvl) {}
  34.             void processADD(cdk::node::expression::ADD * const node, int lvl){}
  35.             void processSUB(cdk::node::expression::SUB * const node, int lvl){}
  36.             void processMUL(cdk::node::expression::MUL * const node, int lvl){}
  37.             void processDIV(cdk::node::expression::DIV * const node, int lvl){}
  38.             void processMOD(cdk::node::expression::MOD * const node, int lvl){}
  39.             void processLT(cdk::node::expression::LT * const node, int lvl){}
  40.             void processLE(cdk::node::expression::LE * const node, int lvl){}
  41.             void processGE(cdk::node::expression::GE * const node, int lvl){}
  42.             void processGT(cdk::node::expression::GT * const node, int lvl){}
  43.             void processNE(cdk::node::expression::NE * const node, int lvl){}
  44.             void processEQ(cdk::node::expression::EQ * const node, int lvl){}
  45.         public:
  46.            
  47.             void processADDRESS(tll::node::expression::ADDRESS * const node, int lvl){}
  48.             void processLAND(tll::node::expression::LAND * const node, int lvl){}
  49.             void processLOR(tll::node::expression::LOR * const node, int lvl){}
  50.             void processMemoryAlloc(tll::node::expression::MemoryAlloc * const node, int lvl){}
  51.             void processPOW(tll::node::expression::POW * const node, int lvl){}
  52.         public:
  53.             void processLeftValue(tll::node::expression::LeftValue * const node, int lvl){}
  54.             void processAssignmentNode(tll::node::expression::AssignmentNode * const node, int lvl){}
  55.         public:
  56.             void processFileNode(tll::node::FileNode * const node, int lvl){
  57.                 node->declarations()->accept(this, lvl);
  58.             }
  59.             void processTLLFunctionNode(tll::node::FunctionNode * const node, int lvl){
  60.                 _num_bytes += node->type()->size(); // return of this function allocated
  61.                 node->body()->accept(this, lvl);
  62.             }
  63.             void processDeclarationNode(tll::node::DeclarationNode * const node, int lvl){
  64.                 node->node()->accept(this, lvl);
  65.             }
  66.         public:
  67.             void processVariableInitializationNode(tll::node::VariableInitializationNode * const node, int lvl){
  68.                 _num_bytes += node->type()->size();
  69.             }
  70.             void processVariableDefinitionNode(tll::node::VariableDefinitionNode * const node, int lvl){
  71.                 _num_bytes += node->type()->size();
  72.             }
  73.             void processVariableDeclarationNode(tll::node::VariableDefinitionNode * const node, int lvl){}
  74.             void processFunctionArgumentsNode(tll::node::FunctionArgumentsNode * const node, int lvl){}
  75.             void processFunctionParametersNode(tll::node::FunctionParametersNode * const node, int lvl){}
  76.             void processFunctionNode(tll::node::FunctionNode * const node, int lvl){
  77.                 if(node->type() != NULL)
  78.                     _num_bytes += node->type()->size(); // return of this function allocated
  79.                 node->body()->accept(this, lvl);           
  80.             }
  81.             void processFunctionDeclarationNode(tll::node::FunctionDeclarationNode * const node, int lvl){}
  82.             void processFunctionInvocationNode(tll::node::expression::FunctionInvocationNode * const node, int lvl){}
  83.             void processFunctionRecursiveInvocationNode(tll::node::expression::FunctionRecursiveInvocationNode * const node,
  84.             int lvl){}
  85.             void processFunctionReturnValue(tll::node::expression::FunctionReturnValue * const node, int lvl){}
  86.         public:
  87.             void processBlockInstructionNode(tll::node::BlockInstructionNode * const node, int lvl){
  88.                 if(node->declarationsblock() != NULL)
  89.                     node->declarationsblock()->accept(this, lvl);
  90.                     if(node->instructionsblock() != NULL)
  91.                         node->instructionsblock()->accept(this, lvl);
  92.             }
  93.             void processInstructionNode(tll::node::InstructionNode * const node, int lvl){}
  94.             void processIndexationNode(tll::node::expression::IndexationNode * const node, int lvl){}
  95.             void processRead(tll::node::expression::Read * const node, int lvl){}
  96.             void processReadInteger(tll::node::expression::ReadInteger * const node, int lvl){}
  97.             void processPrintNode(tll::node::PrintNode * const node, int lvl){}
  98.             void processPrintlnNode(tll::node::PrintlnNode * const node, int lvl){}
  99.             void processNextInstructionNode(tll::node::NextInstructionNode * const node, int lvl){}
  100.             void processStopInstructionNode(tll::node::StopInstructionNode * const node, int lvl){}
  101.             void processReturnInstructionNode(tll::node::ReturnInstructionNode * const node, int lvl){}
  102.         public:
  103.             void processIfThenElseInstructionNode(tll::node::IfThenElseInstructionNode * const node, int lvl){
  104.                 node->thenblock()->accept(this, lvl);
  105.                     node->elseblock()->accept(this, lvl);
  106.             }
  107.             void processIfThenInstructionNode(tll::node::IfThenInstructionNode * const node, int lvl){
  108.                 node->thenblock()->accept(this, lvl);
  109.             }
  110.         public:
  111.             void processForDoInstructionNode(tll::node::ForDoInstructionNode * const node, int lvl){
  112.                 if(node->variablesblock() != NULL)
  113.                     node->variablesblock()->accept(this, lvl);
  114.                 node->doblock()->accept(this, lvl);    
  115.             }
  116.             void processDoUntilElseInstructionNode(tll::node::DoUntilElseInstructionNode * const node, int lvl){
  117.                 node->block()->accept(this, lvl);
  118.                     if(node->elseblock() != NULL)
  119.                         node->elseblock()->accept(this, lvl);
  120.             }
  121.             void processWhileDoElseInstructionNode(tll::node::WhileDoElseInstructionNode * const node, int lvl){
  122.                 node->doblock()->accept(this, lvl);
  123.                 if(node->elseblock() != NULL)
  124.                         node->elseblock()->accept(this, lvl);
  125.             }
  126.             void processNode(cdk::node::Node * const node, int lvl){}
  127.             void processNil(cdk::node::Nil * const node, int lvl){}
  128.             void processData(cdk::node::Data * const node, int lvl){}
  129.             void processComposite(cdk::node::Composite * const node, int lvl){}
  130.             void processLNEG(tll::node::expression::LNEG * const node, int lvl){}
  131.             void processSequence(cdk::node::Sequence * const node, int lvl){
  132.                 for (size_t i = 0; i < node->size(); i++) {
  133.                     node->node(i)->accept(this, lvl);
  134.                 }
  135.             }
  136.            
  137.             void processReverseSequence(tll::node::ReverseSequence * const node, int lvl){
  138.                 for (size_t i = node->size() - 1; i >= 0; i--) {
  139.                     node->node(i)->accept(this, lvl);
  140.                 }
  141.             }
  142.         }; // class StackCounter
  143.     } // namespace semantics
  144. }// namespace tll
  145.  
  146. #endif
Advertisement
Add Comment
Please, Sign In to add comment