Beispiel #1
0
// This tool parses a sequence of declarations followed by a
// sequence of directives. Each directive computes some operation
// on the declarations previously parsed.
//
//    script:
//      translation unit
//      directive-seq
int
main(int argc, char* argv[])
{
  Context cxt;

  if (argc != 2) {
    std::cerr << "usage: test_parse <input-file>\n";
    return -1;
  }

  File input(argv[1]);
  Character_stream cs(input);
  Token_stream ts;
  Lexer lex(cxt, cs, ts);
  Parser parse(cxt, ts);

  // Transform characters into tokens.
  lex();
  if (error_count())
    return 1;

  // Parse the translation unit.
  parse();
  if (error_count())
    return 1;

  // Parse and interpret directives.
  directive_seq(parse);
  return 0;
}
Beispiel #2
0
// Parse the given buffer.
Expr const*
parse(String const& str)
{
  Buffer buf(str);
  Character_stream cs(buf);
  Token_stream ts(buf);
  Lexer lex(cs, ts);
  Parser parse(ts);

  // Lex.
  lex();
  if (error_count()) {
    reset_diagnostics();
    return make_error_node<Expr>();
  }

  // Parse.
  Expr const* expr = parse();
  if (error_count()) {
    reset_diagnostics();
    return make_error_node<Expr>();
  }

  return expr;
}
bool test_file_directory_find_invalid_argument (Test *test)
{
	char *path;
	Directory *directory;

	TITLE ();
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/find"));
        /*
                d stage/find
                f f1
                d stage/find/d1
         */
	CATCH (!(directory = directory_open (path)));
	string_destroy (path);
	CATCH (directory_find_file (NULL, "file"));
	CATCH (error_count () != 1);
	CATCH (error_at (0).error != ErrorInvalidArgument);
	error_reset ();
	CATCH (directory_find_directory (NULL, "directory"));
	CATCH (error_count () != 1);
	CATCH (error_at (0).error != ErrorInvalidArgument);
	error_reset ();
	CATCH (directory_find_file (directory, NULL));
	CATCH (error_count () != 1);
	CATCH (error_at (0).error != ErrorInvalidArgument);
	error_reset ();
	CATCH (directory_find_directory (directory, NULL));
	CATCH (error_count () != 1);
	CATCH (error_at (0).error != ErrorInvalidArgument);
	error_reset ();
	directory_close (directory);
	PASS ();
}
Beispiel #4
0
int
main(int argc, char* argv[])
{
  Context cxt;

  if (argc != 2) {
    std::cerr << "usage: test_parse <input-file>\n";
    return -1;
  }

  File input(argv[1]);
  Character_stream cs(input);
  Token_stream ts(input);
  Lexer lex(cxt, cs, ts);
  Parser parse(cxt, ts);

  // Transform characters into tokens.
  lex();
  if (error_count())
    return -1;

  // Transform tokens into a syntax tree.
  Term& unit = parse();
  if (error_count())
    return 1;

  std::cout << unit << '\n';

}
Beispiel #5
0
static int init(sqlite3 *db, const char *db_name, errorstream_t *error) {
  int result = SQLITE_OK;
  const table_info_t *const *table = gpkg_tables;

  result = sql_exec(db, "PRAGMA application_id = %d", 0x47503130);
  if (result != SQLITE_OK) {
    error_append(error, "Could not set application_id");
  }

  if (result == SQLITE_OK) {
    while (*table != NULL) {
      result = sql_init_table(db, db_name, *table, error);
      if (result != SQLITE_OK) {
        break;
      }
      table++;
    }
  }

  if (result == SQLITE_OK && error_count(error) > 0) {
    result = SQLITE_ERROR;
  }

  return result;
}
static void ST_SRID(sqlite3_context *context, int nbArgs, sqlite3_value **args) {
  spatialdb_t *spatialdb;
  FUNCTION_GEOM_ARG(geomblob);

  FUNCTION_START_STATIC(context, 256);
  spatialdb = (spatialdb_t *)sqlite3_user_data(context);
  FUNCTION_GET_GEOM_ARG_UNSAFE(context, spatialdb, geomblob, 0);

  if (nbArgs == 1) {
    sqlite3_result_int(context, geomblob.srid);
  } else {
    FUNCTION_GET_INT_ARG(geomblob.srid, 1);
    if (binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0) != SQLITE_OK) {
      sqlite3_result_error(context, "Error writing geometry blob header", -1);
      goto exit;
    }
    if (spatialdb->write_blob_header(&FUNCTION_GEOM_ARG_STREAM(geomblob), &geomblob, FUNCTION_ERROR) != SQLITE_OK) {
      if (error_count(FUNCTION_ERROR) == 0) {
        error_append(FUNCTION_ERROR, "Error writing geometry blob header");
      }
      goto exit;
    }
    binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0);
    sqlite3_result_blob(context, binstream_data(&FUNCTION_GEOM_ARG_STREAM(geomblob)), (int) binstream_available(&FUNCTION_GEOM_ARG_STREAM(geomblob)), SQLITE_TRANSIENT);
  }

  FUNCTION_END(context);
  FUNCTION_FREE_GEOM_ARG(geomblob);
}
Beispiel #7
0
unsigned char is_label(char* token){
  int short i = 1;
  unsigned char res = FALSE;

  if(isalpha(*token)){
    while(i < (strlen(token))){
      res = (!isalnum(token[i]) || i == MAX_NAME_LEN) ? FALSE : TRUE;
      if(res == FALSE){     // Breaks loop once an error is detected
        if(i == MAX_NAME_LEN){
          error_count("ERROR: Label is too long:", token);
        }
        return res;
      }
      i++;
    }

    if(get_inst(token)){  // Labels cannot have instruction names
      res = FALSE;
      #ifdef debug
      printf("LABEL >>%s<< HAS INSTRUCTION NAME\n", token);
      #endif /* debug */
    }

    if(get_dir(token)){ // Lables cannot have directive names
      res = FALSE;
      #ifdef debug
      printf("LABEL >>%s<< HAS DIRECTIVE NAME\n", token);
      #endif /* debug */
    }
  }
  return res;
}
Beispiel #8
0
std::size_t ElementSizeMetric::calc3dQuality()
{
    const std::vector<MeshLib::Element*>& elements(_mesh.getElements());
    const std::size_t nElems(elements.size());
    std::size_t error_count(0);

    for (std::size_t k(0); k < nElems; k++)
    {
        Element const& elem (*elements[k]);
        if (elem.getDimension()<3)
        {
            _element_quality_metric[k] = 0.0;
            continue;
        }

        double const volume (elem.getContent());
        if (volume < sqrt(fabs(std::numeric_limits<double>::epsilon())))
            error_count++;

        if (_min > volume) _min = volume;
        if (_max < volume) _max = volume;
        _element_quality_metric[k] = volume;
    }
    return error_count;
}
bool test_size_t_add (Test *test)
{
	size_t result;

	TITLE ();
	size_t_private_max (SIZE_MAX);
	CATCH (!size_t_add (0, 0, NULL));
	CATCH (error_count () != 0);
	CATCH (!size_t_add (1, 0, NULL));
	CATCH (!size_t_add (0, 1, NULL));
	CATCH (!size_t_add (SIZE_MAX / 2, 0, NULL));
	CATCH (!size_t_add (0, SIZE_MAX / 2, NULL));
	CATCH (!size_t_add ((SIZE_MAX / 2) + 1, (SIZE_MAX / 2), NULL));
	CATCH (!size_t_add ((SIZE_MAX / 2), (SIZE_MAX / 2) + 1, NULL));
	CATCH (!size_t_add (0, SIZE_MAX, NULL));
	CATCH (!size_t_add (SIZE_MAX, 0, NULL));
	CATCH (size_t_add (1, SIZE_MAX, NULL));
	CATCH (size_t_add (SIZE_MAX, 1, NULL));
	CATCH (size_t_add (SIZE_MAX / 2, SIZE_MAX, NULL));
	CATCH (size_t_add (SIZE_MAX, SIZE_MAX / 2, NULL));
	CATCH (size_t_add ((SIZE_MAX / 2) + 1, SIZE_MAX, NULL));
	CATCH (size_t_add (SIZE_MAX, (SIZE_MAX / 2) + 1, NULL));
	CATCH (size_t_add (SIZE_MAX - 1, SIZE_MAX, NULL));
	CATCH (size_t_add (SIZE_MAX, SIZE_MAX - 1, NULL));
	CATCH (size_t_add (SIZE_MAX, SIZE_MAX, NULL));
	result = 1;
	CATCH (!size_t_add (1, 2, &result));
	CATCH (result != 3);
	CATCH (size_t_add (1, SIZE_MAX, &result));
	CATCH (result != 3);
	PASS ();
}
Beispiel #10
0
const spatialdb_t *spatialdb_detect_schema(sqlite3 *db) {
  char message_buffer[256];
  errorstream_t error;
  error_init_fixed(&error, message_buffer, 256);

  const spatialdb_t *schemas[] = {
    spatialdb_geopackage_schema(),
    spatialdb_spatialite4_schema(),
    spatialdb_spatialite3_schema(),
    spatialdb_spatialite2_schema(),
    NULL
  };

  const spatialdb_t **schema = &schemas[0];
  while (*schema != NULL) {
    error_reset(&error);
    (*schema)->check_meta(db, "main", SQL_CHECK_PRIMARY_KEY | SQL_CHECK_NULLABLE, &error);
    if (error_count(&error) == 0) {
      break;
    } else {
      schema++;
    }
  }

  if (*schema != NULL) {
    return *schema;
  } else {
    return schemas[0];
  }
}
bool test_file_writer_write_args_system_call (Test *test)
{
        FileWriter *writer;
        FILE *file_readonly, *file_swap;
        char *path;

        TITLE ();
        CATCH (!(file_readonly = fopen ("stage/file_writer/file", "r")));
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/file_writer/args"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!(writer = file_writer_create (path, FileWriterModeTruncate)));
        file_swap = writer->file;
        writer->file = file_readonly;
        CATCH (file_writer_write_args (writer, "%s", "test"));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorSystemCall);
        writer->file = file_swap;
        fclose (file_readonly);
        file_writer_destroy (writer);
        string_destroy (path);
        PASS ();
}
bool test_unsigned_long_long_mul (Test *test)
{
	unsigned long long result;

	TITLE ();
	unsigned_long_long_private_max (ULLONG_MAX);
	CATCH (!unsigned_long_long_mul (0, 0, NULL));
	CATCH (error_count () != 0);
	CATCH (!unsigned_long_long_mul (1, 0, NULL));
	CATCH (!unsigned_long_long_mul (0, 1, NULL));
	CATCH (!unsigned_long_long_mul (1, 1, NULL));
	CATCH (!unsigned_long_long_mul (0, ULLONG_MAX, NULL));
	CATCH (!unsigned_long_long_mul (ULLONG_MAX, 0, NULL));
	CATCH (!unsigned_long_long_mul (1, ULLONG_MAX, NULL));
	CATCH (!unsigned_long_long_mul (ULLONG_MAX, 1, NULL));
	CATCH (!unsigned_long_long_mul (ULLONG_MAX / 2, 2, NULL));
	CATCH (!unsigned_long_long_mul (2, ULLONG_MAX / 2, NULL));
	CATCH (unsigned_long_long_mul ((ULLONG_MAX / 2) + 1, 2, NULL));
	CATCH (unsigned_long_long_mul (2, (ULLONG_MAX / 2) + 1, NULL));
	CATCH (unsigned_long_long_mul (ULLONG_MAX / 2, ULLONG_MAX / 2, NULL));
	CATCH (unsigned_long_long_mul (ULLONG_MAX / 2, ULLONG_MAX / 2, NULL));
	CATCH (unsigned_long_long_mul (ULLONG_MAX, ULLONG_MAX, NULL));
	CATCH (unsigned_long_long_mul (ULLONG_MAX, ULLONG_MAX, NULL));
	result = 1;
	CATCH (!unsigned_long_long_mul (2, 3, &result));
	CATCH (result != 6);
	CATCH (unsigned_long_long_mul (2, ULLONG_MAX, &result));
	CATCH (result != 6);
	PASS ();
}
bool test_size_t_mul (Test *test)
{
	size_t result;

	TITLE ();
	CATCH (!size_t_mul (0, 0, NULL));
	CATCH (error_count () != 0);
	CATCH (!size_t_mul (1, 0, NULL));
	CATCH (!size_t_mul (0, 1, NULL));
	CATCH (!size_t_mul (1, 1, NULL));
	CATCH (!size_t_mul (0, SIZE_MAX, NULL));
	CATCH (!size_t_mul (SIZE_MAX, 0, NULL));
	CATCH (!size_t_mul (1, SIZE_MAX, NULL));
	CATCH (!size_t_mul (SIZE_MAX, 1, NULL));
	CATCH (!size_t_mul (SIZE_MAX / 2, 2, NULL));
	CATCH (!size_t_mul (2, SIZE_MAX / 2, NULL));
	CATCH (size_t_mul ((SIZE_MAX / 2) + 1, 2, NULL));
	CATCH (size_t_mul (2, (SIZE_MAX / 2) + 1, NULL));
	CATCH (size_t_mul (SIZE_MAX / 2, SIZE_MAX / 2, NULL));
	CATCH (size_t_mul (SIZE_MAX / 2, SIZE_MAX / 2, NULL));
	CATCH (size_t_mul (SIZE_MAX, SIZE_MAX, NULL));
	CATCH (size_t_mul (SIZE_MAX, SIZE_MAX, NULL));
	result = 1;
	CATCH (!size_t_mul (2, 3, &result));
	CATCH (result != 6);
	CATCH (size_t_mul (2, SIZE_MAX, &result));
	CATCH (result != 6);
	PASS ();
}
bool test_unsigned_long_long_add (Test *test)
{
	unsigned long long result;

	TITLE ();
	unsigned_long_long_private_max (ULLONG_MAX);
	CATCH (!unsigned_long_long_add (0, 0, NULL));
	CATCH (error_count () != 0);
	CATCH (!unsigned_long_long_add (1, 0, NULL));
	CATCH (!unsigned_long_long_add (0, 1, NULL));
	CATCH (!unsigned_long_long_add (ULLONG_MAX / 2, 0, NULL));
	CATCH (!unsigned_long_long_add (0, ULLONG_MAX / 2, NULL));
	CATCH (!unsigned_long_long_add ((ULLONG_MAX / 2) + 1, (ULLONG_MAX / 2), NULL));
	CATCH (!unsigned_long_long_add ((ULLONG_MAX / 2), (ULLONG_MAX / 2) + 1, NULL));
	CATCH (!unsigned_long_long_add (0, ULLONG_MAX, NULL));
	CATCH (!unsigned_long_long_add (ULLONG_MAX, 0, NULL));
	CATCH (unsigned_long_long_add (1, ULLONG_MAX, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX, 1, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX / 2, ULLONG_MAX, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX, ULLONG_MAX / 2, NULL));
	CATCH (unsigned_long_long_add ((ULLONG_MAX / 2) + 1, ULLONG_MAX, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX, (ULLONG_MAX / 2) + 1, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX - 1, ULLONG_MAX, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX, ULLONG_MAX - 1, NULL));
	CATCH (unsigned_long_long_add (ULLONG_MAX, ULLONG_MAX, NULL));
	result = 1;
	CATCH (!unsigned_long_long_add (1, 2, &result));
	CATCH (result != 3);
	CATCH (unsigned_long_long_add (1, ULLONG_MAX, &result));
	CATCH (result != 3);
	PASS ();
}
Beispiel #15
0
std::size_t ElementSizeMetric::calc2dQuality()
{
    const std::vector<MeshLib::Element*> &elements(_mesh.getElements());
    const std::size_t nElems(elements.size());
    std::size_t error_count(0);

    for (std::size_t k(0); k < nElems; k++)
    {
        Element const& elem (*elements[k]);

        if (elem.getDimension() == 1)
        {
            _element_quality_metric[k] = 0.0;
            continue;
        }
        double const area = elem.getContent();
        if (area < sqrt(fabs(std::numeric_limits<double>::epsilon())))
            error_count++;

        // update _min and _max values
        if (_min > area) _min = area;
        if (_max < area) _max = area;
        _element_quality_metric[k] = area;
    }
    return error_count;
}
Beispiel #16
0
bool test_file_name_from_path_invalid_operation (Test *test)
{
	TITLE ();
	CATCH (file_name_from_path (NULL));
	CATCH (error_count () == 0);
	CATCH (error_at (0).error != ErrorInvalidOperation);
	PASS ();
}
bool test_print_log_begin_invalid_argument (Test *test)
{
        TITLE ();
        CATCH (print_log_begin (NULL));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        PASS ();
}
bool test_file_reader_destroy_invalid_argument (Test *test)
{
        TITLE ();
        file_reader_destroy (NULL);
        CATCH (error_count () != 1);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        PASS ();
}
bool test_print_log_end_invalid_operation (Test *test)
{
        TITLE ();
        CATCH (print_log_end ());
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidOperation);
        PASS ();
}
Beispiel #20
0
bool test_file_directory_read_invalid_argument (Test *test)
{
	TITLE ();
	CATCH (directory_read (NULL));
	CATCH (error_count () != 1);
	CATCH (error_at (0).error != ErrorInvalidArgument);
	PASS ();
}
Beispiel #21
0
bool test_file_directory_open_system_call (Test *test)
{
	TITLE ();
	CATCH (directory_open ("/dev/null/fail"));
	CATCH (error_count () == 0);
	CATCH (error_at (0).error != ErrorSystemCall);
	PASS ();	
}
Beispiel #22
0
bool test_file_directory_open_invalid_operation (Test *test)
{
	TITLE ();
	CATCH (directory_open (NULL));
	CATCH (error_count () == 0);
	CATCH (error_at (0).error != ErrorInvalidOperation);
	PASS ();	
}
bool test_file_writer_create_system_call (Test *test)
{
        TITLE ();
        CATCH (file_writer_create ("/stage/file_writer/does/not/exist/file", FileWriterModeTruncate));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorSystemCall);
        PASS ();
}
bool test_server_destroy_invalid_argument (Test *test)
{
        TITLE ();
        net_server_destroy (NULL);
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        PASS ();
}
bool test_big_int_set_invalid_argument (Test *test)
{
        TITLE ();
        CATCH (big_int_set (NULL, 123ULL));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        PASS ();
}
Beispiel #26
0
/*
  If a label is encountered in parse_record, this function gets called to deal
  with the remaining record. The following tokens in the record can be either
  an instruction, a directive or a comment/null. Anything else is an error
*/
void analyzelabel(char* line, char* token){
  char* nexttoken;
  char* string;
  char* strptr;
  struct firsttoken result;

  #ifdef debug
  printf("FOUND LABEL >>%s<<\n", token);
  #endif /* debug */

  global = token;                       // Global string saving the label token
  string = storeline(line);
  nexttoken = strtok(line, " \t\r\n");

  if(nexttoken != NULL && *nexttoken != ';' && nexttoken[0] != '\r'){

    while(!isalnum(*string)){       // Go to first legible char
      *string++;
    }

    //Points to the start of the next token for the analysis functions

    strptr = storeline(string + strlen(nexttoken));

    #ifdef debug
    printf("TOKEN AFTER LABEL IS >>%s<<\n", nexttoken);
    printf("SENDING TO ANALYZERS: >>%s<<\n", strptr);
    #endif /* debug */

    result = sort(nexttoken);
    flag_first_token_label = TRUE; // indicator used for storing in symtbl
    switch (result.type) {
      case INST:
      analyzeinstruction(strptr, result);
      break;
      case DIR:
      analyzedirective(strptr, result);
      break;
      default:
      error_count("ERROR: Invalid token after label:", nexttoken);
      break;
    }
    flag_first_token_label = FALSE;
  }
  else{                                      // Nothing follows the label
    #ifdef debug
    printf("SOLO LABEL >>%s<<\n", token);
    #endif
    if(!get_entry(token)){            // If label unique, add it with LC
      add_entry(token, LC, LBLTYPE);
    }
    else{
      update_entry(token, LC, LBLTYPE);
    }
  }

  global = NULL; //Reset the global label for further usage
}
bool test_server_create_invalid_argument_4 (Test *test)
{
        TITLE ();
        CATCH (net_server_create ("127.0.0.1", 8888, &on_connect, NULL, NULL));
        CATCH (error_count () != 1);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        CATCH (error_at (0).code != 4);
        PASS ();
}
bool test_server_create_invalid_argument_1 (Test *test)
{
        TITLE ();
        CATCH (net_server_create (NULL, 0, NULL, NULL, NULL));
        CATCH (error_count () != 1);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        CATCH (error_at (0).code != 1);
        PASS ();
}
Beispiel #29
0
bool test_file_directory_current_path_system_call (Test *test)
{
	TITLE ();
	file_path_size (1);
	CATCH (directory_current_path ());
	CATCH (error_count () == 0);
	CATCH (error_at (0).error != ErrorSystemCall);
	PASS ();
}
bool test_file_reader_create_system_call_1 (Test *test)
{
        TITLE ();
        CATCH (file_reader_create ("/stage/error_stat"));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorSystemCall);
        CATCH (error_at (0).code != 1);
        PASS ();
}