v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
class_parser.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 // this only works on clang
6 #ifndef __clang__
7 #ifndef __attribute__
8 #define __attribute__(x) // only used by libclang plugin, so it only needs to exist under clang
9 #endif
10 #endif
11 
12 
13 
14 /**
15  * Use these to expose classes/class functions/class data members via javascript
16  */
17 #define V8TOOLKIT_NONE_STRING "v8toolkit_generate_bindings_none"
18 #define V8TOOLKIT_ALL_STRING "v8toolkit_generate_bindings_all"
19 #define V8TOOLKIT_READONLY_STRING "v8toolkit_generate_bindings_readonly"
20 #define V8TOOLKIT_EXTEND_WRAPPER_STRING "v8toolkit_extend_wrapper"
21 
22 /**
23  * Generate V8ClassWrapper code for the annotated class
24  * ex: class V8TOOLKIT_WRAPPED_CLASS MyClassName {...};
25  */
26 #define V8TOOLKIT_WRAPPED_CLASS __attribute__((annotate(V8TOOLKIT_ALL_STRING)))
27 
28 /** Skip an entry in a class being wrapped and/or bidirectional
29  * ex: struct V8TOOLKIT_WRAPPED_CLASS MyClassName {
30  * V8TOOLKIT_SKIP void do_not_make_binding_for_me();
31  * };
32  */
33 #define V8TOOLKIT_SKIP __attribute__((annotate(V8TOOLKIT_NONE_STRING)))
34 
35 
36 /**
37  * This member cannot be assigned to.
38  * However, it is not "const", as its contents can be changed.
39  */
40 #define V8TOOLKIT_READONLY __attribute__((annotate(V8TOOLKIT_READONLY_STRING)))
41 
42 /**
43  * This function should be called while creating the mapping for this class before it is
44  * finalize()'d
45  */
46 #define V8TOOLKIT_EXTEND_WRAPPER __attribute__((annotate(V8TOOLKIT_EXTEND_WRAPPER_STRING)))
47 
48 
49 /**
50  * For setting a name alias to be used for javascript to refer to the type as
51  * -- basically sets a different constructor name when you don't have control
52  * over the class definition
53  * Usage: using MyTypeInt V8TOOLKIT_NAME_ALIAS = MyType<int>;
54  * using MyTypeChar V8TOOLKIT_NAME_ALIAS = MyType<char>;
55  * Otherwise both of those would get the same constructor name (MyType) and code generation would fail
56  */
57 #define V8TOOLKIT_NAME_ALIAS_STRING "v8toolkit_name_alias"
58 #define V8TOOLKIT_NAME_ALIAS __attribute__((annotate(V8TOOLKIT_NAME_ALIAS_STRING)))
59 
60 
61 /**
62  * Overrides the default name to be the name specified instead
63  */
64 #define V8TOOLKIT_USE_NAME_PREFIX "v8toolkit_use_name_"
65 #define V8TOOLKIT_USE_NAME(name) \
66  __attribute__((annotate(V8TOOLKIT_USE_NAME_PREFIX #name)))
67 
68 
69 
70 /**
71  * Use this to create a JavaScript constructor function with the specified name
72  */
73 #define V8TOOLKIT_EXPOSE_STATIC_METHODS_AS_PREFIX "v8toolkit_expose_static_methods_as_"
74 #define V8TOOLKIT_EXPOSE_STATIC_METHODS_AS(name) \
75  __attribute__((annotate(V8TOOLKIT_EXPOSE_STATIC_METHODS_AS_PREFIX #name)))
76 
77 
78 /**
79  * For classes with multiple inheritance, allows you to specify type(s) not to use.
80  * Templates should be specified with only the base template name, not with template parameters
81  * e.g. MyTemplatedType not MyTemplatedType<int, char*> - does not support
82  * MI to select one where type inherits from two different versions of same template
83  */
84 #define V8TOOLKIT_IGNORE_BASE_TYPE_PREFIX "v8toolkit_ignore_base_type_"
85 #define V8TOOLKIT_IGNORE_BASE_TYPE(name) \
86  __attribute__((annotate(V8TOOLKIT_IGNORE_BASE_TYPE_PREFIX #name)))
87 
88 /**
89  * For classes with multiple inheritance, allows you to specify which one to use
90  * Templates should be specified with only the base template name, not with template parameters
91  * e.g. MyTemplatedType not MyTemplatedType<int, char*> - does not support
92  * MI to select one where type inherits from two different specializations of same template
93  */
94 #define V8TOOLKIT_USE_BASE_TYPE_PREFIX "v8toolkit_use_base_type_"
95 #define V8TOOLKIT_USE_BASE_TYPE(name) \
96  __attribute__((annotate(V8TOOLKIT_USE_BASE_TYPE_PREFIX #name)))
97 
98 
99 /**
100  * This can be specified in a forward declaration of a type to eliminate all constructors from being wrapped
101  */
102 #define V8TOOLKIT_DO_NOT_WRAP_CONSTRUCTORS_STRING "v8toolkit_do_not_wrap_constructors"
103 #define V8TOOLKIT_DO_NOT_WRAP_CONSTRUCTORS __attribute__((annotate(V8TOOLKIT_DO_NOT_WRAP_CONSTRUCTORS_STRING)))
104 
105 
106 #define V8TOOLKIT_BIDIRECTIONAL_CLASS_STRING "v8toolkit_generate_bidirectional"
107 #define V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR_STRING "v8toolkit_generate_bidirectional_constructor"
108 #define V8TOOLKIT_BIDIRECTIONAL_INTERNAL_PARAMETER_STRING "V8toolkit_generate_bidirectional_internal_parameter"
109 /**
110  * Generate JSWrapper class for the annotated class
111  * ex: class V8TOOLKIT_BIDIRECTIONAL_CLASS MyClassName {...};
112  */
113 #define V8TOOLKIT_BIDIRECTIONAL_CLASS __attribute__((annotate(V8TOOLKIT_BIDIRECTIONAL_CLASS_STRING)))
114 
115 /**
116  * Annotate the constructor bidirectional should use with this
117  */
118 #define V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR __attribute__((annotate(V8TOOLKIT_BIDIRECTIONAL_CONSTRUCTOR_STRING)))
119 
120 /**
121  * Unused, but may come back.
122  * Marks a parameter as one that is always the same, not something that will change per instance
123  */
124 #define V8TOOLKIT_BIDIRECTIONAL_INTERNAL_PARAMETER __attribute__((annotate(V8TOOLKIT_BIDIRECTIONAL_INTERNAL_PARAMETER_STRING)))
125 
126 
127 #define V8TOOLKIT_CUSTOM_EXTENSION_STRING "v8toolkit_custom_extension"
128 
129 /**
130  * function will be called to extend the functionality of the constructor FunctionTemplate
131  */
132 #define V8TOOLKIT_CUSTOM_EXTENSION __attribute__((annotate(V8TOOLKIT_CUSTOM_EXTENSION_STRING)))