-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathast_type.cc
executable file
·53 lines (42 loc) · 1.29 KB
/
ast_type.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
/* File: ast_type.cc
* -----------------
* Implementation of type node classes.
*/
#include "ast_type.h"
#include "ast_decl.h"
#include <string.h>
/* Class constants
* ---------------
* These are public constants for the built-in base types (int, double, etc.)
* They can be accessed with the syntax Type::intType. This allows you to
* directly access them and share the built-in types where needed rather that
* creates lots of copies.
*/
Type *Type::intType = new Type("int");
Type *Type::doubleType = new Type("double");
Type *Type::voidType = new Type("void");
Type *Type::boolType = new Type("bool");
Type *Type::nullType = new Type("null");
Type *Type::stringType = new Type("string");
Type *Type::errorType = new Type("error");
Type::Type(const char *n) {
Assert(n);
typeName = strdup(n);
}
void Type::PrintChildren(int indentLevel) {
printf("%s", typeName);
}
NamedType::NamedType(Identifier *i) : Type(*i->GetLocation()) {
Assert(i != NULL);
(id=i)->SetParent(this);
}
void NamedType::PrintChildren(int indentLevel) {
id->Print(indentLevel+1);
}
ArrayType::ArrayType(yyltype loc, Type *et) : Type(loc) {
Assert(et != NULL);
(elemType=et)->SetParent(this);
}
void ArrayType::PrintChildren(int indentLevel) {
elemType->Print(indentLevel+1);
}