Skip to content

Commit

Permalink
Create namespaces only if there is value to put
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jul 19, 2023
1 parent 549e4a0 commit bc3e3d4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 21 deletions.
7 changes: 4 additions & 3 deletions languages/c/templates/modules/include/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
#include <firebolt.h>
/* ${IMPORTS} */

#ifdef __cplusplus
${if.declarations}#ifdef __cplusplus
extern "C" {
#endif

// Enums

/* ${ENUMS} */

// Accessors
/* ${ACCESSORS} */

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

#ifdef __cplusplus
}
#endif
#endif${end.if.declarations}

#endif // Header Include Guard
13 changes: 9 additions & 4 deletions languages/c/templates/modules/src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,28 @@
/* ${IMPORTS} */
#include "${info.title.lowercase}.h"

namespace FireboltSDK {
${if.types}namespace FireboltSDK {
namespace ${info.Title} {
// Types
/* ${TYPES} */
}
}
}${end.if.types}

/* ${ENUMS} */

#ifdef __cplusplus
${if.definitions}#ifdef __cplusplus
extern "C" {
#endif

// Accessors
/* ${ACCESSORS} */

// Methods
/* ${METHODS} */

// Events
/* ${EVENTS} */

#ifdef __cplusplus
}
#endif
#endif${end.if.definitions}
6 changes: 3 additions & 3 deletions languages/c/templates/schemas/include/common/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
#include <firebolt.h>
/* ${IMPORTS} */

#ifdef __cplusplus
${if.declarations}#ifdef __cplusplus
extern "C" {
#endif

// Enums

/* ${ENUMS} */

// Types
/* ${TYPES} */

#ifdef __cplusplus
}
#endif
#endif${end.if.declarations}

#endif // Header Include Guard
4 changes: 2 additions & 2 deletions languages/c/templates/schemas/src/jsondata_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
/* ${IMPORTS} */
#include "common/${info.title.lowercase}.h"

namespace FireboltSDK {
${if.schemas}namespace FireboltSDK {
namespace ${info.Title} {
// Types

/* ${SCHEMAS} */
}
}
}${end.if.schemas}
9 changes: 7 additions & 2 deletions languages/c/templates/schemas/src/module_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@

/* ${ENUMS} */

#ifdef __cplusplus
${if.definitions}#ifdef __cplusplus
extern "C" {
#endif

// Accessors
/* ${ACCESSORS} */

// Methods
/* ${METHODS} */

// Events
/* ${EVENTS} */

#ifdef __cplusplus
}
#endif
#endif${end.if.definitions}
1 change: 0 additions & 1 deletion languages/c/templates/sections/accessors.c
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// Accessors
${schema.list}
3 changes: 0 additions & 3 deletions languages/c/templates/sections/methods.c
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@

// Methods

${method.list}
11 changes: 8 additions & 3 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import isString from 'crocks/core/isString.js'
import predicates from 'crocks/predicates/index.js'
const { isObject, isArray, propEq, pathSatisfies, propSatisfies } = predicates

import { isRPCOnlyMethod, isProviderInterfaceMethod, getProviderInterface, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext, getSemanticVersion, getSetterFor, getProvidedCapabilities, isPolymorphicPullMethod, hasPublicAPIs, createPolymorphicMethods } from '../shared/modules.mjs'
import { isRPCOnlyMethod, isProviderInterfaceMethod, getProviderInterface, getPayloadFromEvent, providerHasNoParameters, isTemporalSetMethod, isCallsMetricsMethod, isExcludedMethod, hasMethodAttributes, getMethodAttributes, isEventMethodWithContext, getSemanticVersion, getSetterFor, getProvidedCapabilities, isPolymorphicPullMethod, hasPublicAPIs, createPolymorphicMethods } from '../shared/modules.mjs'
import isEmpty from 'crocks/core/isEmpty.js'
import { getLinkedSchemaPaths, getSchemaConstraints, isSchema, localizeDependencies, isDefinitionReferencedBySchema } from '../shared/json-schema.mjs'

Expand Down Expand Up @@ -507,6 +507,11 @@ const insertMacros = (fContents = '', macros = {}) => {
const quote = config.operators ? config.operators.stringQuotation : '"'
const or = config.operators ? config.operators.or : ' | '

fContents = fContents.replace(/\$\{if\.types\}(.*?)\$\{end\.if\.types\}/gms, macros.types.trim() ? '$1' : '')
fContents = fContents.replace(/\$\{if\.schemas\}(.*?)\$\{end\.if\.schemas\}/gms, macros.schemas.trim() ? '$1' : '')
fContents = fContents.replace(/\$\{if\.declarations\}(.*?)\$\{end\.if\.declarations\}/gms, (macros.accessors.trim() || macros.declarations.trim() || macros.enums.trim()) ? '$1' : '')
fContents = fContents.replace(/\$\{if\.definitions\}(.*?)\$\{end\.if\.definitions\}/gms, (macros.accessors.trim() || macros.methods.trim() || macros.events.trim()) ? '$1' : '')

fContents = fContents.replace(/\$\{module.list\}/g, macros.module)
fContents = fContents.replace(/[ \t]*\/\* \$\{METHODS\} \*\/[ \t]*\n/, macros.methods)
fContents = fContents.replace(/[ \t]*\/\* \$\{ACCESSORS\} \*\/[ \t]*\n/, macros.accessors)
Expand Down Expand Up @@ -638,7 +643,7 @@ const generateEnums = (json, templates, options = { destination: '' }) => {
return compose(
option(''),
map(val => {
let template = getTemplate(`/sections/enum.${suffix}`, templates)
let template = val ? getTemplate(`/sections/enum.${suffix}`, templates) : val
return template ? template.replace(/\$\{schema.list\}/g, val.trimEnd()) : val
}),
map(reduce((acc, val) => acc.concat(val).concat('\n'), '')),
Expand Down Expand Up @@ -1037,7 +1042,7 @@ function generateMethods(json = {}, examples = {}, templates = {}) {
}

// TODO: this is called too many places... let's reduce that to just generateMethods
function insertMethodMacros(template, methodObj, json, templates, examples={}) {
function insertMethodMacros(template, methodObj, json, templates, examples = {}) {
const moduleName = getModuleName(json)

const info = {
Expand Down

0 comments on commit bc3e3d4

Please sign in to comment.