mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-22 17:39:19 +00:00
validate more statements
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* @typedef {import('./Statement').Statement} Statement
|
||||
* @typedef {import('../body-types').Local} Local
|
||||
* @typedef {import('../body-types').ResolvedIdent} ResolvedIdent
|
||||
* @typedef {import('../body-types').ValidateInfo} ValidateInfo
|
||||
* @typedef {import('../tokenizer').Token} Token
|
||||
*/
|
||||
const { KeywordStatement } = require("./KeywordStatement");
|
||||
const { checkNonVarDeclStatement } = require('../statement-validater');
|
||||
const { Local, ResolvedIdent } = require('../body-types');
|
||||
|
||||
class ForStatement extends KeywordStatement {
|
||||
/** @type {ResolvedIdent[] | Local[]} */
|
||||
@@ -24,7 +24,26 @@ class ForStatement extends KeywordStatement {
|
||||
* @param {ValidateInfo} vi
|
||||
*/
|
||||
validate(vi) {
|
||||
|
||||
if (this.init) {
|
||||
this.init.forEach(x => {
|
||||
if (x instanceof ResolvedIdent) {
|
||||
x.resolveExpression(vi);
|
||||
} else if (x instanceof Local) {
|
||||
if (x.init) {
|
||||
x.init.resolveExpression(vi);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if (this.test) {
|
||||
this.test.resolveExpression(vi);
|
||||
}
|
||||
if (this.update) {
|
||||
this.update.forEach(e => e.resolveExpression(vi));
|
||||
}
|
||||
if (this.iterable) {
|
||||
this.iterable.resolveExpression(vi);
|
||||
}
|
||||
if (this.statement) {
|
||||
vi.statementStack.unshift('for');
|
||||
checkNonVarDeclStatement(this.statement, vi);
|
||||
|
||||
@@ -19,9 +19,10 @@ class IfStatement extends KeywordStatement {
|
||||
* @param {ValidateInfo} vi
|
||||
*/
|
||||
validate(vi) {
|
||||
const value = this.test.resolveExpression(vi);
|
||||
checkBooleanBranchCondition(value, () => this.test.tokens, vi.problems);
|
||||
|
||||
if (this.test) {
|
||||
const value = this.test.resolveExpression(vi);
|
||||
checkBooleanBranchCondition(value, () => this.test.tokens, vi.problems);
|
||||
}
|
||||
if (this.statement) {
|
||||
vi.statementStack.unshift('if');
|
||||
checkNonVarDeclStatement(this.statement, vi);
|
||||
@@ -29,7 +30,7 @@ class IfStatement extends KeywordStatement {
|
||||
}
|
||||
if (this.elseStatement) {
|
||||
vi.statementStack.unshift('else');
|
||||
checkNonVarDeclStatement(this.statement, vi);
|
||||
checkNonVarDeclStatement(this.elseStatement, vi);
|
||||
vi.statementStack.shift();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ class SwitchStatement extends KeywordStatement {
|
||||
} else {
|
||||
vi.problems.push(ParseProblem.Error(c.tokens, `Expression expected`));
|
||||
}
|
||||
})
|
||||
});
|
||||
caseblock.statements.forEach(statement => statement.validate(vi));
|
||||
})
|
||||
|
||||
vi.statementStack.shift();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
const { KeywordStatement } = require("./KeywordStatement");
|
||||
const { ResolvedIdent } = require('../body-types');
|
||||
const { Block } = require('./Block');
|
||||
|
||||
class TryStatement extends KeywordStatement {
|
||||
/** @type {(ResolvedIdent|Local[])[]} */
|
||||
@@ -28,6 +29,16 @@ class TryStatement extends KeywordStatement {
|
||||
this.block.validate(vi);
|
||||
vi.statementStack.shift();
|
||||
}
|
||||
|
||||
this.catches.forEach(c => {
|
||||
if (c instanceof Block) {
|
||||
// finally
|
||||
c.validate(vi);
|
||||
} else if (c.block) {
|
||||
// catch block
|
||||
c.block.validate(vi);
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,9 +16,10 @@ class WhileStatement extends KeywordStatement {
|
||||
* @param {ValidateInfo} vi
|
||||
*/
|
||||
validate(vi) {
|
||||
const value = this.test.resolveExpression(vi);
|
||||
checkBooleanBranchCondition(value, () => this.test.tokens, vi.problems);
|
||||
|
||||
if (this.test) {
|
||||
const value = this.test.resolveExpression(vi);
|
||||
checkBooleanBranchCondition(value, () => this.test.tokens, vi.problems);
|
||||
}
|
||||
if (this.statement) {
|
||||
vi.statementStack.unshift('while');
|
||||
this.statement.validate(vi);
|
||||
|
||||
Reference in New Issue
Block a user