Skip to content

Commit 2910847

Browse files
committed
[WIP] golden test
1 parent c2244db commit 2910847

File tree

5 files changed

+47
-3
lines changed

5 files changed

+47
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "duplicate_macro.h"
2+
3+
void f(dup x);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Parsed success because required for scoping.
2+
typedef int dup;
3+
// Parse not attempted.
4+
#define dup dup

hs-bindgen/src-internal/HsBindgen/Frontend/Analysis/DeclIndex.hs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ data DeclIndex = DeclIndex {
104104
}
105105
deriving stock (Show, Generic)
106106

107+
-- TODO_PR: Add conflicts to decl index.
108+
109+
-- TODO_PR: Succeeded, external, unusable.
110+
107111
emptyIndex :: DeclIndex
108112
emptyIndex =
109113
DeclIndex Map.empty Map.empty Map.empty Map.empty Map.empty Set.empty
@@ -115,6 +119,10 @@ emptyIndex =
115119
-- | Construction state (internal type)
116120
data PartialIndex = PartialIndex{
117121
index :: DeclIndex
122+
-- TODO_PR.
123+
-- indexDomain :: Set C.QualPrelimDeclId
124+
-- State `indexDomain = union [succeeded, notAttempted, failed]`
125+
-- conflicts :: Map C.QualPrelimDeclId (Set SingleLoc)
118126
, errors :: !(Map C.QualPrelimDeclId DeclIndexError)
119127
}
120128
deriving (Generic)
@@ -228,17 +236,22 @@ fromParseResults results =
228236
-- for macros; for other kinds of declarations, clang will have
229237
-- reported an error already.
230238
--
231-
-- TODO: there are cases where one declaration is an actual C
239+
-- There are cases where one declaration is an actual C
232240
-- construct like a variable declaration, but the new
233241
-- declaration is a macro of the same name that simply defers to
234242
-- the C construct. This is apparently a valid pattern, which
235243
-- for example occurs in @stdio.h@:
236244
--
237245
-- > typedef int FILE;
238246
-- > extern FILE *const stdin;
239-
-- > #define stdin (stdin)
247+
-- > #define stdin (stdin)
240248
--
241-
-- See issue #1155.
249+
-- Note that in examples like this, we will always "succeed" in
250+
-- parsing the macro, because proper macro handling does not
251+
-- happen until after the @DeclIndex@ has been built (at this
252+
-- point the macro is merely a list of tokens). So whether the
253+
-- macro is something we can handle or not is irrelevant at this
254+
-- point.
242255
failure $ Redeclaration{
243256
redeclarationId = C.declQualPrelimDeclId $ new.psDecl
244257
, redeclarationOld = old.psDecl.declInfo.declLoc
@@ -276,9 +289,12 @@ sameMacro = (==) `on` (map tokenSpelling . unparsedTokens)
276289
Construction errors
277290
-------------------------------------------------------------------------------}
278291

292+
-- TODO_PR: Delete completely or define "ConflictingDeclarations ::
293+
-- (C.QualPrelimDeclId, Set. SingleLoc)" type and reuse in selection.
279294
data DeclIndexError =
280295
Redeclaration {
281296
redeclarationId :: C.QualPrelimDeclId
297+
-- TODO_PR:
282298
, redeclarationOld :: SingleLoc
283299
, redeclarationNew :: SingleLoc
284300
}
@@ -289,12 +305,15 @@ data DeclIndexError =
289305

290306
instance PrettyForTrace DeclIndexError where
291307
prettyForTrace = \case
308+
-- TODO_PR:
292309
Redeclaration{..} -> PP.hcat [
293310
prettyForTrace (C.Located redeclarationOld redeclarationId)
294311
, " was redeclared at "
295312
, PP.showToCtxDoc redeclarationNew
296313
, ". No binding generated."
297314
]
315+
-- TODO_PR: Change wording (probably even use the same trace message
316+
-- type).
298317
SharedKey{..} ->
299318
PP.hang "Duplicate in declaration index detected:" 2 $
300319
prettyForTrace sharedKeyParseResult

hs-bindgen/src-internal/HsBindgen/Frontend/Pass/Select.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Decl = C.Decl Select
5151
-- transitive dependencies are available.
5252
--
5353
-- @TransitiveAvailability@ deals with the second type.
54+
55+
-- TODO_PR: Let's call this transitive usability.
5456
data TransitiveAvailability =
5557
TransitivelyAvailable
5658
-- | For each transitive dependency, we try to give the root cause of

hs-bindgen/test/hs-bindgen/Test/HsBindgen/Golden.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ test_documentation_data_kind_pragma =
205205
test_edge_cases_adios :: TestCase
206206
test_edge_cases_adios = defaultTest "edge-cases/adios"
207207

208+
test_edge_cases_duplicate :: TestCase
209+
test_edge_cases_duplicate = (defaultTest "edge-cases/duplicate") {
210+
testTracePredicate = customTracePredicate' [
211+
"dup"
212+
, "f"
213+
] $ \case
214+
TraceFrontend (FrontendConstructTranslationUnit _) ->
215+
Just $ Expected "dup"
216+
TraceFrontend (FrontendSelect ()) ->
217+
Just $ expectFromQualPrelimDeclId i
218+
_otherwise ->
219+
Nothing
220+
221+
}
222+
208223
test_edge_cases_distilled_lib_1 :: TestCase
209224
test_edge_cases_distilled_lib_1 = defaultTest "edge-cases/distilled_lib_1"
210225

@@ -1034,6 +1049,7 @@ testCases = manualTestCases ++ [
10341049
, test_documentation_data_kind_pragma
10351050
, test_documentation_doxygen_docs
10361051
, test_edge_cases_adios
1052+
, test_edge_cases_duplicate
10371053
, test_edge_cases_distilled_lib_1
10381054
, test_edge_cases_failing_select_no_match
10391055
, test_edge_cases_failing_thread_local

0 commit comments

Comments
 (0)