mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: enum
This commit is contained in:
@@ -60,7 +60,6 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||||||
// println('cgen.stmt()')
|
// println('cgen.stmt()')
|
||||||
// g.writeln('//// stmt start')
|
// g.writeln('//// stmt start')
|
||||||
match node {
|
match node {
|
||||||
ast.Import {}
|
|
||||||
ast.ConstDecl {
|
ast.ConstDecl {
|
||||||
for i, field in it.fields {
|
for i, field in it.fields {
|
||||||
field_type_sym := g.table.get_type_symbol(field.typ)
|
field_type_sym := g.table.get_type_symbol(field.typ)
|
||||||
@@ -69,6 +68,14 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||||||
g.writeln(';')
|
g.writeln(';')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ast.EnumDecl {
|
||||||
|
g.writeln('enum $it.name {')
|
||||||
|
for i, val in it.vals {
|
||||||
|
g.writeln('\t${it.name}_$val, // $i')
|
||||||
|
}
|
||||||
|
g.writeln('}')
|
||||||
|
}
|
||||||
|
ast.Import {}
|
||||||
ast.FnDecl {
|
ast.FnDecl {
|
||||||
g.reset_tmp_count()
|
g.reset_tmp_count()
|
||||||
g.fn_decl = it // &it
|
g.fn_decl = it // &it
|
||||||
@@ -194,7 +201,7 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
verror('cgen.stmt(): bad node')
|
verror('cgen.stmt(): unhandled node ' + typeof(node))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ typedef struct {
|
|||||||
int age;
|
int age;
|
||||||
} User;
|
} User;
|
||||||
|
|
||||||
|
enum Color {
|
||||||
|
Color_red, // 0
|
||||||
|
Color_green, // 1
|
||||||
|
Color_blue, // 2
|
||||||
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int a = 10;
|
int a = 10;
|
||||||
a++;
|
a++;
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ struct User {
|
|||||||
age int
|
age int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum Color {
|
||||||
|
red green blue
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct One {
|
struct One {
|
||||||
two Two
|
two Two
|
||||||
|
|||||||
Reference in New Issue
Block a user