mirror of
https://github.com/adelphes/android-dev-ext.git
synced 2025-12-23 01:48:18 +00:00
remove validation modules that used old parser types
This commit is contained in:
@@ -1,93 +0,0 @@
|
|||||||
const { ModuleBlock, FieldBlock, TypeDeclBlock } = require('../parser9');
|
|
||||||
const ParseProblem = require('../parsetypes/parse-problem');
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {TypeDeclBlock} type
|
|
||||||
* @param {ParseProblem[]} probs
|
|
||||||
*/
|
|
||||||
function checkDuplicateFieldName(type, probs) {
|
|
||||||
/** @type {Map<string,FieldBlock>} */
|
|
||||||
let names = new Map();
|
|
||||||
type.fields.forEach(field => {
|
|
||||||
if (!field.name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const value = names.get(field.name);
|
|
||||||
if (value === undefined) {
|
|
||||||
names.set(field.name, field);
|
|
||||||
} else {
|
|
||||||
if (value !== null) {
|
|
||||||
probs.push(ParseProblem.Error(value, `Duplicate field: ${field.name}`));
|
|
||||||
names.set(field.name, null);
|
|
||||||
}
|
|
||||||
probs.push(ParseProblem.Error(field, `Duplicate field: ${field.name}`));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// check enclosed types
|
|
||||||
type.types.forEach(type => checkDuplicateFieldName(type, probs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {string} outername
|
|
||||||
* @param {TypeDeclBlock[]} types
|
|
||||||
* @param {ParseProblem[]} probs
|
|
||||||
*/
|
|
||||||
function checkDuplicateTypeNames(outername, types, probs) {
|
|
||||||
/** @type {Map<string,TypeDeclBlock>} */
|
|
||||||
let names = new Map();
|
|
||||||
types.forEach(type => {
|
|
||||||
const name = type.simpleName;
|
|
||||||
if (!name) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const value = names.get(name);
|
|
||||||
if (value === undefined) {
|
|
||||||
names.set(name, type);
|
|
||||||
} else {
|
|
||||||
if (value !== null) {
|
|
||||||
probs.push(ParseProblem.Error(value.name_token, `Duplicate type: ${outername}${name}`));
|
|
||||||
names.set(name, null);
|
|
||||||
}
|
|
||||||
probs.push(ParseProblem.Error(type.name_token, `Duplicate type: ${outername}${name}`));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// check enclosed types
|
|
||||||
types.forEach(type => {
|
|
||||||
checkDuplicateTypeNames(`${outername}${type.simpleName}.`, type.types, probs);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {TypeDeclBlock} type
|
|
||||||
* @param {ParseProblem[]} probs
|
|
||||||
*/
|
|
||||||
function checkDuplicateTypeVariableName(type, probs) {
|
|
||||||
type.typevars.forEach((tv, i) => {
|
|
||||||
const name = tv.name;
|
|
||||||
if (tv.name === '?') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (type.typevars.findIndex(tv => tv.name === name) < i) {
|
|
||||||
probs.push(ParseProblem.Error(tv.decl, `Duplicate type variable: ${name}`));
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// check enclosed types
|
|
||||||
type.types.forEach(type => {
|
|
||||||
checkDuplicateTypeVariableName(type, probs);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ModuleBlock} mod
|
|
||||||
*/
|
|
||||||
module.exports = function(mod) {
|
|
||||||
const probs = [];
|
|
||||||
mod.types.forEach(type => {
|
|
||||||
checkDuplicateFieldName(type, probs);
|
|
||||||
checkDuplicateTypeVariableName(type, probs);
|
|
||||||
});
|
|
||||||
checkDuplicateTypeNames('', mod.types, probs);
|
|
||||||
return probs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
const { ModuleBlock } = require('./../parser9');
|
|
||||||
const ParseProblem = require('./../parsetypes/parse-problem');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ModuleBlock} mod
|
|
||||||
*/
|
|
||||||
module.exports = function(mod) {
|
|
||||||
return mod.packages.slice(1).map(
|
|
||||||
pkg => {
|
|
||||||
return ParseProblem.Error(pkg, 'Additional package declaration');
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
const { ModuleBlock, TypeDeclBlock, MethodBlock } = require('../parser9');
|
|
||||||
const ParseProblem = require('../parsetypes/parse-problem');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {TypeDeclBlock} type
|
|
||||||
* @param {ParseProblem[]} probs
|
|
||||||
*/
|
|
||||||
function checkTypeParseErrors(type, probs) {
|
|
||||||
type.parseErrors.forEach(err => probs.push(ParseProblem.Error(err, `Invalid, incomplete or unsupported declaration`)));
|
|
||||||
type.methods.filter(m => m.parseErrors).forEach(m => checkMethodParseErrors(m, probs));
|
|
||||||
type.types.forEach(type => checkTypeParseErrors(type, probs));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {MethodBlock} method
|
|
||||||
* @param {ParseProblem[]} probs
|
|
||||||
*/
|
|
||||||
function checkMethodParseErrors(method, probs) {
|
|
||||||
method.parseErrors.forEach(err => probs.push(ParseProblem.Error(err, `Invalid, incomplete or unsupported declaration`)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ModuleBlock} mod
|
|
||||||
*/
|
|
||||||
module.exports = function(mod) {
|
|
||||||
const probs = [];
|
|
||||||
mod.parseErrors.forEach(err => probs.push(ParseProblem.Error(err, `Invalid, incomplete or unsupported declaration`)));
|
|
||||||
mod.types.forEach(type => checkTypeParseErrors(type, probs));
|
|
||||||
return probs;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
const { ModuleBlock, PackageBlock, ImportBlock, TypeDeclBlock } = require('../parser9');
|
|
||||||
const ParseProblem = require('../parsetypes/parse-problem');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {ModuleBlock} mod
|
|
||||||
*/
|
|
||||||
module.exports = function(mod) {
|
|
||||||
let have_imports, have_type;
|
|
||||||
const problems = [];
|
|
||||||
for (let decl of mod.decls()) {
|
|
||||||
let p;
|
|
||||||
switch (true) {
|
|
||||||
case decl instanceof PackageBlock:
|
|
||||||
if (have_imports || have_type) {
|
|
||||||
p = ParseProblem.Error(decl, 'package must be declared before import and type declarations');
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case decl instanceof ImportBlock:
|
|
||||||
if (have_type) {
|
|
||||||
p = ParseProblem.Error(decl, 'imports must be declared before type declarations');
|
|
||||||
}
|
|
||||||
have_imports = true;
|
|
||||||
break;
|
|
||||||
case decl instanceof TypeDeclBlock:
|
|
||||||
have_type = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (p) {
|
|
||||||
problems.push(p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return problems;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user