diff options
Diffstat (limited to 'node/DeclNode.hh')
| -rw-r--r-- | node/DeclNode.hh | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/node/DeclNode.hh b/node/DeclNode.hh index 8360426..f51fa1b 100644 --- a/node/DeclNode.hh +++ b/node/DeclNode.hh @@ -4,22 +4,43 @@ #include <list> #include "BaseNode.hh" +#include "LiteralNode.hh" namespace pcc { -class VarDeclNode : public BaseNode { +class DeclNode : public BaseNode { public: - VarDeclNode(Context* context, VariableList* scope, - std::list<Declaration> decls); - + DeclNode(Context* context, VariableList* scope); // the scope of variable is an inherited attribute, but we don't have a good // way to set inherited attribute during the construction of AST, so we call - // this in parent's constructor + // this in parent's constructor. void SetScope(VariableList* scope); + virtual Value CodeGen() = 0; + + protected: + VariableList* scope_; +}; + +class VarDeclNode : public DeclNode { + public: + VarDeclNode(Context* context, VariableList* scope, + std::list<Declaration>&& decls); virtual Value CodeGen() override; protected: std::list<Declaration> decls_; - VariableList* scope_; +}; + +// name and type +using Constant = std::pair<std::string, std::shared_ptr<ExprNode>>; + +class ConstDeclNode : public DeclNode { + public: + ConstDeclNode(Context* context, VariableList* scope, + std::list<Constant>&& decls); + virtual Value CodeGen() override; + + protected: + std::list<Constant> decls_; }; } // namespace pcc |
