-
Notifications
You must be signed in to change notification settings - Fork 3.4k
embind: tsgen function params name #20141
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
Changes from 4 commits
b1a0036
265dcf3
356f375
ecbf3a9
8e79f11
011eaf9
15b4ca2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,28 @@ var LibraryEmbindShared = { | |
_free(ptr); | ||
return rv; | ||
}, | ||
|
||
$getFunctionName__deps: [], | ||
$getFunctionName: (signature) => { | ||
signature = signature.trim(); | ||
const argsIndex = signature.indexOf("("); | ||
if (argsIndex !== -1) { | ||
assert(signature[signature.length - 1] == ")", "Unmatching paranthesis for argument names."); | ||
return signature.substr(0, argsIndex); | ||
} else { | ||
return signature; | ||
} | ||
}, | ||
$getFunctionArgsName__deps: [], | ||
$getFunctionArgsName: (signature) => { | ||
signature = signature.trim(); | ||
const argsIndex = signature.indexOf("(") + 1; | ||
if (argsIndex !== 0) { | ||
assert(signature[signature.length - 1] == ")", "Unmatching paranthesis for argument names."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added assertion for unmatching parenthesis in function signature There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return signature.substr(argsIndex, signature.length - argsIndex - 1).replaceAll(" ", "").split(",").filter(n => n.length); | ||
} else { | ||
return []; | ||
} | ||
}, | ||
$heap32VectorToArray: (count, firstElement) => { | ||
var array = []; | ||
for (var i = 0; i < count; i++) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,22 +257,30 @@ var LibraryEmbind = { | |
$registerIntegerType: (id) => { | ||
registerType(id, new IntegerType(id)); | ||
}, | ||
$createFunctionDefinition__deps: ['$FunctionDefinition', '$heap32VectorToArray', '$readLatin1String', '$Argument', '$whenDependentTypesAreResolved'], | ||
$createFunctionDefinition__deps: ['$FunctionDefinition', '$heap32VectorToArray', '$readLatin1String', '$Argument', '$whenDependentTypesAreResolved', '$getFunctionName', '$getFunctionArgsName'], | ||
$createFunctionDefinition: (name, argCount, rawArgTypesAddr, hasThis, cb) => { | ||
const argTypes = heap32VectorToArray(argCount, rawArgTypesAddr); | ||
name = readLatin1String(name); | ||
|
||
whenDependentTypesAreResolved([], argTypes, function(argTypes) { | ||
whenDependentTypesAreResolved([], argTypes, function (argTypes) { | ||
const argsName = getFunctionArgsName(name); | ||
name = getFunctionName(name); | ||
const returnType = argTypes[0]; | ||
let thisType = null; | ||
let argStart = 1; | ||
if (hasThis) { | ||
thisType = argTypes[1]; | ||
argStart = 2; | ||
} | ||
if (argsName.length) | ||
assert(argsName.length == (argTypes.length - hasThis - 1), 'Argument names should match number of parameters.'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added assertions for argument names to match expected number of parameters |
||
const args = []; | ||
for (let i = argStart; i < argTypes.length; i++) { | ||
args.push(new Argument(`_${i - argStart}`, argTypes[i])); | ||
for (let i = argStart, x = 0; i < argTypes.length; i++) { | ||
if (x < argsName.length) { | ||
args.push(new Argument(argsName[x++], argTypes[i])); | ||
} else { | ||
args.push(new Argument(`_${i - argStart}`, argTypes[i])); | ||
} | ||
} | ||
const funcDef = new FunctionDefinition(name, returnType, args, thisType); | ||
cb(funcDef); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Parentheses for argument names should match.'