-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement minimal default name mangling (#331)
This commit changes name mangling so that there are minimal changes by default, not attempting to create Haskell-style names. One significant difference with the previous implementation is that it can now add a prefix if/when the first character is not valid, used to handle leading underscores when creating type constructors. `MkHsName` is removed, replaced by `mkHsNamePrefixInvalid` and `mkHsNameDropInvalid` functions that are now passed to `translateName` like other options. `ctxFieldVarSingleConstr` is removed since constructors now have the same name as types by default, and we do not generate sum types anyway. If we do so in the future, we need to decide how to do name mangling for constructors as well as accessors. `HsBindgen.C.Fold.Type.mkDefnName` is changed to follow the conventions of the new defaults.
- Loading branch information
1 parent
fa2ce3d
commit 69519d3
Showing
54 changed files
with
1,218 additions
and
1,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
DeclData (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1c", structConstr = "MkCS1c", structFields = Field {fieldName = "cS1c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS1c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))})) | ||
DeclData (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS1", structConstr = "MkCS1", structFields = Field {fieldName = "cS1_c", fieldType = HsTypRef "CS1c"} ::: Field {fieldName = "cS1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))})) | ||
DeclData (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 4, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2innerdeep", structConstr = "MkCS2innerdeep", structFields = Field {fieldName = "cS2innerdeep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 1 (Seq [PokeByteOff 2 0 0])))})) | ||
DeclData (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2inner", structConstr = "MkCS2inner", structFields = Field {fieldName = "cS2inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "cS2inner_deep", fieldType = HsTypRef "CS2innerdeep"} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))})) | ||
DeclData (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "CS2", structConstr = "MkCS2", structFields = Field {fieldName = "cS2_inner", fieldType = HsTypRef "CS2inner"} ::: Field {fieldName = "cS2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))})) | ||
DeclData (Struct {structName = "S1_c", structConstr = "S1_c", structFields = Field {fieldName = "s1_c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s1_c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "S1_c", structConstr = "S1_c", structFields = Field {fieldName = "s1_c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s1_c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "S1_c", structConstr = "S1_c", structFields = Field {fieldName = "s1_c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s1_c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "S1_c", structConstr = "S1_c", structFields = Field {fieldName = "s1_c_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s1_c_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))})) | ||
DeclData (Struct {structName = "S1", structConstr = "S1", structFields = Field {fieldName = "s1_c", fieldType = HsTypRef "S1_c"} ::: Field {fieldName = "s1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "S1", structConstr = "S1", structFields = Field {fieldName = "s1_c", fieldType = HsTypRef "S1_c"} ::: Field {fieldName = "s1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "S1", structConstr = "S1", structFields = Field {fieldName = "s1_c", fieldType = HsTypRef "S1_c"} ::: Field {fieldName = "s1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "S1", structConstr = "S1", structFields = Field {fieldName = "s1_c", fieldType = HsTypRef "S1_c"} ::: Field {fieldName = "s1_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))})) | ||
DeclData (Struct {structName = "S2_inner_deep", structConstr = "S2_inner_deep", structFields = Field {fieldName = "s2_inner_deep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "S2_inner_deep", structConstr = "S2_inner_deep", structFields = Field {fieldName = "s2_inner_deep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 4, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "S2_inner_deep", structConstr = "S2_inner_deep", structFields = Field {fieldName = "s2_inner_deep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "S2_inner_deep", structConstr = "S2_inner_deep", structFields = Field {fieldName = "s2_inner_deep_b", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 1 (Seq [PokeByteOff 2 0 0])))})) | ||
DeclData (Struct {structName = "S2_inner", structConstr = "S2_inner", structFields = Field {fieldName = "s2_inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s2_inner_deep", fieldType = HsTypRef "S2_inner_deep"} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "S2_inner", structConstr = "S2_inner", structFields = Field {fieldName = "s2_inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s2_inner_deep", fieldType = HsTypRef "S2_inner_deep"} ::: VNil}) (StorableInstance {storableSizeOf = 8, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "S2_inner", structConstr = "S2_inner", structFields = Field {fieldName = "s2_inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s2_inner_deep", fieldType = HsTypRef "S2_inner_deep"} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 4]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "S2_inner", structConstr = "S2_inner", structFields = Field {fieldName = "s2_inner_a", fieldType = HsPrimType HsPrimCInt} ::: Field {fieldName = "s2_inner_deep", fieldType = HsTypRef "S2_inner_deep"} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 4 1])))})) | ||
DeclData (Struct {structName = "S2", structConstr = "S2", structFields = Field {fieldName = "s2_inner", fieldType = HsTypRef "S2_inner"} ::: Field {fieldName = "s2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) | ||
DeclInstance (InstanceStorable (Struct {structName = "S2", structConstr = "S2", structFields = Field {fieldName = "s2_inner", fieldType = HsTypRef "S2_inner"} ::: Field {fieldName = "s2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) (StorableInstance {storableSizeOf = 12, storableAlignment = 4, storablePeek = Lambda "ptr" (Ap (StructCon (Struct {structName = "S2", structConstr = "S2", structFields = Field {fieldName = "s2_inner", fieldType = HsTypRef "S2_inner"} ::: Field {fieldName = "s2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil})) [PeekByteOff 0 0,PeekByteOff 0 8]), storablePoke = Lambda "ptr" (Lambda "s" (ElimStruct 0 (Struct {structName = "S2", structConstr = "S2", structFields = Field {fieldName = "s2_inner", fieldType = HsTypRef "S2_inner"} ::: Field {fieldName = "s2_d", fieldType = HsPrimType HsPrimCInt} ::: VNil}) 2 (Seq [PokeByteOff 3 0 0,PokeByteOff 3 8 1])))})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
data CS1c = MkCS1c {cS1c_a :: CInt, cS1c_b :: CInt} | ||
instance Storable CS1c | ||
data S1_c = S1_c {s1_c_a :: CInt, s1_c_b :: CInt} | ||
instance Storable S1_c | ||
where {sizeOf = \_ -> 8; | ||
alignment = \_ -> 4; | ||
peek = \ptr_0 -> (pure MkCS1c <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 4; | ||
peek = \ptr_0 -> (pure S1_c <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 4; | ||
poke = \ptr_1 -> \s_2 -> case s_2 of | ||
{MkCS1c cS1c_a_3 | ||
cS1c_b_4 -> pokeByteOff ptr_1 0 cS1c_a_3 >> pokeByteOff ptr_1 4 cS1c_b_4}} | ||
data CS1 = MkCS1 {cS1_c :: CS1c, cS1_d :: CInt} | ||
instance Storable CS1 | ||
{S1_c s1_c_a_3 | ||
s1_c_b_4 -> pokeByteOff ptr_1 0 s1_c_a_3 >> pokeByteOff ptr_1 4 s1_c_b_4}} | ||
data S1 = S1 {s1_c :: S1_c, s1_d :: CInt} | ||
instance Storable S1 | ||
where {sizeOf = \_ -> 12; | ||
alignment = \_ -> 4; | ||
peek = \ptr_0 -> (pure MkCS1 <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 8; | ||
peek = \ptr_0 -> (pure S1 <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 8; | ||
poke = \ptr_1 -> \s_2 -> case s_2 of | ||
{MkCS1 cS1_c_3 | ||
cS1_d_4 -> pokeByteOff ptr_1 0 cS1_c_3 >> pokeByteOff ptr_1 8 cS1_d_4}} | ||
data CS2innerdeep = MkCS2innerdeep {cS2innerdeep_b :: CInt} | ||
instance Storable CS2innerdeep | ||
{S1 s1_c_3 | ||
s1_d_4 -> pokeByteOff ptr_1 0 s1_c_3 >> pokeByteOff ptr_1 8 s1_d_4}} | ||
data S2_inner_deep = S2_inner_deep {s2_inner_deep_b :: CInt} | ||
instance Storable S2_inner_deep | ||
where {sizeOf = \_ -> 4; | ||
alignment = \_ -> 4; | ||
peek = \ptr_0 -> pure MkCS2innerdeep <*> peekByteOff ptr_0 0; | ||
peek = \ptr_0 -> pure S2_inner_deep <*> peekByteOff ptr_0 0; | ||
poke = \ptr_1 -> \s_2 -> case s_2 of | ||
{MkCS2innerdeep cS2innerdeep_b_3 -> pokeByteOff ptr_1 0 cS2innerdeep_b_3}} | ||
data CS2inner | ||
= MkCS2inner {cS2inner_a :: CInt, cS2inner_deep :: CS2innerdeep} | ||
instance Storable CS2inner | ||
{S2_inner_deep s2_inner_deep_b_3 -> pokeByteOff ptr_1 0 s2_inner_deep_b_3}} | ||
data S2_inner | ||
= S2_inner {s2_inner_a :: CInt, s2_inner_deep :: S2_inner_deep} | ||
instance Storable S2_inner | ||
where {sizeOf = \_ -> 8; | ||
alignment = \_ -> 4; | ||
peek = \ptr_0 -> (pure MkCS2inner <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 4; | ||
peek = \ptr_0 -> (pure S2_inner <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 4; | ||
poke = \ptr_1 -> \s_2 -> case s_2 of | ||
{MkCS2inner cS2inner_a_3 | ||
cS2inner_deep_4 -> pokeByteOff ptr_1 0 cS2inner_a_3 >> pokeByteOff ptr_1 4 cS2inner_deep_4}} | ||
data CS2 = MkCS2 {cS2_inner :: CS2inner, cS2_d :: CInt} | ||
instance Storable CS2 | ||
{S2_inner s2_inner_a_3 | ||
s2_inner_deep_4 -> pokeByteOff ptr_1 0 s2_inner_a_3 >> pokeByteOff ptr_1 4 s2_inner_deep_4}} | ||
data S2 = S2 {s2_inner :: S2_inner, s2_d :: CInt} | ||
instance Storable S2 | ||
where {sizeOf = \_ -> 12; | ||
alignment = \_ -> 4; | ||
peek = \ptr_0 -> (pure MkCS2 <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 8; | ||
peek = \ptr_0 -> (pure S2 <*> peekByteOff ptr_0 0) <*> peekByteOff ptr_0 8; | ||
poke = \ptr_1 -> \s_2 -> case s_2 of | ||
{MkCS2 cS2_inner_3 | ||
cS2_d_4 -> pokeByteOff ptr_1 0 cS2_inner_3 >> pokeByteOff ptr_1 8 cS2_d_4}} | ||
{S2 s2_inner_3 | ||
s2_d_4 -> pokeByteOff ptr_1 0 s2_inner_3 >> pokeByteOff ptr_1 8 s2_d_4}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.