MCPcopy Create free account
hub / github.com/defold/defold / gen_cpp_header

Function gen_cpp_header

scripts/dmsdk/gen_cpp.py:160–295  ·  view source on GitHub ↗
(basepath, c_header_path, out_path, info, ast, state, includes, docs)

Source from the content-addressed store, hash-verified

158 l('')
159
160def gen_cpp_header(basepath, c_header_path, out_path, info, ast, state, includes, docs):
161 _reset_globals()
162
163 l('// Generated, do not edit!')
164 l('// Generated with cwd=%s and cmd=%s\n' % (os.getcwd(), ' '.join(sys.argv)))
165
166 license = info.get('license', 'License: Defold License (https://github.com/defold/defold/blob/dev/LICENSE.txt)')
167 license = license.split('\n')
168 license = '\n'.join(['// ' + line for line in license])
169
170 l('%s\n' % license)
171
172 basename = os.path.basename(out_path).replace('.', '_')
173 basename = basename.upper()
174 l('#ifndef DMSDK_%s' % basename)
175 l('#define DMSDK_%s' % basename)
176 l('')
177 l('#if !defined(__cplusplus)')
178 l(' #error "This file is supported in C++ only!"')
179 l('#endif')
180 l('')
181
182 api_name = docs.get('name', None)
183 if api_name is None:
184 api_name = os.path.splitext(os.path.basename(out_path))[0].capitalize()
185
186 language = 'C++'
187 brief = docs.get('brief', '')
188 description = docs.get('desc', '')
189 description = description.replace('\n', '\n * ')
190
191 if api_name is None:
192 api_name = os.path.splitext(os.path.basename(out_path))[0].capitalize()
193
194 namespace = info.get('namespace', None)
195
196 source_path = os.path.relpath(out_path, basepath)
197 doc_header = gen_doc_header(api_name, brief, description, language, namespace, source_path)
198 l(doc_header)
199
200 for include in includes:
201 if os.path.normpath(out_path).endswith(os.path.normpath(include)):
202 continue # skip self includes
203 l('#include <%s>' % include)
204
205 l('')
206 l('#include <%s>' % c_header_path)
207 l('')
208
209 if not namespace:
210 raise Exception("C++ header has no 'namespace' defined!")
211
212 l('namespace %s' % info['namespace'])
213 l('{')
214
215 ignores = info.get('ignore', [])
216 prefixes = info.get('rename', {})
217

Callers

nothing calls this directly

Calls 10

get_cpp_funcFunction · 0.85
add_c_docsFunction · 0.85
replaceMethod · 0.80
_reset_globalsFunction · 0.70
lFunction · 0.70
gen_doc_headerFunction · 0.70
rename_symbolsFunction · 0.70
gen_docFunction · 0.70
getMethod · 0.65
splitMethod · 0.65

Tested by

no test coverage detected