|
@@ -66,13 +66,13 @@ export class SemanticAnalyser {
|
|
|
findFunction (name) {
|
|
|
if(name.match(/^\$.+$/)) {
|
|
|
const fun = LanguageDefinedFunction.getFunction(name);
|
|
|
- if(!!!fun) {
|
|
|
+ if(!fun) {
|
|
|
throw ProcessorErrorFactory.not_implemented(name);
|
|
|
}
|
|
|
return fun;
|
|
|
} else {
|
|
|
const val = this.ast.functions.find( v => v.name === name);
|
|
|
- if (!!!val) {
|
|
|
+ if (!val) {
|
|
|
return null;
|
|
|
}
|
|
|
return val;
|
|
@@ -114,15 +114,15 @@ export class SemanticAnalyser {
|
|
|
throw ProcessorErrorFactory.array_dimension_not_int_full(declaration.sourceInfo);
|
|
|
}
|
|
|
}
|
|
|
- this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
|
|
|
+ this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type, isConst: declaration.isConst});
|
|
|
return;
|
|
|
}
|
|
|
this.evaluateArrayLiteral(declaration.id, declaration.lines, declaration.columns, declaration.type, declaration.initial);
|
|
|
- this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type});
|
|
|
+ this.insertSymbol(declaration.id, {id: declaration.id, lines: declaration.lines, columns: declaration.columns, type: declaration.type, isConst: declaration.isConst});
|
|
|
|
|
|
} else {
|
|
|
if(declaration.initial === null) {
|
|
|
- this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
|
|
|
+ this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type, isConst: declaration.isConst});
|
|
|
return;
|
|
|
}
|
|
|
const resultType = this.evaluateExpressionType(declaration.initial);
|
|
@@ -132,7 +132,7 @@ export class SemanticAnalyser {
|
|
|
const info = stringInfo[0];
|
|
|
throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
|
|
|
}
|
|
|
- this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type})
|
|
|
+ this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type, isConst: declaration.isConst})
|
|
|
} else if((!declaration.type.isCompatible(resultType) && !Config.enable_type_casting)
|
|
|
|| (!declaration.type.isCompatible(resultType) && Config.enable_type_casting
|
|
|
&& !Store.canImplicitTypeCast(declaration.type, resultType))) {
|
|
@@ -140,7 +140,7 @@ export class SemanticAnalyser {
|
|
|
const info = stringInfo[0];
|
|
|
throw ProcessorErrorFactory.incompatible_types_full(info.type, info.dim, declaration.sourceInfo);
|
|
|
} else {
|
|
|
- this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type});
|
|
|
+ this.insertSymbol(declaration.id, {id: declaration.id, type: declaration.type, isConst: declaration.isConst});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -264,7 +264,7 @@ export class SemanticAnalyser {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- evaluateArrayLiteral (id, lines, columns, type, literal) {
|
|
|
+ evaluateArrayLiteral (/*id, lines, columns, type, literal*/) {
|
|
|
/* if (literal instanceof ArrayLiteral) {
|
|
|
const dimType = this.evaluateExpressionType(lines);
|
|
|
if (!dimType.isCompatible(Types.INTEGER)) {
|
|
@@ -519,10 +519,15 @@ export class SemanticAnalyser {
|
|
|
for (let i = 0; i < actualParametersList.length; ++i) {
|
|
|
const param = actualParametersList[i];
|
|
|
const formalParam = fun.formalParameters[i];
|
|
|
- const id = formalParam.id;
|
|
|
+ // const id = formalParam.id;
|
|
|
if(formalParam.byRef) {
|
|
|
- if (!(param instanceof VariableLiteral || param instanceof ArrayAccess)) {
|
|
|
- throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
|
|
|
+ if(param instanceof VariableLiteral) {
|
|
|
+ const variable = this.findSymbol(param.id, this.symbolMap);
|
|
|
+ if (variable.isConst) {
|
|
|
+ throw ProcessorErrorFactory.invalid_const_ref_full(fun.name, param.toString(), param.sourceInfo);
|
|
|
+ }
|
|
|
+ } else if (!(param instanceof VariableLiteral || param instanceof ArrayAccess)) {
|
|
|
+ throw ProcessorErrorFactory.invalid_parameter_type_full(fun.name, param.toString(), param.sourceInfo);
|
|
|
}
|
|
|
}
|
|
|
const resultType = this.evaluateExpressionType(param);
|
|
@@ -542,7 +547,7 @@ export class SemanticAnalyser {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
|
|
|
+ throw ProcessorErrorFactory.invalid_parameter_type_full(fun.name, param.toString(), param.sourceInfo);
|
|
|
}
|
|
|
} else if (resultType instanceof MultiType) {
|
|
|
if(!resultType.isCompatible(formalParam.type)) {
|
|
@@ -553,7 +558,7 @@ export class SemanticAnalyser {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
|
|
|
+ throw ProcessorErrorFactory.invalid_parameter_type_full(fun.name, param.toString(), param.sourceInfo);
|
|
|
}
|
|
|
} else if(!formalParam.type.isCompatible(resultType)) {
|
|
|
if(Config.enable_type_casting && !formalParam.byRef) {
|
|
@@ -561,7 +566,7 @@ export class SemanticAnalyser {
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- throw ProcessorErrorFactory.invalid_parameter_type_full(id, param.toString(), param.sourceInfo);
|
|
|
+ throw ProcessorErrorFactory.invalid_parameter_type_full(fun.name, param.toString(), param.sourceInfo);
|
|
|
}
|
|
|
|
|
|
}
|