v2: process unsafe statements

pull/3855/head
Alexey 2020-02-26 22:45:03 +03:00 committed by GitHub
parent b1ea908b3b
commit 70f085be18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 6 deletions

View File

@ -13,10 +13,10 @@ FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | Selecto
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
LineComment | MultiLineComment | AssertStmt
pub type Stmt = VarDecl | GlobalDecl | FnDecl | Return | Module | Import | ExprStmt |
ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt |
HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt |
LineComment | MultiLineComment | AssertStmt | UnsafeStmt
pub type Type = StructType | ArrayType
@ -421,6 +421,11 @@ pub:
stmts []Stmt
}
pub struct UnsafeStmt {
pub:
stmts []Stmt
}
pub struct AssignExpr {
pub:
op token.Kind

View File

@ -191,6 +191,11 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
ast.StructDecl {
f.struct_decl(it)
}
ast.UnsafeStmt {
f.writeln('unsafe {')
f.stmts(it.stmts)
f.writeln('}')
}
ast.VarDecl {
// type_sym := f.table.get_type_symbol(it.typ)
if it.is_mut {

View File

@ -118,3 +118,9 @@ fn fn_with_assign_stmts() {
fn fn_with_multi_return() (int, string) {
return 0, 'test'
}
fn unsafe_fn() {
unsafe {
malloc(2)
}
}

View File

@ -123,3 +123,6 @@ fn fn_with_multi_return() (int,string) {
return 0,'test'
}
fn unsafe_fn() {
unsafe { malloc(2) }
}

View File

@ -291,8 +291,10 @@ pub fn (p mut Parser) stmt() ast.Stmt {
}
.key_unsafe {
p.next()
p.parse_block()
return ast.Stmt{}
stmts := p.parse_block()
return ast.UnsafeStmt{
stmts: stmts
}
}
.key_defer {
p.next()