Commit graph

98 commits

Author SHA1 Message Date
Rongsong Shen
c582108917 fix SEGV issue & merge xmake 2025-04-21 17:52:24 +08:00
Rongsong Shen
45a69c993f fix cmake 2025-04-21 14:11:49 +08:00
Rongsong Shen
5d64af4841 merge code 2025-04-21 13:13:34 +08:00
Jonah Beckford
edc0d97de0 bugfix: Remove attribute from struct types
GCC does not support some attributes on types:

> warning: ‘visibility’ attribute ignored on types
2023-09-26 20:13:30 -07:00
Jonah Beckford
014d4ea4df Implement attrs: extendedattribute and extraheader 2023-09-25 21:23:22 -07:00
Jonah Beckford
311b9cb0e0 Fix clang-tidy bugprone-macro-parentheses
Correct the definition of capnp_use(x) macro.

> recommended to surround macro arguments
> in the replacement list with parentheses. This
> ensures that the argument value is calculated
> properly.
2023-08-03 18:19:55 -07:00
Jonah Beckford
c662042a60 Read schemas in binary on Windows 2023-06-22 12:11:03 -07:00
David Lamparter
632f0d73a1 Update autogenerated files
Signed-off-by: David Lamparter <equinox@diac24.net>
2023-04-23 14:35:11 +02:00
David Lamparter
79d6035e3f Revert "Merge pull request #54 from cbrune/curt/const"
This reverts commit 4109705a8d, reversing
changes made to 5c4e497a72.
2023-04-23 14:33:18 +02:00
David Lamparter
eb1839e001 Fix bool defaults for non-first bit
Fixes: #58
Signed-off-by: David Lamparter <equinox@diac24.net>
2023-04-23 14:30:11 +02:00
David Lamparter
b2b7ade9c0 Fix random warnings
Signed-off-by: David Lamparter <equinox@diac24.net>
2023-04-23 14:21:58 +02:00
David Lamparter
c79b3afbbd
Merge pull request #24 from jlferrer/fix_compiler_big_files 2023-04-23 14:12:52 +02:00
David Lamparter
4109705a8d
Merge pull request #54 from cbrune/curt/const 2023-04-23 14:11:49 +02:00
David Lamparter
5c4e497a72
Merge pull request #53 from cbrune/curt/reduce-imports 2023-04-23 14:11:30 +02:00
David Lamparter
0653675ef4
Merge pull request #52 from cbrune/curt/namespace 2023-04-23 14:11:13 +02:00
David Lamparter
560f2c7cb9
Merge pull request #45 from snar/p-field 2023-04-23 14:10:24 +02:00
Curt Brune
3385b1e73a add #define definitions for integer constants
When working with integer constants, it is convenient to use #define
macros for the constants, as opposed to a variable of constant type.

This patch adds a '#define CONSTANT (value)' definition to the
generated header files.  The name of the constant is in
SCREAMING_SNAKE_CASE, converted from the regular camelCase.

Signed-off-by: Curt Brune <curt@enfabrica.net>
2022-10-27 13:11:32 -07:00
Curt Brune
40d689516a add 'const' keyword to generated constants
This patch adds the 'const' keyword to constant definitions generated
by the compiler.  Previously the compiler generated constants like
this:

  foo.h
  ======

  extern int foo;

  foo.c
  ======

  int foo = 5;

With this patch, the generated code looks like:

  foo.h
  ======

  extern const int foo;

  foo.c
  ======

  const int foo = 5;

Signed-off-by: Curt Brune <curt@enfabrica.net>
2022-10-14 09:17:09 -07:00
Curt Brune
c70796b9fb add a capnp annotation for creating name spaces
This patch adds an annotation for creating name spaces within
capnproto files with the C-language code generator.

Use the annotation like this:

  using C = import "/c.capnp";
  $C.namespace("sample_namespace_");

The string passed into the namespace annotation is prepended to the
name of all the struct's in the schema file.

Signed-off-by: Curt Brune <curt@enfabrica.net>
2022-10-14 09:15:11 -07:00
Curt Brune
1772643adb only generate '#include' for imports that are used
This patch modifies the code generator to only generate C-language
`#include <imported_schema.h>` lines for imports that are actually used.

Imagine this transitive import scenario: schema A imports a definition
from schema B.  However, the definition imported from schema B was
itself imported from schema C.

In this case, the code generated for schema A need not include the
header file for schema B, as it only needs definitions from schema C.

Signed-off-by: Curt Brune <curt@enfabrica.net>
2022-10-14 09:14:31 -07:00
Jason Heeris
024dca615a
Merge pull request #42 from detly/annotations
Two extra annotations: donotinclude and typedefto
2021-05-10 17:43:14 +08:00
Jason Heeris
b619a87c61
Merge pull request #44 from detly/nested_unions
Fix code generation for nested unions.
2021-05-10 17:37:05 +08:00
Alexandre Snarskii
72efa0bb27 Allow field name to be 'p'. 2021-02-01 13:43:04 +03:00
Jason Heeris
6661fc9d2d Fix code generation for nested unions.
When a union is nested inside another union, it must be enclosed in a struct
so that its "which" member is not overlapping with its other members.
2021-01-14 10:43:46 +08:00
Jason Heeris
9153fc39c4 Add an annotation to typedef structs and enums.
A new annotation 'typedefto' allows you to make a typedef in the generated
code for structs and enums (but not union 'which' enums).
2021-01-02 09:28:31 +08:00
Jason Heeris
fe3a57de13 Added extra line break after structure size block. 2021-01-02 09:28:31 +08:00
Jason Heeris
b995a09c03 Add an annotation to skip including header files generated from specific
schema files.

Some schema files (eg. those that only decalare annotations) do not actually
result in any generated C code. They do not need to have a corresponding
include directive for C files generated from schemas that include them. This
introduces a "donotinclude" annotation that takes the Cap'n Proto ID (a
UInt64) of any such files and skips generating the include directive for them.
2021-01-02 09:28:31 +08:00
Jason Heeris
e13c143c99 Fix bug where enums were treated interchangeably with uint16_t.
ANSI C makes no guarantee about the size of an enum, only that it will be the
minimum required integer type that can hold all the given values. Treating
enums as interchangeable with uint16_t data caused undefined behavoiur on
platforms where enums were always at least 32 bits.
2020-12-28 21:46:37 +08:00
Joel Carlson
9053ebe6ee compiler/str.h: include stdarg.h for va_list
With some toolchains, compilation of str.c produced the following error:

compiler/str.h:56:50: error: unknown type name ‘va_list’
 int str_vaddf(struct str *v, const char *format, va_list ap) ATTR(2,0);
                                                  ^~~~~~~

One toolchain had the following in its stdarg.h:
"We deliberately do not define va_list when called from
stdio.h, because ANSI C says that stdio.h is not supposed to
define va_list."

str.c includes stdio.h, but none of the prior includes result in the
inclusion of stdarg.h. Therefore, explicitly include it in str.h to fix
the issue on toolchains following this ANSI C rule.

Signed-off-by: Joel Carlson <JoelsonCarl@gmail.com>
2019-04-22 20:58:49 +01:00
jose luis ferrer
d9240320c1 compiler: Allocate all possible space for constants
When the c-capnp compiler runs, currently only takes the len of 1st
segment in the list as a capacity used in the generator for constants
definitions.

This works when the schema processing only generates 1 segment, or the
1st segment has 8192 bytes. There are cases where the fd returns
multiple segments an the first one has very low capacity (e.g. 96 or 80).
Hence, if more constants require to be allocated for the current schema
it will have misleading positions.

This commit takes a conservative approach by summing up all the lenghts
of capnproto segments obtained at the fd_init call of the compiler.
Those values are taken to set the memory allocation and the max
capacity for the segment utilized in the code generation.
2018-02-01 15:13:18 +01:00
Alexis Ballier
704a34fa65 Use proper format specifiers for size_t. 2017-05-19 19:26:47 +02:00
David Lamparter
aa1f31d401 Silence empty struct warning
Last but not least, -Wpedantic warns about empty structs.  With this,
-Wpedantic build is now clean of warnings on gcc 5.4.0 and clang 4.0.
2017-05-19 09:45:01 +02:00
David Lamparter
b0810da2c3 Silence warning on unused struct parameter
When generating code for an empty struct, the read_/write_ functions
would print warnings about the unused "s" pointer.  Silence these.
2017-05-19 09:40:37 +02:00
David Lamparter
99e9412c02 Silence GCC unnamed union warning
We need the unnamed struct/union support, this is user-facing API.
So, silence the -Wpedantic warning.
2017-05-19 09:35:09 +02:00
Alex Helfet
989acc3414 Most .capnp files use "/c.capnp".fieldgetset. Recompile from schema files. 2017-03-26 23:40:55 +01:00
Alex Helfet
a379aa89ac Compiler generates absolute #include paths from .capnp imports with leading /'s.
As specified in https://capnproto.org/language.html#imports and implemented
in the C++ compiler output plugin.
2017-03-26 18:43:57 +01:00
Alex Helfet
6b52d615a2 Add all .capnp files to make dist archive. 2017-03-26 15:23:35 +01:00
Alex Helfet
362173091d compiler: If an explicit symbol wasn't provided, make generated capn_val%d variables static. 2017-03-23 20:18:29 +00:00
Alex Helfet
f16fae57b3 Fix GCC warnings in initializers for capn_val0 and capn_seg. 2017-03-22 06:48:58 +00:00
David Lamparter
54a7bb7ffb compiler: drop outdated find_node comment & IDs 2016-07-20 08:48:22 +02:00
David Lamparter
c322bc9618 compiler: apply name infix on include filenames
This fixes #include output when $C.nameinfix is used.
2016-07-19 15:21:56 +02:00
David Lamparter
da663f83ef compiler: add annotation to enable field get/set
Generating per-field getters/setters adds a lot of functions; this makes
them switchable with an annotation in the source schema.
2016-07-19 15:21:05 +02:00
David Lamparter
52ca907f14 compiler: add find_node_mayfail(), remove hack
Fixes github issue #11, also makes it easier to use annotations.
2016-07-19 15:14:00 +02:00
David Lamparter
5d787b698e compiler: add "C::nameinfix" annotation
allows changing output filenames from "foo.capnp.c" to
"foo.capnpSOMETHING.c" where SOMETHING is the argument to the
annotation.
2016-06-22 15:16:40 +02:00
David Lamparter
87591da455 Update autogenerated files 2016-06-22 14:24:28 +02:00
David Lamparter
48535d02bd whitespace fixes 2016-06-22 13:44:56 +02:00
Michael Gartsbein
05f5884385 add u to avoid undefined shl 2016-05-05 11:40:13 +03:00
Michael Gartsbein
12ad949df8 working with stricter compiler flags 2016-04-28 12:01:08 +03:00
David Lamparter
e9df12b387 don't write out empty structs
"struct { } foo" is not valid ISO C99; while gcc/clang/icc support it,
other compilers and tools don't (e.g. pycparser)
2016-04-06 14:18:29 -03:00
Michael Gartsbein
61a43a4998 static const instead of function in size getters 2016-03-29 10:25:33 +03:00