summaryrefslogtreecommitdiffstats
path: root/hl/src/H5LTanalyze.l
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2021-04-05 22:35:03 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2021-04-05 22:35:03 (GMT)
commit4402e696e43e4428a37953edbfd67c448ba93ac1 (patch)
treeb2cffca0aa461b4e0440d18cfc16cab9258e98d7 /hl/src/H5LTanalyze.l
parent4d459e1cebb8b4ba3e74054ac5501603dc2698c2 (diff)
downloadhdf5-4402e696e43e4428a37953edbfd67c448ba93ac1.zip
hdf5-4402e696e43e4428a37953edbfd67c448ba93ac1.tar.gz
hdf5-4402e696e43e4428a37953edbfd67c448ba93ac1.tar.bz2
Normalized high-level library with develop
Diffstat (limited to 'hl/src/H5LTanalyze.l')
-rw-r--r--hl/src/H5LTanalyze.l108
1 files changed, 35 insertions, 73 deletions
diff --git a/hl/src/H5LTanalyze.l b/hl/src/H5LTanalyze.l
index 660b1f7..fd1cbe5 100644
--- a/hl/src/H5LTanalyze.l
+++ b/hl/src/H5LTanalyze.l
@@ -18,16 +18,15 @@
*/
%{
+#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <hdf5.h>
-#include "H5LTparse.h"
-/* Turn off suggest const & malloc attribute warnings in gcc */
-#if defined __GNUC__ && 402 <= __GNUC__ * 100 + __GNUC_MINOR__
-#pragma GCC diagnostic ignored "-Wsuggest-attribute=const"
-#endif
+#include "H5private.h"
+#include "H5LTparse.h"
+static char *trim_quotes(const char *);
int my_yyinput(char *, int);
#undef YY_INPUT
#define YY_INPUT(b, r, ms) (r=my_yyinput(b, ms))
@@ -42,43 +41,8 @@ int my_yyinput(char *, int);
extern char *myinput;
extern size_t input_len;
-#define STACK_SIZE 16
-
-/*variables for compound type*/
-struct cmpd_info {
- hid_t id;
- hbool_t is_field;
- hbool_t first_memb;
-};
-extern struct cmpd_info cmpd_stack[STACK_SIZE];
-extern int csindex;
-
-/*variables for array type*/
-struct arr_info {
- hsize_t dims[H5S_MAX_RANK];
- int ndim;
- hbool_t is_dim;
-};
-extern struct arr_info arr_stack[STACK_SIZE];
-extern int asindex;
-
-/*variables for enumerate type*/
-extern hbool_t is_enum;
-extern hbool_t is_enum_memb;
-
-/*variables for string type*/
-extern hbool_t is_str_size;
-
-/*variables for opaque type*/
-extern hbool_t is_opq_size;
-extern hbool_t is_opq_tag;
-
-hbool_t first_quote = 1;
-
%}
-%s TAG_STRING
-
%%
H5T_STD_I8BE {return hid(H5T_STD_I8BE_TOKEN);}
@@ -124,9 +88,9 @@ STRSIZE {return token(STRSIZE_TOKEN);}
STRPAD {return token(STRPAD_TOKEN);}
CSET {return token(CSET_TOKEN);}
CTYPE {return token(CTYPE_TOKEN);}
-H5T_STR_NULLTERM {return token(H5T_STR_NULLTERM_TOKEN);}
-H5T_STR_NULLPAD {return token(H5T_STR_NULLPAD_TOKEN);}
-H5T_STR_SPACEPAD {return token(H5T_STR_SPACEPAD_TOKEN);}
+H5T_STR_NULLTERM {return token(H5T_STR_NULLTERM_TOKEN);}
+H5T_STR_NULLPAD {return token(H5T_STR_NULLPAD_TOKEN);}
+H5T_STR_SPACEPAD {return token(H5T_STR_SPACEPAD_TOKEN);}
H5T_CSET_ASCII {return token(H5T_CSET_ASCII_TOKEN);}
H5T_CSET_UTF8 {return token(H5T_CSET_UTF8_TOKEN);}
H5T_C_S1 {return token(H5T_C_S1_TOKEN);}
@@ -142,36 +106,16 @@ H5T_OPAQUE {return token(H5T_OPAQUE_TOKEN);}
OPQ_SIZE {return token(OPQ_SIZE_TOKEN);}
OPQ_TAG {return token(OPQ_TAG_TOKEN);}
-[0-9]+ {
- if( is_str_size || (is_enum && is_enum_memb) ||
- is_opq_size || (asindex>-1 && arr_stack[asindex].is_dim) ||
- (csindex>-1 && cmpd_stack[csindex].is_field) ) {
- H5LTyylval.ival = atoi(yytext);
- return NUMBER;
- } else
- REJECT;
+[0-9]+ {
+ H5LTyylval.ival = HDatoi(yytext);
+ return NUMBER;
}
-"\"" {
- /*if it's first quote, and is a compound field name or an enum symbol*/
- if((is_opq_tag || is_enum || (csindex>-1 && cmpd_stack[csindex].is_field))
- && first_quote) {
- first_quote = 0;
- BEGIN TAG_STRING;
- } else /*if it's second quote*/
- first_quote = 1;
- return token('"');
- }
-<TAG_STRING>[^\"]+ {
-#ifdef H5_HAVE_WIN32_API
- H5LTyylval.sval = _strdup(yytext);
-#else /* H5_HAVE_WIN32_API */
- H5LTyylval.sval = strdup(yytext);
-#endif /* H5_HAVE_WIN32_API */
- BEGIN INITIAL;
+["][^\"]+["] {
+ H5LTyylval.sval = trim_quotes(yytext);
return STRING;
}
-
+
"{" {return token('{');}
"}" {return token('}');}
"[" {return token('[');}
@@ -179,21 +123,39 @@ OPQ_TAG {return token(OPQ_TAG_TOKEN);}
":" {return token(':');}
";" {return token(';');}
[ \t\n]* ;
-"\n" { return 0; }
%%
+
+/* Allocate a copy of `quoted` with the double quote character at
+ * the beginning and the one at the end both removed. The caller is
+ * responsible for free()ing the copy.
+ */
+static char *
+trim_quotes(const char *quoted)
+{
+ size_t len = HDstrlen(quoted);
+ char *trimmed;
+
+ HDassert(quoted[0] == '"' && quoted[len - 1] == '"');
+
+ trimmed = HDstrdup(quoted + 1);
+ trimmed[len - 2] = '\0';
+
+ return trimmed;
+}
+
int my_yyinput(char *buf, int max_size)
{
int ret;
-
- memcpy(buf, myinput, input_len);
+
+ HDmemcpy(buf, myinput, input_len);
ret = (int)input_len;
return ret;
}
int H5LTyyerror(const char *msg)
{
- printf("ERROR: %s before \"%s\".\n", msg, yytext);
+ HDprintf("ERROR: %s before \"%s\".\n", msg, yytext);
return 0;
}