From 6743f229982176bfc2bdd2b3ab5c75ca62f45b35 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 1 Feb 2012 16:42:21 -0500 Subject: [PATCH] Revert "Remove leading underscores from identifiers directly in lexer" This reverts commit f071e095a2a8f76dd78becfa103b952af68e148d. The reason why the underscores are needed in the first place is because we want to make sure sequences and variants to not have clash between fields called e.g. "stream" and the dynamic scope "stream.event.header.". Therefore, we need to keep the leading underscores as part of the internal identifier representation. Signed-off-by: Mathieu Desnoyers --- formats/ctf-text/types/array.c | 2 +- formats/ctf-text/types/enum.c | 2 +- formats/ctf-text/types/float.c | 2 +- formats/ctf-text/types/integer.c | 2 +- formats/ctf-text/types/sequence.c | 2 +- formats/ctf-text/types/string.c | 2 +- formats/ctf-text/types/struct.c | 2 +- formats/ctf-text/types/variant.c | 2 +- formats/ctf/metadata/ctf-lexer.l | 11 +---------- include/babeltrace/ctf-text/types.h | 9 +++++++++ 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/formats/ctf-text/types/array.c b/formats/ctf-text/types/array.c index 6dc84480..3aaa6331 100644 --- a/formats/ctf-text/types/array.c +++ b/formats/ctf-text/types/array.c @@ -41,7 +41,7 @@ int ctf_text_array_write(struct stream_pos *ppos, struct definition *definition) fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); } if (elem->id == CTF_TYPE_INTEGER) { diff --git a/formats/ctf-text/types/enum.c b/formats/ctf-text/types/enum.c index 12031c24..b973d494 100644 --- a/formats/ctf-text/types/enum.c +++ b/formats/ctf-text/types/enum.c @@ -44,7 +44,7 @@ int ctf_text_enum_write(struct stream_pos *ppos, struct definition *definition) fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); field_nr_saved = pos->field_nr; pos->field_nr = 0; diff --git a/formats/ctf-text/types/float.c b/formats/ctf-text/types/float.c index 5897ce9d..77651124 100644 --- a/formats/ctf-text/types/float.c +++ b/formats/ctf-text/types/float.c @@ -40,7 +40,7 @@ int ctf_text_float_write(struct stream_pos *ppos, struct definition *definition) fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); fprintf(pos->fp, "%g", float_definition->value); return 0; diff --git a/formats/ctf-text/types/integer.c b/formats/ctf-text/types/integer.c index 46803f64..f56a753b 100644 --- a/formats/ctf-text/types/integer.c +++ b/formats/ctf-text/types/integer.c @@ -43,7 +43,7 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); if (pos->string && (integer_declaration->encoding == CTF_STRING_ASCII diff --git a/formats/ctf-text/types/sequence.c b/formats/ctf-text/types/sequence.c index 6a0472f8..3fe5ff17 100644 --- a/formats/ctf-text/types/sequence.c +++ b/formats/ctf-text/types/sequence.c @@ -41,7 +41,7 @@ int ctf_text_sequence_write(struct stream_pos *ppos, struct definition *definiti fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); } if (elem->id == CTF_TYPE_INTEGER) { diff --git a/formats/ctf-text/types/string.c b/formats/ctf-text/types/string.c index 82bc361f..1ac38c46 100644 --- a/formats/ctf-text/types/string.c +++ b/formats/ctf-text/types/string.c @@ -43,7 +43,7 @@ int ctf_text_string_write(struct stream_pos *ppos, fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); fprintf(pos->fp, "\"%s\"", string_definition->value); return 0; diff --git a/formats/ctf-text/types/struct.c b/formats/ctf-text/types/struct.c index b1395351..a10e4da1 100644 --- a/formats/ctf-text/types/struct.c +++ b/formats/ctf-text/types/struct.c @@ -42,7 +42,7 @@ int ctf_text_struct_write(struct stream_pos *ppos, struct definition *definition fprintf(pos->fp, " "); if (pos->print_names && definition->name != 0) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); if (pos->print_names || len > 1) fprintf(pos->fp, "{"); } diff --git a/formats/ctf-text/types/variant.c b/formats/ctf-text/types/variant.c index 871b8d58..da069c8a 100644 --- a/formats/ctf-text/types/variant.c +++ b/formats/ctf-text/types/variant.c @@ -37,7 +37,7 @@ int ctf_text_variant_write(struct stream_pos *ppos, struct definition *definitio fprintf(pos->fp, " "); if (pos->print_names) fprintf(pos->fp, "%s = ", - g_quark_to_string(definition->name)); + rem_(g_quark_to_string(definition->name))); fprintf(pos->fp, "{"); } pos->depth++; diff --git a/formats/ctf/metadata/ctf-lexer.l b/formats/ctf/metadata/ctf-lexer.l index 322832be..f5ff02f1 100644 --- a/formats/ctf/metadata/ctf-lexer.l +++ b/formats/ctf/metadata/ctf-lexer.l @@ -30,15 +30,6 @@ static void yyunput (int c, register char * yy_bp , yyscan_t yyscanner) __attribute__((unused)); static int input (yyscan_t yyscanner) __attribute__((unused)); -static inline -const char *rem_(const char *str) -{ - if (str[0] == '_') - return &str[1]; - else - return str; -} - %} %x comment_ml comment_sl string_lit char_const @@ -131,7 +122,7 @@ _Imaginary setstring(yyextra, yylval, yytext); return _IMAGINARY; [1-9]{DIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return DECIMAL_CONSTANT; 0{OCTALDIGIT}*{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return OCTAL_CONSTANT; 0[xX]{HEXDIGIT}+{INTEGER_SUFFIX}? setstring(yyextra, yylval, yytext); return HEXADECIMAL_CONSTANT; -{IDENTIFIER} printf_debug("\n", yytext); setstring(yyextra, yylval, rem_(yytext)); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; +{IDENTIFIER} printf_debug("\n", yytext); setstring(yyextra, yylval, yytext); if (is_type(yyextra, yytext)) return ID_TYPE; else return IDENTIFIER; [ \t\n]+ ; /* ignore */ . return ERROR; %% diff --git a/include/babeltrace/ctf-text/types.h b/include/babeltrace/ctf-text/types.h index 3db8a106..101873a9 100644 --- a/include/babeltrace/ctf-text/types.h +++ b/include/babeltrace/ctf-text/types.h @@ -75,4 +75,13 @@ void print_pos_tabs(struct ctf_text_stream_pos *pos) */ int print_field(struct definition *definition); +static inline +const char *rem_(const char *str) +{ + if (str[0] == '_') + return &str[1]; + else + return str; +} + #endif /* _BABELTRACE_CTF_TEXT_TYPES_H */ -- 2.34.1