]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Merge branch 'master' of github.com:graphitemaster/gmqcc
authorDale Weiler <killfieldengine@gmail.com>
Sun, 23 Dec 2012 06:06:57 +0000 (06:06 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 23 Dec 2012 06:06:57 +0000 (06:06 +0000)
1  2 
Makefile
exec.c
lexer.c
main.c
opts.c

diff --combined Makefile
index 94b25e377ad4afdca79c5cfab92c249fe107aa68,020d40b54c6438cd58ed6b4f7859bb019a18b446..b6ea92b7338508acbcdc37873f65f3b222f5ab7e
+++ b/Makefile
@@@ -27,10 -27,10 +27,10 @@@ ifeq ($(track), no
      CFLAGS += -DNOTRACK
  endif
  
 -OBJ_D = util.o code.o ast.o ir.o conout.o ftepp.o opts.o
 -OBJ_T = test.o util.o conout.o
 -OBJ_C = main.o lexer.o parser.o
 -OBJ_X = exec-standalone.o util.o conout.o
 +OBJ_D = util.o code.o ast.o ir.o conout.o ftepp.o opts.o file.o
 +OBJ_T = test.o util.o conout.o file.o
 +OBJ_C = main.o lexer.o parser.o file.o
 +OBJ_X = exec-standalone.o util.o conout.o file.o
  
  ifneq ("$(CYGWIN)", "")
        #nullify the common variables that
@@@ -89,6 -89,7 +89,7 @@@ clean
  $(OBJ_D) $(OBJ_C) $(OBJ_X): gmqcc.h opts.def
  main.o:   lexer.h
  parser.o: ast.h lexer.h
+ lexer.o:  lexer.h
  ast.o:    ast.h ir.h
  ir.o:     ir.h
  
diff --combined exec.c
index 0b9b3621f308536e4e9b58e1e48098577f943c67,6a94941b4194bbdceac4fe0e2e8192f3fea19508..c1aa695f23c43f67813f69e775d51e9e69a14e6a
--- 1/exec.c
--- 2/exec.c
+++ b/exec.c
@@@ -53,28 -53,29 +53,28 @@@ static void qcvmerror(qc_program *prog
  
  qc_program* prog_load(const char *filename)
  {
 -    qc_program *prog;
 -    prog_header header;
 -    FILE *file;
 +    qc_program   *prog;
 +    prog_header   header;
 +    FILE         *file   = file_open(filename, "rb");
  
 -    file = util_fopen(filename, "rb");
      if (!file)
          return NULL;
  
 -    if (fread(&header, sizeof(header), 1, file) != 1) {
 +    if (file_read(&header, sizeof(header), 1, file) != 1) {
          loaderror("failed to read header from '%s'", filename);
 -        fclose(file);
 +        file_close(file);
          return NULL;
      }
  
      if (header.version != 6) {
          loaderror("header says this is a version %i progs, we need version 6\n", header.version);
 -        fclose(file);
 +        file_close(file);
          return NULL;
      }
  
      prog = (qc_program*)mem_a(sizeof(qc_program));
      if (!prog) {
 -        fclose(file);
 +        file_close(file);
          printf("failed to allocate program data\n");
          return NULL;
      }
      }
  
  #define read_data(hdrvar, progvar, reserved)                           \
 -    if (fseek(file, header.hdrvar.offset, SEEK_SET) != 0) {            \
 +    if (file_seek(file, header.hdrvar.offset, SEEK_SET) != 0) {        \
          loaderror("seek failed");                                      \
          goto error;                                                    \
      }                                                                  \
 -    if (fread(vec_add(prog->progvar, header.hdrvar.length + reserved), \
 -              sizeof(*prog->progvar),                                  \
 -              header.hdrvar.length, file)                              \
 -        != header.hdrvar.length)                                       \
 -    {                                                                  \
 +    if (file_read (                                                    \
 +            vec_add(prog->progvar, header.hdrvar.length + reserved),   \
 +            sizeof(*prog->progvar),                                    \
 +            header.hdrvar.length,                                      \
 +            file                                                       \
 +        )!= header.hdrvar.length                                       \
 +    ) {                                                                \
          loaderror("read failed");                                      \
          goto error;                                                    \
      }
      read_data1(strings);
      read_data2(globals, 2); /* reserve more in case a RETURN using with the global at "the end" exists */
  
 -    fclose(file);
 +    file_close(file);
  
      /* profile counters */
      memset(vec_add(prog->profile, vec_size(prog->code)), 0, sizeof(prog->profile[0]) * vec_size(prog->code));
@@@ -977,6 -976,17 +977,17 @@@ int main(int argc, char **argv
          printf("Program's system-checksum = 0x%04x\n", (unsigned int)prog->crc16);
          printf("Entity field space: %u\n", (unsigned int)prog->entityfields);
          printf("Globals: %u\n", (unsigned int)vec_size(prog->globals));
+         printf("Counts:\n"
+                "      code: %lu\n"
+                "      defs: %lu\n"
+                "    fields: %lu\n"
+                " functions: %lu\n"
+                "   strings: %lu\n",
+                (unsigned long)vec_size(prog->code),
+                (unsigned long)vec_size(prog->defs),
+                (unsigned long)vec_size(prog->fields),
+                (unsigned long)vec_size(prog->functions),
+                (unsigned long)vec_size(prog->strings));
      }
  
      if (opts_info) {
diff --combined lexer.c
index cf554fb2d41fb2512766f647a2c9810f76373f67,01842cc0f5df9dc3b9ca0e912d8c87acb57c7fe5..e506aec31ef8c105f7c3ef5de7a74eefd560d809
+++ b/lexer.c
@@@ -50,8 -50,6 +50,6 @@@ static const char *keywords_fg[] = 
      "typedef",
      "goto",
  
-     "noreturn",
      "__builtin_debug_printtype"
  };
  static size_t num_keywords_fg = sizeof(keywords_fg) / sizeof(keywords_fg[0]);
@@@ -186,7 -184,7 +184,7 @@@ static void lex_token_new(lex_file *lex
  lex_file* lex_open(const char *file)
  {
      lex_file *lex;
 -    FILE *in = util_fopen(file, "rb");
 +    FILE *in = file_open(file, "rb");
  
      if (!in) {
          lexerror(NULL, "open failed: '%s'\n", file);
  
      lex = (lex_file*)mem_a(sizeof(*lex));
      if (!lex) {
 -        fclose(in);
 +        file_close(in);
          lexerror(NULL, "out of memory\n");
          return NULL;
      }
@@@ -260,7 -258,7 +258,7 @@@ void lex_close(lex_file *lex
          vec_free(lex->modelname);
  
      if (lex->file)
 -        fclose(lex->file);
 +        file_close(lex->file);
  #if 0
      if (lex->tok)
          token_delete(lex->tok);
@@@ -1117,6 -1115,15 +1115,15 @@@ int lex_do(lex_file *lex
      switch (ch)
      {
          case '[':
+             nextch = lex_getch(lex);
+             if (nextch == '[') {
+                 lex_tokench(lex, ch);
+                 lex_tokench(lex, nextch);
+                 lex_endtoken(lex);
+                 return (lex->tok.ttype = TOKEN_ATTRIBUTE_OPEN);
+             }
+             lex_ungetch(lex, nextch);
+             /* FALL THROUGH */
          case '(':
          case ':':
          case '?':
                  return (lex->tok.ttype = ch);
              else
                  return (lex->tok.ttype = TOKEN_OPERATOR);
+         case ']':
+             if (lex->flags.noops) {
+                 nextch = lex_getch(lex);
+                 if (nextch == ']') {
+                     lex_tokench(lex, ch);
+                     lex_tokench(lex, nextch);
+                     lex_endtoken(lex);
+                     return (lex->tok.ttype = TOKEN_ATTRIBUTE_CLOSE);
+                 }
+                 lex_ungetch(lex, nextch);
+             }
+             /* FALL THROUGH */
          case ')':
          case ';':
          case '{':
          case '}':
-         case ']':
  
          case '#':
              lex_tokench(lex, ch);
diff --combined main.c
index d732ef9bd0d1c8175cd750ac0ca10a7839a6b622,558edc339ef25b52393176f8fa780592b503482a..107098a6e582acf312b9663b2511ec651c2500aa
--- 1/main.c
--- 2/main.c
+++ b/main.c
@@@ -139,8 -139,8 +139,8 @@@ static bool options_parse(int argc, cha
      bool argend = false;
      size_t itr;
      char  buffer[1024];
 -    char *redirout = (char*)stdout;
 -    char *redirerr = (char*)stderr;
 +    char *redirout = NULL;
 +    char *redirerr = NULL;
      char *config   = NULL;
  
      while (!argend && argc > 1) {
@@@ -474,7 -474,7 +474,7 @@@ static bool progs_nextline(char **out, 
      char  *end;
  
      line = *out;
 -    len = util_getline(&line, alen, src);
 +    len  = file_getline(&line, alen, src);
      if (len == -1)
          return false;
  
@@@ -508,6 -508,11 +508,11 @@@ int main(int argc, char **argv) 
          return usage();
      }
  
+     if (OPTS_FLAG(TRUE_EMPTY_STRINGS) && OPTS_FLAG(FALSE_EMPTY_STRINGS)) {
+         con_err("-ftrue-empty-strings and -ffalse-empty-strings are mutually exclusive");
+         exit(1);
+     }
      /* the standard decides which set of operators to use */
      if (opts.standard == COMPILER_GMQCC) {
          operators      = c_operators;
  
      if (opts.pp_only) {
          if (opts_output_wasset) {
 -            outfile = util_fopen(opts.output, "wb");
 +            outfile = file_open(opts.output, "wb");
              if (!outfile) {
                  con_err("failed to open `%s` for writing\n", opts.output);
                  retval = 1;
                  goto cleanup;
              }
          }
 -        else
 -            outfile = stdout;
 +        else {
 +         /* TODO: stdout without stdout .. */
 +        }
      }
  
      if (!opts.pp_only) {
  
          progs_src = true;
  
 -        src = util_fopen("progs.src", "rb");
 +        src = file_open("progs.src", "rb");
          if (!src) {
              con_err("failed to open `progs.src` for reading\n");
              retval = 1;
          }
  
  srcdone:
 -        fclose(src);
 +        file_close(src);
          mem_d(line);
      }
  
                  }
                  out = ftepp_get();
                  if (out)
 -                    fprintf(outfile, "%s", out);
 +                    file_printf(outfile, "%s", out);
                  ftepp_flush();
              }
              else {
diff --combined opts.c
index 69e93b428fdcdb84689a3c3ddb3a817c2589b75c,43c4563454866d574f58bf2b9b35cd743ed73f0b..5c48286d2d9a7557fc7528efdacf678ffa082a1a
--- 1/opts.c
--- 2/opts.c
+++ b/opts.c
@@@ -53,6 -53,7 +53,7 @@@ static void opts_setdefault() 
      opts_set(opts.warn,  WARN_UNKNOWN_PRAGMAS,           true);
      opts_set(opts.warn,  WARN_UNREACHABLE_CODE,          true);
      opts_set(opts.warn,  WARN_CPP,                       true);
+     opts_set(opts.warn,  WARN_UNKNOWN_ATTRIBUTE,         true);
      /* flags */
      opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
      opts_set(opts.flags, FTEPP,                          false);
@@@ -169,7 -170,7 +170,7 @@@ static size_t opts_ini_parse 
      char *read_name;
      char *read_value;
  
 -    while (util_getline(&line, &linesize, filehandle) != EOF) {
 +    while (file_getline(&line, &linesize, filehandle) != EOF) {
          parse_beg = line;
  
          /* handle BOM */
@@@ -315,11 -316,11 +316,11 @@@ void opts_ini_init(const char *file) 
      
      if (!file) {
          /* try ini */
 -        if (!(ini = fopen((file = "gmqcc.ini"), "r")))
 +        if (!(ini = file_open((file = "gmqcc.ini"), "r")))
              /* try cfg */
 -            if (!(ini = fopen((file = "gmqcc.cfg"), "r")))
 +            if (!(ini = file_open((file = "gmqcc.cfg"), "r")))
                  return;
 -    } else if (!(ini = fopen(file, "r")))
 +    } else if (!(ini = file_open(file, "r")))
          return;
  
      con_out("found ini file `%s`\n", file);
          vec_free(error);
      }
  
 -    fclose(ini);
 +    file_close(ini);
  }