File: CppLoader.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (184 lines) | stat: -rw-r--r-- 5,196 bytes parent folder | download | duplicates (3)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#pragma once
#include "Core/Gen/CppTypes.h"
#include "Core/Io/Url.h"
#include "CppDoc.h"
#include "RootArray.h"
#include "NamedThread.h"
#include "World.h"

namespace storm {
	STORM_PKG(core.lang);

	class Package;

	/**
	 * Load objects that are defined in C++ somewhere.
	 */
	class CppLoader {
		STORM_VALUE;
	public:
		// Create, note which set of functions to be loaded.
		CppLoader(Engine &e, const CppWorld *world, World &into, MAYBE(Package *) root, MAYBE(Url *) docPath);

		// Load all types into a RootArray. This makes it possible to create instances of these types from C++.
		void loadTypes();

		// Load all threads.
		void loadThreads();

		// Set super types for all types here. Assumes threads are loaded.
		void loadSuper();

		// Load all templates into a RootArray. This makes template instantiations possible.
		void loadTemplates();

		// Insert everything into the packages where they belong.
		void loadPackages();

		// Create all exported variables in their appropriate places. Assumes types and threads are
		// placed in their packages.
		void loadVariables();

		// Create all functions in their appropriate places. Assumes types and threads are placed in
		// their packages and that variables are properly created (we might need type layout etc. in this step).
		void loadFunctions();

		// Create other metadata provided by this package (such as license and version information).
		void loadMeta();

	private:
		// Engine to load into.
		UNKNOWN(PTR_NOGC) Engine *e;

		// Source.
		UNKNOWN(PTR_NOGC) const CppWorld *world;

		// Destination.
		UNKNOWN(PTR_NOGC) World *into;

		// Assume all non-external package paths are relative to this package. Null means the system
		// root should be used.
		MAYBE(Package *) rootPackage;

		// Documentation file.
		MAYBE(Url *) docUrl;

		// Get the number of types.
		Nat typeCount() const;

		// Get the number of templates.
		Nat templateCount() const;

		// Get the number of named threads.
		Nat threadCount() const;

		// Get the number of functions.
		Nat functionCount() const;

		// Get the number of variables.
		Nat variableCount() const;

		// Get the number of enum values.
		Nat enumValueCount() const;

		// Get the number of licenses.
		Nat licenseCount() const;

		// Get the number of versions.
		Nat versionCount() const;

		// Get the number of source files.
		Nat sourceCount() const;

		// Create all licenses in their appropriate places.
		void loadLicenses();

		// Create all versions in their appropriate places.
		void loadVersions();

		// Find a NameSet corresponding to a given name.
		NameSet *findPkg(const wchar *name);

		// Find a NameSet corresponding to a given name, always relative to the root. Does not try to create packages.
		NameSet *findAbsPkg(const wchar *name);

		// Find a type as referred by a CppTypeRef.
		Value findValue(const CppTypeRef &ref);

		// Find the vtable for the type indicated.
		const void *findVTable(const CppTypeRef &ref);

		// De-virtualize a function wrt the functions first parameter.
		const void *deVirtualize(const CppTypeRef &ref, const void *fn);

		// Create a gc type for the CppType with id 'id'.
		GcType *createGcType(Nat id);

		// Create a new type based on the type description.
		Type *createType(Nat id, const CppType &type);

		// Find an external type based on the name given in the description.
		Type *findType(const CppType &type);

		// Load a single function.
		void loadFunction(const CppFunction &fn);

		// Load a free function.
		void loadFreeFunction(const CppFunction &fn);

		// Load member function.
		void loadMemberFunction(const CppFunction &fn, bool cast);

		// Load parameters for a function.
		Array<Value> *loadFnParams(const CppParam *params);

		// Load a variable.
		void loadVariable(const CppVariable &var);

		// Load an enum value.
		void loadEnumValue(const CppEnumValue &val);

		// Load a template.
		TemplateList *loadTemplate(const CppTemplate &t);

		// Get a visibility object from the C++ access.
		Visibility *visibility(CppAccess a);

		// Create documentation. Returns null if not present for the current function.
		CppDoc *createDoc(Named *entity, Nat id, MAYBE(const CppParam *) params);
		void setDoc(Named *entity, Nat id, MAYBE(const CppParam *) params);

		// Set position information on a named entity.
		void setPos(Named *entity, CppSrcPos pos);

		// Create all sources.
		void createSources();

		// See if various types are external.
		inline bool external(const CppType &t) const { return typeKind(t) == CppType::tExternal; }
		inline bool external(const CppTemplate &t) const { return t.generate == null; }
		inline bool external(const CppThread &t) const { return t.external; }

		// See if a type shall be delayed.
		inline bool delayed(const CppType &t) const {
			CppType::Kind k = typeKind(t);
			return k == CppType::tCustom
				|| k == CppType::tEnum
				|| k == CppType::tBitmaskEnum;
		}
	};

	/**
	 * Exception thrown during boot, before the "real" exception support is active.
	 */
	class CppLoadError : public ::Exception {
	public:
		CppLoadError(const String &msg) : msg(msg) {}
		virtual String what() const {
			return msg;
		}
	private:
		String msg;
	};

}