File: Template.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; 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 (91 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download | duplicates (2)
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
#pragma once
#include "Name.h"
#include "Named.h"
#include "ValueArray.h"
#include "Core/Fn.h"
#include "Core/Gen/CppTypes.h"

namespace storm {
	STORM_PKG(core.lang);

	/**
	 * Defines something that generated Named objects based on the parameter list given.
	 * An example of use-cases is to implement template types, but it could also be used
	 * to implement template functions and packages among other things.
	 *
	 * If this class is added to a NameSet, it will be queried if no regular Named is found
	 * and therefore has the chance to generate a Named that will be used as a substitute.
	 * Any created Named will be added to the NameSet as usual to ensure proper operation
	 * of the rest of the system.
	 */
	class Template : public ObjectOn<Compiler> {
		STORM_CLASS;
	public:
		// Ctor.
		STORM_CTOR Template(Str *name);

		// Name.
		Str *name;

		// Called when something with our name is not found. Returns null if nothing is found.
		virtual MAYBE(Named *) STORM_FN generate(SimplePart *part);

		// Is this a placeholder template object? These will not be inserted in packages by 'TemplateList'.
		virtual Bool STORM_FN placeholder();
	};

	/**
	 * Template generated from a function in C++.
	 */
	class TemplateCppFn : public Template {
		STORM_CLASS;
	public:
		typedef CppTemplate::GenerateFn GenerateFn;

		// Ctor.
		TemplateCppFn(Str *name, GenerateFn fn);

		// Generate function.
		UNKNOWN(PTR_GC) GenerateFn fn;

		// Generate things.
		virtual MAYBE(Named *) STORM_FN generate(SimplePart *part);
		virtual MAYBE(Type *) STORM_FN generate(ValueArray *part);
	};


	/**
	 * Placeholder template for foreign template definitions from C++.
	 */
	class TemplatePlaceholder : public TemplateCppFn {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR TemplatePlaceholder(Str *name);

		// This is a placeholder!
		virtual Bool STORM_FN placeholder();

		// Generate things.
		virtual MAYBE(Named *) STORM_FN generate(SimplePart *part);
		virtual MAYBE(Type *) STORM_FN generate(ValueArray *part);
	};


	/**
	 * Template generated from a function in Storm/C++.
	 */
	class TemplateFn : public Template {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR TemplateFn(Str *name, Fn<MAYBE(Named *), Str *, SimplePart *> *fn);

		// Function for generation.
		Fn<MAYBE(Named *), Str *, SimplePart *> *fn;

		// Generate stuff.
		virtual MAYBE(Named *) STORM_FN generate(SimplePart *part);
	};

}