-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.h
86 lines (71 loc) · 2.8 KB
/
util.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef DJ2LL_UTIL_HEADER
#define DJ2LL_UTIL_HEADER
#ifdef __cplusplus
extern "C" {
#endif
#include "ast.h"
#include "symtbl.h"
#include "typecheck.h"
// the five built-in DJ types and an error type
#define BAD_TYPE -5 // illegal type
#define NO_OBJECT -4 // the type of Object's superclass
#define ANY_OBJECT -3 // the type of "null"
#define TYPE_BOOL -2
#define TYPE_NAT -1
#define OBJECT_TYPE 0 // the type of every user-defined class' superclass
// colors for pretty-printing error messages
// just having a little fun!
#define LRESET "\033[0m"
#define LRED "\033[31m"
#define LGREEN "\033[32m"
#define LBOLDRED "\33[1m\033[31m"
#define LBOLDGREEN "\033[1m\033[32m"
#define LBOLDMAGENTA "\033[1m\033[35m"
char *BRBTR(char *arg);
char *BGBTR(char *arg);
char *BMBTR(char *arg);
#define FOURSPACES " "
#define EIGHTSPACES FOURSPACES FOURSPACES
#define TWELVESPACES EIGHTSPACES FOURSPACES
#define NULL_CHECK(somePointer) \
if (somePointer == NULL) { \
fprintf( \
stderr, \
"%s(internal error)\nFound NULL pointer with name %s%s\"%s\"%s%s in " \
"function%s%s \"%s\"%s%s, exiting.\n%s", \
LRED, LRESET, LBOLDGREEN, #somePointer, LRESET, LRED, LRESET, \
LBOLDMAGENTA, __func__, LRESET, LRED, LRESET); \
exit(-1); \
}
#define DEBUG_TYPE(someType) \
printf("type of expr with variable name %s from function %s is %s\n", \
#someType, __func__, typeString(someType));
typedef struct {
int classNum;
int methodIndex;
int paramType;
int returnType;
} methodInfo;
typedef struct {
int indexST; // index in the symbol table this variable resides
int isStatic;
} classVarInfo;
classVarInfo lookupVarIndex(char *identifier, int CCE, int lineNumber);
void reportLookupError(char *requestedVar, int lineNumber);
int lookupMainST(char *desired, int lineNumber);
int lookupClassesST(char *desired, int lineNumber);
int lookupClassVars(char *desired, int lineNumber, int CCE);
int lookupVarType(char *desired, int CCE, int MCE, int usageLine);
methodInfo findMethodIndex(int CCE, char *methodName, int lineNumber);
int join(int a, int b);
void printMainST(void);
void printVarDeclST(VarDecl *st, int size, char *theClass, char *modifier);
void printMethodDeclST(MethodDecl *st, int size, char *theClass);
void printClassesST(void);
char *typeString(int t);
char *nodeTypeString(ASTNodeType t);
char *numToString(int n);
#ifdef __cplusplus
}
#endif
#endif // #DJ2LL_UTIL_HEADER