From: Mathieu Desnoyers Date: Wed, 1 Feb 2012 21:42:21 +0000 (-0500) Subject: Revert "Remove leading underscores from identifiers directly in lexer" X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=6743f229982176bfc2bdd2b3ab5c75ca62f45b35;p=deliverable%2Fbabeltrace.git 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 --- diff --git a/formats/ctf-text/types/array.c b/formats/ctf-text/types/array.c index 6dc84480c..3aaa63314 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 12031c242..b973d494b 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 5897ce9d7..77651124d 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 46803f640..f56a753bb 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 6a0472f87..3fe5ff170 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 82bc361f2..1ac38c46f 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 b1395351d..a10e4da1d 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 871b8d58a..da069c8ac 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 322832bed..f5ff02f1a 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 3db8a1069..101873a9d 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 */