Переглянути джерело

Update invalid op message

Disable command drag and click log
Lucas de Souza 5 роки тому
батько
коміт
6e5d7cf739

+ 4 - 4
i18n/pt/error.json

@@ -55,10 +55,10 @@
   "vector_line_outbounds": "Número de linhas $0 é inválido para a matriz $1 que possui $2 linhas",
   "vector_not_matrix_full": "Erro na linha $0: $1 não é uma matriz",
   "vector_not_matrix": "$1 não é uma matriz",
-  "invalid_infix_op_full": "Erro na linha $0: não é possível aplicar a operação $1 entre os tipos $2 e $3",
-  "invalid_infix_op": "Não é possível aplicar a operação $0 entre os tipos $1 e $2",
-  "invalid_unary_op_full": "Erro na linha $0: não é possível aplicar a operação $1 ao tipo $2",
-  "invalid_unary_op": "Não é possível aplicar a operação $0 ao tipo $1",
+  "invalid_infix_op_full": "Erro na linha $0: a expressão $1 é inválida, pois o operador $2 não pode ser aplicado aos tipos $3 e $4",
+  "invalid_infix_op": "A expressão $0 é inválida, pois o operador $1 não pode ser aplicado aos tipos $2 e $3",
+  "invalid_unary_op_full": "Erro na linha $0: a expressão $1 é inválida, pois o operador $2 não pode ser aplicado ao tipo $3",
+  "invalid_unary_op": "A expressão $0 é inválida, pois o operador $1 não pode ser aplicado ao tipo $2",
   "unknown_op": "Erro interno crítico: Operação $0 desconhecida",
   "duplicate_function": "A função $0 na linha: $1, coluna: $2 já foi definida anteriormente.",
   "duplicate_variable": "A variável $0 na linha: $1, coluna: $2 já foi declarada anteriormente.",

+ 0 - 1
js/iassign-integration-functions.js

@@ -241,7 +241,6 @@ function prepareEnvironment () {
 
   $('.div_to_body').click(function(e) {
     // trackingMatrix.push(adCoords(e, 1));
-    console.log("Log click");
     ivprogCore.registerClick(e.pageX, e.pageY, e.target.classList['value']);
   });
 

+ 8 - 8
js/processor/error/processorErrorFactory.js

@@ -340,28 +340,28 @@ export const ProcessorErrorFactory  = Object.freeze({
     const context = [expected, actual];
     return new RuntimeError(LocalizedStrings.getError("invalid_array_literal_column", context));
   },
-  invalid_unary_op_full: (opName, type, dim, sourceInfo) => {
+  invalid_unary_op_full: (expString, opName, type, dim, sourceInfo) => {
     if(sourceInfo) {
-      const context = [sourceInfo.line, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
+      const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
       return new RuntimeError(LocalizedStrings.getError("invalid_unary_op_full", context));
     } else {
       return ProcessorErrorFactory.invalid_unary_op(opName, type, dim);
     }
   },
-  invalid_unary_op: (opName, type, dim) => {
-    const context = [LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
+  invalid_unary_op: (expString, opName, type, dim) => {
+    const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(type, dim)];
     return new RuntimeError(LocalizedStrings.getError("invalid_unary_op", context));
   },
-  invalid_infix_op_full: (opName, typeLeft, dimLeft, typeRight, dimRight,  sourceInfo) => {
+  invalid_infix_op_full: (expString, opName, typeLeft, dimLeft, typeRight, dimRight,  sourceInfo) => {
     if(sourceInfo) {
-      const context = [sourceInfo.line, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
+      const context = [sourceInfo.line, expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
       return new RuntimeError(LocalizedStrings.getError("invalid_infix_op_full", context));
     } else {
       return ProcessorErrorFactory.invalid_infix_op(opName, typeLeft, dimLeft, typeRight, dimRight);
     }
   },
-  invalid_infix_op: (opName, typeLeft, dimLeft, typeRight, dimRight) => {
-    const context = [LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
+  invalid_infix_op: (expString, opName, typeLeft, dimLeft, typeRight, dimRight) => {
+    const context = [expString, LocalizedStrings.translateOp(opName), LocalizedStrings.translateType(typeLeft, dimLeft), LocalizedStrings.translateType(typeRight, dimRight)];
     return new RuntimeError(LocalizedStrings.getError("invalid_infix_op", context));
   },
   array_dimension_not_positive_full: (sourceInfo) => {

+ 1 - 1
js/processor/lib/math.js

@@ -150,7 +150,7 @@ export function createLogFun () {
   const logFun = (sto, _) => {
     const x = sto.applyStore('x');
     if (x.value.isNegative()) {
-      return Promise.reject("the value passed to log function cannot be negative");
+      return Promise.reject(new Error("the value passed to log function cannot be negative"));
     }
     let result = Decimal.log10(x.value);
     if(result.dp() > Config.decimalPlaces) {

+ 20 - 4
js/processor/semantic/semanticAnalyser.js

@@ -150,12 +150,28 @@ export class SemanticAnalyser {
     if(expression instanceof UnaryApp) {
       const op = expression.op;
       const resultType = this.evaluateExpressionType(expression.left);
-      return resultTypeAfterUnaryOp(op, resultType);
+      const finalResult = resultTypeAfterUnaryOp(op, resultType);
+      if (Types.UNDEFINED.isCompatible(finalResult)) {
+        const stringInfo = resultType.stringInfo();
+        const info = stringInfo[0];
+        const expString = expression.toString();
+        throw ProcessorErrorFactory.invalid_unary_op_full(expString, op, info.type, info.dim, expression.sourceInfo);
+      }
+      return finalResult;
     } else if (expression instanceof InfixApp) {
       const op = expression.op;
       const resultTypeLeft = this.evaluateExpressionType(expression.left);
       const resultTypeRight = this.evaluateExpressionType(expression.right);
-      return resultTypeAfterInfixOp(op, resultTypeLeft, resultTypeRight);
+      const finalResult = resultTypeAfterInfixOp(op, resultTypeLeft, resultTypeRight);
+      if (Types.UNDEFINED.isCompatible(finalResult)) {
+        const stringInfoLeft = resultTypeLeft.stringInfo();
+        const infoLeft = stringInfoLeft[0];
+        const stringInfoRight = resultTypeRight.stringInfo();
+        const infoRight = stringInfoRight[0];
+        const expString = expression.toString();
+        throw ProcessorErrorFactory.invalid_infix_op_full(expString,op, infoLeft.type, infoLeft.dim, infoRight.type, infoRight.dim, expression.sourceInfo);
+      }
+      return finalResult;
     } else if (expression instanceof Literal) {
       return this.evaluateLiteralType(expression);
     } else if (expression instanceof FunctionCall) {
@@ -498,7 +514,7 @@ export class SemanticAnalyser {
     if (fun.formalParameters.length !== actualParametersList.length) {
       throw ProcessorErrorFactory.invalid_parameters_size_full(fun.name, actualParametersList.length, fun.formalParameters.length, null);
     }
-    for (let i = 0; i < actualParametersList.length; i++) {
+    for (let i = 0; i < actualParametersList.length; ++i) {
       const param = actualParametersList[i];
       const formalParam = fun.formalParameters[i];
       const id = formalParam.id;
@@ -510,7 +526,7 @@ export class SemanticAnalyser {
       const resultType = this.evaluateExpressionType(param);
       if(resultType instanceof MultiType && formalParam.type instanceof MultiType) {
         let shared = 0
-        for (let j = 0; j < resultType.types.length; j++) {
+        for (let j = 0; j < resultType.types.length; ++j) {
           const element = resultType.types[j];
           if(formalParam.type.types.indexOf(element) !== -1) {
             shared++;

+ 1 - 0
js/services/localizedStringsService.js

@@ -1,6 +1,7 @@
 import { LanguageService } from "./languageService";
 import line_i18n from 'line-i18n';
 import Langs from './../../i18n';
+import { Operators } from "./../ast/operators";
 
 class IVProgLocalizedStrings extends line_i18n.LocalizedStrings {
 

+ 3 - 0
js/visualUI/functions.js

@@ -626,6 +626,9 @@ function prepareDragHandler (evt) {
 var command_in_drag;
 
 function addSortableHandler (element, id_function) {
+  if(true) { // DISABLE COMMAND DRAG
+    return;
+  }
   var n_group = 'commands_drag_' + id_function;
   Sortable.create(element, {
     handle: '.command_drag',