struct lex_file -> lex_file

This commit is contained in:
Dale Weiler 2012-04-28 05:25:19 -04:00
parent 89ed723efa
commit 33b1995fa5
6 changed files with 34 additions and 34 deletions

View file

@ -57,7 +57,7 @@ static const char *const error_list[] = {
"Preprocessor Error:"
};
int error(struct lex_file *file, int status, const char *msg, ...) {
int error(lex_file *file, int status, const char *msg, ...) {
char bu[1024*4]; /* enough? */
char fu[1024*4]; /* enough? */
va_list va;

20
gmqcc.h
View file

@ -113,7 +113,7 @@ typedef char intptr_size_is_correct [sizeof(uintptr_t)== sizeof(int*)?1:-1];
//===================================================================
//============================ lex.c ================================
//===================================================================
struct lex_file {
typedef struct lex_file_t {
FILE *file; /* file handler */
char *name; /* name of file */
char peek [5];
@ -124,7 +124,7 @@ struct lex_file {
int length; /* bytes left to parse */
int size; /* never changes (size of file) */
int line; /* what line are we on? */
};
} lex_file;
/*
* It's important that this table never exceed 32 keywords, the ascii
@ -164,11 +164,11 @@ enum {
LEX_IDENT
};
int lex_token (struct lex_file *);
void lex_reset (struct lex_file *);
void lex_close (struct lex_file *);
struct lex_file *lex_include(struct lex_file *, char *);
struct lex_file *lex_open (FILE *);
int lex_token (lex_file *);
void lex_reset (lex_file *);
void lex_close (lex_file *);
lex_file *lex_include(lex_file *, char *);
lex_file *lex_open (FILE *);
//===================================================================
//========================== error.c ================================
@ -178,12 +178,12 @@ struct lex_file *lex_open (FILE *);
#define ERROR_INTERNAL (SHRT_MAX+2)
#define ERROR_COMPILER (SHRT_MAX+3)
#define ERROR_PREPRO (SHRT_MAX+4)
int error(struct lex_file *, int, const char *, ...);
int error(lex_file *, int, const char *, ...);
//===================================================================
//========================== parse.c ================================
//===================================================================
int parse_gen(struct lex_file *);
int parse_gen(lex_file *);
//===================================================================
//========================== typedef.c ==============================
@ -195,7 +195,7 @@ typedef struct typedef_node_t {
void typedef_init();
void typedef_clear();
typedef_node *typedef_find(const char *);
int typedef_add (struct lex_file *file, const char *, const char *);
int typedef_add (lex_file *file, const char *, const char *);
//===================================================================

36
lex.c
View file

@ -32,8 +32,8 @@ static const char *const lex_keywords[] = {
"for", "typedef"
};
struct lex_file *lex_open(FILE *fp) {
struct lex_file *lex = mem_a(sizeof(struct lex_file));
lex_file *lex_open(FILE *fp) {
lex_file *lex = mem_a(sizeof(lex_file));
if (!lex || !fp)
return NULL;
@ -49,20 +49,20 @@ struct lex_file *lex_open(FILE *fp) {
return lex;
}
void lex_close(struct lex_file *file) {
void lex_close(lex_file *file) {
if (!file) return;
fclose(file->file); /* may already be closed */
mem_d (file);
}
static void lex_addch(int ch, struct lex_file *file) {
static void lex_addch(int ch, lex_file *file) {
if (file->current < sizeof(file->lastok)-1)
file->lastok[file->current++] = (char)ch;
if (file->current == sizeof(file->lastok)-1)
file->lastok[file->current] = (char)'\0';
}
static inline void lex_clear(struct lex_file *file) {
static inline void lex_clear(lex_file *file) {
file->current = 0;
}
@ -71,13 +71,13 @@ static inline void lex_clear(struct lex_file *file) {
* This doesn't play with file streams, the lexer has
* it's own internal state for this.
*/
static int lex_inget(struct lex_file *file) {
static int lex_inget(lex_file *file) {
file->length --;
if (file->last > 0)
return file->peek[--file->last];
return fgetc(file->file);
}
static void lex_unget(int ch, struct lex_file *file) {
static void lex_unget(int ch, lex_file *file) {
if (file->last < sizeof(file->peek))
file->peek[file->last++] = ch;
file->length ++;
@ -87,7 +87,7 @@ static void lex_unget(int ch, struct lex_file *file) {
* This is trigraph and digraph support, a feature not qc compiler
* supports. Moving up in this world!
*/
static int lex_trigraph(struct lex_file *file) {
static int lex_trigraph(lex_file *file) {
int ch;
if ((ch = lex_inget(file)) != '?') {
lex_unget(ch, file);
@ -112,7 +112,7 @@ static int lex_trigraph(struct lex_file *file) {
}
return '?';
}
static int lex_digraph(struct lex_file *file, int first) {
static int lex_digraph(lex_file *file, int first) {
int ch = lex_inget(file);
switch (first) {
case '<':
@ -132,7 +132,7 @@ static int lex_digraph(struct lex_file *file, int first) {
return first;
}
static int lex_getch(struct lex_file *file) {
static int lex_getch(lex_file *file) {
int ch = lex_inget(file);
static int str = 0;
@ -153,7 +153,7 @@ static int lex_getch(struct lex_file *file) {
return ch;
}
static int lex_get(struct lex_file *file) {
static int lex_get(lex_file *file) {
int ch;
if (!isspace(ch = lex_getch(file)))
return ch;
@ -168,7 +168,7 @@ static int lex_get(struct lex_file *file) {
return ' ';
}
static int lex_skipchr(struct lex_file *file) {
static int lex_skipchr(lex_file *file) {
int ch;
int it;
@ -192,7 +192,7 @@ static int lex_skipchr(struct lex_file *file) {
return LEX_CHRLIT;
}
static int lex_skipstr(struct lex_file *file) {
static int lex_skipstr(lex_file *file) {
int ch;
lex_clear(file);
lex_addch('"', file);
@ -211,7 +211,7 @@ static int lex_skipstr(struct lex_file *file) {
return LEX_STRLIT;
}
static int lex_skipcmt(struct lex_file *file) {
static int lex_skipcmt(lex_file *file) {
int ch;
lex_clear(file);
ch = lex_getch(file);
@ -257,7 +257,7 @@ static int lex_skipcmt(struct lex_file *file) {
return LEX_COMMENT;
}
static int lex_getsource(struct lex_file *file) {
static int lex_getsource(lex_file *file) {
int ch = lex_get(file);
/* skip char/string/comment */
@ -270,7 +270,7 @@ static int lex_getsource(struct lex_file *file) {
}
}
int lex_token(struct lex_file *file) {
int lex_token(lex_file *file) {
int ch = lex_getsource(file);
int it;
@ -323,7 +323,7 @@ int lex_token(struct lex_file *file) {
return ch;
}
void lex_reset(struct lex_file *file) {
void lex_reset(lex_file *file) {
file->current = 0;
file->last = 0;
file->length = file->size;
@ -338,7 +338,7 @@ void lex_reset(struct lex_file *file) {
* should check if names are the same to prevent endless include
* recrusion.
*/
struct lex_file *lex_include(struct lex_file *lex, char *file) {
lex_file *lex_include(lex_file *lex, char *file) {
util_strrq(file);
if (strncmp(lex->name, file, strlen(lex->name)) == 0) {
error(lex, ERROR_LEX, "Source file cannot include itself\n");

2
main.c
View file

@ -138,7 +138,7 @@ int main(int argc, char **argv) {
switch (items_data[itr].type) {
case 0:
fpp = fopen(items_data[itr].name, "r");
struct lex_file *lex = lex_open(fpp);
lex_file *lex = lex_open(fpp);
parse_gen(lex);
lex_close(lex);
break;

View file

@ -48,7 +48,7 @@ void compile_constant_debug() {
* Generates a parse tree out of the lexees generated by the lexer. This
* is where the tree is built. This is where valid check is performed.
*/
int parse_gen(struct lex_file *file) {
int parse_gen(lex_file *file) {
int token = 0;
while ((token = lex_token(file)) != ERROR_LEX && file->length >= 0) {
switch (token) {
@ -262,8 +262,8 @@ int parse_gen(struct lex_file *file) {
if (token == '\n')
return error(file, ERROR_PARSE, "Invalid use of include preprocessor directive: wanted #include \"file.h\"\n");
char *copy = util_strdup(file->lastok);
struct lex_file *next = lex_include(file, copy);
char *copy = util_strdup(file->lastok);
lex_file *next = lex_include(file, copy);
if (!next) {
error(file, ERROR_INTERNAL, "Include subsystem failure\n");

View file

@ -49,7 +49,7 @@ void typedef_clear() {
}
}
int typedef_add(struct lex_file *file, const char *from, const char *to) {
int typedef_add(lex_file *file, const char *from, const char *to) {
unsigned int hash = typedef_hash(to);
typedef_node *find = typedef_table[hash];