Skip to content

Commit

Permalink
cppsdK: use primitive types from templates, instead defined variable
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Oct 27, 2023
1 parent 2c64bf9 commit 9a35a85
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 19 deletions.
8 changes: 1 addition & 7 deletions languages/cpp/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"unwrapResultObjects": false,
"createPolymorphicMethods": true,
"excludeDeclarations": true,
"overrideRule": true,
"aggregateFiles": [
"/include/firebolt.h",
"/src/firebolt.cpp"
Expand All @@ -22,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/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
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
2 changes: 0 additions & 2 deletions src/macrofier/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const macrofy = async (
additionalSchemaTemplates,
additionalMethodTemplates,
excludeDeclarations,
overrideRule,
aggregateFiles,
operators,
primitives,
Expand Down Expand Up @@ -111,7 +110,6 @@ const macrofy = async (
typer.setPrimitives(primitives)
typer.setAllocatedPrimitiveProxies(allocatedPrimitiveProxies)
typer.setConvertTuples(convertTuplesToArraysOrObjects)
typer.setOverrideRule(overrideRule)

let templatesPermission = {}
if (persistPermission) {
Expand Down
14 changes: 5 additions & 9 deletions src/macrofier/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import { getPath, localizeDependencies } from '../shared/json-schema.mjs'
import path from "path"

let convertTuplesToArraysOrObjects = false
let overrideRule = false
const templates = {}
const state = {}
const primitives = {
let primitives = {
"integer": "number",
"number": "number",
"boolean": "boolean",
Expand All @@ -40,7 +39,9 @@ function setTemplates(t) {
}

function setPrimitives(p) {
Object.assign(primitives, p)
if (p) {
primitives = p
}
}

function setConvertTuples(t) {
Expand All @@ -51,10 +52,6 @@ function setAllocatedPrimitiveProxies(m) {
Object.assign(allocatedPrimitiveProxies, m)
}

function setOverrideRule(rule) {
overrideRule = rule
}

const capitalize = str => str ? str[0].toUpperCase() + str.substr(1) : str
const indent = (str, padding) => {
let first = true
Expand Down Expand Up @@ -389,7 +386,7 @@ const insertTupleMacros = (content, schema, module, title, options) => {

const getPrimitiveType = (type, templateDir = 'types') => {
const template = getTemplate(path.join(templateDir, type)) || getTemplate(path.join(templateDir, 'generic'))
return overrideRule === true ? (template || primitives[type]) : (primitives[type] || template)
return (primitives[type] || template)
}

const pickBestType = types => Array.isArray(types) ? types.find(t => t !== 'null') : types
Expand Down Expand Up @@ -799,7 +796,6 @@ export default {
setPrimitives,
setConvertTuples,
setAllocatedPrimitiveProxies,
setOverrideRule,
getMethodSignatureParams,
getMethodSignatureResult,
getSchemaShape,
Expand Down
1 change: 0 additions & 1 deletion src/sdk/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const run = async ({
additionalSchemaTemplates: config.additionalSchemaTemplates,
additionalMethodTemplates: config.additionalMethodTemplates,
excludeDeclarations: config.excludeDeclarations,
overrideRule: config.overrideRule,
staticModuleNames: staticModuleNames,
hideExcluded: true,
aggregateFiles: config.aggregateFiles,
Expand Down

0 comments on commit 9a35a85

Please sign in to comment.