-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast_decl.cc
executable file
·71 lines (56 loc) · 1.89 KB
/
ast_decl.cc
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* File: ast_decl.cc
* -----------------
* Implementation of Decl node classes.
*/
#include "ast_decl.h"
#include "ast_type.h"
#include "ast_stmt.h"
Decl::Decl(Identifier *n) : Node(*n->GetLocation()) {
Assert(n != NULL);
(id=n)->SetParent(this);
}
VarDecl::VarDecl(Identifier *n, Type *t) : Decl(n) {
Assert(n != NULL && t != NULL);
(type=t)->SetParent(this);
}
void VarDecl::PrintChildren(int indentLevel) {
type->Print(indentLevel+1);
id->Print(indentLevel+1);
}
ClassDecl::ClassDecl(Identifier *n, NamedType *ex, List<NamedType*> *imp, List<Decl*> *m) : Decl(n) {
// extends can be NULL, impl & mem may be empty lists but cannot be NULL
Assert(n != NULL && imp != NULL && m != NULL);
extends = ex;
if (extends) extends->SetParent(this);
(implements=imp)->SetParentAll(this);
(members=m)->SetParentAll(this);
}
void ClassDecl::PrintChildren(int indentLevel) {
id->Print(indentLevel+1);
if (extends) extends->Print(indentLevel+1, "(extends) ");
implements->PrintAll(indentLevel+1, "(implements) ");
members->PrintAll(indentLevel+1);
}
InterfaceDecl::InterfaceDecl(Identifier *n, List<Decl*> *m) : Decl(n) {
Assert(n != NULL && m != NULL);
(members=m)->SetParentAll(this);
}
void InterfaceDecl::PrintChildren(int indentLevel) {
id->Print(indentLevel+1);
members->PrintAll(indentLevel+1);
}
FnDecl::FnDecl(Identifier *n, Type *r, List<VarDecl*> *d) : Decl(n) {
Assert(n != NULL && r!= NULL && d != NULL);
(returnType=r)->SetParent(this);
(formals=d)->SetParentAll(this);
body = NULL;
}
void FnDecl::SetFunctionBody(Stmt *b) {
(body=b)->SetParent(this);
}
void FnDecl::PrintChildren(int indentLevel) {
returnType->Print(indentLevel+1, "(return type) ");
id->Print(indentLevel+1);
formals->PrintAll(indentLevel+1, "(formals) ");
if (body) body->Print(indentLevel+1, "(body) ");
}