Skip to content

Commit

Permalink
Rename 'deduced' to 'resolved'
Browse files Browse the repository at this point in the history
  • Loading branch information
sashi0034 committed Jan 3, 2025
1 parent 21a3e7e commit 6742cbd
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 117 deletions.
140 changes: 70 additions & 70 deletions server/src/compile/analyzer.ts

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions server/src/compile/checkFunction.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import {diagnostic} from "../code/diagnostic";
import {ParsedRange} from "./nodes";
import {
DeducedType,
ResolvedType,
SymbolFunction,
SymbolScope
} from "./symbols";
import {isTypeMatch} from "./checkType";
import {ParsedToken} from "./parsedToken";
import {getNodeLocation, stringifyNodeType} from "./nodesUtils";
import {resolveTemplateTypes, stringifyDeducedType, stringifyDeducedTypes, TemplateTranslation} from "./symbolUtils";
import {resolveTemplateTypes, stringifyResolvedType, stringifyResolvedTypes, TemplateTranslation} from "./symbolUtils";

export interface FunctionMatchingArgs {
scope: SymbolScope;
callerIdentifier: ParsedToken;
callerRange: ParsedRange;
callerArgRanges: ParsedRange[];
callerArgTypes: (DeducedType | undefined)[];
callerArgTypes: (ResolvedType | undefined)[];
calleeFunc: SymbolFunction;
templateTranslators: (TemplateTranslation | undefined)[];
}
Expand All @@ -26,7 +26,7 @@ export interface FunctionMatchingArgs {
*/
export function checkFunctionMatch(
args: FunctionMatchingArgs
): DeducedType | undefined {
): ResolvedType | undefined {
pushReferenceOfFuncOrConstructor(args.callerIdentifier, args.scope, args.calleeFunc);
return checkFunctionMatchInternal(args, args.calleeFunc);
}
Expand All @@ -38,7 +38,7 @@ function pushReferenceOfFuncOrConstructor(callerIdentifier: ParsedToken, scope:
function checkFunctionMatchInternal(
args: FunctionMatchingArgs,
overloadedHead: SymbolFunction
): DeducedType | undefined {
): ResolvedType | undefined {
const {scope, callerRange, callerArgRanges, callerArgTypes, calleeFunc, templateTranslators} = args;
const calleeParams = calleeFunc.sourceNode.paramList;

Expand Down Expand Up @@ -81,7 +81,7 @@ function checkFunctionMatchInternal(

if (handleErrorWhenOverloaded(callerRange, callerArgTypes, calleeFunc, overloadedHead, templateTranslators) === false) {
diagnostic.addError(getNodeLocation(callerRange),
`Cannot convert '${stringifyDeducedType(actualType)}' to parameter type '${stringifyDeducedType(expectedType)}'.`);
`Cannot convert '${stringifyResolvedType(actualType)}' to parameter type '${stringifyResolvedType(expectedType)}'.`);
}
}

Expand All @@ -106,21 +106,21 @@ function handleTooMuchCallerArgs(args: FunctionMatchingArgs, overloadedHead: Sym

function handleErrorWhenOverloaded(
callerRange: ParsedRange,
callerArgs: (DeducedType | undefined)[],
callerArgs: (ResolvedType | undefined)[],
calleeFunc: SymbolFunction,
overloadedHead: SymbolFunction,
templateTranslators: (TemplateTranslation | undefined)[]
) {
if (calleeFunc === overloadedHead) return false; // Not overloaded

let message = 'No viable function.';
message += `\nArguments types: (${stringifyDeducedTypes(callerArgs)})`;
message += `\nArguments types: (${stringifyResolvedTypes(callerArgs)})`;
message += '\nCandidates considered:';

let cursor: SymbolFunction | undefined = overloadedHead;
while (cursor !== undefined) {
const resolvedTypes = cursor.parameterTypes.map(t => resolveTemplateTypes(templateTranslators, t));
message += `\n(${stringifyDeducedTypes(resolvedTypes)})`;
message += `\n(${stringifyResolvedTypes(resolvedTypes)})`;
cursor = cursor.nextOverload;
}

Expand Down
18 changes: 9 additions & 9 deletions server/src/compile/checkType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
DeducedType,
ResolvedType,
isSourcePrimitiveType,
PrimitiveType,
SourceType,
Expand All @@ -14,7 +14,7 @@ import {getNodeLocation} from "./nodesUtils";
import {findScopeShallowly, findScopeWithParentByNodes, isScopeChildOrGrandchild} from "./symbolScopes";
import {diagnostic} from "../code/diagnostic";
import assert = require("assert");
import {findSymbolShallowly, resolveTemplateType, stringifyDeducedType} from "./symbolUtils";
import {findSymbolShallowly, resolveTemplateType, stringifyResolvedType} from "./symbolUtils";
import {getGlobalSettings} from "../code/settings";

/**
Expand All @@ -25,13 +25,13 @@ import {getGlobalSettings} from "../code/settings";
* @param nodeRange
*/
export function checkTypeMatch(
src: DeducedType | undefined,
dest: DeducedType | undefined,
src: ResolvedType | undefined,
dest: ResolvedType | undefined,
nodeRange: ParsedRange,
): boolean {
if (isTypeMatch(src, dest)) return true;

diagnostic.addError(getNodeLocation(nodeRange), `'${stringifyDeducedType(src)}' cannot be converted to '${stringifyDeducedType(dest)}'.`);
diagnostic.addError(getNodeLocation(nodeRange), `'${stringifyResolvedType(src)}' cannot be converted to '${stringifyResolvedType(dest)}'.`);
return false;
}

Expand All @@ -41,15 +41,15 @@ export function checkTypeMatch(
* @param dest
*/
export function isTypeMatch(
src: DeducedType | undefined, dest: DeducedType | undefined
src: ResolvedType | undefined, dest: ResolvedType | undefined
): boolean {
if (src === undefined || dest === undefined) return true;

let resolvedSrc: DeducedType | undefined = src;
let resolvedSrc: ResolvedType | undefined = src;
if (src.templateTranslate !== undefined)
resolvedSrc = resolveTemplateType(src.templateTranslate, src);

let resolvedDest: DeducedType | undefined = dest;
let resolvedDest: ResolvedType | undefined = dest;
if (dest.templateTranslate !== undefined)
resolvedDest = resolveTemplateType(dest.templateTranslate, dest);

Expand All @@ -59,7 +59,7 @@ export function isTypeMatch(
}

function isTypeMatchInternal(
src: DeducedType, dest: DeducedType
src: ResolvedType, dest: ResolvedType
): boolean {
const srcType = src.symbolType;
const destType = dest.symbolType;
Expand Down
12 changes: 6 additions & 6 deletions server/src/compile/symbolBuiltin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {createSymbolScope} from "./symbolScopes";
import {createVirtualToken} from "./tokenUtils";
import {TokenKind} from "./tokens";
import {numberTypeSet} from "./tokenReservedWords";
import {PrimitiveType, SymbolType, SymbolKind, DeducedType} from "./symbols";
import {PrimitiveType, SymbolType, SymbolKind, ResolvedType} from "./symbols";
import assert = require("node:assert");

function createBuiltinType(virtualToken: ParsedToken, name: PrimitiveType): SymbolType {
Expand All @@ -26,19 +26,19 @@ const builtinNumberTypeMap: Map<string, SymbolType> = (() => {

export const builtinStringType: SymbolType = createBuiltinType(createVirtualToken(TokenKind.String, 'string'), PrimitiveType.String);

export const deducedBuiltinString: DeducedType = {symbolType: builtinStringType, sourceScope: undefined};
export const resolvedBuiltinString: ResolvedType = {symbolType: builtinStringType, sourceScope: undefined};

export const builtinIntType = builtinNumberTypeMap.get('int')!;

export const deducedBuiltinInt: DeducedType = {symbolType: builtinIntType, sourceScope: undefined};
export const resolvedBuiltinInt: ResolvedType = {symbolType: builtinIntType, sourceScope: undefined};

export const builtinFloatType = builtinNumberTypeMap.get('float')!;

export const deducedBuiltinFloat: DeducedType = {symbolType: builtinFloatType, sourceScope: undefined};
export const resolvedBuiltinFloat: ResolvedType = {symbolType: builtinFloatType, sourceScope: undefined};

export const builtinDoubleType = builtinNumberTypeMap.get('double')!;

export const deducedBuiltinDouble: DeducedType = {symbolType: builtinDoubleType, sourceScope: undefined};
export const resolvedBuiltinDouble: ResolvedType = {symbolType: builtinDoubleType, sourceScope: undefined};

function assignBuiltinNumberType(key: string): SymbolType {
const type = builtinNumberTypeMap.get(key);
Expand All @@ -48,7 +48,7 @@ function assignBuiltinNumberType(key: string): SymbolType {

export const builtinBoolType: SymbolType = createBuiltinType(createVirtualToken(TokenKind.Reserved, 'bool'), PrimitiveType.Bool);

export const deducedBuiltinBool: DeducedType = {symbolType: builtinBoolType, sourceScope: undefined};
export const resolvedBuiltinBool: ResolvedType = {symbolType: builtinBoolType, sourceScope: undefined};

export const builtinVoidType: SymbolType = createBuiltinType(createVirtualToken(TokenKind.Reserved, 'void'), PrimitiveType.Void);

Expand Down
32 changes: 16 additions & 16 deletions server/src/compile/symbolUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
DeducedType,
ResolvedType,
PrimitiveType,
SymbolAndScope,
SymbolFunction,
Expand Down Expand Up @@ -59,11 +59,11 @@ export function insertSymbolObject(map: SymbolMap, symbol: SymbolObject): boolea
return result === undefined;
}

export type TemplateTranslation = Map<ParsedToken, DeducedType | undefined>;
export type TemplateTranslation = Map<ParsedToken, ResolvedType | undefined>;

export function resolveTemplateType(
templateTranslate: TemplateTranslation | undefined, type: DeducedType | undefined
): DeducedType | undefined {
templateTranslate: TemplateTranslation | undefined, type: ResolvedType | undefined
): ResolvedType | undefined {
if (templateTranslate === undefined) return type;

if (type === undefined) return undefined;
Expand All @@ -80,13 +80,13 @@ export function resolveTemplateType(
}

export function resolveTemplateTypes(
templateTranslate: (TemplateTranslation | undefined)[], type: DeducedType | undefined
): DeducedType | undefined {
templateTranslate: (TemplateTranslation | undefined)[], type: ResolvedType | undefined
): ResolvedType | undefined {
return templateTranslate
.reduce((arg, t) => t !== undefined ? resolveTemplateType(t, arg) : arg, type);
}

export function isDeducedAutoType(type: DeducedType | undefined): boolean {
export function isResolvedAutoType(type: ResolvedType | undefined): boolean {
return type !== undefined && type.symbolType.symbolKind === SymbolKind.Type && type.symbolType.sourceType === PrimitiveType.Auto;
}

Expand All @@ -104,7 +104,7 @@ export function stringifyScopeSuffix(scope: SymbolScope | undefined): string {
return suffix.length === 0 ? '' : suffix + '::';
}

export function stringifyDeducedType(type: DeducedType | undefined,): string {
export function stringifyResolvedType(type: ResolvedType | undefined,): string {
if (type === undefined) return '(undefined)';

let suffix = '';
Expand All @@ -113,21 +113,21 @@ export function stringifyDeducedType(type: DeducedType | undefined,): string {
if (type.symbolType.symbolKind === SymbolKind.Function) {
const func: SymbolFunction = type.symbolType;
const returnType = func.returnType;
const params = func.parameterTypes.map(t => stringifyDeducedType(t)).join(', ');
return `${stringifyDeducedType(returnType)}(${params})` + suffix;
const params = func.parameterTypes.map(t => stringifyResolvedType(t)).join(', ');
return `${stringifyResolvedType(returnType)}(${params})` + suffix;
}

// if (hasScopeSuffix) suffix = stringifyScopeSuffix(type.sourceScope) + suffix;

if (type.templateTranslate !== undefined) {
suffix = `<${Array.from(type.templateTranslate.values()).map(t => stringifyDeducedType(t)).join(', ')}>${suffix}`;
suffix = `<${Array.from(type.templateTranslate.values()).map(t => stringifyResolvedType(t)).join(', ')}>${suffix}`;
}

return type.symbolType.declaredPlace.text + suffix;
}

export function stringifyDeducedTypes(types: (DeducedType | undefined)[]): string {
return types.map(t => stringifyDeducedType(t)).join(', ');
export function stringifyResolvedTypes(types: (ResolvedType | undefined)[]): string {
return types.map(t => stringifyResolvedType(t)).join(', ');
}

/**
Expand All @@ -138,10 +138,10 @@ export function stringifySymbolObject(symbol: SymbolObject): string {
if (symbol.symbolKind === SymbolKind.Type) {
return fullName;
} else if (symbol.symbolKind === SymbolKind.Function) {
const head = symbol.returnType === undefined ? '' : stringifyDeducedType(symbol.returnType) + ' ';
return `${head}${fullName}(${stringifyDeducedTypes(symbol.parameterTypes)})`;
const head = symbol.returnType === undefined ? '' : stringifyResolvedType(symbol.returnType) + ' ';
return `${head}${fullName}(${stringifyResolvedTypes(symbol.parameterTypes)})`;
} else if (symbol.symbolKind === SymbolKind.Variable) {
return `${stringifyDeducedType(symbol.type)} ${fullName}`;
return `${stringifyResolvedType(symbol.type)} ${fullName}`;
}

assert(false);
Expand Down
10 changes: 5 additions & 5 deletions server/src/compile/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ export interface SymbolType extends SymbolBase {
readonly symbolKind: SymbolKind.Type;
readonly sourceType: SourceType;
readonly templateTypes?: ParsedToken[]; // e.g. <T, U>
readonly baseList?: (DeducedType | undefined)[];
readonly baseList?: (ResolvedType | undefined)[];
readonly isHandler?: boolean,
readonly membersScope: SymbolScope | undefined;
}

export interface SymbolFunction extends SymbolBase {
readonly symbolKind: SymbolKind.Function;
readonly sourceNode: NodeFunc | NodeFuncDef | NodeIntfMethod;
readonly returnType: DeducedType | undefined;
readonly parameterTypes: (DeducedType | undefined)[];
readonly returnType: ResolvedType | undefined;
readonly parameterTypes: (ResolvedType | undefined)[];
nextOverload: SymbolFunction | undefined;
readonly isInstanceMember: boolean;
readonly accessRestriction: AccessModifier | undefined;
}

export interface SymbolVariable extends SymbolBase {
readonly symbolKind: SymbolKind.Variable;
readonly type: DeducedType | undefined;
readonly type: ResolvedType | undefined;
readonly isInstanceMember: boolean;
readonly accessRestriction: AccessModifier | undefined;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ export interface SymbolAndScope {
/**
* The type of symbol that has been resolved by deduction.
*/
export interface DeducedType {
export interface ResolvedType {
readonly symbolType: SymbolType | SymbolFunction;
readonly sourceScope: SymbolScope | undefined;
readonly isHandler?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/signatureHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {findScopeContainingPosition} from "./serviceHelper";
import {ParameterInformation, SignatureInformation} from "vscode-languageserver-types";
import {isAheadPosition, isPositionInRange} from "../compile/tokenUtils";
import {ComplementKind, CompletionArgument} from "../compile/symbolComplement";
import {resolveTemplateType, stringifyDeducedType} from "../compile/symbolUtils";
import {resolveTemplateType, stringifyResolvedType} from "../compile/symbolUtils";

export function serveSignatureHelp(
diagnosedScope: SymbolScope, caret: Position, uri: URI
Expand Down Expand Up @@ -49,7 +49,7 @@ function getFunctionSignature(hint: CompletionArgument, expectedCallee: SymbolFu
const paramIdentifier = expectedCallee.sourceNode.paramList[i];
const paramType = expectedCallee.parameterTypes[i];

let label = stringifyDeducedType(resolveTemplateType(hint.templateTranslate, paramType));
let label = stringifyResolvedType(resolveTemplateType(hint.templateTranslate, paramType));
if (paramIdentifier.identifier !== undefined) label += ' ' + paramIdentifier.identifier?.text;
const parameter: ParameterInformation = {label: label};

Expand Down

0 comments on commit 6742cbd

Please sign in to comment.