Skip to content

Commit

Permalink
Merge pull request #65 from GTkorvo/TypeID
Browse files Browse the repository at this point in the history
Change type_id name to avoid problems with OSX14
  • Loading branch information
eisenhauer authored Sep 19, 2023
2 parents 2f3fe98 + cadab42 commit 67e411c
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 121 deletions.
2 changes: 1 addition & 1 deletion cod/cod.l
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ return {RETURN(RETURN_TOKEN);}
[A-Za-z_][A-Za-z0-9_]* {
yylval.info.string = create_string_from_yytext();
if (is_defined_type(yylval.info.string)) {
RETURN(type_id);
RETURN(type_identifier);
} else if (is_enumeration_constant(yylval.info.string)) {
RETURN(enumeration_constant);
} else {
Expand Down
4 changes: 2 additions & 2 deletions cod/cod.y
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ cod_dup_list(sm_list list)
%token <info> string_constant
%token <info> floating_constant
%token <info> identifier_ref
%token <info> type_id
%token <info> type_identifier
%token <info> enumeration_constant

%type <info> struct_or_union;
Expand Down Expand Up @@ -1039,7 +1039,7 @@ type_specifier:
$$->node.type_specifier.lx_srcpos = $1.lx_srcpos;
$$->node.type_specifier.token = STRING;
}
| type_id {
| type_identifier {
$$ = cod_new_identifier();
$$->node.identifier.lx_srcpos = $1.lx_srcpos;
$$->node.identifier.id = $1.string;
Expand Down
82 changes: 6 additions & 76 deletions cod/pregen_source/Linux/cod.l
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ extern int my_yy_input();
#endif
static
int
is_defined_type(id)
char *id;
is_defined_type(char *id)
{
int i = 0;
while(types && types[i]) {
Expand All @@ -83,8 +82,7 @@ char *id;
}
static
int
is_enumeration_constant(id)
char *id;
is_enumeration_constant(char *id)
{
int i = 0;
while(enums && enums[i]) {
Expand Down Expand Up @@ -185,7 +183,7 @@ return {RETURN(RETURN_TOKEN);}
[A-Za-z_][A-Za-z0-9_]* {
yylval.info.string = create_string_from_yytext();
if (is_defined_type(yylval.info.string)) {
RETURN(type_id);
RETURN(type_identifier);
} else if (is_enumeration_constant(yylval.info.string)) {
RETURN(enumeration_constant);
} else {
Expand Down Expand Up @@ -329,7 +327,7 @@ static char *create_string_from_yytext()

static void check_strbuf()
{
int cur_len = string_buf_ptr - string_buffer;
intptr_t cur_len = string_buf_ptr - string_buffer;
if ((cur_len + 1) == buffer_len) {
buffer_len += 20;
string_buffer = realloc(string_buffer, buffer_len + 1);
Expand Down Expand Up @@ -361,87 +359,21 @@ yywrap YY_PROTO(( void ))
}


#ifndef input
/* flex, not lex */
void yy_delete_buffer YY_PROTO((YY_BUFFER_STATE b));

#ifdef WINNT
/* old Windows code for MKS Toolkit version of flex */

static void
terminate_string_parse()
{
yyrestart(NULL);
}

#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
{
return (void *) malloc( size );
}

static char* current_input_string;

int my_yy_input(buf,result,max_size) {

if (current_input_string == NULL)
{

result = 0;
}
else
if (max_size < strlen(current_input_string))
{
memcpy((void*)buf, current_input_string, max_size);
current_input_string += max_size;
result = max_size;
} else {
int n = strlen(current_input_string);
memcpy((void*)buf, current_input_string, n+1);
current_input_string = NULL;
result = n;
}

/* printf("my_yy_input buf[%s],result[%d]\n",buf,result);*/
return result;
}

static void
setup_for_string_parse(string, defined_types, enum_constants)
const char *string;
char **defined_types;
char **enum_constants;
{
type_count = defined_type_count;
types = defined_types;
enums = enum_constants;

current_input_string = string;
lex_offset = 1;
line_count = 1;
}
#else

static YY_BUFFER_STATE bb = NULL;

static void
reset_types_table(defined_types, enumerated_constants)
char **defined_types;
char **enumerated_constants;
reset_types_table(char **defined_types, char **enumerated_constants)
{
types = defined_types;
enums = enumerated_constants;
}

static void
setup_for_string_parse(string, defined_types, enum_constants)
const char *string;
char **defined_types;
char **enum_constants;
setup_for_string_parse(const char *string, char **defined_types, char **enum_constants)
{
types = defined_types;
enums = enum_constants;
Expand All @@ -462,5 +394,3 @@ terminate_string_parse()
}
}

#endif
#endif
6 changes: 3 additions & 3 deletions cod/pregen_source/Linux/cod.tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
string_constant = 335,
floating_constant = 336,
identifier_ref = 337,
type_id = 338,
type_identifier = 338,
enumeration_constant = 339
};
#endif
Expand Down Expand Up @@ -231,7 +231,7 @@
#define string_constant 335
#define floating_constant 336
#define identifier_ref 337
#define type_id 338
#define type_identifier 338
#define enumeration_constant 339


Expand Down Expand Up @@ -891,7 +891,7 @@ static const char *const yytname[] =
"STATIC", "EXTERN_TOKEN", "STRUCT", "ENUM", "UNION", "CONST", "SIZEOF",
"TYPEDEF", "RETURN_TOKEN", "CONTINUE", "BREAK", "GOTO", "PRINT", "COMMA",
"DOTDOTDOT", "integer_constant", "character_constant", "string_constant",
"floating_constant", "identifier_ref", "type_id", "enumeration_constant",
"floating_constant", "identifier_ref", "type_identifier", "enumeration_constant",
"$accept", "start", "primary_expression", "postfix_expression",
"argument_expression_list", "unary_expression", "unary_operator",
"cast_expression", "multiplicative_expression", "additive_expression",
Expand Down
6 changes: 3 additions & 3 deletions cod/pregen_source/Linux/cod.tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
string_constant = 335,
floating_constant = 336,
identifier_ref = 337,
type_id = 338,
type_identifier = 338,
enumeration_constant = 339
};
#endif
Expand Down Expand Up @@ -204,15 +204,15 @@
#define string_constant 335
#define floating_constant 336
#define identifier_ref 337
#define type_id 338
#define type_identifier 338
#define enumeration_constant 339




#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE
#line 187 "cod/cod.y"
#line 201 "cod/cod.y"
{
lx_info info;
sm_ref reference;
Expand Down
4 changes: 2 additions & 2 deletions cod/pregen_source/Linux/cod.y
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ cod_dup_list(sm_list list)
%token <info> string_constant
%token <info> floating_constant
%token <info> identifier_ref
%token <info> type_id
%token <info> type_identifier
%token <info> enumeration_constant

%type <info> struct_or_union;
Expand Down Expand Up @@ -1039,7 +1039,7 @@ type_specifier:
$$->node.type_specifier.lx_srcpos = $1.lx_srcpos;
$$->node.type_specifier.token = STRING;
}
| type_id {
| type_identifier {
$$ = cod_new_identifier();
$$->node.identifier.lx_srcpos = $1.lx_srcpos;
$$->node.identifier.id = $1.string;
Expand Down
Loading

0 comments on commit 67e411c

Please sign in to comment.