aboutsummaryrefslogtreecommitdiffstats
path: root/c_compiler/include/declaration.hpp
blob: bcd12a722bc5c542a6670b536eff803d6d5d7314 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#ifndef AST_DECLARATION_HPP
#define AST_DECLARATION_HPP

#include "node.hpp"
#include "type.hpp"
#include "expression.hpp"

#include <memory>

class Declaration;

typedef std::shared_ptr<Declaration> DeclarationPtr;


class Declaration : public Node {
private:
    TypePtr type_;
    std::string id_;
    ExpressionPtr initializer_;
    DeclarationPtr next_declaration_;
    DeclarationPtr next_list_declaration_;
    bool extern_declaration_;
    
public:
    Declaration(const std::string& id = "", Expression* initializer = nullptr);

    virtual void print() const;
    virtual void printXml() const;
    virtual VariableStackBindings printAsm(VariableStackBindings bindings, unsigned& label_count) const;

    VariableStackBindings localAsm(VariableStackBindings bindings, unsigned& label_count) const;

    void linkDeclaration(Declaration* next_declaration);
    void linkListDeclaration(Declaration* next_list_declaration);

    void setType(TypePtr type);
    void setInitializer(Expression* initializer);
    void setExternDeclaration(bool is_extern);

    DeclarationPtr getNext() const;
    DeclarationPtr getNextListItem() const;
    std::string getId() const;
    TypePtr getType() const;
};

#endif