declnode.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #ifndef DECLNODE_H
  2. #define DECLNODE_H
  3. struct DeclNode : public Node{
  4. int pos;
  5. string file;
  6. DeclNode():pos(-1){}
  7. virtual void proto( DeclSeq *d,Environ *e ){}
  8. virtual void semant( Environ *e ){}
  9. virtual void translate( Codegen *g ){}
  10. virtual void transdata( Codegen *g ){}
  11. };
  12. struct DeclSeqNode : public Node{
  13. vector<DeclNode*> decls;
  14. DeclSeqNode(){}
  15. ~DeclSeqNode(){ for(;decls.size();decls.pop_back())delete decls.back(); }
  16. void proto( DeclSeq *d,Environ *e );
  17. void semant( Environ *e );
  18. void translate( Codegen *g );
  19. void transdata( Codegen *g );
  20. void push_back( DeclNode *d ){ decls.push_back( d ); }
  21. int size(){ return decls.size(); }
  22. };
  23. #include "exprnode.h"
  24. #include "stmtnode.h"
  25. //'kind' shouldn't really be in Parser...
  26. //should probably be LocalDeclNode,GlobalDeclNode,ParamDeclNode
  27. struct VarDeclNode : public DeclNode{
  28. string ident,tag;
  29. int kind;bool constant;
  30. ExprNode *expr;
  31. DeclVarNode *sem_var;
  32. VarDeclNode( const string &i,const string &t,int k,bool c,ExprNode *e ):ident(i),tag(t),kind(k),constant(c),expr(e),sem_var(0){}
  33. ~VarDeclNode(){ delete expr;delete sem_var; }
  34. void proto( DeclSeq *d,Environ *e );
  35. void semant( Environ *e );
  36. void translate( Codegen *g );
  37. };
  38. struct FuncDeclNode : public DeclNode{
  39. string ident,tag;
  40. DeclSeqNode *params;
  41. StmtSeqNode *stmts;
  42. FuncType *sem_type;
  43. Environ *sem_env;
  44. FuncDeclNode( const string &i,const string &t,DeclSeqNode *p,StmtSeqNode *ss ):ident(i),tag(t),params(p),stmts(ss){}
  45. ~FuncDeclNode(){ delete params;delete stmts; }
  46. void proto( DeclSeq *d,Environ *e );
  47. void semant( Environ *e );
  48. void translate( Codegen *g );
  49. };
  50. struct StructDeclNode : public DeclNode{
  51. string ident;
  52. DeclSeqNode *fields;
  53. StructType *sem_type;
  54. StructDeclNode( const string &i,DeclSeqNode *f ):ident(i),fields(f){}
  55. ~StructDeclNode(){ delete fields; }
  56. void proto( DeclSeq *d,Environ *e );
  57. void semant( Environ *e );
  58. void translate( Codegen *g );
  59. };
  60. struct DataDeclNode : public DeclNode{
  61. ExprNode *expr;
  62. string str_label;
  63. DataDeclNode( ExprNode *e ):expr(e){}
  64. ~DataDeclNode(){ delete expr; }
  65. void proto( DeclSeq *d,Environ *e );
  66. void semant( Environ *e );
  67. void translate( Codegen *g );
  68. void transdata( Codegen *g );
  69. };
  70. struct VectorDeclNode : public DeclNode{
  71. string ident,tag;
  72. ExprSeqNode *exprs;
  73. int kind;
  74. VectorType *sem_type;
  75. VectorDeclNode( const string &i,const string &t,ExprSeqNode *e,int k ):ident(i),tag(t),exprs(e),kind(k){}
  76. ~VectorDeclNode(){ delete exprs; }
  77. void proto( DeclSeq *d,Environ *e );
  78. void translate( Codegen *g );
  79. };
  80. #endif