mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
update check for cast expression
This commit is contained in:
@@ -1378,6 +1378,34 @@ function isExpressionStart(token) {
|
|||||||
return /^(ident|primitive-type|[\w-]+-literal|(inc|plumin|unary)-operator|open-bracket|new-operator)$/.test(token.kind);
|
return /^(ident|primitive-type|[\w-]+-literal|(inc|plumin|unary)-operator|open-bracket|new-operator)$/.test(token.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Token} token first token following the close bracket
|
||||||
|
* @param {ResolvedIdent} matches - the bracketed expression
|
||||||
|
*/
|
||||||
|
function isCastExpression(token, matches) {
|
||||||
|
// working out if this is supposed to be a cast expression is problematic.
|
||||||
|
// (a) + b -> cast or binary expression (depends on how a is resolved)
|
||||||
|
// if the bracketed expression cannot be resolved:
|
||||||
|
// (a) b -> assumed to be a cast
|
||||||
|
// (a) + b -> assumed to be an expression
|
||||||
|
// (a) 5 -> assumed to be a cast
|
||||||
|
// (a) + 5 -> assumed to be an expression
|
||||||
|
if (matches.types[0] && !(matches.types[0] instanceof AnyType)) {
|
||||||
|
// resolved type - this must be a cast
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!matches.types[0]) {
|
||||||
|
// not a type - this must be an expression
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// if we reach here, the type is AnyType - we assume a cast if the next
|
||||||
|
// value is the start of an expression, except for +/-
|
||||||
|
if (token.kind === 'plumin-operator') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.isExpressionStart(token);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {TokenList} tokens
|
* @param {TokenList} tokens
|
||||||
* @param {Local[]} locals
|
* @param {Local[]} locals
|
||||||
@@ -1478,7 +1506,7 @@ function rootTerm(tokens, locals, method, imports, typemap) {
|
|||||||
matches = expression(tokens, locals, method, imports, typemap);
|
matches = expression(tokens, locals, method, imports, typemap);
|
||||||
const close_bracket = tokens.current;
|
const close_bracket = tokens.current;
|
||||||
tokens.expectValue(')');
|
tokens.expectValue(')');
|
||||||
if (isExpressionStart(tokens.current)) {
|
if (isCastExpression(tokens.current, matches)) {
|
||||||
// typecast
|
// typecast
|
||||||
const type = matches.types[0];
|
const type = matches.types[0];
|
||||||
if (!type) {
|
if (!type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user