cgen: optional fixes; make http compile

pull/4312/head^2
Alexander Medvednikov 2020-04-09 14:03:47 +02:00
parent 9e201e1f93
commit d7ae9d7279
2 changed files with 52 additions and 46 deletions

View File

@ -28,11 +28,11 @@ mut:
pub struct FetchConfig { pub struct FetchConfig {
pub mut: pub mut:
method string method string
data string='' data string
params map[string]string=map[string]string params map[string]string
headers map[string]string=map[string]string headers map[string]string
cookies map[string]string=map[string]string cookies map[string]string
user_agent string='v' user_agent string//='v' QTODO
verbose bool=false verbose bool=false
} }

View File

@ -1858,7 +1858,8 @@ fn (g mut Gen) return_statement(node ast.Return) {
} }
ast.CallExpr { ast.CallExpr {
// TODO: why? // TODO: why?
if !it.is_method { // if !it.is_method {
if it.name == 'error' {
is_error = true // TODO check name 'error' is_error = true // TODO check name 'error'
} }
} }
@ -2564,9 +2565,15 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
// println(var) or println println(str.var) // println(var) or println println(str.var)
expr := node.args[0].expr expr := node.args[0].expr
is_var := match expr { is_var := match expr {
ast.SelectorExpr { true } ast.SelectorExpr {
ast.Ident { true } true
else { false } }
ast.Ident {
true
}
else {
false
}
} }
// `println(int_str(10))` // `println(int_str(10))`
// sym := g.table.get_type_symbol(node.args[0].typ) // sym := g.table.get_type_symbol(node.args[0].typ)
@ -2597,7 +2604,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
g.write('*') g.write('*')
} }
g.expr(expr) g.expr(expr)
if sym.kind ==.struct_ && styp != 'ptr' && !sym.has_method('str') { if sym.kind == .struct_ && styp != 'ptr' && !sym.has_method('str') {
g.write(', 0') // trailing 0 is initial struct indent count g.write(', 0') // trailing 0 is initial struct indent count
} }
} }
@ -3117,7 +3124,6 @@ fn (g mut Gen) gen_str_for_struct(info table.Struct, styp string) {
g.gen_str_for_type(sym, field_styp) g.gen_str_for_type(sym, field_styp)
} }
} }
s := styp.replace('.', '__') s := styp.replace('.', '__')
g.definitions.write('string ${s}_str($styp it, int indent_count) {\n') g.definitions.write('string ${s}_str($styp it, int indent_count) {\n')
// generate ident / indent length = 4 spaces // generate ident / indent length = 4 spaces
@ -3154,7 +3160,7 @@ fn (g mut Gen) gen_str_for_struct(info table.Struct, styp string) {
fn (g Gen) type_to_fmt(typ table.Type) string { fn (g Gen) type_to_fmt(typ table.Type) string {
sym := g.table.get_type_symbol(typ) sym := g.table.get_type_symbol(typ)
if sym.kind == .struct_ { if sym.kind == .struct_ {
return "%.*s" return '%.*s'
} else if typ == table.string_type { } else if typ == table.string_type {
return "\'%.*s\'" return "\'%.*s\'"
} else if typ == table.bool_type { } else if typ == table.bool_type {