From 9317f3eb6c6ccb4c01d4937f3e55f778c069ad87 Mon Sep 17 00:00:00 2001 From: Pauli Date: Sat, 7 Jul 2018 13:52:55 +0300 Subject: [PATCH 1/3] Support header dependecies This allows removing Core.h include from DataDefs.h. --- Common.pm | 14 +++++++++++++- StructFields.pm | 9 +++++++-- StructType.pm | 7 ++++++- df.graphics.xml | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Common.pm b/Common.pm index 96ed480c0..3654cb23e 100644 --- a/Common.pm +++ b/Common.pm @@ -19,7 +19,7 @@ BEGIN { &is_primitive_type &primitive_type_name &get_primitive_base - *weak_refs *strong_refs ®ister_ref &decode_type_name_ref + *weak_refs *strong_refs *header_refs &header_ref ®ister_ref &decode_type_name_ref &with_capture_traits &with_emit_traits *cur_header_name %header_data &with_header_file @@ -213,6 +213,7 @@ sub get_primitive_base($;$) { our %weak_refs; our %strong_refs; +our %header_refs; sub register_ref($;$) { # Register a reference to another type. @@ -235,6 +236,12 @@ sub register_ref($;$) { } } +sub header_ref($;$) { + my ($header) = @_; + + $header_refs{$header}++; +} + sub decode_type_name_ref($;%) { # Interpret the type-name field of a tag my ($tag,%flags) = @_; @@ -288,6 +295,7 @@ sub with_header_file(&$) { local %weak_refs; local %strong_refs; + local %header_refs; # Emit the actual type definition my @code = with_emit { @@ -308,6 +316,10 @@ sub with_header_file(&$) { emit "#pragma GCC system_header"; emit "#endif"; + for my $strong (sort { $a cmp $b } keys %header_refs) { + emit "#include \"$strong\""; + } + for my $strong (sort { $a cmp $b } keys %strong_refs) { my $sdef = type_header_def($strong); emit "#ifndef $sdef"; diff --git a/StructFields.pm b/StructFields.pm index 19adcb4ea..623ad1921 100644 --- a/StructFields.pm +++ b/StructFields.pm @@ -92,8 +92,8 @@ our $cur_init_value = undef; sub add_simple_init($); my %custom_primitive_handlers = ( - 'stl-string' => sub { return "std::string"; }, - 'stl-fstream' => sub { return "std::fstream"; }, + 'stl-string' => sub { header_ref("string"); return "std::string"; }, + 'stl-fstream' => sub { header_ref("fstream"); return "std::fstream"; }, ); my %custom_primitive_inits = ( @@ -110,17 +110,21 @@ my %custom_container_handlers = ( 'stl-vector' => sub { my $item = get_container_item_type($_, -void => 'void*'); $item = 'char' if $item eq 'bool'; + header_ref("vector"); return "std::vector<$item >"; }, 'stl-deque' => sub { my $item = get_container_item_type($_, -void => 'void*'); + header_ref("deque"); return "std::deque<$item >"; }, 'stl-set' => sub { my $item = get_container_item_type($_, -void => 'void*'); + header_ref("set"); return "std::set<$item >"; }, 'stl-bit-vector' => sub { + header_ref("vector"); return "std::vector"; }, 'df-flagarray' => sub { @@ -415,6 +419,7 @@ sub render_field_metadata_rec($$) { local $_; local %weak_refs; local %strong_refs; + local %header_refs; my $meta = $field->getAttribute('ld:meta'); my $subtype = $field->getAttribute('ld:subtype'); diff --git a/StructType.pm b/StructType.pm index cfc6a6962..34a18be00 100644 --- a/StructType.pm +++ b/StructType.pm @@ -198,7 +198,12 @@ sub render_struct_type { my $ispec = ''; for my $extra ($tag->findnodes('extra-include')) { - register_ref $extra->getAttribute('type-name'), 1; + my $tname = $extra->getAttribute('type-name'); + if ($tname) { + register_ref $tname, 1; + } else { + header_ref $extra->getAttribute('filename'); + } } if ($inherits) { diff --git a/df.graphics.xml b/df.graphics.xml index 333057ba0..ec6f8d68f 100644 --- a/df.graphics.xml +++ b/df.graphics.xml @@ -92,6 +92,7 @@ + From 953a096f1d1c65f4d1c7ef9c741af364a45a0663 Mon Sep 17 00:00:00 2001 From: Pauli Date: Sat, 7 Jul 2018 13:54:31 +0300 Subject: [PATCH 2/3] Use pragma once in df headers --- Common.pm | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Common.pm b/Common.pm index 3654cb23e..f25adabb8 100644 --- a/Common.pm +++ b/Common.pm @@ -310,8 +310,7 @@ sub with_header_file(&$) { # Add wrapping my @all = with_emit { my $def = type_header_def($header_name); - emit "#ifndef $def"; - emit "#define $def"; + emit "#pragma once"; emit "#ifdef __GNUC__"; emit "#pragma GCC system_header"; emit "#endif"; @@ -321,10 +320,7 @@ sub with_header_file(&$) { } for my $strong (sort { $a cmp $b } keys %strong_refs) { - my $sdef = type_header_def($strong); - emit "#ifndef $sdef"; emit "#include \"$strong.h\""; - emit "#endif"; } emit_block { @@ -341,8 +337,6 @@ sub with_header_file(&$) { push @lines, @code; } "namespace $main_namespace "; - - emit "#endif"; }; $header_data{$header_name} = \@all; From e93d828073efae353a599e4410e4953dc8ceacb7 Mon Sep 17 00:00:00 2001 From: Pauli Date: Sat, 7 Jul 2018 14:11:24 +0300 Subject: [PATCH 3/3] Include all dependecies in df headers This allows including df/*.h without including any dependecies first. It also helps ycm error reporting to avoid wrong errors when opening headers when it tries to compile header as c++ source file. --- Bitfield.pm | 2 ++ Common.pm | 3 +++ Enum.pm | 2 ++ StructFields.pm | 2 ++ codegen.pl | 1 + 5 files changed, 10 insertions(+) diff --git a/Bitfield.pm b/Bitfield.pm index 67edf38a0..2dfe43b62 100644 --- a/Bitfield.pm +++ b/Bitfield.pm @@ -94,6 +94,8 @@ sub render_bitfield_core { emit "static bitfield_identity identity;"; emit "static bitfield_identity *get() { return &identity; }"; } "template<> struct ${export_prefix}identity_$traits_name ", ";"; + header_ref("Export.h"); + header_ref("DataDefs.h"); }; with_emit_static { diff --git a/Common.pm b/Common.pm index f25adabb8..ae5464e9a 100644 --- a/Common.pm +++ b/Common.pm @@ -204,6 +204,9 @@ sub get_primitive_base($;$) { my ($tag, $default) = @_; my $base = $tag->getAttribute('base-type') || $default || 'uint32_t'; + if ($base =~ /u?int[136]?[2468]_t/) { + header_ref("cstdint"); + } $primitive_types{$base} or die "Must be primitive: $base\n"; return $base; diff --git a/Enum.pm b/Enum.pm index 8521e3cdd..a739d5a91 100644 --- a/Enum.pm +++ b/Enum.pm @@ -91,6 +91,8 @@ sub render_enum_tables($$$$$$) { emit "static enum_identity identity;"; emit "static enum_identity *get() { return &identity; }"; } "template<> struct ${export_prefix}identity_$traits_name ", ";"; + header_ref("Export.h"); + header_ref("DataDefs.h"); }; # Enumerate enum attributes diff --git a/StructFields.pm b/StructFields.pm index 623ad1921..82219fbc6 100644 --- a/StructFields.pm +++ b/StructFields.pm @@ -39,6 +39,8 @@ sub with_struct_block(&$;$%) { my $is_union = is_attr_true($tag,'is-union'); my $kwd = ($is_union ? "union" : "struct"); my $exp = $export_prefix; #$flags{-export} ? $export_prefix : ''; + header_ref("Export.h"); + header_ref("DataDefs.h"); my $prefix = $kwd.' '.$exp.($name ? $name.' ' : ''); emit_comment $tag, -attr => 1; diff --git a/codegen.pl b/codegen.pl index 13086ebfc..e8f4bd2ed 100755 --- a/codegen.pl +++ b/codegen.pl @@ -96,6 +96,7 @@ BEGIN my $prefix = get_container_item_type($tag, -weak => 1, -void => 'void'); emit_comment $tag; emit 'extern ', $export_prefix, $prefix, ' *', $name, ';', get_comment($tag); + header_ref("Export.h"); push @items, [ $prefix, $name ]; push @fields, $tag->findnodes('ld:item');