Parcourir la source

Fix linkage and header deps.

Stefano Cossu il y a 2 ans
Parent
commit
57fc0af0b0

+ 12 - 12
Makefile

@@ -29,11 +29,9 @@ DBG_CFLAGS = -Itest -O0 -g3 -DDEBUG
 LDFLAGS = -L. -L$(libdir) -llmdb -lxxhash -luuid
 
 CODEC_DIR = src/codec
-CODEC_SRC = $(wildcard src/codec_*.c)
+CODEC_SRC = $(wildcard src/codec/{codec,grammar,lexer}*.c)
 CODEC_OBJ = $(CODEC_SRC:.c=.o)
 CODEC_DBG_OBJ = $(CODEC_SRC:.c=_dbg.o)
-PARSER_SRC = $(CODEC_SRC:src/codec_%=src/codec/parser_%)
-PARSER_OBJ = $(PARSER_SRC:.c=.o)
 
 
 
@@ -52,8 +50,8 @@ SRC = $(EXT_SRC) $(LSUP_SRC)
 TEST_SRC = $(wildcard test/*.c) test.c
 
 EXT_OBJ = $(EXT_SRC:.c=.o)
-OBJ = $(EXT_OBJ) $(PARSER_OBJ) $(CODEC_OBJ) $(LSUP_SRC:.c=.o)
-DBG_OBJ = $(EXT_OBJ) $(PARSER_OBJ) $(CODEC_DBG_OBJ) $(LSUP_SRC:.c=_dbg.o)
+OBJ = $(EXT_OBJ) $(CODEC_OBJ) $(LSUP_SRC:.c=.o)
+DBG_OBJ = $(EXT_OBJ) $(CODEC_DBG_OBJ) $(LSUP_SRC:.c=_dbg.o)
 
 DEPLIBS = libxxhash liblmdb
 LIBS = liblsuprdf.a liblsuprdf.so
@@ -106,6 +104,7 @@ liblsuprdf_dbg.a: $(DBG_OBJ)
 
 # Dynamic debug library.
 liblsuprdf_dbg.so: $(DBG_OBJ)
+	$(warning Making $(DBG_OBJ))
 	$(CC) -shared $(LDFLAGS) -o $@ $^
 
 
@@ -119,14 +118,15 @@ parsers: $(PARSER_SRC) ## Make intermediate parser sources for development.
 
 # Codecs.
 # Parser C sources.
-$(CODEC_DIR)/parser_%.c: $(CODEC_DIR)/lexer_%.re $(CODEC_DIR)/grammar_%.c $(CODEC_DIR)/grammar_%.h src/codec.c
+$(CODEC_DIR)/parser_%.c: $(CODEC_DIR)/lexer_%.re $(CODEC_DIR)/grammar_%.c include/codec/tokens_%.h src/codec.c
 	$(LEXER) $< -o $@ -T --case-ranges
 
 
-.SECONDARY: $(CODEC_DIR)/grammar_%.c
+.PRECIOUS: $(CODEC_DIR)/grammar_%.c include/codec/tokens_%.h
 # Parser generators.
-$(CODEC_DIR)/grammar_%.c $(CODEC_DIR)/grammar_%.h: $(CODEC_DIR)/grammar_%.y
+$(CODEC_DIR)/grammar_%.c include/codec/grammar_%.h: $(CODEC_DIR)/grammar_%.y
 	$(PARSER) $< -q -T$(CODEC_DIR)/lempar.c -d$(CODEC_DIR)
+	mv $(CODEC_DIR)/grammar_*.h include/codec
 
 
 # Ext libraries.
@@ -156,15 +156,15 @@ debug_install: install debug ## Install standard and debug libraries.
 	cp liblsuprdf_dbg.{a,so} $(DESTDIR)$(libdir)
 	
 
-.PHONY: clean ## Clean up artifacts.
+.PHONY: clean ## Clean up artifacts, including language parsers.
 clean:
 	rm -f src/*.[aod] ./*[aod] src/codec/*[aod]
+	rm -f include/codec/grammar_*.h
+	rm -f src/codec/{grammar,parser}_*.c
 
 
-.PHONY: deepclean ## Clean up external libraries and language parsers as well.
+.PHONY: deepclean ## Clean up external libraries.
 deepclean: clean
-	rm -f src/codec/grammar_*.{c,h}
-	rm -f src/codec/parser_*.c
 	cd $(MDB_DIR); make clean
 	cd $(XXHASH_DIR); make clean
 

+ 1 - 1
include/codec_nt.h → include/codec/codec_nt.h

@@ -1,7 +1,7 @@
 #ifndef _LSUP_CODEC_NT_H
 #define _LSUP_CODEC_NT_H
 
-#include "codec.h"
+#include "codec/parser_nt.h"
 
 /** @brief N-Triples codec.
  */

+ 1 - 1
include/codec_ttl.h → include/codec/codec_ttl.h

@@ -1,7 +1,7 @@
 #ifndef _LSUP_CODEC_TTL_H
 #define _LSUP_CODEC_TTL_H
 
-#include "codec.h"
+#include "codec/parser_ttl.h"
 
 /** @brief Turtle codec.
  */

+ 2 - 1
include/parser_nt.h → include/codec/parser_nt.h

@@ -1,7 +1,8 @@
 #ifndef _LSUP_NT_PARSER_H
 #define _LSUP_NT_PARSER_H
 
-#include "graph.h"
+#include "codec.h"
+
 
 /** @brief Parse a single term.
  *

+ 12 - 1
include/parser_ttl.h → include/codec/parser_ttl.h

@@ -1,7 +1,18 @@
 #ifndef _LSUP_TTL_PARSER_H
 #define _LSUP_TTL_PARSER_H
 
-#include "graph.h"
+#include "codec.h"
+
+
+// Parser interface. Required because Lemon doesn't export these in the header
+// automatically.
+/*
+void *TTLParseAlloc( void*(*malloc)(size_t));
+void TTLParseFree(void *pParser, void(*free)(void*) );
+void TTLParse(void *pParser, int tokenCode, uint8_t *token, ...);
+void TTLParseTrace(FILE *stream, char *zPrefix);
+*/
+
 
 /** @brief Parse a single term.
  *

+ 2 - 1
include/lsup_rdf.h

@@ -1,6 +1,7 @@
 #ifndef _LSUP_RDF_H
 #define _LSUP_RDF_H
 
-#include "codec_nt.h"
+#include "codec/codec_nt.h"
+#include "codec/codec_ttl.h"
 
 #endif

+ 2 - 2
src/codec.c

@@ -194,5 +194,5 @@ LSUP_bnode_add_collection (LSUP_GraphIterator *it, LSUP_Term **ol)
  */
 
 char unescape_char (const char c);
-inline uint8_t *uint8_dup (const uint8_t *str);
-inline uint8_t *uint8_ndup (const uint8_t *str, size_t size);
+uint8_t *uint8_dup (const uint8_t *str);
+uint8_t *uint8_ndup (const uint8_t *str, size_t size);

+ 1 - 2
src/codec_nt.c → src/codec/codec_nt.c

@@ -1,5 +1,4 @@
-#include "codec_nt.h"
-#include "parser_nt.h"
+#include "codec/codec_nt.h"
 
 /** @brief List of characters to be escaped in serialized literals.
  *

+ 2 - 3
src/codec_ttl.c → src/codec/codec_ttl.c

@@ -1,5 +1,4 @@
-#include "codec_ttl.h"
-#include "parser_ttl.h"
+#include "codec/codec_ttl.h"
 
 /** @brief List of characters to be escaped in serialized literals.
  *
@@ -177,7 +176,7 @@ const LSUP_Codec ttl_codec = {
     .encode_graph_iter  = gr_to_ttl_iter,
     .encode_graph_done  = gr_to_ttl_done,
 
-    .decode_term        = LSUP_ttl_parse_term,
+    //.decode_term        = LSUP_ttl_parse_term,
     .decode_graph       = LSUP_ttl_parse_doc,
 };
 

+ 0 - 7
src/codec/grammar_nt.h

@@ -1,7 +0,0 @@
-#define T_EOF                              1
-#define T_DOT                              2
-#define T_IRIREF                           3
-#define T_BNODE                            4
-#define T_LITERAL                          5
-#define T_EOL                              6
-#define T_WS                               7

+ 2 - 1
src/codec/grammar_nt.y

@@ -8,9 +8,10 @@
  * To generate the parser, run: `lemon ${FILE}'
  */
 
-#include "graph.h"
+#include "codec.h"
 }
 
+%name NTParse
 
 %token_type { LSUP_Term * }
 %token_prefix "T_"

+ 3 - 1
src/codec/grammar_ttl.y

@@ -13,9 +13,11 @@
 #include "codec.h"
 
 
-DEFINE XSD_PFX "http://www.w3.org/2001/XMLSchema#"
+DEFINE XSD_PFX "http://www.w3.org/2001/XMLSchema#" // FIXME
 }
 
+%name TTLParse
+
 %stack_overflow {
     log_error ("Stack oveflow in TTL parsing. Please jettison the parser.";
 }

+ 6 - 14
src/codec/lexer_nt.re

@@ -1,6 +1,5 @@
-#include "codec.h"
-#include "grammar_nt.h"
-#include "parser_nt.h"
+#include "codec/grammar_base_nt.h"
+#include "codec/grammar_nt.h"
 
 
 #define YYCTYPE     uint8_t
@@ -64,13 +63,6 @@ static void parse_init(ParseIterator *it, FILE *fh)
 }
 
 
-// Parser interface.
-
-void *ParseAlloc();
-void Parse();
-void ParseFree();
-
-
 // Lexer.
 
 static int lex (ParseIterator *it, LSUP_Term **term)
@@ -256,7 +248,7 @@ LSUP_nt_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     ParseIterator parse_it;
     parse_init (&parse_it, fh);
 
-    void *parser = ParseAlloc (malloc);
+    void *parser = NTParseAlloc (malloc);
 
     LSUP_rc rc;
 
@@ -296,7 +288,7 @@ LSUP_nt_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
             goto finally;
         }
 
-        Parse (parser, ttype, term, it);
+        NTParse (parser, ttype, term, it);
 
         if (ttype == T_EOF) break;
     };
@@ -310,8 +302,8 @@ LSUP_nt_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     *gr_p = gr;
 
 finally:
-    Parse (parser, 0, NULL, it);
-    ParseFree (parser, free);
+    NTParse (parser, 0, NULL, it);
+    NTParseFree (parser, free);
 
     LSUP_graph_add_done (it);
     LSUP_term_free (term);

+ 17 - 13
src/codec/lexer_ttl.re

@@ -1,6 +1,5 @@
-#include "codec.h"
-#include "grammar_ttl.h"
-#include "parser_ttl.h"
+#include "codec/parser_ttl.h"
+#include "codec/grammar_ttl.h"
 
 
 /** @brief TTL is UTF-8 encoded.
@@ -78,12 +77,17 @@ static void parse_init (ParseIterator *it, FILE *fh)
 }
 
 
-// Parser interface.
-
-void *ParseAlloc();
-void Parse();
-void ParseFree();
-
+// Parser interface. Required because Lemon doesn't export these in the header
+// automatically.
+/*
+void *TTLParseAlloc( void*(*malloc)(size_t));
+void TTLParseFree(void *pParser, void(*free)(void*) );
+void TTLParse(void *pParser, int tokenCode, YYCTYPE *token, ...);
+void TTLParseTrace(FILE *stream, char *zPrefix);
+*/
+void *TTLParseAlloc();
+void TTLParse();
+void TTLParseFree();
 
 // Lexer.
 
@@ -294,7 +298,7 @@ LSUP_ttl_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     ParseIterator parse_it;
     parse_init (&parse_it, fh);
 
-    void *parser = ParseAlloc (malloc);
+    void *parser = TTLParseAlloc (malloc);
 
     LSUP_rc rc;
 
@@ -343,7 +347,7 @@ LSUP_ttl_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
             goto finally;
         }
 
-        Parse (parser, ttype, token, state);
+        TTLParse (parser, ttype, token, state);
 
         if (ttype == T_EOF) break;
     };
@@ -357,8 +361,8 @@ LSUP_ttl_parse_doc (FILE *fh, LSUP_Graph **gr_p, size_t *ct, char **err_p)
     *gr_p = gr;
 
 finally:
-    Parse (parser, 0, NULL, state);
-    ParseFree (parser, free);
+    TTLParse (parser, 0, NULL, state);
+    TTLParseFree (parser, free);
 
     LSUP_graph_add_done (state->it);
     free (state);