mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
public enums + more public structs (libs/examples/tests)
This commit is contained in:
parent
1a2db54bc1
commit
3d6bdc2dc3
@ -6,6 +6,12 @@ module compiler
|
||||
|
||||
fn (p mut Parser) enum_decl(_enum_name string) {
|
||||
mut enum_name := _enum_name
|
||||
is_pub := p.tok == .key_pub
|
||||
if is_pub {
|
||||
p.next()
|
||||
p.check(.key_enum)
|
||||
enum_name = p.check_name()
|
||||
}
|
||||
// Specify full type name
|
||||
if !p.builtin_mod && p.mod != 'main' {
|
||||
enum_name = p.prepend_mod(enum_name)
|
||||
@ -49,6 +55,7 @@ fn (p mut Parser) enum_decl(_enum_name string) {
|
||||
parent: 'int'
|
||||
cat: TypeCategory.enum_
|
||||
enum_vals: fields.clone()
|
||||
is_public: is_pub
|
||||
})
|
||||
p.check(.rcbr)
|
||||
p.fgenln('\n')
|
||||
|
@ -320,10 +320,12 @@ fn (p mut Parser) parse(pass Pass) {
|
||||
p.fgen(' ')
|
||||
p.enum_decl(name)
|
||||
}
|
||||
// enum without a name, only allowed in code, translated from C
|
||||
// it's a very bad practice in C as well, but is used unfortunately (for example, by DOOM)
|
||||
// such fields are basically int consts
|
||||
else if p.pref.translated {
|
||||
// enum without a name, only allowed in code,
|
||||
// translated from C. it's a very bad practice
|
||||
// in C as well, but is used unfortunately
|
||||
// (for example, by DOOM). such fields are
|
||||
// basically int consts
|
||||
p.enum_decl('int')
|
||||
}
|
||||
else {
|
||||
@ -335,6 +337,7 @@ fn (p mut Parser) parse(pass Pass) {
|
||||
.key_fn { p.fn_decl() }
|
||||
.key_const { p.const_decl() }
|
||||
.key_struct { p.struct_decl() }
|
||||
.key_enum { p.enum_decl('') }
|
||||
else {
|
||||
p.error('wrong pub keyword usage')
|
||||
}
|
||||
@ -1101,7 +1104,7 @@ fn (p mut Parser) get_type() string {
|
||||
}
|
||||
}
|
||||
else if !t.is_public && t.mod != p.mod && t.name != '' {
|
||||
p.warn('type `$t.name` is private')
|
||||
p.error('type `$t.name` is private')
|
||||
}
|
||||
}
|
||||
if typ == 'void' {
|
||||
|
@ -1,6 +1,6 @@
|
||||
module crypto
|
||||
|
||||
enum Hash {
|
||||
pub enum Hash {
|
||||
MD4
|
||||
MD5
|
||||
SHA1
|
||||
|
@ -10,7 +10,7 @@ import glm
|
||||
|
||||
// import darwin
|
||||
|
||||
struct Shader {
|
||||
pub struct Shader {
|
||||
program_id int
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ module gl
|
||||
#flag @VROOT/thirdparty/glad/glad.o
|
||||
|
||||
// joe-c: fix & remove
|
||||
enum TmpGlImportHack{}
|
||||
pub enum TmpGlImportHack{}
|
||||
|
||||
pub fn init_glad() {
|
||||
ok := C.gladLoadGL()
|
||||
|
@ -4,14 +4,14 @@
|
||||
|
||||
module gx
|
||||
|
||||
struct Color {
|
||||
pub struct Color {
|
||||
pub:
|
||||
r int
|
||||
g int
|
||||
b int
|
||||
}
|
||||
|
||||
const (
|
||||
pub const (
|
||||
// Primary colors
|
||||
Blue = Color { r: 0, g: 0, b: 255 }
|
||||
Red = Color { r: 255, g: 0, b: 0 }
|
||||
|
@ -305,7 +305,7 @@ fn escape(s string, mode EncodingMode) string {
|
||||
//
|
||||
// URL's String method uses the escaped_path method to obtain the path. See the
|
||||
// escaped_path method for more details.
|
||||
struct URL {
|
||||
pub struct URL {
|
||||
pub: mut:
|
||||
scheme string
|
||||
opaque string // encoded opaque data
|
||||
|
@ -5,7 +5,7 @@
|
||||
module sync
|
||||
|
||||
#include <pthread.h>
|
||||
struct Mutex {
|
||||
pub struct Mutex {
|
||||
mutex C.pthread_mutex_t
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ module sync
|
||||
// Mutex HANDLE
|
||||
type MHANDLE voidptr
|
||||
|
||||
struct Mutex {
|
||||
pub struct Mutex {
|
||||
mut:
|
||||
mx MHANDLE // mutex handle
|
||||
state MutexState // mutex state
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
module sync
|
||||
|
||||
struct WaitGroup {
|
||||
pub struct WaitGroup {
|
||||
mut:
|
||||
mu Mutex
|
||||
active int
|
||||
|
Loading…
Reference in New Issue
Block a user