Skip to content

Commit

Permalink
feat: Fix issues in generated headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Santhosh Ramani committed Sep 6, 2023
1 parent 8b37a49 commit fd66f37
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 61 deletions.
12 changes: 6 additions & 6 deletions languages/cpp/templates/declarations/default.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
${method.name}
${method.description}
${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}${end.if.deprecated}
*/
virtual int32_t ${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}${method.result.type}& ${method.result.name}${end.if.result} ) = 0;
/*
${method.name}
${method.description}
${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}${end.if.deprecated}
*/
virtual int32_t ${method.Name}( ${method.signature.params}${if.result}${if.params}, ${end.if.params}${method.result.type}& ${method.result.name}${end.if.result} ) = 0;
18 changes: 8 additions & 10 deletions languages/cpp/templates/declarations/event.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* ${method.name} - ${method.description} */
struct I${method.Name}Notification {
virtual void ${method.Name} ( ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${method.result.properties} ) = 0;
};

virtual int32_t subscribe ( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${method.Name}Notification& notification ) = 0;
virtual int32_t unsubscribe ( I${method.Name}Notification& notification ) = 0;

// signature callback params: ${event.signature.callback.params}
// method result properties : ${method.result.properties}
/* ${method.name} - ${method.description} */
struct I${method.Name}Notification {
virtual void ${method.Name} ( ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${method.result.properties} ) = 0;
};
// signature callback params: ${event.signature.callback.params}
// method result properties : ${method.result.properties}
virtual int32_t subscribe ( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${method.Name}Notification& notification ) = 0;
virtual int32_t unsubscribe ( I${method.Name}Notification& notification ) = 0;
14 changes: 7 additions & 7 deletions languages/cpp/templates/declarations/polymorphic-pull-event.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* ${method.name} - ${method.description} */
struct I{method.Name}Notification {
virtual void ${method.Name} ( ${method.pulls.param.type}& value ) = 0;
};
virtual int32_t subscribe ( I{method.Name}Notification& notification ) = 0;
virtual int32_t unsubscribe ( I{method.Name}Notification& notification ) = 0;
/* ${method.name} - ${method.description} */
struct I{method.Name}Notification {
virtual void ${method.Name} ( ${method.pulls.param.type}& value ) = 0;
};

virtual int32_t subscribe ( I{method.Name}Notification& notification ) = 0;
virtual int32_t unsubscribe ( I{method.Name}Notification& notification ) = 0;

4 changes: 2 additions & 2 deletions languages/cpp/templates/declarations/polymorphic-pull.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/* ${method.name} - ${method.description} */
virtual int32_t ${method.Name}( ${method.signature.params} ) = 0;
/* ${method.name} - ${method.description} */
virtual int32_t ${method.Name}( ${method.signature.params} ) = 0;
10 changes: 5 additions & 5 deletions languages/cpp/templates/declarations/polymorphic-reducer.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ${method.summary}
* ${method.params}
*/
virtual int32_t ${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}) = 0;
/*
* ${method.summary}
* ${method.params}
*/
virtual int32_t ${method.Name}(${method.signature.params}${if.result.properties}${if.params}, ${end.if.params}${end.if.result.properties}${method.result.properties}) = 0;
10 changes: 5 additions & 5 deletions languages/cpp/templates/declarations/property.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* ${method.description}
* ${method.params}
*/
virtual int32_t ${method.Name} (${method.signature.params}${if.params}, ${end.if.params}${method.result.properties}) = 0;
/*
* ${method.description}
* ${method.params}
*/
virtual int32_t ${method.Name} (${method.signature.params}${if.params}, ${end.if.params}${method.result.properties}) = 0;
10 changes: 5 additions & 5 deletions languages/cpp/templates/declarations/setter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
${method.rpc.name}
${method.description}
*/
virtual int32_t ${method.Name}( ${method.signature.params} ) = 0;
/*
${method.rpc.name}
${method.description}
*/
virtual int32_t ${method.Name}( ${method.signature.params} ) = 0;
12 changes: 6 additions & 6 deletions languages/cpp/templates/modules/include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
namespace ${info.Title} {

// Enums
/* ${ENUMS} */
/* ${ENUMS} */

// Types
/* ${TYPES} */

struct I${info.Title} {
struct I${info.Title} {

virtual ~I${info.Title} = default;
virtual ~I${info.Title} = default;

// Methods & Events
/* ${DECLARATIONS} */
// Methods & Events
/* ${DECLARATIONS} */

};
};

} //namespace ${info.Title}
}${end.if.declarations}
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/additionalProperties.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
std::unordered_map<std::string,${type}> title;
${title} value;
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/array.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
std::vector<${type}> ${title};
std::vector<${type}>
1 change: 0 additions & 1 deletion languages/cpp/templates/types/null.h
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
nullptr
2 changes: 1 addition & 1 deletion languages/cpp/templates/types/property.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property}; // ${summary}
${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property};
6 changes: 1 addition & 5 deletions languages/cpp/templates/types/tuple.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
/* ${title} */
struct ${title} {

${properties}

};
std::pair<${type},${type}> ${title};
12 changes: 6 additions & 6 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ const promoteSchema = (location, property, title, document, destinationPath) =>
}

// only consider sub-objects and sub enums to be sub-schemas
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum) || (schema.type === 'array' && schema.items)
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum) // || (schema.type === 'array' && schema.items)

const promoteAndNameSubSchemas = (obj) => {
// make a copy so we don't polute our inputs
Expand Down Expand Up @@ -506,7 +506,7 @@ const generateMacros = (obj, templates, languages, options = {}) => {
macros.types[dir] = getTemplate('/sections/types', templates).replace(/\$\{schema.list\}/g, schemasArray.filter(x => !x.enum).map(s => s.body).filter(body => body).join('\n'))
macros.enums[dir] = getTemplate('/sections/enums', templates).replace(/\$\{schema.list\}/g, schemasArray.filter(x => x.enum).map(s => s.body).filter(body => body).join('\n'))
})

state.typeTemplateDir = 'types'
const examples = generateExamples(obj, templates, languages)
const allMethodsArray = generateMethods(obj, examples, templates)
const methodsArray = allMethodsArray.filter(m => m.body && !m.event && (!options.hideExcluded || !m.excluded))
Expand Down Expand Up @@ -1483,7 +1483,7 @@ function generateResultParams(result, json, templates, {name = ''}={}) {
const template = getTemplate('/parameters/result', templates)
return Object.entries(result.properties).map( ([name, type]) => template
.replace(/\$\{method\.param\.name\}/g, name)
.replace(/\$\{method\.param\.type\}/g, types.getSchemaType(type, json, {name: name, moduleTitle: moduleTitle, result: true}))
.replace(/\$\{method\.param\.type\}/g, types.getSchemaType(type, json, {name: name, moduleTitle: moduleTitle, result: true, namespace: true}))
).join(', ') // most languages separate params w/ a comma, so leaving this here for now
}
// tuples get unwrapped
Expand All @@ -1492,14 +1492,14 @@ function generateResultParams(result, json, templates, {name = ''}={}) {
const template = getTemplate('/parameters/result', templates)
return result.items.map( (type) => template
.replace(/\$\{method\.param\.name\}/g, type['x-property'])
.replace(/\$\{method\.param\.type\}/g, types.getSchemaType(type, json, {name: name, moduleTitle: moduleTitle, result: true}))
.replace(/\$\{method\.param\.type\}/g, types.getSchemaType(type, json, {name: name, moduleTitle: moduleTitle, result: true, namespace: true}))
).join(', ')
}
// everything else is just output as-is
else {
const template = getTemplate('/parameters/result', templates)
const type = types.getSchemaType(result, json, {name: name, moduleTitle: moduleTitle, result: true})

const template = getTemplate('/parameters/result', templates)
const type = types.getSchemaType(result, json, {name: name, moduleTitle: moduleTitle, result: true, namespace: true})
if (type === 'undefined') {
console.log(`Warning: undefined type for ${name}`)
}
Expand Down

0 comments on commit fd66f37

Please sign in to comment.