Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPPSDK: add overrideRule to handle template generation + remove enum level checking #141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions languages/cpp/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"extractSubSchemas": true,
"unwrapResultObjects": false,
"createPolymorphicMethods": true,
"excludeDeclarations":true,
"excludeDeclarations": true,
"aggregateFiles": [
"/include/firebolt.h",
"/src/firebolt.cpp"
Expand All @@ -21,12 +21,7 @@
"/src/jsondata_module.h"
],
"persistPermission": true,
"primitives": {
"boolean": "bool",
"integer": "int32_t",
"number": "float",
"string": "std::string"
},
"primitives": {},
"langVersion" : "c++17",
"additionalSchemaTemplates": [ "json-types" ],
"additionalMethodTemplates": [ "declarations", "declarations-override" ]
Expand Down
1 change: 1 addition & 0 deletions languages/cpp/templates/json-types/object-empty-property.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
using ${title} = WPEFramework::Core::JSON::VariantContainer;
1 change: 1 addition & 0 deletions languages/cpp/templates/types/boolean.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool
1 change: 1 addition & 0 deletions languages/cpp/templates/types/integer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int32_t
1 change: 1 addition & 0 deletions languages/cpp/templates/types/number.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
float
2 changes: 2 additions & 0 deletions languages/cpp/templates/types/object-empty-property.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* ${title} */
using ${title} = std::string;
1 change: 1 addition & 0 deletions languages/cpp/templates/types/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
std::string
23 changes: 12 additions & 11 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ function generateSchemas(json, templates, options) {
else {
content = content.replace(/\$\{if\.description\}(.*?)\{end\.if\.description\}/gms, '$1')
}
const schemaShape = types.getSchemaShape(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: options.section})
const schemaShape = types.getSchemaShape(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: options.section })

content = content
.replace(/\$\{schema.title\}/, (schema.title || name))
Expand Down Expand Up @@ -943,7 +943,7 @@ function getRelatedSchemaLinks(schema = {}, json = {}, templates = {}, options =
.map(path => path.substring(2).split('/'))
.map(path => getPathOr(null, path, json))
.filter(schema => schema.title)
.map(schema => '[' + types.getSchemaType(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: state.section }) + '](' + getLinkForSchema(schema, json, { name: schema.title }) + ')') // need full module here, not just the schema
.map(schema => '[' + types.getSchemaType(schema, json, { templateDir: state.typeTemplateDir, destination: state.destination, section: state.section }) + '](' + getLinkForSchema(schema, json) + ')') // need full module here, not just the schema
.filter(link => link)
.join('\n')

Expand Down Expand Up @@ -1252,16 +1252,16 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
const pullsResultType = pullsResult && types.getSchemaShape(pullsResult, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section })
const pullsForType = pullsResult && types.getSchemaType(pullsResult, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section })
const pullsParamsType = pullsParams ? types.getSchemaShape(pullsParams, json, { destination: state.destination, templateDir: state.typeTemplateDir, section: state.section }) : ''
const serializedParams = flattenedMethod.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'parameter-serialization', property: param.name, required: param.required || false, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n')
const resultInst = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-instantiation', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, getSchemaShape skips anonymous types, like primitives
const resultInit = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-initialization', property: flattenedMethod.result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) // w/out level: 1, getSchemaShape skips anonymous types, like primitives
const serializedEventParams = event ? flattenedMethod.params.filter(p => p.name !== 'listen').map(param => types.getSchemaShape(param.schema, json, {templateDir: 'parameter-serialization', property: param.name, required: param.required || false, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true })).join('\n') : ''
const serializedParams = flattenedMethod.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'parameter-serialization', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n')
const resultInst = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-instantiation', property: flattenedMethod.result.name, required: flattenedMethod.result.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) // w/out primitive: true, getSchemaShape skips anonymous types, like primitives
const resultInit = types.getSchemaShape(flattenedMethod.result.schema, json, { templateDir: 'result-initialization', property: flattenedMethod.result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) // w/out primitive: true, getSchemaShape skips anonymous types, like primitives
const serializedEventParams = event ? flattenedMethod.params.filter(p => p.name !== 'listen').map(param => types.getSchemaShape(param.schema, json, {templateDir: 'parameter-serialization', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n') : ''
// this was wrong... check when we merge if it was fixed
const callbackSerializedParams = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-parameter-serialization', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const callbackSerializedParams = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-parameter-serialization', property: result.name, required: event.result.schema.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : ''

const callbackResultInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-result-instantiation', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const callbackResultInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-result-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : ''
// hmm... how is this different from callbackSerializedParams? i guess they get merged?
const callbackResponseInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-response-instantiation', property: result.name, destination: state.destination, section: state.section, level: 1, skipTitleOnce: true }) : ''
const callbackResponseInst = event ? types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-response-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) : ''
const resultType = result.schema ? types.getSchemaType(result.schema, json, { templateDir: state.typeTemplateDir }) : ''
const resultJsonType = result.schema ? types.getSchemaType(result.schema, json, { templateDir: 'json-types' }) : ''
const resultParams = generateResultParams(result.schema, json, templates, { name: result.name})
Expand Down Expand Up @@ -1349,7 +1349,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
.replace(/\$\{method\.result\.summary\}/g, result.summary)
.replace(/\$\{method\.result\.link\}/g, getLinkForSchema(result.schema, json)) //, baseUrl: options.baseUrl
.replace(/\$\{method\.result\.type\}/g, types.getSchemaType(result.schema, json, { templateDir: state.typeTemplateDir, title: true, asPath: false, destination: state.destination, result: true })) //, baseUrl: options.baseUrl
.replace(/\$\{method\.result\.json\}/, types.getSchemaType(result.schema, json, { templateDir: 'json-types', destination: state.destination, section: state.section, title: true, code: false, link: false, asPath: false, expandEnums: false, namespace: true }))
.replace(/\$\{method\.result\.json\}/g, types.getSchemaType(result.schema, json, { templateDir: 'json-types', destination: state.destination, section: state.section, title: true, code: false, link: false, asPath: false, expandEnums: false, namespace: true }))
// todo: what does prefix do?
.replace(/\$\{event\.result\.type\}/g, isEventMethod(methodObj) ? types.getMethodSignatureResult(event, json, { destination: state.destination, section: state.section, callback: true }) : '')
.replace(/\$\{event\.result\.json\.type\}/g, resultJsonType)
Expand All @@ -1358,6 +1358,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
.replace(/\$\{method\.result\}/g, generateResult(result.schema, json, templates, { name: result.name }))
.replace(/\$\{method\.result\.json\.type\}/g, resultJsonType)
.replace(/\$\{method\.result\.instantiation\}/g, resultInst)
.replace(/\$\{method\.result\.initialization\}/g, resultInit)
.replace(/\$\{method\.result\.properties\}/g, resultParams)
.replace(/\$\{method\.result\.instantiation\.with\.indent\}/g, indent(resultInst, ' '))
.replace(/\$\{method\.example\.value\}/g, JSON.stringify(methodObj.examples[0].result.value))
Expand Down Expand Up @@ -1603,7 +1604,7 @@ function insertParameterMacros(template, param, method, module) {
.replace(/\$\{method.param.type\}/g, type)
.replace(/\$\{json.param.type\}/g, jsonType)
.replace(/\$\{method.param.link\}/g, getLinkForSchema(param.schema, module)) //getType(param))
.replace(/\$\{method.param.constraints\}/g, constraints) //getType(param))
.replace(/\$\{method.param.constraints\}/g, constraints) //getType(param))
}

function insertCapabilityMacros(template, capabilities, method, module) {
Expand Down
Loading
Loading