Ejemplo n.º 1
0
int NMethodCall::checkParams(Node* funcParams) {
	int isValid = 1;

	node_children_t thisParams = children[0]->getChildren();
	int thisSize = thisParams.size();
	int expectedSize = funcParams->getChildrenSize();
	/* Do we have the same number of expected and given arguments? */
	if(thisSize != expectedSize) {
		printErrorHeader("method call");
		error_num_args(name, expectedSize, thisSize);
		isValid = 0;

	}

	/* Compare the arguments and ensure they are of the same type. */
	int i = 0;
	int j = 0;
	int expectedType, givenType;
	string varName;
	while( i < expectedSize && j < thisSize) {
		expectedType = funcParams->getChild(i)->getType();
		givenType = thisParams[j]->getType();
		if(!compareTypes(expectedType, givenType)) {
			varName = thisParams[j]->getID();
			printErrorHeader("method call");
			error_type_mismatch(varName, givenType, expectedType);
			isValid = 0;
		}
		++i;
		++j;
	}

	return isValid;
}
Ejemplo n.º 2
0
static void vhandleError(FILE* file, BaseAST* ast, const char *fmt, va_list args) {
  if (err_ignore)
    return;

  bool guess = false;
  if (file == stderr)
    guess = printErrorHeader(ast);

  if (err_user || developer) {
    vfprintf(file, fmt, args);
  }

  if (fPrintIDonError && ast)
    fprintf(file, " [%d]", ast->id);

  if (file == stderr)
    printErrorFooter(guess);
  fprintf(file, "\n");

  if (file == stderr)
    printCallStackOnError();

  if (!err_user && !developer)
    return;

  if (exit_immediately) {
    if (ignore_errors_for_pass) {
      exit_end_of_pass = true;
    } else if (!ignore_errors) {
      clean_exit(1);
    }
  }
}
Ejemplo n.º 3
0
int NUnaryOp::checkBoolean() {
	if(type != BOOLEAN) {
		printErrorHeader("unary operator");
		error_type_mismatch(op, type, BOOLEAN);
		return 0;
	}

	return 1;
}
Ejemplo n.º 4
0
int NMethodCall::check() {
	int isValid = 1;

	Node* nodePtr = table->lookup(name);
	
	/* Does the method exist in scope? */
	if(nodePtr == NULL) {
		printErrorHeader("method call");
		error_var_not_found(name);
		isValid = 0;
	}
	
	else { 
		/* Is the identifier a function or procedure? */
		if(!(nodePtr->getNodeType() == FUNC 
				|| nodePtr->getNodeType() == PROCEDURE)) {
			printErrorHeader("method call");
			error_not_func(name);
			isValid = 0;
		}
		/* Check that the parameters (child nodes) are valid. */
		isValid &= Node::check();	
		/*
		 * Get the types of the expected paramaters. We have a list of
		 * parameters if the size of the function node's children = 2.
		 */
		if(nodePtr->getChildrenSize() == 2) {
			Node* param = nodePtr->getChild(1);
			isValid &= checkParams(param);	
		}
			
	}



	return isValid;
}
Ejemplo n.º 5
0
void handleError(const char* fmt, ...) {
  fflush(stdout);
  fflush(stderr);

  if (err_ignore) {
    return;
  }

  bool guess = printErrorHeader(NULL);

  //
  // Only print out the arguments if this is a user error or we're
  // in developer mode.
  //
  if (err_user || developer) {
    va_list args;

    va_start(args, fmt);

    vfprintf(stderr, fmt, args);

    va_end(args);
  }

  printErrorFooter(guess);
  fprintf(stderr, "\n");

  printCallStackOnError();

  if (!err_user && !developer) {
    return;
  }

  if (exit_immediately) {
    if (ignore_errors_for_pass) {
      exit_end_of_pass = true;
    } else if (!ignore_errors && !(ignore_user_errors && err_user)) {
      clean_exit(1);
    }
  }
}
Ejemplo n.º 6
0
int NUnaryOp::check() {
	int isValid = 1;

	this->type = resolveType();

	/* Do we have a unary boolean expression? (i.e. NOT) */
	if(op == LNOT) {
		return checkBoolean();
	}

	/* Valid if the type is a number and the children are valid. */
	isValid &= Node::check();

	/* Is the type invalid? */
	if(type == INVALIDTYPE) {
		printErrorHeader("unary operator");
		error_type_mismatch(op, children[0]->getType(), TNUMBER);
		isValid = 0;
	}

	return isValid;
}
Ejemplo n.º 7
0
    void ErrorReporter::reportError(Error *error)
    {
        printErrorHeader(error);
        printDecoratedLines(error);
        
        cerr << "\n";

        if (!error->getAdditionalInformation().empty()) {
            cerr << "\n  " << Utilities::stringWithLineIndentation(error->getAdditionalInformation(), DECORATE_INDENTATION);
        }

        cerr << endl;
        
        if (error->getType() == ErrorType::Warning)
            m_numberOfReportedWarnings++;
        else
            m_numberOfReportedErrors++;
        
        delete error;
        
        if (error->getType() == ErrorType::Internal)
            exit(EXIT_FAILURE);
    }