viml_expressions_lexer.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifdef USE_KLEE
  2. # include <klee/klee.h>
  3. #else
  4. # include <string.h>
  5. # include <stdio.h>
  6. #endif
  7. #include <stddef.h>
  8. #include <stdint.h>
  9. #include <assert.h>
  10. #include "nvim/viml/parser/expressions.h"
  11. #include "nvim/viml/parser/parser.h"
  12. #include "nvim/mbyte.h"
  13. #include "nvim/memory.c"
  14. #include "nvim/mbyte.c"
  15. #include "nvim/charset.c"
  16. #include "nvim/garray.c"
  17. #include "nvim/gettext.c"
  18. #include "nvim/keycodes.c"
  19. #include "nvim/viml/parser/expressions.c"
  20. #define INPUT_SIZE 7
  21. uint8_t avoid_optimizing_out;
  22. void simple_get_line(void *cookie, ParserLine *ret_pline)
  23. {
  24. ParserLine **plines_p = (ParserLine **)cookie;
  25. *ret_pline = **plines_p;
  26. (*plines_p)++;
  27. }
  28. int main(const int argc, const char *const *const argv,
  29. const char *const *const environ)
  30. {
  31. char input[INPUT_SIZE];
  32. uint8_t shift;
  33. int flags;
  34. avoid_optimizing_out = argc;
  35. #ifndef USE_KLEE
  36. sscanf(argv[2], "%d", &flags);
  37. #endif
  38. #ifdef USE_KLEE
  39. klee_make_symbolic(input, sizeof(input), "input");
  40. klee_make_symbolic(&shift, sizeof(shift), "shift");
  41. klee_make_symbolic(&flags, sizeof(flags), "flags");
  42. klee_assume(shift < INPUT_SIZE);
  43. klee_assume(flags <= (kELFlagPeek|kELFlagAllowFloat|kELFlagForbidEOC
  44. |kELFlagForbidScope|kELFlagIsNotCmp));
  45. #endif
  46. ParserLine plines[] = {
  47. {
  48. #ifdef USE_KLEE
  49. .data = &input[shift],
  50. .size = sizeof(input) - shift,
  51. #else
  52. .data = (const char *)argv[1],
  53. .size = strlen(argv[1]),
  54. #endif
  55. .allocated = false,
  56. },
  57. {
  58. .data = NULL,
  59. .size = 0,
  60. .allocated = false,
  61. },
  62. };
  63. #ifdef USE_KLEE
  64. assert(plines[0].size <= INPUT_SIZE);
  65. assert((plines[0].data[0] != 5) | (plines[0].data[0] != argc));
  66. #endif
  67. ParserLine *cur_pline = &plines[0];
  68. ParserState pstate = {
  69. .reader = {
  70. .get_line = simple_get_line,
  71. .cookie = &cur_pline,
  72. .lines = KV_INITIAL_VALUE,
  73. .conv.vc_type = CONV_NONE,
  74. },
  75. .pos = { 0, 0 },
  76. .colors = NULL,
  77. .can_continuate = false,
  78. };
  79. kvi_init(pstate.reader.lines);
  80. allocated_memory_limit = 0;
  81. LexExprToken token = viml_pexpr_next_token(&pstate, flags);
  82. if (flags & kELFlagPeek) {
  83. assert(pstate.pos.line == 0 && pstate.pos.col == 0);
  84. } else {
  85. assert((pstate.pos.line == 0)
  86. ? (pstate.pos.col > 0)
  87. : (pstate.pos.line == 1 && pstate.pos.col == 0));
  88. }
  89. assert(allocated_memory == 0);
  90. assert(ever_allocated_memory == 0);
  91. #ifndef USE_KLEE
  92. fprintf(stderr, "tkn: %s\n", viml_pexpr_repr_token(&pstate, token, NULL));
  93. #endif
  94. }