tidy array constructors and fix some warnings

This commit is contained in:
Dave Holoway
2020-06-10 15:11:16 +01:00
parent b175b52065
commit dd9d23c64a
4 changed files with 13 additions and 17 deletions

View File

@@ -1004,7 +1004,7 @@ function isArrayAssignable(variable_type, value) {
if (value.elements.length === 0) { if (value.elements.length === 0) {
return true; return true;
} }
const required_element_type = variable_type.arrdims > 1 ? new ArrayType(variable_type.base, variable_type.arrdims - 1) : variable_type.base; const required_element_type = variable_type.elementType;
for (let i=0; i < value.elements.length; i++) { for (let i=0; i < value.elements.length; i++) {
const element = value.elements[i]; const element = value.elements[i];
let is_assignable; let is_assignable;
@@ -1751,7 +1751,7 @@ function arrayElementOrConstructor(tokens, open_array, matches, index) {
.filter(v => v.type instanceof ArrayType) .filter(v => v.type instanceof ArrayType)
.map(v => new ArrayElement(v, index)); .map(v => new ArrayElement(v, index));
const types = matches.types.map(t => t instanceof ArrayType ? new ArrayType(t.base, t.arrdims+1) : new ArrayType(t, 1)); const types = matches.types.map(t => new ArrayType(t, 1));
if (!variables[0] && !types[0]) { if (!variables[0] && !types[0]) {
addproblem(tokens, ParseProblem.Error(open_array, `Invalid array expression: '${matches.source}' is not an array type`)); addproblem(tokens, ParseProblem.Error(open_array, `Invalid array expression: '${matches.source}' is not an array type`));
@@ -1928,13 +1928,7 @@ function qualifiers(matches, tokens, locals, method, imports, typemap) {
* @param {ResolvedIdent} matches * @param {ResolvedIdent} matches
*/ */
function arrayTypeExpression(matches) { function arrayTypeExpression(matches) {
const types = matches.types.map(t => { const types = matches.types.map(t => new ArrayType(t, 1));
if (t instanceof ArrayType) {
return new ArrayType(t.base, t.arrdims + 1);
}
return new ArrayType(t, 1);
});
return new ResolvedIdent(`${matches.source}[]`, [], [], types); return new ResolvedIdent(`${matches.source}[]`, [], [], types);
} }

View File

@@ -49,7 +49,7 @@ class AnyMethod extends Method {
* @param {string} name * @param {string} name
*/ */
constructor(name) { constructor(name) {
super(name, [], ''); super(null, name, [], '');
} }
get returnType() { get returnType() {
@@ -70,13 +70,7 @@ class Local {
this.finalToken = modifiers.find(m => m.source === 'final') || null; this.finalToken = modifiers.find(m => m.source === 'final') || null;
this.name = name; this.name = name;
this.decltoken = decltoken; this.decltoken = decltoken;
if (postnamearrdims > 0) { this.type = postnamearrdims > 0 ? new ArrayType(type, postnamearrdims): type;
this.type = (type instanceof ArrayType)
? new ArrayType(type.base, type.arrdims + postnamearrdims)
: new ArrayType(type, postnamearrdims);
} else {
this.type = type;
}
this.init = null; this.init = null;
} }
} }

View File

@@ -198,6 +198,13 @@ class SourceInitialiser extends MethodBase {
this._decl = decl; this._decl = decl;
} }
/**
* @returns {SourceParameter[]}
*/
get parameters() {
return [];
}
get returnType() { get returnType() {
return PrimitiveType.map.V; return PrimitiveType.map.V;
} }

View File

@@ -34,6 +34,7 @@ function typeIdentList(tokens, scope, imports, typemap) {
* @param {Map<string,JavaType>} typemap * @param {Map<string,JavaType>} typemap
*/ */
function typeIdent(tokens, scope, imports, typemap) { function typeIdent(tokens, scope, imports, typemap) {
/** @type {JavaType[]} */
let types = [], package_name = ''; let types = [], package_name = '';
switch(tokens.current.kind) { switch(tokens.current.kind) {
case 'ident': case 'ident':