Rune - Rework resolver
[rune.git] / librune / export.h
1 /*
2  * EXPORT.H
3  *
4  * (c)Copyright 1993-2014, Matthew Dillon, All Rights Reserved.  See the  
5  *    COPYRIGHT file at the base of the distribution.
6  */
7
8 /*
9  * Headers needed by others using this library
10  */
11 #include <sys/types.h>
12 #include <stdint.h>
13 #include <limits.h>
14
15 #include "lex.h"
16 #include "sym.h"
17 #include "type.h"
18 #include "decl.h"
19 #include "exp.h"
20 #include "stmt.h"
21 #include "parse.h"
22 #include "insn.h"
23 #include "context.h"
24
25 /*
26  * debug_lex.c
27  */
28 void LexDebugLine(token_t *tok);
29
30 /*
31  * decl.c
32  */
33 Declaration *FindDeclId(SemGroup *db, string_t id, int *eno);
34 Declaration *FindDeclIdLevel(SemGroup *db, string_t id, int level, int *eno);
35 Declaration *FindDeclByIndex(SemGroup *sg, int index);
36 void DeclPrintError(Declaration *d, int type);
37 Declaration *FindDeclPath(LexRef *lexRef, SemGroup *osg, SemGroup *sg,
38                         Type *nomatch, string_t *ary, int mask,
39                         int *visibility, int level, int *eno);
40 Declaration *FindDeclPathAltContext(LexRef *lexRef, SemGroup *osg, SemGroup *sg,
41                         Type *nomatch, string_t *ary, int mask,
42                         int *visibility, int level, int *eno);
43 void *FindDLLSymbol(SemGroup *osg, SemGroup *sg, string_t id);
44
45 /*
46  * exp.c
47  */
48 void ExpPrintError(Exp *exp, int type);
49
50 /*
51  * lex.c
52  */
53 Lex *LexOpen(const char *path, token_t *tok);
54 void LexClose(Lex **plex);
55 int LexRedactToken(token_t *tok, int bytes);
56 int LexPeekToken(token_t *tok);
57 int LexToken(token_t *tok);
58 int LexSkipToken(token_t *tok, int type);
59 int LexStripQuotes(token_t *tok, token_t *tmp);
60 int LexError(token_t *tok, int err);
61 void LexPrintError(token_t *tok);
62 void LexPrintRef(LexRef *lr, int type);
63 void LexInitRef(LexRef *lr, token_t *tok);
64 void LexDupRef(LexRef *s, LexRef *d);
65 void LexDoneRef(LexRef *lr);
66 const char *LexErrStr(token_t *tok);
67
68 /*
69  * misc.c
70  */
71 void LibRuneInit(void);
72
73 /*
74  * heap.c
75  */
76 void *heapAlloc(PointerStor *ps, Type *type);
77
78 /*
79  * parse.c
80  */
81 int ParseOpen(Stmt *st, Parse **pp, void **dll);
82 void ParseDone(Parse *p);
83 void ParseClose(Parse **pp);
84 void AddImportPath(const char *path, int flags);
85 void PrefixImportPaths(const char *basePath);
86
87 /*
88  * parse1.c
89  */
90 int ParseModule(Parse *p, Stmt *st, int t);
91 int ParseStmt(Parse *p, int t, Stmt **pst);
92 int ParseDeclarationStmt(Parse *p, int t, int idRequired, Stmt **pst,
93                         int dop, Scope *scope);
94
95 /*
96  * parse2.c
97  */
98 int ParseScopeQual(Parse *p, int t, Scope *scope);
99 int ParseStorageQual(Parse *p, int t, int *pmask);
100 int ParseDeclaration(Parse *p, int t, Declaration **pd, int idRequired,
101                         int dop, Scope *scope);
102 int ParseType(Parse *p, int t, Type **ptype, int sqflags);
103 int ParseDeclType(Parse *p, int t, Type **ptype, SemGroup **psg,
104                         int scopeFlags, int rqflags, string_t *id,
105                         int idRequired, int isLocked);
106
107 /*
108  * parse3.c
109  */
110 int ParseExp(Parse *p, int t, Exp **pexp);
111 int ParseParenthesizedExp(Parse *p, int t, Exp **pexp, int docomp);
112 int ParseNotExp(Parse *p, int t, Exp **pexp);
113
114 /*
115  * resolve.c
116  */
117 void ResolveProject(Parse *p, Stmt *st);
118 void CollapseProject(Stmt *st);
119
120 /*
121  * stmt.c
122  */
123 Stmt *BuildRootImportStmt(const char *path);
124 void StmtPrintError(Stmt *st, int type);
125
126 /*
127  * strtable.c
128  */
129 string_t StrTableEscapeQuotedString(const char *str, int len, int term);
130 string_t StrTableAlloc(const char *str, int len, int special);
131 string_t StrTableToken(token_t *tok);
132 string_t StrTableInt(int v);
133 string_t StrTableDup(string_t str);
134 int     StrTableSpecial(string_t id);
135 int     StrTableLen(string_t id);
136 int     StrCmpToken(string_t id, token_t *tok);
137 void ReplaceStrTable(string_t *pstr, string_t id);
138 void RelStrTable(string_t *pstr);
139 const char *StripPathId(const char *path, int *len);
140 int SimpleIntToken(token_t *tok, int *rv);
141 int SimpleRunesizeToken(token_t *tok, runesize_t *rv);
142 int StrTableEnumerate(string_t id);
143
144 /*
145  * sym.c
146  */
147 int SymKeywordFind(const char *ptr, int len, int t);
148
149 /*
150  * type.c
151  */
152 char *TypeToStr(Type *type, char **pstr);
153 int SameType(Type *t1, Type *t2, int sqFlags2);
154 int SimilarType(Type *t1, Type *t2);
155 int SimilarSemGroup(SemGroup *s1, SemGroup *s2);
156 int MatchType(Type *super, Type *type);
157 void InternalRegisterType(const char *str, const char *linkname, Type *type);
158 Type *InternalRegisteredTypeLookup(string_t id);
159 void initType(Type *type, typelist_t *list, int op);
160 void initQualType(Type *type, typelist_t *list, int op, int sqflags);
161 void initPtrType(Type *type, Type *ptrto, int sqflags);
162 void initCPtrType(Type *type, Type *ptrto, int sqflags);
163 SemGroup *BaseType(Type **ptype);
164
165 /*
166  * High-level Interpreter and Generator
167  */
168 runctx_p RunUnresolvedStmt(runctx_p ct, Stmt *st);
169 genctx_p GenUnresolvedStmt(genctx_p ct, Stmt *st);
170
171 void RunUnresolvedExp(runctx_p ct, rundata_t *data, Exp *exp);
172 int64_t Run64DefaultExp(runctx_p ct, Exp *exp);
173 gendata_t *GenUnresolvedExp(genctx_p ct, Exp *exp);
174
175 extern typelist_t DynamicTypeList;
176 extern typelist_t CompoundTypeList;
177 extern typelist_t ArgsTypeList;
178 extern typelist_t StorageTypeList;
179
180 extern void **DefaultDynamicVector;
181
182 extern Type DynamicRValueType;
183 extern Type DynamicLValueType;
184 extern Type NumericType;
185 extern Type IntegralType;
186 extern Type SIntegerType;
187 extern Type UIntegerType;
188 extern Type VoidType;
189 extern Type BoolType;
190 extern Type Int8Type;
191 extern Type UInt8Type;
192 extern Type Int16Type;
193 extern Type UInt16Type;
194 extern Type Int32Type;
195 extern Type UInt32Type;
196 extern Type Int64Type;
197 extern Type UInt64Type;
198 extern Type Int128Type;
199 extern Type UInt128Type;
200
201 extern Type FloatType;
202 extern Type Float32Type;
203 extern Type Float64Type;
204 extern Type Float128Type;
205
206 extern Type CCharType;
207 extern Type StrType;            /* NOTE: const char *, chars are unsigned */
208 extern Type CharPtrType;
209 extern Type CharPtrPtrType;
210 extern Type VoidPtrType;
211 extern Type VoidRefType;
212 extern Type CVoidPtrType;
213 extern Type LVoidPtrType;
214 extern Type PointerType;        /* generic pointer placeholder */
215
216 extern Type LexRefType;         /* run-time access class tie-ins */
217 extern Type ScopeType;
218 extern Type DeclarationType;
219 extern Type SemGroupType;
220 extern Type TypeType;
221 extern Type FILLERTypeType;
222 extern Type FILLERDeclType;
223
224 extern Type IntPtrType;
225 extern Type UIntPtrType;
226 extern Type OffType;
227 extern Type SizeType;
228
229 extern Type *BaseTypeAry[];
230 extern typereglist_t TypeRegList;
231