Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1653x 1653x 1653x 1653x 1653x 1653x 1653x 1653x 725x 698x 698x 4x 4x 4x 4x 698x 1653x 928x 928x 395x 386x 1x 1x 1x 386x 1x 1x 1x 1x 386x 393x 395x 384x 384x 384x 385x 384x 384x 384x 385x 395x 9x 9x 393x 395x 391x 391x 3x 3x 395x 2x 2x 390x 395x 395x 1x 390x 57x 57x 57x 57x 332x 928x 429x 533x 104x 104x 1253x 1253x 1x 1x 389x 389x 389x 389x 389x 389x 1x | import {ExpressionNode} from "../../nodes";
import {VoidType} from "../../types/basic";
import * as Expressions from "../../2_statements/expressions";
import {IMethodDefinition} from "../../types/_method_definition";
import {MethodParameters} from "./method_parameters";
import {WParenRight, WParenRightW} from "../../1_lexer/tokens";
import {Source} from "./source";
import {AbstractType} from "../../types/basic/_abstract_type";
import {TypeUtils} from "../_type_utils";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {Constant} from "./constant";
import {checkOffsetLength} from "./_check_offset_length";
import {checkTextSymbol} from "./_check_text_symbol";
import {BuiltInMethod} from "../_builtin";
export class MethodCallParam {
/** returns the type of the unnamed argument, if any */
public static runSyntax(node: ExpressionNode, input: SyntaxInput, method: IMethodDefinition | VoidType): AbstractType | undefined {
if (!(node.get() instanceof Expressions.MethodCallParam)) {
const message = "MethodCallParam, unexpected input";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
const children = node.getChildren();
if (children.length < 2 || children.length > 3) {
const message = "MethodCallParam, unexpected child length";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
const child = children[1];
if (child.get() instanceof WParenRight || child.get() instanceof WParenRightW) {
if (!(method instanceof VoidType)) {
const required = method.getParameters().getRequiredParameters();
if (required.length > 0) {
const message = "Parameter \"" + required[0].getName() + "\" must be supplied";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
}
} else if (child instanceof ExpressionNode
&& (child.get() instanceof Expressions.Source
|| child.get() instanceof Expressions.ConstantString)) {
if (!(method instanceof VoidType)) {
if (method.getParameters().getImporting().length === 0) {
const message = "Method \"" + method.getName() + "\" has no importing parameters";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
} else if (method.getParameters().getRequiredParameters().length > 1) {
const message = "Method \"" + method.getName() + "\" has more than one importing or changing parameter";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
}
let targetType: AbstractType | undefined = undefined;
if (!(method instanceof VoidType)) {
const name = method.getParameters().getDefaultImporting();
if (name === undefined) {
const message = "No default importing parameter";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
for (const i of method.getParameters().getImporting()) {
if (i.getName().toUpperCase() === name) {
targetType = i.getType();
break;
}
}
} else {
targetType = method;
}
let sourceType: AbstractType | undefined = undefined;
if (child.get() instanceof Expressions.Source) {
sourceType = Source.runSyntax(child, input, targetType);
if (checkOffsetLength(child, sourceType, method, input)) {
return;
}
} else if (child.get() instanceof Expressions.ConstantString) {
sourceType = Constant.runSyntax(child);
}
if (sourceType === undefined) {
const message = "No source type determined, method source";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
} else if (checkTextSymbol(child, targetType, input)) {
return;
} else if (this.isAssignable(sourceType, targetType, child, method, input) === false) {
const message = "Method parameter type not compatible";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
return sourceType;
} else if (child instanceof ExpressionNode && child.get() instanceof Expressions.ParameterListS) {
new MethodParameters().checkExporting(child, input, method);
} else if (child.get() instanceof Expressions.MethodParameters) {
new MethodParameters().runSyntax(child, input, method);
} else {
const message = "MethodCallParam, unexpected child";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
return undefined;
}
private static isAssignable(sourceType: AbstractType, targetType: AbstractType | undefined, child: ExpressionNode,
method: IMethodDefinition | VoidType, input: SyntaxInput): boolean {
const typeUtils = new TypeUtils(input.scope);
return method instanceof BuiltInMethod
? typeUtils.isAssignableBuiltin(sourceType, targetType, child)
: typeUtils.isAssignableStrict(sourceType, targetType, child);
}
}
|