mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: process unsafe statements
This commit is contained in:
parent
b1ea908b3b
commit
70f085be18
@ -16,7 +16,7 @@ CastExpr | EnumVal | Assoc | SizeOf | None | MapInit
|
|||||||
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
|
||||||
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
|
||||||
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
|
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
|
||||||
LineComment | MultiLineComment | AssertStmt
|
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
|
||||||
|
|
||||||
pub type Type = StructType | ArrayType
|
pub type Type = StructType | ArrayType
|
||||||
|
|
||||||
@ -421,6 +421,11 @@ pub:
|
|||||||
stmts []Stmt
|
stmts []Stmt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct UnsafeStmt {
|
||||||
|
pub:
|
||||||
|
stmts []Stmt
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AssignExpr {
|
pub struct AssignExpr {
|
||||||
pub:
|
pub:
|
||||||
op token.Kind
|
op token.Kind
|
||||||
|
@ -191,6 +191,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
|
|||||||
ast.StructDecl {
|
ast.StructDecl {
|
||||||
f.struct_decl(it)
|
f.struct_decl(it)
|
||||||
}
|
}
|
||||||
|
ast.UnsafeStmt {
|
||||||
|
f.writeln('unsafe {')
|
||||||
|
f.stmts(it.stmts)
|
||||||
|
f.writeln('}')
|
||||||
|
}
|
||||||
ast.VarDecl {
|
ast.VarDecl {
|
||||||
// type_sym := f.table.get_type_symbol(it.typ)
|
// type_sym := f.table.get_type_symbol(it.typ)
|
||||||
if it.is_mut {
|
if it.is_mut {
|
||||||
|
@ -118,3 +118,9 @@ fn fn_with_assign_stmts() {
|
|||||||
fn fn_with_multi_return() (int, string) {
|
fn fn_with_multi_return() (int, string) {
|
||||||
return 0, 'test'
|
return 0, 'test'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unsafe_fn() {
|
||||||
|
unsafe {
|
||||||
|
malloc(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -123,3 +123,6 @@ fn fn_with_multi_return() (int,string) {
|
|||||||
return 0,'test'
|
return 0,'test'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unsafe_fn() {
|
||||||
|
unsafe { malloc(2) }
|
||||||
|
}
|
||||||
|
@ -291,8 +291,10 @@ pub fn (p mut Parser) stmt() ast.Stmt {
|
|||||||
}
|
}
|
||||||
.key_unsafe {
|
.key_unsafe {
|
||||||
p.next()
|
p.next()
|
||||||
p.parse_block()
|
stmts := p.parse_block()
|
||||||
return ast.Stmt{}
|
return ast.UnsafeStmt{
|
||||||
|
stmts: stmts
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.key_defer {
|
.key_defer {
|
||||||
p.next()
|
p.next()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user