From 522ca7d625feb8cf149eaf21dcc560e925982ff2 Mon Sep 17 00:00:00 2001 From: Robert A Dingwell Date: Fri, 11 Oct 2024 17:07:02 -0400 Subject: [PATCH] Moved new function below existing one to make diff easier to read --- examples/browser/cql4browsers.js | 58 +++++++++++++++--------------- src/elm/reusable.ts | 60 ++++++++++++++++---------------- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/examples/browser/cql4browsers.js b/examples/browser/cql4browsers.js index c42e4f8f..3aac8549 100644 --- a/examples/browser/cql4browsers.js +++ b/examples/browser/cql4browsers.js @@ -6813,6 +6813,35 @@ class FunctionRef extends expression_1.Expression { this.library = json.libraryName; this.functionDefs = null; } + async exec(ctx) { + const args = await this.execArgs(ctx); + // Filter out functions w/ wrong number of arguments. + const fDefs = this.getFunctionDefs(ctx, args); + // If there is still > 1 matching function, calculate a score based on quality of matches + if (fDefs.length > 1) { + // TODO + } + if (fDefs.length === 0) { + throw new Error('no function with matching signature could be found'); + } + // Moved context creation below the functionDef checks because it's not needed if + // there are no matching function defs + let child_ctx; + if (this.library) { + const libCtx = ctx.getLibraryContext(this.library); + child_ctx = libCtx ? libCtx.childContext() : undefined; + } + else { + child_ctx = ctx.childContext(); + } + // By this point, we should have only one function, but until implementation is completed, + // use the last one (no matter how many still remain) + const functionDef = fDefs[fDefs.length - 1]; + for (let i = 0; i < functionDef.parameters.length; i++) { + child_ctx.set(functionDef.parameters[i].name, args[i]); + } + return functionDef.expression.execute(child_ctx); + } getFunctionDefs(ctx, args) { if (this.functionDefs != null) { // cache hit @@ -6850,35 +6879,6 @@ class FunctionRef extends expression_1.Expression { this.functionDefs = functionDefs; return functionDefs; } - async exec(ctx) { - const args = await this.execArgs(ctx); - // Filter out functions w/ wrong number of arguments. - const fDefs = this.getFunctionDefs(ctx, args); - // If there is still > 1 matching function, calculate a score based on quality of matches - if (fDefs.length > 1) { - // TODO - } - if (fDefs.length === 0) { - throw new Error('no function with matching signature could be found'); - } - // Moved context creation below the functionDef checks because it's not needed if - // there are no matching function defs - let child_ctx; - if (this.library) { - const libCtx = ctx.getLibraryContext(this.library); - child_ctx = libCtx ? libCtx.childContext() : undefined; - } - else { - child_ctx = ctx.childContext(); - } - // By this point, we should have only one function, but until implementation is completed, - // use the last one (no matter how many still remain) - const functionDef = fDefs[fDefs.length - 1]; - for (let i = 0; i < functionDef.parameters.length; i++) { - child_ctx.set(functionDef.parameters[i].name, args[i]); - } - return functionDef.expression.execute(child_ctx); - } } exports.FunctionRef = FunctionRef; class OperandRef extends expression_1.Expression { diff --git a/src/elm/reusable.ts b/src/elm/reusable.ts index 2df40ff0..57800827 100644 --- a/src/elm/reusable.ts +++ b/src/elm/reusable.ts @@ -68,6 +68,36 @@ export class FunctionRef extends Expression { this.functionDefs = null; } + async exec(ctx: Context) { + const args = await this.execArgs(ctx); + // Filter out functions w/ wrong number of arguments. + const fDefs = this.getFunctionDefs(ctx, args); + // If there is still > 1 matching function, calculate a score based on quality of matches + if (fDefs.length > 1) { + // TODO + } + + if (fDefs.length === 0) { + throw new Error('no function with matching signature could be found'); + } + // Moved context creation below the functionDef checks because it's not needed if + // there are no matching function defs + let child_ctx; + if (this.library) { + const libCtx = ctx.getLibraryContext(this.library); + child_ctx = libCtx ? libCtx.childContext() : undefined; + } else { + child_ctx = ctx.childContext(); + } + // By this point, we should have only one function, but until implementation is completed, + // use the last one (no matter how many still remain) + const functionDef = fDefs[fDefs.length - 1]; + for (let i = 0; i < functionDef.parameters.length; i++) { + child_ctx.set(functionDef.parameters[i].name, args[i]); + } + return functionDef.expression.execute(child_ctx); + } + getFunctionDefs(ctx: Context, args: any) { if (this.functionDefs != null) { // cache hit @@ -105,36 +135,6 @@ export class FunctionRef extends Expression { this.functionDefs = functionDefs; return functionDefs; } - - async exec(ctx: Context) { - const args = await this.execArgs(ctx); - // Filter out functions w/ wrong number of arguments. - const fDefs = this.getFunctionDefs(ctx, args); - // If there is still > 1 matching function, calculate a score based on quality of matches - if (fDefs.length > 1) { - // TODO - } - - if (fDefs.length === 0) { - throw new Error('no function with matching signature could be found'); - } - // Moved context creation below the functionDef checks because it's not needed if - // there are no matching function defs - let child_ctx; - if (this.library) { - const libCtx = ctx.getLibraryContext(this.library); - child_ctx = libCtx ? libCtx.childContext() : undefined; - } else { - child_ctx = ctx.childContext(); - } - // By this point, we should have only one function, but until implementation is completed, - // use the last one (no matter how many still remain) - const functionDef = fDefs[fDefs.length - 1]; - for (let i = 0; i < functionDef.parameters.length; i++) { - child_ctx.set(functionDef.parameters[i].name, args[i]); - } - return functionDef.expression.execute(child_ctx); - } } export class OperandRef extends Expression {