Skip to content

Commit 3d80cf2

Browse files
committed
Fix c.fixincludes not detecting missing, custom headers
1 parent 1933def commit 3d80cf2

File tree

6 files changed

+34
-11
lines changed

6 files changed

+34
-11
lines changed

include/deemon/api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ __pragma_GCC_diagnostic_ignored(Walloc_size_larger_than)
545545
#if (defined(__INTELLISENSE__) || defined(__VASSISTX_INSPECT__)) && defined(__cplusplus)
546546
/* Highlight invalid usage of `NULL' in functions returning `int' */
547547
#undef NULL
548-
#define NULL __NULLPTR
548+
#define NULL __NULLPTR /*!export-*/
549549
#endif /* __INTELLISENSE__ && __cplusplus */
550550

551551
#ifndef Dee_BREAKPOINT

include/deemon/type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
/* To satisfy "fixincludes" (these includes are intentionally missing) */
8282
/*!fixincludes fake_include "alloc.h" // CONFIG_FIXED_ALLOCATOR_S_IS_AUTO, DeeObject_Free, DeeObject_Malloc, DeeSlab_Invoke */
8383
/*!fixincludes fake_include "gc.h" // DeeGCObject_Free, DeeGCObject_Malloc */
84-
/*!fixincludes fake_include "object.h" // DeeAssert_BadObjectType, DeeAssert_BadObjectTypeOpt, DeeObject_Check, Dee_Incref, Dee_buffer */
84+
/*!fixincludes fake_include "object.h" // DeeAssert_BadObjectType, DeeAssert_BadObjectTypeOpt, DeeObject_Check, Dee_Incref */
8585
/*!fixincludes fake_include "string.h" // DeeString_Hash, DeeString_STR */
8686
/*!fixincludes fake_include "tuple.h" // DeeTuple_ELEM, DeeTuple_SIZE */
8787

include/deemon/util/hash.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727

2828
#include "../types.h" /* Dee_hash_t */
2929

30+
#include <stddef.h> /* size_t */
31+
#include <stdint.h> /* uint8_t, uint16_t, uint32_t, uintptr_t */
32+
3033
#ifndef __INTELLISENSE__
3134
#ifdef CONFIG_NO_STRING_H
3235
#undef CONFIG_HAVE_STRING_H

include/deemon/util/weakref.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030

3131
#include "../types.h" /* DREF, DeeObject, Dee_unlockinfo */
3232

33-
#include <stdbool.h>
34-
#include <stddef.h>
33+
#include <stdbool.h> /* bool */
34+
#include <stddef.h> /* NULL, size_t */
35+
#include <stdint.h> /* uintptr_t */
3536

3637
DECL_BEGIN
3738

lib/c/fixincludes.dee

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ local final DEFAULT_HEADERS_BY_INCLUDE: {string: Header} = {
345345
#undef DEFAULT_HEADER
346346
}.frozen;
347347

348+
local final DEFAULT_HEADERS_BY_EXPORT: {string: Set with {Header...}} = (() -> {
349+
local byExport: {string: Set with {Header...}} = Dict();
350+
for (local hdr: DEFAULT_HEADERS_BY_INCLUDE.values) {
351+
for (local export: hdr.exports) {
352+
local exp = byExport.get(export);
353+
if (exp is none)
354+
byExport[export] = exp = HashSet();
355+
exp.insert({hdr});
356+
}
357+
}
358+
return byExport.frozen;
359+
})();
348360

349361
class SrcIncludeInfo {
350362
this = default;
@@ -1475,7 +1487,8 @@ insert_first_include:
14751487
if (combination.any(e -> e.filename == filename))
14761488
goto next_keyword; /* Symbol is defined by the file we're trying to fix -> ignore */
14771489
if (combination.all(e -> (
1478-
(e.filename in includedFilenames)
1490+
(e.filename in includedFilenames) ||
1491+
(e.includes.any(includedSystemIncludes.operator contains))
14791492
))) {
14801493
goto next_keyword; /* Symbol is defined by the file we're trying to fix -> ignore */
14811494
}
@@ -1489,7 +1502,8 @@ insert_first_include:
14891502
for (local hdr: combination) {
14901503
local hdrFilename = hdr.filename;
14911504
if (hdrFilename !in includedFilenames &&
1492-
hdrFilename !in missingByFilename)
1505+
!hdr.includes.any(includedSystemIncludes.operator contains) &&
1506+
(hdr.filename ?? hdr.shortestInclude) !in missingByFilename)
14931507
stillMissingIncludes += 2;
14941508
if (kwd in hdr.exportsFromAlwaysIncludes)
14951509
stillMissingIncludes += 1; /* Discourage this inclusion over the original header */
@@ -1502,10 +1516,10 @@ insert_first_include:
15021516
}
15031517
assert usedCombination !is none;
15041518
for (local hdr: usedCombination) {
1505-
local hdrFilename = hdr.filename;
1506-
local importedKeywords: (Set with string) | none = missingByFilename.get(hdrFilename);
1519+
local hdrIdent = hdr.filename ?? hdr.shortestInclude;
1520+
local importedKeywords: (Set with string) | none = missingByFilename.get(hdrIdent);
15071521
if (importedKeywords is none) {
1508-
missingByFilename[hdrFilename] = importedKeywords = HashSet();
1522+
missingByFilename[hdrIdent] = importedKeywords = HashSet();
15091523
missingHeaders.append(hdr);
15101524
}
15111525
importedKeywords.insert(kwd);
@@ -1514,7 +1528,7 @@ next_keyword:;
15141528
}
15151529
return (
15161530
for (local hdr: missingHeaders)
1517-
(hdr, missingByFilename[hdr.filename])
1531+
(hdr, missingByFilename[hdr.filename ?? hdr.shortestInclude])
15181532
);
15191533
}
15201534

@@ -1980,7 +1994,10 @@ class FixIncludes {
19801994
@@always included by other headers are replace with those other headers
19811995
@@in the returned sequence.
19821996
public function getHeaderByExport(keyword: string): Set with {Header...} {
1983-
return headersByExport.get(keyword, {});
1997+
local result: (Set with {Header...}) | none = headersByExport.get(keyword);
1998+
if (result is none)
1999+
result = DEFAULT_HEADERS_BY_EXPORT.get(keyword, Set());
2000+
return result;
19842001
}
19852002

19862003
@@Return the header specified by @dep and included by @base

src/deemon/runtime/hash-io.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <deemon/types.h> /* Dee_hash_t */
2626
#include <deemon/util/hash-io.h> /* Dee_HASH_HIDXIO_COUNT, Dee_hash_* */
2727

28+
#include <stddef.h> /* NULL */
29+
2830
DECL_BEGIN
2931

3032
/*DFUNDEF WUNUSED NONNULL((1)) Dee_hash_vidx_t DFCALL Dee_hash_gethidx8(union Dee_hash_htab *__restrict htab, Dee_hash_hidx_t index);*/

0 commit comments

Comments
 (0)