mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: __offsetof keyword for C offsetof() macro
This commit is contained in:
committed by
Alexander Medvednikov
parent
31b7991a93
commit
8512c9fc9d
@@ -227,6 +227,7 @@ fn (p mut Parser) name_expr() string {
|
||||
p.string_expr()
|
||||
return 'charptr'
|
||||
}
|
||||
|
||||
// known_type := p.table.known_type(name)
|
||||
orig_name := name
|
||||
is_c := name == 'C' && p.peek() == .dot
|
||||
@@ -718,6 +719,21 @@ fn (p mut Parser) factor() string {
|
||||
// p.fgen('$sizeof_typ)')
|
||||
return 'int'
|
||||
}
|
||||
.key_offsetof {
|
||||
p.next()
|
||||
p.check(.lpar)
|
||||
|
||||
offsetof_typ := p.get_type()
|
||||
p.check(.comma)
|
||||
|
||||
member := p.check_name()
|
||||
p.check(.rpar)
|
||||
|
||||
p.gen('__offsetof($offsetof_typ, $member)')
|
||||
|
||||
return 'int'
|
||||
}
|
||||
|
||||
.amp, .dot, .mul {
|
||||
// (dot is for enum vals: `.green`)
|
||||
return p.name_expr()
|
||||
|
||||
Reference in New Issue
Block a user