commit some files I forgot
authorMatthias Braun <matze@braunis.de>
Wed, 20 Feb 2008 15:03:07 +0000 (15:03 +0000)
committerMatthias Braun <matze@braunis.de>
Wed, 20 Feb 2008 15:03:07 +0000 (15:03 +0000)
[r18902]

ast.c
diagnostic.c
parser.c
parsetest/shouldfail/segfault1.c [new file with mode: 0644]
parsetest/shouldfail/segfault2.c [new file with mode: 0644]
parsetest/shouldfail/segfault3.c [new file with mode: 0644]
symbol_t.h [new file with mode: 0644]
symbol_table.c
token.c
tokens_punctuator.inc [new file with mode: 0644]

diff --git a/ast.c b/ast.c
index 4bc91a1..d2de04e 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -1520,8 +1520,10 @@ bool is_constant_expression(const expression_t *expression)
                return false;
        }
 
-       case EXPR_UNKNOWN:
        case EXPR_INVALID:
+               return true;
+
+       case EXPR_UNKNOWN:
                break;
        }
        panic("invalid expression found (is constant expression)");
index 02008d9..bbefc77 100644 (file)
@@ -87,6 +87,7 @@ static void diagnosticvf(const char *const fmt, va_list ap)
                                        break;
                                }
 
+#ifndef PPTEST
                                case 'E': {
                                        const expression_t* const expr = va_arg(ap, const expression_t*);
                                        print_expression(expr);
@@ -108,6 +109,7 @@ static void diagnosticvf(const char *const fmt, va_list ap)
                                        print_type_ext(type, sym, NULL);
                                        break;
                                }
+#endif
 
                                case 'K': {
                                        const token_t* const token = va_arg(ap, const token_t*);
index 26c5692..3323840 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -478,6 +478,10 @@ static void eat_paren(void)
                if(token.type == ')' || token.type == ';' || token.type == '}') {
                        return;
                }
+               if(token.type == ')') {
+                       next_token();
+                       return;
+               }
                if(token.type == '(') {
                        eat_paren();
                        continue;
@@ -488,7 +492,6 @@ static void eat_paren(void)
                }
                next_token();
        }
-       eat(')');
 }
 
 #define expect(expected)                           \
diff --git a/parsetest/shouldfail/segfault1.c b/parsetest/shouldfail/segfault1.c
new file mode 100644 (file)
index 0000000..39748b1
--- /dev/null
@@ -0,0 +1,4 @@
+#include <stdio.h>
+int main(int argc, char** argv) {
+       printf("chk",%s);
+       return 0;;}
diff --git a/parsetest/shouldfail/segfault2.c b/parsetest/shouldfail/segfault2.c
new file mode 100644 (file)
index 0000000..36bcabc
--- /dev/null
@@ -0,0 +1,54 @@
+                                          double L ,o ,P
+                                         ,_=dt,T,Z,D=1,d,
+                                         s[999],E,h= 8,I,
+                                         J,K,w[999],M,m,O
+                                        ,n[999],j=33e-3,i=
+                                        1E3,r,t, u,v ,W,S=
+                                        74.5,l=221,X=7.26,
+                                        a,B,A=32.2,c, F,H;
+                                        int N,q, C, y,p,U;
+                                       Window z; char f[52]
+                                    ; GC k; main(){ Display*e=
+ XOpenDisplay( 0); z=RootWindow(e,0); for (XSetForeground(e,k=XCreateGC (e,z,0,0),BlackPixel(e,0))
+; scanf("%lf%lf%lf",y +n,w+y, y+s)+1; y ++); XSelectInput(e,z= XCreateSimpleWindow(e,z,0,0,400,400,
+0,0,WhitePixel(e,0) ),KeyPressMask); for(XMapWindow(e,z); ; T=sin(O)){ struct timeval G={ 0,dt*1e6}
+; K= cos(j); N=1e4; M+= H*_; Z=D*K; F+=_*P; r=E*K; W=cos( O); m=K*W; H=K*T; O+=D*_*F/ K+d/K*E*_; B=
+sin(j); a=B*T*D-E*W; XClearWindow(e,z); t=T*E+ D*B*W; j+=d*_*D-_*F*E; P=W*E*B-T*D; for (o+=(I=D*W+E
+*T*B,E*d/K *B+v+B/K*F*D)*_; p<y; ){ T=p[s]+i; E=c-p[w]; D=n[p]-L; K=D*m-B*T-H*E; if(p [n]+w[ p]+p[s
+]== 0|K <fabs(W=T*r-I*E +D*P) |fabs(D=t *D+Z *T-a *E)> K)N=1e4; else{ q=W/K *4E2+2e2; C= 2E2+4e2/ K
+ *D; N-1E4&& XDrawLine(e ,z,k,N ,U,q,C); N=q; U=C; } ++p; } L+=_* (X*t +P*M+m*l); T=X*X+ l*l+M *M;
+  XDrawString(e,z,k ,20,380,f,17); D=v/l*15; i+=(B *l-M*r -X*Z)*_; for(; XPending(e); u *=CS!=N){
+                                   XEvent z; XNextEvent(e ,&z);
+                                       ++*((N=XLookupKeysym
+                                         (&z.xkey,0))-IT?
+                                         N-LT? UP-N?& E:&
+                                         J:& u: &h); --*(
+                                         DN -N? N-DT ?N==
+                                         RT?&u: & W:&h:&J
+                                          ); } m=15*F/l;
+                                          c+=(I=M/ l,l*H
+                                          +I*M+a*X)*_; H
+                                          =A*r+v*X-F*l+(
+                                          E=.1+X*4.9/l,t
+                                          =T*m/32-I*T/24
+                                           )/S; K=F*M+(
+                                           h* 1e4/l-(T+
+                                           E*5*T*E)/3e2
+                                           )/S-X*d-B*A;
+                                           a=2.63 /l*d;
+                                           X+=( d*l-T/S
+                                            *(.19*E +a
+                                            *.64+J/1e3
+                                            )-M* v +A*
+                                            Z)*_; l +=
+                                            K *_; W=d;
+                                            sprintf(f,
+                                            "%5d  %3d"
+                                            "%7d",p =l
+                                           /1.7,(C=9E3+
+                              O*57.3)%0550,(int)i); d+=T*(.45-14/l*
+                             X-a*130-J* .14)*_/125e2+F*_*v; P=(T*(47
+                             *I-m* 52+E*94 *D-t*.38+u*.21*E) /1e2+W*
+                             179*v)/2312; select(p=0,0,0,0,&G); v-=(
+                              W*F-T*(.63*m-I*.086+m*E*19-D*25-.11*u
+                               )/107e2)*_; D=cos(o); E=sin(o); } }
diff --git a/parsetest/shouldfail/segfault3.c b/parsetest/shouldfail/segfault3.c
new file mode 100644 (file)
index 0000000..93bbbb6
--- /dev/null
@@ -0,0 +1,3 @@
+struct K { };
+
+struct K bla = { 1, 2 };
diff --git a/symbol_t.h b/symbol_t.h
new file mode 100644 (file)
index 0000000..44b9900
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * This file is part of cparser.
+ * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+#ifndef SYMBOL_T_H
+#define SYMBOL_T_H
+
+#include <stdbool.h>
+#include "ast.h"
+#include "token_t.h"
+
+struct pp_definition {
+       source_position_t  source_position;
+       bool               expanding;
+       token_t            replacement_list[];
+};
+
+struct symbol_t {
+       const char     *string;
+       unsigned short  ID;
+       unsigned short  pp_ID;
+       declaration_t  *declaration;
+       pp_definition  *pp_define;
+};
+
+#endif
index 51f37d9..cef0421 100644 (file)
@@ -32,7 +32,7 @@ void init_symbol_table_entry(symbol_t *entry, const char *string)
 {
        entry->string      = string;
        entry->ID          = T_IDENTIFIER;
-       entry->pp_ID       = 0;
+       entry->pp_ID       = TP_IDENTIFIER;
        entry->declaration = NULL;
 }
 
diff --git a/token.c b/token.c
index 5c5df4c..52ff730 100644 (file)
--- a/token.c
+++ b/token.c
@@ -170,7 +170,7 @@ void print_pp_token(FILE *f, const token_t *token)
                fprintf(f, "symbol '%s'", token->v.symbol->string);
                break;
        case TP_NUMBER:
-               fprintf(f, "number %lld", token->v.intvalue);
+               fprintf(f, "number %s", token->v.string.begin);
                break;
        case TP_STRING_LITERAL:
                fprintf(f, "string '%s'", token->v.string.begin);
diff --git a/tokens_punctuator.inc b/tokens_punctuator.inc
new file mode 100644 (file)
index 0000000..4894426
--- /dev/null
@@ -0,0 +1,56 @@
+/*PUNCTUATOR(LESSCOLON,                "<:",   = '[')
+PUNCTUATOR(COLONGREATER,             ":>",   = ']')
+PUNCTUATOR(LESSPERCENT,              "<%",   = '{')
+PUNCTUATOR(PERCENTGREATER,           "%>",   = '}')
+PUNCTUATOR(PERCENTCOLON,             "%:",   = '#')
+PUNCTUATOR(PERCENTCOLONPERCENTCOLON, "%:%:", = T_HASHHASH)*/
+
+PUNCTUATOR(RBRACK,          "[", = '[')
+PUNCTUATOR(LBRACK,          "]", = ']')
+PUNCTUATOR(LBRACE,          "(", = '(')
+PUNCTUATOR(RBRACE,          ")", = ')')
+PUNCTUATOR(RCURLY,          "{", = '{')
+PUNCTUATOR(LCURLY,          "}", = '}')
+PUNCTUATOR(DOT,             ".", = '.')
+PUNCTUATOR(AND,             "&", = '&')
+PUNCTUATOR(ASTERISK,        "*", = '*')
+PUNCTUATOR(PLUS,            "+", = '+')
+PUNCTUATOR(MINUS,           "-", = '-')
+PUNCTUATOR(TILDE,           "~", = '~')
+PUNCTUATOR(EXCLAMATIONMARK, "!", = '!')
+PUNCTUATOR(SLASH,           "/", = '/')
+PUNCTUATOR(PERCENT,         "%", = '%')
+PUNCTUATOR(LESS,            "<", = '<')
+PUNCTUATOR(GREATER,         ">", = '>')
+PUNCTUATOR(CARET,           "^", = '^')
+PUNCTUATOR(PIPE,            "|", = '|')
+PUNCTUATOR(QUESTIONMARK,    "?", = '?')
+PUNCTUATOR(COLON,           ":", = ':')
+PUNCTUATOR(SEMICOLON,       ";", = ';')
+PUNCTUATOR(EQUAL,           "=", = '=')
+PUNCTUATOR(COMMA,           ",", = ',')
+PUNCTUATOR(HASH,            "#", = '#')
+
+PUNCTUATOR(MINUSGREATER,             "->", = 265)
+PUNCTUATOR(PLUSPLUS,                 "++",)
+PUNCTUATOR(MINUSMINUS,               "--",)
+PUNCTUATOR(LESSLESS,                 "<<",)
+PUNCTUATOR(GREATERGREATER,           ">>",)
+PUNCTUATOR(LESSEQUAL,                "<=",)
+PUNCTUATOR(GREATEREQUAL,             ">=",)
+PUNCTUATOR(EQUALEQUAL,               "==",)
+PUNCTUATOR(EXCLAMATIONMARKEQUAL,     "!=",)
+PUNCTUATOR(ANDAND,                   "&&",)
+PUNCTUATOR(PIPEPIPE,                 "||",)
+PUNCTUATOR(DOTDOTDOT,                "...",)
+PUNCTUATOR(ASTERISKEQUAL,            "*=",)
+PUNCTUATOR(SLASHEQUAL,               "/=",)
+PUNCTUATOR(PERCENTEQUAL,             "%=",)
+PUNCTUATOR(PLUSEQUAL,                "+=",)
+PUNCTUATOR(MINUSEQUAL,               "-=",)
+PUNCTUATOR(LESSLESSEQUAL,            "<<=",)
+PUNCTUATOR(GREATERGREATEREQUAL,      ">>=",)
+PUNCTUATOR(ANDEQUAL,                 "&=",)
+PUNCTUATOR(CARETEQUAL,               "^=",)
+PUNCTUATOR(PIPEEQUAL,                "|=",)
+PUNCTUATOR(HASHHASH,                 "##",)