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

Create namespaces only if there is value to put #117

Merged
merged 1 commit into from
Jul 24, 2023
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
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
Loading