Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/herb/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
$INCFLAGS << " -I#{prism_src_path}/util"

$CFLAGS << " -fvisibility=hidden"
$CFLAGS << " -DHERB_EXCLUDE_PRETTYPRINT"
$CFLAGS << " -DPRISM_EXCLUDE_PRETTYPRINT"
$CFLAGS << " -DPRISM_EXCLUDE_JSON"
$CFLAGS << " -DPRISM_EXCLUDE_PACK"
$CFLAGS << " -DPRISM_EXCLUDE_SERIALIZATION"

herb_src_files = Dir.glob("#{$srcdir}/../../src/**/*.c").map { |file| file.delete_prefix("../../../../ext/herb/") }.sort

Expand Down
2 changes: 1 addition & 1 deletion java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ PRISM_BUILD = $(PRISM_PATH)/build

JAVAC = $(JAVA_HOME)/bin/javac
JAVA_CMD = $(JAVA_HOME)/bin/java
CFLAGS = -std=c99 -Wall -Wextra -fPIC -O2
CFLAGS = -std=c99 -Wall -Wextra -fPIC -O2 -DHERB_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON -DPRISM_EXCLUDE_PACK -DPRISM_EXCLUDE_SERIALIZATION
INCLUDES = -I. -I$(SRC_DIR)/include -I$(PRISM_INCLUDE) $(JNI_INCLUDES)
LDFLAGS = -shared
LIBS = $(PRISM_BUILD)/libprism.a
Expand Down
7 changes: 6 additions & 1 deletion javascript/packages/node/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@
],
"defines": [
"PRISM_EXPORT_SYMBOLS=static",
"PRISM_STATIC=1"
"PRISM_STATIC=1",
"HERB_EXCLUDE_PRETTYPRINT",
"PRISM_EXCLUDE_PRETTYPRINT",
"PRISM_EXCLUDE_JSON",
"PRISM_EXCLUDE_PACK",
"PRISM_EXCLUDE_SERIALIZATION"
],
"cflags": [
"-Wall",
Expand Down
10 changes: 10 additions & 0 deletions rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ fn main() {
.flag("-std=c99")
.flag("-fPIC")
.opt_level(2)
.define("HERB_EXCLUDE_PRETTYPRINT", None)
.define("PRISM_EXCLUDE_PRETTYPRINT", None)
.define("PRISM_EXCLUDE_JSON", None)
.define("PRISM_EXCLUDE_PACK", None)
.define("PRISM_EXCLUDE_SERIALIZATION", None)
.include(&vendor_prism_include)
.files(&prism_sources)
.warnings(false);
Expand Down Expand Up @@ -72,6 +77,11 @@ fn main() {
.flag("-Wno-unused-parameter")
.flag("-fPIC")
.opt_level(2)
.define("HERB_EXCLUDE_PRETTYPRINT", None)
.define("PRISM_EXCLUDE_PRETTYPRINT", None)
.define("PRISM_EXCLUDE_JSON", None)
.define("PRISM_EXCLUDE_PACK", None)
.define("PRISM_EXCLUDE_SERIALIZATION", None)
.include(&include_dir)
.include(&prism_include)
.files(&c_sources);
Expand Down
15 changes: 10 additions & 5 deletions src/include/pretty_print.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#ifndef HERB_PRETTY_PRINT_H
#define HERB_PRETTY_PRINT_H

#include "analyze/analyzed_ruby.h"
#include "ast_nodes.h"
#include "location.h"
#include "util/hb_buffer.h"
#ifdef HERB_EXCLUDE_PRETTYPRINT
// Pretty print support excluded
#else

#include <stdbool.h>
# include "analyze/analyzed_ruby.h"
# include "ast_nodes.h"
# include "location.h"
# include "util/hb_buffer.h"

# include <stdbool.h>

void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
Expand Down Expand Up @@ -101,3 +105,4 @@ void pretty_print_errors(
);

#endif
#endif
8 changes: 7 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

#include "include/ast_node.h"
#include "include/ast_nodes.h"
#include "include/ast_pretty_print.h"

#ifndef HERB_EXCLUDE_PRETTYPRINT
# include "include/ast_pretty_print.h"
#endif

#include "include/extract.h"
#include "include/herb.h"
#include "include/io.h"
Expand Down Expand Up @@ -84,8 +88,10 @@ int main(const int argc, char* argv[]) {
if (argc > 3 && string_equals(argv[3], "--silent")) { silent = 1; }

if (!silent) {
#ifndef HERB_EXCLUDE_PRETTYPRINT
ast_pretty_print_node((AST_NODE_T*) root, 0, 0, &output);
puts(output.value);
#endif

print_time_diff(start, end, "parsing");
}
Expand Down
30 changes: 18 additions & 12 deletions src/pretty_print.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#include "include/pretty_print.h"
#include "include/ast_nodes.h"
#include "include/ast_pretty_print.h"
#include "include/errors.h"
#include "include/token_struct.h"
#include "include/util.h"
#include "include/util/hb_buffer.h"
#include "include/util/hb_string.h"

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HERB_EXCLUDE_PRETTYPRINT
// Pretty print support excluded
#else

# include "include/pretty_print.h"
# include "include/ast_nodes.h"
# include "include/ast_pretty_print.h"
# include "include/errors.h"
# include "include/token_struct.h"
# include "include/util.h"
# include "include/util/hb_buffer.h"
# include "include/util/hb_string.h"

# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>

void pretty_print_indent(hb_buffer_T* buffer, const size_t indent) {
for (size_t i = 0; i < indent; i++) {
Expand Down Expand Up @@ -249,3 +253,5 @@ void pretty_print_string_property(
if (!hb_string_is_empty(quoted)) { free(quoted.data); }
}
}

#endif
2 changes: 2 additions & 0 deletions src/ruby_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ void herb_parse_ruby_to_stdout(char* source) {

pm_visit_node(root, herb_prism_visit, data);

#ifndef PRISM_EXCLUDE_PRETTYPRINT
pm_prettyprint(&buffer, &parser, root);
printf("%s\n", buffer.value);
#endif

pm_buffer_free(&buffer);
pm_node_destroy(&parser, root);
Expand Down
6 changes: 6 additions & 0 deletions templates/src/ast_pretty_print.c.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#ifdef HERB_EXCLUDE_PRETTYPRINT
// Pretty print support excluded
#else

#include "include/analyze/helpers.h"
#include "include/ast_node.h"
#include "include/ast_nodes.h"
Expand Down Expand Up @@ -110,3 +114,5 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
<%- end -%>
}
}

#endif
4 changes: 4 additions & 0 deletions templates/src/errors.c.erb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ void error_free(ERROR_T* error) {
}
}

#ifndef HERB_EXCLUDE_PRETTYPRINT

void error_pretty_print_array(
const char* name, hb_array_T* array, const size_t indent, const size_t relative_indent, const bool last_property,
hb_buffer_T* buffer
Expand Down Expand Up @@ -245,3 +247,5 @@ void error_pretty_print(ERROR_T* error, const size_t indent, const size_t relati
<%- end -%>
}
}

#endif
5 changes: 5 additions & 0 deletions templates/src/include/ast_pretty_print.h.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef HERB_AST_PRETTY_PRINT_H
#define HERB_AST_PRETTY_PRINT_H

#ifdef HERB_EXCLUDE_PRETTYPRINT
// Pretty print support excluded
#else

#include "ast_nodes.h"
#include "util/hb_buffer.h"

Expand All @@ -12,3 +16,4 @@ void ast_pretty_print_node(
);

#endif
#endif
12 changes: 7 additions & 5 deletions templates/src/include/errors.h.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ const char* error_human_type(ERROR_T* error);

void error_free(ERROR_T* error);

void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);
#ifndef HERB_EXCLUDE_PRETTYPRINT
void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);

void error_pretty_print_array(
const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
hb_buffer_T* buffer
);
void error_pretty_print_array(
const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
hb_buffer_T* buffer
);
#endif

#endif
5 changes: 3 additions & 2 deletions wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ INCLUDE_DIR = ../include
PRISM_INCLUDE = $(PRISM_PATH)/include
PRISM_SRC = $(PRISM_PATH)/src
PRISM_UTIL = $(PRISM_PATH)/src/util
PRISM_EXCLUDE_FLAGS = -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON -DPRISM_EXCLUDE_PACK
PRISM_EXCLUDE_FLAGS = -DPRISM_EXCLUDE_PRETTYPRINT -DPRISM_EXCLUDE_JSON -DPRISM_EXCLUDE_PACK -DPRISM_EXCLUDE_SERIALIZATION
HERB_EXCLUDE_FLAGS = -DHERB_EXCLUDE_PRETTYPRINT

OPT_FLAGS = -Oz -g0 -flto -fdata-sections -ffunction-sections

CFLAGS = -I$(INCLUDE_DIR) -I$(PRISM_INCLUDE) -I$(PRISM_SRC) -I$(PRISM_UTIL) -DPRISM_STATIC=1 -DPRISM_EXPORT_SYMBOLS=static $(PRISM_EXCLUDE_FLAGS) $(OPT_FLAGS)
CFLAGS = -I$(INCLUDE_DIR) -I$(PRISM_INCLUDE) -I$(PRISM_SRC) -I$(PRISM_UTIL) -DPRISM_STATIC=1 -DPRISM_EXPORT_SYMBOLS=static $(PRISM_EXCLUDE_FLAGS) $(HERB_EXCLUDE_FLAGS) $(OPT_FLAGS)
WASM_FLAGS = -s WASM=1 \
-s SINGLE_FILE=1 \
-s EXPORT_ES6=1 \
Expand Down
Loading