Skip to content

Commit

Permalink
Don't change C codename when importing primitive C types
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Dec 4, 2020
1 parent 12eff3c commit 4e2868c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
5 changes: 4 additions & 1 deletion nelua/analyzer.lua
Expand Up @@ -424,7 +424,10 @@ function visitors.Annotation(context, node, symbol)
codename = symbol.name
end
if objattr._type then
objattr:set_codename(codename)
-- changing codename only on non primitives
if not objattr.is_primitive then
objattr:set_codename(codename)
end
else
objattr.codename = codename
end
Expand Down
4 changes: 4 additions & 0 deletions nelua/typedefs.lua
Expand Up @@ -79,6 +79,10 @@ primtypes.stringview = types.StringViewType('stringview')
primtypes.any = types.AnyType('any', 2*cpusize)
primtypes.varanys = types.VaranysType('varanys')

for _,type in pairs(primtypes) do
type.is_primitive = true
end

-- Map of literal suffixes for arithmetic types.
typedefs.number_literal_types = {
_i = 'integer', _integer = 'integer',
Expand Down
15 changes: 0 additions & 15 deletions nelua/types.lua
Expand Up @@ -569,7 +569,6 @@ VoidType.nodecl = true
VoidType.is_nolvalue = true
VoidType.is_comptime = true
VoidType.is_void = true
VoidType.is_primitive = true

function VoidType:_init(name)
Type._init(self, name, 0)
Expand All @@ -588,7 +587,6 @@ AutoType.is_auto = true
AutoType.nodecl = true
AutoType.is_comptime = true
AutoType.is_nilable = true
AutoType.is_primitive = true
AutoType.is_unpointable = true
AutoType.is_polymorphic = true

Expand All @@ -614,7 +612,6 @@ TypeType.is_comptime = true
TypeType.nodecl = true
TypeType.is_unpointable = true
TypeType.is_polymorphic = true
TypeType.is_primitive = true

function TypeType:_init(name)
Type._init(self, name, 0)
Expand All @@ -639,7 +636,6 @@ local NiltypeType = types.typeclass()
types.NiltypeType = NiltypeType
NiltypeType.is_niltype = true
NiltypeType.is_nilable = true
NiltypeType.is_primitive = true
NiltypeType.is_unpointable = true

function NiltypeType:_init(name)
Expand All @@ -660,7 +656,6 @@ local NilptrType = types.typeclass()
types.NilptrType = NilptrType
NilptrType.is_nolvalue = true
NilptrType.is_nilptr = true
NilptrType.is_primitive = true
NilptrType.is_unpointable = true

function NilptrType:_init(name, size)
Expand Down Expand Up @@ -689,7 +684,6 @@ end
local BooleanType = types.typeclass()
types.BooleanType = BooleanType
BooleanType.is_boolean = true
BooleanType.is_primitive = true

function BooleanType:_init(name, size)
Type._init(self, name, size)
Expand Down Expand Up @@ -719,7 +713,6 @@ local AnyType = types.typeclass()
types.AnyType = AnyType
AnyType.is_any = true
AnyType.is_nilable = true
AnyType.is_primitive = true

function AnyType:_init(name, size)
Type._init(self, name, size)
Expand All @@ -745,7 +738,6 @@ types.VaranysType = VaranysType
VaranysType.is_varanys = true
VaranysType.is_varargs = true
VaranysType.is_nolvalue = true
VaranysType.is_primitive = true

function VaranysType:_init(name, size)
Type._init(self, name, size)
Expand All @@ -762,7 +754,6 @@ types.CVarargsType = CVarargsType
CVarargsType.is_cvarargs = true
CVarargsType.is_varargs = true
CVarargsType.is_nolvalue = true
CVarargsType.is_primitive = true

function CVarargsType:_init(name, size)
Type._init(self, name, size)
Expand All @@ -778,7 +769,6 @@ end
local ArithmeticType = types.typeclass()
types.ArithmeticType = ArithmeticType
ArithmeticType.is_arithmetic = true
ArithmeticType.is_primitive = true
ArithmeticType.get_convertible_from_type = Type.get_convertible_from_type

function ArithmeticType:_init(name, size)
Expand Down Expand Up @@ -1349,7 +1339,6 @@ end)

local TableType = types.typeclass()
types.TableType = TableType
TableType.is_primitive = true
TableType.is_table = true

function TableType:_init(name)
Expand Down Expand Up @@ -1439,7 +1428,6 @@ end
local EnumType = types.typeclass(IntegralType)
types.EnumType = EnumType
EnumType.is_enum = true
EnumType.is_primitive = false -- to allow using custom nicknames

EnumType.shape = shaper.fork_shape(IntegralType.shape, {
-- Fixed length for the array.
Expand Down Expand Up @@ -2026,14 +2014,12 @@ function PointerType:_init(subtype)
self.nickname = 'pointer'
self.codename = 'nlpointer'
self.is_generic_pointer = true
self.is_primitive = true
elseif subtype.name == 'cchar' then -- cstring
self.nodecl = true
self.nickname = 'cstring'
self.codename = 'nlcstring'
self.is_cstring = true
self.is_stringy = true
self.is_primitive = true
else
self.codename = subtype.codename .. '_ptr'
end
Expand Down Expand Up @@ -2182,7 +2168,6 @@ local StringViewType = types.typeclass(RecordType)
types.StringViewType = StringViewType
StringViewType.is_stringview = true
StringViewType.is_stringy = true
StringViewType.is_primitive = true

function StringViewType:_init(name)
self.codename = 'nlstringview'
Expand Down

0 comments on commit 4e2868c

Please sign in to comment.