Rune - Initial PointerStor/LValueStor rework
[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 int64_t resolveGetConstExpInt64(Exp *exp);
50 float128_t resolveGetConstExpFloat128(Exp *exp);
51
52 /*
53  * lex.c
54  */
55 Lex *LexOpen(const char *path, token_t *tok);
56 void LexClose(Lex **plex);
57 int LexRedactToken(token_t *tok, int bytes);
58 int LexPeekToken(token_t *tok);
59 int LexToken(token_t *tok);
60 int LexSkipToken(token_t *tok, int type);
61 int LexStripQuotes(token_t *tok, token_t *tmp);
62 int LexError(token_t *tok, int err);
63 void LexPrintError(token_t *tok);
64 void LexPrintRef(LexRef *lr, int type);
65 void LexInitRef(LexRef *lr, token_t *tok);
66 void LexDupRef(LexRef *s, LexRef *d);
67 void LexDoneRef(LexRef *lr);
68 const char *LexErrStr(token_t *tok);
69
70 /*
71  * misc.c
72  */
73 void LibRuneInit(void);
74
75 /*
76  * heap.c
77  */
78 void *heapAlloc(PointerStor *ps, Type *type);
79
80 /*
81  * parse.c
82  */
83 int ParseOpen(Stmt *st, Parse **pp, void **dll);
84 void ParseDone(Parse *p);
85 void ParseClose(Parse **pp);
86 void AddImportPath(const char *path, int flags);
87 void PrefixImportPaths(const char *basePath);
88
89 /*
90  * parse1.c
91  */
92 int ParseModule(Parse *p, Stmt *st, int t);
93 int ParseStmt(Parse *p, int t, Stmt **pst);
94 int ParseDeclarationStmt(Parse *p, int t, int idRequired, Stmt **pst,
95                         int dop, Scope *scope);
96
97 /*
98  * parse2.c
99  */
100 int ParseScopeQual(Parse *p, int t, Scope *scope);
101 int ParseStorageQual(Parse *p, int t, int *pmask);
102 int ParseDeclaration(Parse *p, int t, Declaration **pd, int idRequired,
103                         int dop, Scope *scope);
104 int ParseType(Parse *p, int t, Type **ptype, int sqflags);
105 int ParseDeclType(Parse *p, int t, Type **ptype, SemGroup **psg,
106                         int scopeFlags, int rqflags, string_t *id,
107                         int idRequired, int isLocked);
108
109 /*
110  * parse3.c
111  */
112 int ParseExp(Parse *p, int t, Exp **pexp);
113 int ParseParenthesizedExp(Parse *p, int t, Exp **pexp, int docomp);
114 int ParseNotExp(Parse *p, int t, Exp **pexp);
115
116 /*
117  * resolve.c
118  */
119 void ResolveProject(Parse *p, Stmt *st);
120 void CollapseProject(Stmt *st);
121
122 /*
123  * stmt.c
124  */
125 Stmt *BuildRootImportStmt(const char *path);
126 void StmtPrintError(Stmt *st, int type);
127
128 /*
129  * strtable.c
130  */
131 string_t StrTableEscapeQuotedString(const char *str, int len, int term);
132 string_t StrTableAlloc(const char *str, int len, int special);
133 string_t StrTableToken(token_t *tok);
134 string_t StrTableInt(int v);
135 string_t StrTableDup(string_t str);
136 int     StrTableSpecial(string_t id);
137 int     StrTableLen(string_t id);
138 int     StrCmpToken(string_t id, token_t *tok);
139 void    *StrTableGetInfo(const char *str);
140 void    StrTableSetInfo(const char *str, void *info);
141 void ReplaceStrTable(string_t *pstr, string_t id);
142 void RelStrTable(string_t *pstr);
143 const char *StripPathId(const char *path, int *len);
144 int SimpleIntToken(token_t *tok, int *rv);
145 int SimpleRunesizeToken(token_t *tok, runesize_t *rv);
146 int StrTableEnumerate(string_t id);
147
148 /*
149  * sym.c
150  */
151 int SymKeywordFind(const char *ptr, int len, int t);
152
153 /*
154  * type.c
155  */
156 char *TypeToStr(Type *type, char **pstr);
157 int SameType(Type *t1, Type *t2, int sqFlags2);
158 int SimilarType(Type *t1, Type *t2);
159 int SimilarSemGroup(SemGroup *s1, SemGroup *s2);
160 int MatchType(Type *super, Type *type);
161 void InternalRegisterType(const char *str, const char *linkname, Type *type);
162 Type *InternalRegisteredTypeLookup(string_t id);
163 void initType(Type *type, typelist_t *list, int op);
164 void initQualType(Type *type, typelist_t *list, int op, int sqflags);
165 void initPtrType(Type *type, Type *ptrto, int sqflags);
166 void initCPtrType(Type *type, Type *ptrto, int sqflags);
167 SemGroup *BaseType(Type **ptype);
168
169 /*
170  * High-level Interpreter and Generator
171  */
172 runctx_p RunUnresolvedStmt(runctx_p ct, Stmt *st);
173 genctx_p GenUnresolvedStmt(genctx_p ct, Stmt *st);
174
175 void RunUnresolvedExp(runctx_p ct, rundata_t *data, Exp *exp);
176 int64_t Run64DefaultExp(runctx_p ct, Exp *exp);
177 gendata_t *GenUnresolvedExp(genctx_p ct, Exp *exp);
178
179 extern typelist_t DynamicTypeList;
180 extern typelist_t CompoundTypeList;
181 extern typelist_t ArgsTypeList;
182 extern typelist_t StorageTypeList;
183
184 extern void **DefaultDynamicVector;
185
186 extern Type DynamicRValueType;
187 extern Type DynamicLValueType;
188 extern Type NumericType;
189 extern Type IntegralType;
190 extern Type SIntegerType;
191 extern Type UIntegerType;
192 extern Type VoidType;
193 extern Type BoolType;
194 extern Type Int8Type;
195 extern Type UInt8Type;
196 extern Type Int16Type;
197 extern Type UInt16Type;
198 extern Type Int32Type;
199 extern Type UInt32Type;
200 extern Type Int64Type;
201 extern Type UInt64Type;
202 extern Type Int128Type;
203 extern Type UInt128Type;
204
205 extern Type FloatType;
206 extern Type Float32Type;
207 extern Type Float64Type;
208 extern Type Float128Type;
209
210 extern Type CCharType;
211 extern Type StrType;            /* NOTE: const char *, chars are unsigned */
212 extern Type CharPtrType;
213 extern Type CharPtrPtrType;
214 extern Type VoidPtrType;
215 extern Type VoidRefType;
216 extern Type CVoidPtrType;
217 extern Type LVoidPtrType;
218 extern Type PointerType;        /* generic pointer placeholder */
219 extern Type PointerInfoType;
220
221 extern Type LexRefType;         /* run-time access class tie-ins */
222 extern Type ScopeType;
223 extern Type DeclarationType;
224 extern Type SemGroupType;
225 extern Type TypeType;
226 extern Type FILLERTypeType;
227 extern Type FILLERDeclType;
228
229 extern Type IntPtrType;
230 extern Type UIntPtrType;
231 extern Type OffType;
232 extern Type SizeType;
233
234 extern Type *BaseTypeAry[];
235 extern typereglist_t TypeRegList;
236