mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
resolve new object contructors
This commit is contained in:
@@ -1598,8 +1598,8 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
|||||||
const new_token = tokens.current;
|
const new_token = tokens.current;
|
||||||
tokens.expectValue('new');
|
tokens.expectValue('new');
|
||||||
const ctr_type = typeIdent(tokens, scope, imports, typemap, {no_array_qualifiers:true, type_vars:[]});
|
const ctr_type = typeIdent(tokens, scope, imports, typemap, {no_array_qualifiers:true, type_vars:[]});
|
||||||
let match = new ResolvedIdent(`new ${ctr_type.resolved.simpleTypeName}`, [], [], [ctr_type.resolved]);
|
let match = new ResolvedIdent(`new ${ctr_type.resolved.simpleTypeName}`, [], [], []);
|
||||||
let ctr_args = [], type_body = null, newtokens;
|
let newtokens;
|
||||||
switch(tokens.current.value) {
|
switch(tokens.current.value) {
|
||||||
case '[':
|
case '[':
|
||||||
match = arrayQualifiers(match, tokens, mdecls, scope, imports, typemap);
|
match = arrayQualifiers(match, tokens, mdecls, scope, imports, typemap);
|
||||||
@@ -1611,9 +1611,10 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
|||||||
}
|
}
|
||||||
return new ResolvedIdent(match.source, [new NewArray(new_token, ctr_type, match)], [], [], '', newtokens);
|
return new ResolvedIdent(match.source, [new NewArray(new_token, ctr_type, match)], [], [], '', newtokens);
|
||||||
case '(':
|
case '(':
|
||||||
tokens.inc();
|
let ctr_args = [], commas = [], type_body = null;
|
||||||
|
let open_bracket = tokens.consume();
|
||||||
if (!tokens.isValue(')')) {
|
if (!tokens.isValue(')')) {
|
||||||
({ expressions: ctr_args } = expressionList(tokens, mdecls, scope, imports, typemap));
|
({ expressions: ctr_args, commas } = expressionList(tokens, mdecls, scope, imports, typemap));
|
||||||
tokens.expectValue(')');
|
tokens.expectValue(')');
|
||||||
}
|
}
|
||||||
newtokens = tokens.markEnd();
|
newtokens = tokens.markEnd();
|
||||||
@@ -1622,13 +1623,11 @@ function newTerm(tokens, mdecls, scope, imports, typemap) {
|
|||||||
// anonymous type - just skip for now
|
// anonymous type - just skip for now
|
||||||
type_body = skipBody(tokens);
|
type_body = skipBody(tokens);
|
||||||
}
|
}
|
||||||
break;
|
return new ResolvedIdent(match.source, [new NewObject(new_token, ctr_type, open_bracket, ctr_args, commas, type_body)], [], [], '', newtokens);
|
||||||
default:
|
|
||||||
newtokens = tokens.markEnd();
|
|
||||||
addproblem(tokens, ParseProblem.Error(tokens.current, 'Constructor expression expected'));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return new ResolvedIdent(match.source, [new NewObject(new_token, ctr_type, ctr_args, type_body)], [], [], '', newtokens);
|
newtokens = tokens.markEnd();
|
||||||
|
addproblem(tokens, ParseProblem.Error(tokens.current, 'Constructor expression expected'));
|
||||||
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -317,3 +317,4 @@ function isCallCompatible(m, arg_types) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.MethodCallExpression = MethodCallExpression;
|
exports.MethodCallExpression = MethodCallExpression;
|
||||||
|
exports.resolveConstructorCall = resolveConstructorCall;
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
const { Expression } = require("./Expression");
|
const { Expression } = require("./Expression");
|
||||||
const { ArrayType } = require('java-mti');
|
const { ArrayType } = require('java-mti');
|
||||||
const { FixedLengthArrayType, SourceArrayType } = require('../source-types');
|
const { FixedLengthArrayType, SourceArrayType } = require('../source-types');
|
||||||
const ParseProblem = require('../parsetypes/parse-problem');
|
|
||||||
const { checkArrayIndex } = require('../expression-resolver');
|
const { checkArrayIndex } = require('../expression-resolver');
|
||||||
|
const { resolveConstructorCall } = require('./MethodCallExpression');
|
||||||
|
|
||||||
class NewArray extends Expression {
|
class NewArray extends Expression {
|
||||||
/**
|
/**
|
||||||
@@ -61,14 +61,18 @@ class NewObject extends Expression {
|
|||||||
/**
|
/**
|
||||||
* @param {Token} new_token
|
* @param {Token} new_token
|
||||||
* @param {SourceTypeIdent} object_type
|
* @param {SourceTypeIdent} object_type
|
||||||
|
* @param {Token} open_bracket
|
||||||
* @param {ResolvedIdent[]} ctr_args
|
* @param {ResolvedIdent[]} ctr_args
|
||||||
|
* @param {Token[]} commas
|
||||||
* @param {Token[]} type_body
|
* @param {Token[]} type_body
|
||||||
*/
|
*/
|
||||||
constructor(new_token, object_type, ctr_args, type_body) {
|
constructor(new_token, object_type, open_bracket, ctr_args, commas, type_body) {
|
||||||
super();
|
super();
|
||||||
this.new_token = new_token;
|
this.new_token = new_token;
|
||||||
this.object_type = object_type;
|
this.object_type = object_type;
|
||||||
|
this.open_bracket = open_bracket;
|
||||||
this.ctr_args = ctr_args;
|
this.ctr_args = ctr_args;
|
||||||
|
this.commas = commas;
|
||||||
this.type_body = type_body;
|
this.type_body = type_body;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +80,7 @@ class NewObject extends Expression {
|
|||||||
* @param {ResolveInfo} ri
|
* @param {ResolveInfo} ri
|
||||||
*/
|
*/
|
||||||
resolveExpression(ri) {
|
resolveExpression(ri) {
|
||||||
|
resolveConstructorCall(ri, this.object_type.resolved.constructors, this.open_bracket, this.ctr_args, this.commas, () => this.tokens());
|
||||||
return this.object_type.resolved;
|
return this.object_type.resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user