-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathast.cc
55 lines (47 loc) · 1.19 KB
/
ast.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
/* File: ast.cc
* ------------
*/
#include "ast.h"
#include "ast_type.h"
#include "ast_decl.h"
#include <string.h> // strdup
#include <stdio.h> // printf
#include "errors.h"
#include "scope.h"
Node::Node(yyltype loc) {
location = new yyltype(loc);
parent = NULL;
nodeScope = NULL;
}
Node::Node() {
location = NULL;
parent = NULL;
nodeScope = NULL;
}
Decl *Node::FindDecl(Identifier *idToFind, lookup l) {
Decl *mine;
if (!nodeScope) PrepareScope();
if (nodeScope && (mine = nodeScope->Lookup(idToFind)))
return mine;
if (l == kDeep && parent)
return parent->FindDecl(idToFind, l);
return NULL;
}
Identifier::Identifier(yyltype loc, const char *n) : Node(loc) {
name = strdup(n);
cached = NULL;
}
Decl *Identifier::GetDeclRelativeToBase(Type *baseType)
{
if (!cached) {
if (!baseType)
cached = FindDecl(this);
else if (!baseType->IsNamedType())
return NULL; // only classes are aggregates
else {
Decl *cd = dynamic_cast<NamedType*>(baseType)->GetDeclForType();
cached = (cd ? cd->FindDecl(this, kShallow) : NULL);
}
}
return cached;
}