v2: time - prefix C struct & ast.TypeName to ast.Type

pull/3929/head
Joe Conigliaro 2020-03-04 01:06:21 +11:00
parent 448ed41562
commit 147ecc5e17
4 changed files with 11 additions and 16 deletions

View File

@ -15,6 +15,6 @@ struct C.tm {
fn C.timegm(&tm) time_t
fn make_unix_time(t tm) int {
fn make_unix_time(t C.tm) int {
return int(C.timegm(&t))
}

View File

@ -12,24 +12,23 @@ pub type Expr = InfixExpr | IfExpr | StringLiteral | IntegerLiteral | CharLitera
FloatLiteral | Ident | CallExpr | BoolLiteral | StructInit | ArrayInit | SelectorExpr | PostfixExpr |
AssignExpr | PrefixExpr | MethodCallExpr | IndexExpr | RangeExpr | MatchExpr |
CastExpr | EnumVal | Assoc | SizeOf | None | MapInit | IfGuardExpr | ParExpr | OrExpr |
ConcatExpr | TypeName | AsCast
ConcatExpr | Type | AsCast
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
// pub type Type = StructType | ArrayType
pub struct StructType {
fields []Field
}
// pub struct StructType {
// fields []Field
// }
pub struct ArrayType {}
// pub struct ArrayType {}
pub struct TypeName {
pub struct Type {
pub:
name string
typ table.Type
}

View File

@ -564,7 +564,7 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
ast.StructInit {
return c.check_struct_init(it)
}
ast.TypeName {
ast.Type {
return it.typ
}
/*

View File

@ -583,9 +583,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
// `map[string]int` initialization
if p.tok.lit == 'map' && p.peek_tok.kind == .lsbr {
map_type := p.parse_map_type()
map_type_sym := p.table.get_type_symbol(map_type)
return ast.TypeName{
name: map_type_sym.name
return ast.Type{
typ: map_type
}
}
@ -1746,9 +1744,7 @@ fn (p mut Parser) match_expr() ast.Expr {
// if sym.kind == .sum_type {
// p.warn('is sum')
typ := p.parse_type()
typ_sym := p.table.get_type_symbol(typ)
match_exprs << ast.TypeName{
name: typ_sym.name
match_exprs << ast.Type{
typ: typ
}
p.scope.register_var(ast.VarDecl{