v8toolkit  0.0.1
Utility library for embedding V8 Javascript engine in a c++ program
parsed_method.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "class_parser.h"
4 #include "helper_functions.h"
5 
6 
7 
8 
9 
10 
11 
12 struct ClassFunction {
13 
14 
15  // class the method is in
17  bool is_static;
18  bool is_virtual;
19 
20  // if this virtual function doesn't exist in a parent class
22 
23  struct TypeInfo {
24 
25  private:
26  static string convert_simple_typename_to_jsdoc(string simple_type_name);
27 
28  public:
29  QualType type;
30 
31  // removes reference and all pointers, but keeps qualifications on the "plain type"
32  // double const * const **& => double const
33  // double * const **& => double
34  QualType plain_type;
35 
36  CXXRecordDecl const * get_plain_type_decl() const;
37 
38  /// name of actual type
39  string name;
40 
41  /// name of type without reference or pointers
42  string plain_name;
43 
44  /// corresponding javascript type
45  string get_jsdoc_type_name() const;
46 
47  TypeInfo(QualType const & type);
48 
49  // return if the type (or the type being pointed/referred to) is const (not is the pointer const)
50  // double * const => false
51  // double const * => true
52  bool is_const() const;
53 
55 
56  bool is_templated() const;
57  void for_each_templated_type(std::function<void(QualType)>) const;
58 
59  bool is_void() const {return this->type->isVoidType();}
60  };
61 
62 
63  /* PARAMETER INFO */
64  class ParameterInfo {
65  friend class ClassFunction;
66  protected:
68  CompilerInstance & compiler_instance;
69  ParmVarDecl const * parameter_decl;
70  int position;
71  string name;
72  string default_value;
73 
74  // description of parameter pulled from doxygen comment
75  string description = "";
76 
77 
78  public:
79  ParameterInfo(ClassFunction & method, int position, ParmVarDecl const * parameter_decl, CompilerInstance & compiler_instance);
80  string generate_js_stub();
81 
82  TypeInfo const type;
83 
84 
85  }; // end ParameterInfo
86 
89  vector<ParameterInfo> parameters;
90  CXXMethodDecl const * method_decl;
91 
92  // c++ name
93  string name;
94 
95  // name used in javascript
96  string js_name;
97  CompilerInstance & compiler_instance;
99 
100  string get_default_argument_tuple_string() const;
101 
102  // returns string containing function name and input parameters - this function is likely not exactly correct
103  // per c++ standard
104  string get_signature_string();
105 
106  ClassFunction(WrappedClass & wrapped_class,
107  CXXMethodDecl const * method_decl);
108 
109 
110 
111  // returns true if the methods have the same name and input parameters
112  bool compare_signatures(ClassFunction const & other);
113 
114  string get_parameter_types_string() const;
117  string get_js_input_parameter_string() const;
118 
119 
120 };
121 
122 
124 public:
125  MemberFunction(WrappedClass & wrapped_class, CXXMethodDecl const * method_decl);
126  string generate_js_bindings();
127  string generate_js_stub();
128  string generate_bidirectional();
129 };
130 
132 public:
133  StaticFunction(WrappedClass & wrapped_class, CXXMethodDecl const * method_decl);
134  string generate_js_bindings();
135  string generate_js_stub();
136 };
137 
139 
140 public:
141  ConstructorFunction(WrappedClass & wrapped_class, CXXConstructorDecl const * constructor_decl);
142 
143  string generate_js_bindings();
144  string generate_js_stub();
145 
146  CXXConstructorDecl const * const constructor_decl;
147 
148 };
149 
150 struct WrappedClass;
151 struct DataMember {
153  WrappedClass & declared_in; // level in the hierarchy the member is actually declared at - may match wrapped_class
154  string short_name;
155  string long_name;
157  FieldDecl const * field_decl;
159 
160  // whether the WRAPPING should be const, not necessarily whether the actual c++ type is
161  bool is_const = false;
162 
163  DataMember(WrappedClass & wrapped_class, WrappedClass & declared_in, FieldDecl * field_decl);
164 
165  string get_js_stub();
166  string get_bindings();
167 
168 };
TypeInfo return_type
Definition: parsed_method.h:87
WrappedClass & wrapped_class
Definition: parsed_method.h:16
WrappedClass & declared_in
WrappedClass & wrapped_class
vector< ParameterInfo > parameters
Definition: parsed_method.h:89
ParmVarDecl const * parameter_decl
Definition: parsed_method.h:69
string name
name of actual type
Definition: parsed_method.h:39
string get_parameter_types_string() const
ClassFunction::TypeInfo type
string get_return_and_parameter_types_string() const
CXXRecordDecl const * get_plain_type_decl() const
TypeInfo plain_without_const() const
string get_signature_string()
CompilerInstance & compiler_instance
Definition: parsed_method.h:68
ClassFunction(WrappedClass &wrapped_class, CXXMethodDecl const *method_decl)
string get_js_input_parameter_string() const
Annotations annotations
string long_name
CXXConstructorDecl const *const constructor_decl
FieldDecl const * field_decl
string get_default_argument_tuple_string() const
bool compare_signatures(ClassFunction const &other)
string return_type_comment
Definition: parsed_method.h:88
string get_return_and_class_and_parameter_types_string() const
CompilerInstance & compiler_instance
Definition: parsed_method.h:97
string get_jsdoc_type_name() const
corresponding javascript type
void for_each_templated_type(std::function< void(QualType)>) const
string short_name
CXXMethodDecl const * method_decl
Definition: parsed_method.h:90
Annotations annotations
Definition: parsed_method.h:98
string plain_name
name of type without reference or pointers
Definition: parsed_method.h:42
TypeInfo(QualType const &type)