Project

General

Profile

root / trunk / compiler / cppAst / ast / identifiers / FunctionIdentifier.hpp @ 2

1 2 krennw
/**
2
  *
3
  *                  OOAS Compiler - C++ AST
4
  *
5
  * Copyright 2015, AIT Austrian Institute of Technology.
6
  * All rights reserved.
7
  *
8
  * SEE THE "LICENSE" FILE FOR THE TERMS UNDER WHICH THIS FILE IS PROVIDED.
9
  *
10
  * If you modify the file please update the list of contributors below to in-
11
  * clude your name. Please also stick to the coding convention of using TABs
12
  * to do the basic (block-level) indentation and spaces for anything after
13
  * that. (Enable the display of special chars and it should be pretty obvious
14
  * what this means.) Also, remove all trailing whitespace.
15
  *
16
  * Contributors:
17
  *               Willibald Krenn (AIT)
18
  *               Stephan Zimmerer (AIT)
19
  *               Christoph Czurda (AIT)
20
  *
21
  */
22
23
24
25
26
#pragma once
27
28
#include <ast/identifiers/Scope.hpp>
29
#include <ast/statements/Block.hpp>
30
#include <ast/identifiers/ParameterIdentifier.hpp>
31
#include <deque>
32
#include <ast/Containers.hpp>
33
34
namespace Ast {
35
36
class FunctionIdentifier
37
        : public Scope
38
{
39
protected:
40
        ParameterList m_parameter;
41
        Statement* m_body;
42
43
        FunctionIdentifier(IdentifierKind id):
44
                Scope(id),
45
                m_parameter(),
46
                m_body (nullptr)
47
        {};
48
        FunctionIdentifier(const FunctionIdentifier& toCopy):
49
                Scope(toCopy),
50
                m_parameter (toCopy.m_parameter),
51
                m_body      (toCopy.m_body)
52
        {}
53
public:
54
55
        void init (std::int32_t line, std::int32_t col, const char* text,
56
                        IScope* scopeRef, Type* typeRef, const char* prefix,
57
                        ParameterList* parameterListRef, SymbolTable* symbolTableRef, Statement* bodyRef)
58
        {
59
                Scope::init(line,col,text,scopeRef,typeRef,prefix,symbolTableRef);
60
                m_parameter = std::move(*parameterListRef);
61
                m_body = bodyRef;
62
        }
63
64
        std::deque<ParameterIdentifier*>& parameter() {return m_parameter;}
65
        const std::deque<ParameterIdentifier*>& parameter() const {return m_parameter;}
66
        Statement* body() const {return m_body;};
67
        size_t parameterCount() const {return m_parameter.size(); }
68
69
        void setBody(Statement* body) {m_body = body;};
70
        void addParameter(ParameterIdentifier* aParameter) {m_parameter.push_back(aParameter);};
71
        std::string getScopeName() const override {return toString();}
72
};
73
}