Skip to content

Commit

Permalink
Merge pull request #93 from georgejecook/reflection-fix
Browse files Browse the repository at this point in the history
increases reflection class limit to 1000 classes, from previous 250
  • Loading branch information
georgejecook authored Sep 23, 2024
2 parents cf86a92 + c72fc13 commit 5b95c78
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 20 deletions.
15 changes: 15 additions & 0 deletions src/lib/framework/Reflection.brs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,20 @@ function mr_getClass(name)
end if
end function

function mr_getClass2(name)
if false
end if
end function

function mr_getClass3(name)
if false
end if
end function

function mr_getClass4(name)
if false
end if
end function

function mr_getAllXMLCompNames(name)
end function
66 changes: 46 additions & 20 deletions src/lib/reflection/ReflectionUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,55 @@ export default class ReflectionUtil {
}

public updateClassLookupFunction(file: BrsFile) {
let func = file.ast.statements[0] as FunctionStatement;
let that = this;
if (func?.func?.body?.statements.length > 0) {
let classNames = this.fileMap.classNames.filter((n: string) => {
let file = this.fileMap.getFileForClass(n);
if (!file) {
console.log('MISSING FILE for class:', n);
return false;
} else {
return that.shouldParseReflectionFile(file.bscFile);
}
}).map((n) => n.replace(/\./g, '_'));
let codeText = `if false
? "maestro reflection"`;
for (let name of classNames) {
codeText += `\n else if name = "${name}"
return ${name}`;
let classNames = this.fileMap.classNames.filter((n: string) => {
let file = this.fileMap.getFileForClass(n);
if (!file) {
console.log('MISSING FILE for class:', n);
return false;
} else {
return this.shouldParseReflectionFile(file.bscFile);
}
}).map((n) => n.replace(/\./g, '_'));

let funcIndex = 0;
const maxFuncs = 4;
for (let i = 0; i < Math.min(classNames.length, maxFuncs * 250); i += 250) {
let chunk = classNames.slice(i, i + 250);
let isLastFunction = (i + 250) >= classNames.length;
let codeText = this.generateFunctionBody(chunk, isLastFunction, funcIndex);

let func = file.ast.statements[funcIndex] as FunctionStatement;
if (func?.func?.body?.statements.length > 0) {
func.func.body.statements[funcIndex === 0 ? 1 : 0] = new RawCodeStatement(codeText);
} else {
console.error(`Function at index ${funcIndex} does not have the expected structure.`);
}
codeText += '\n end if';
func.func.body.statements[1] = new RawCodeStatement(codeText);

funcIndex++;
}
}

generateFunctionBody(classNames: string[], isLastFunction: boolean, index: number): string {
let codeText = `if false\n ? "maestro reflection"`;

for (let name of classNames) {
codeText += `\nelse if name = "${name}"\n return ${name}`;
}

if (!isLastFunction) {
let nextFunctionName = `mr_getClass${index + 2}`;
codeText += `\nelse\n return ${nextFunctionName}(name)`;
} else {
codeText += `\nelse\n return false`;
}

codeText += `\nend if`;

return codeText;
}

public updateXMLCompTypesFunction(file: BrsFile) {
let func = file.ast.statements[1] as FunctionStatement;
let func = file.ast.statements[4] as FunctionStatement;
if (func) {
let text = '{\n';

Expand Down Expand Up @@ -83,4 +107,6 @@ export default class ReflectionUtil {
}
return true;
}


}
Loading

0 comments on commit 5b95c78

Please sign in to comment.