Skip to content

Commit e39bb1b

Browse files
committed
1 parent b7832f4 commit e39bb1b

File tree

125 files changed

+28486
-25272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+28486
-25272
lines changed

src/main/c/yarp/.gitignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/.bundle/
2+
/.idea/
3+
/.yardoc
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/top-100-gems/
10+
/tmp/
11+
/vendor/bundle
12+
13+
/build/
14+
/lib/yarp/yarp.*
15+
/lib/yarp.bundle
16+
/lib/yarp.so
17+
test.rb
18+
*.dSYM
19+
*~
20+
21+
test.c
22+
a.out
23+
24+
/ext/yarp/api_node.c
25+
/include/yarp/ast.h
26+
/java/org/yarp/AbstractNodeVisitor.java
27+
/java/org/yarp/Loader.java
28+
/java/org/yarp/Nodes.java
29+
/lib/yarp/node.rb
30+
/lib/yarp/serialize.rb
31+
/src/node.c
32+
/src/prettyprint.c
33+
/src/serialize.c
34+
/src/token_type.c
35+
/src/**/*.o
36+
37+
compile_commands.json
38+
.cache/
39+
40+
autom4te.cache
41+
configure
42+
config.log
43+
config.status
44+
Makefile
45+
/include/yarp/config.h
46+
/config.h.in
47+
48+
tags

src/main/c/yarp/Makefile.in

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
# V=0 quiet, V=1 verbose. other values don't work.
3+
V = 0
4+
V0 = $(V:0=)
5+
Q1 = $(V:1=)
6+
Q = $(Q1:0=@)
7+
ECHO1 = $(V:1=@ :)
8+
ECHO = $(ECHO1:0=@ echo)
9+
10+
SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
11+
12+
DEFS := @DEFS@
13+
CPPFLAGS := @DEFS@ -Iinclude
14+
CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wsign-conversion -fPIC -fvisibility=hidden
15+
CC := @CC@
16+
17+
HEADERS := $(shell find include -name '*.h')
18+
SOURCES := $(shell find src -name '*.c')
19+
SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
20+
STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
21+
22+
all: shared static
23+
24+
shared: build/librubyparser.$(SOEXT)
25+
static: build/librubyparser.a
26+
27+
build/librubyparser.$(SOEXT): $(SHARED_OBJECTS)
28+
$(ECHO) "linking $@"
29+
$(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
30+
31+
build/librubyparser.a: $(STATIC_OBJECTS)
32+
$(ECHO) "building $@"
33+
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
34+
35+
build/shared/%.o: src/%.c Makefile $(HEADERS)
36+
$(ECHO) "compiling $@"
37+
$(Q) mkdir -p $(@D)
38+
$(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
39+
40+
build/static/%.o: src/%.c Makefile $(HEADERS)
41+
$(ECHO) "compiling $@"
42+
$(Q) mkdir -p $(@D)
43+
$(Q) $(CC) $(DEBUG_FLAGS) -DYP_STATIC $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
44+
45+
clean:
46+
$(Q) rm -f -r build
47+
48+
.PHONY: clean
49+
50+
all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
51+
all-no-debug: OPTFLAGS := -O3
52+
all-no-debug: all

src/main/c/yarp/configure.ac

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
m4_define([_YP_VERSION_MAJOR], [0])
2+
m4_define([_YP_VERSION_MINOR], [4])
3+
m4_define([_YP_VERSION_PATCH], [0])
4+
m4_define([_YP_VERSION], [_YP_VERSION_MAJOR._YP_VERSION_MINOR._YP_VERSION_PATCH])
5+
6+
AC_INIT([YARP],[_YP_VERSION],[https://github.com/ruby/yarp/issues/new],[yarp],[https://github.com/ruby/yarp])
7+
8+
AC_PROG_CC
9+
AC_C_INLINE
10+
AC_DEFINE([_XOPEN_SOURCE], [700], [_XOPEN_SOURCE])
11+
AC_DEFINE([YP_VERSION_MAJOR], [_YP_VERSION_MAJOR], [YP_VERSION_MAJOR])
12+
AC_DEFINE([YP_VERSION_MINOR], [_YP_VERSION_MINOR], [YP_VERSION_MINOR])
13+
AC_DEFINE([YP_VERSION_PATCH], [_YP_VERSION_PATCH], [YP_VERSION_PATCH])
14+
AC_DEFINE([YP_VERSION], ["_YP_VERSION"], [YP_VERSION])
15+
16+
AC_CHECK_FUNCS([mmap])
17+
AC_CHECK_FUNCS([snprintf])
18+
AC_CHECK_FUNCS([strncasecmp])
19+
20+
AC_CONFIG_HEADERS([include/yarp/config.h:config.h.in])
21+
AC_CONFIG_FILES([Makefile])
22+
AC_OUTPUT

src/main/c/yarp/include/yarp.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#ifndef YARP_H
2+
#define YARP_H
3+
4+
#include "yarp/defines.h"
5+
#include "yarp/ast.h"
6+
#include "yarp/diagnostic.h"
7+
#include "yarp/node.h"
8+
#include "yarp/pack.h"
9+
#include "yarp/parser.h"
10+
#include "yarp/regexp.h"
11+
#include "yarp/unescape.h"
12+
#include "yarp/util/yp_buffer.h"
13+
#include "yarp/util/yp_char.h"
14+
#include "yarp/util/yp_memchr.h"
15+
#include "yarp/util/yp_strpbrk.h"
16+
17+
#include <assert.h>
18+
#include <stdarg.h>
19+
#include <stdbool.h>
20+
#include <stdint.h>
21+
#include <stdio.h>
22+
#include <stdlib.h>
23+
#include <string.h>
24+
25+
#ifndef _WIN32
26+
#include <strings.h>
27+
#endif
28+
29+
void yp_serialize_content(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
30+
31+
void yp_print_node(yp_parser_t *parser, yp_node_t *node);
32+
33+
// The YARP version and the serialization format.
34+
YP_EXPORTED_FUNCTION const char * yp_version(void);
35+
36+
// Initialize a parser with the given start and end pointers.
37+
YP_EXPORTED_FUNCTION void yp_parser_init(yp_parser_t *parser, const char *source, size_t size, const char *filepath);
38+
39+
// Register a callback that will be called whenever YARP changes the encoding it
40+
// is using to parse based on the magic comment.
41+
YP_EXPORTED_FUNCTION void yp_parser_register_encoding_changed_callback(yp_parser_t *parser, yp_encoding_changed_callback_t callback);
42+
43+
// Register a callback that will be called when YARP encounters a magic comment
44+
// with an encoding referenced that it doesn't understand. The callback should
45+
// return NULL if it also doesn't understand the encoding or it should return a
46+
// pointer to a yp_encoding_t struct that contains the functions necessary to
47+
// parse identifiers.
48+
YP_EXPORTED_FUNCTION void yp_parser_register_encoding_decode_callback(yp_parser_t *parser, yp_encoding_decode_callback_t callback);
49+
50+
// Free any memory associated with the given parser.
51+
YP_EXPORTED_FUNCTION void yp_parser_free(yp_parser_t *parser);
52+
53+
// Parse the Ruby source associated with the given parser and return the tree.
54+
YP_EXPORTED_FUNCTION yp_node_t * yp_parse(yp_parser_t *parser);
55+
56+
// Pretty-prints the AST represented by the given node to the given buffer.
57+
YP_EXPORTED_FUNCTION void yp_prettyprint(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
58+
59+
// Serialize the AST represented by the given node to the given buffer.
60+
YP_EXPORTED_FUNCTION void yp_serialize(yp_parser_t *parser, yp_node_t *node, yp_buffer_t *buffer);
61+
62+
// Parse and serialize the AST represented by the given source to the given
63+
// buffer.
64+
YP_EXPORTED_FUNCTION void yp_parse_serialize(const char *source, size_t size, yp_buffer_t *buffer);
65+
66+
// Returns a string representation of the given token type.
67+
YP_EXPORTED_FUNCTION const char * yp_token_type_to_str(yp_token_type_t token_type);
68+
69+
#endif

0 commit comments

Comments
 (0)