Skip to content

Commit

Permalink
Moved new function below existing one to make diff easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
rdingwell committed Oct 11, 2024
1 parent 394b55b commit 522ca7d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
58 changes: 29 additions & 29 deletions examples/browser/cql4browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
60 changes: 30 additions & 30 deletions src/elm/reusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 522ca7d

Please sign in to comment.