compiler: fix building_v

pull/1900/head
Alexander Medvednikov 2019-09-08 17:19:42 +03:00
parent 6dcdb224a1
commit 71224ad17c
2 changed files with 7 additions and 6 deletions

View File

@ -97,6 +97,7 @@ mut:
// You could pass several -cflags XXX arguments. They will be merged with each other. // You could pass several -cflags XXX arguments. They will be merged with each other.
// You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'. // You can also quote several options at the same time: -cflags '-Os -fno-inline-small-functions'.
ccompiler string // the name of the used C compiler ccompiler string // the name of the used C compiler
building_v bool
} }
@ -811,6 +812,7 @@ fn new_v(args[]string) &V {
} }
obfuscate := args.contains('-obf') obfuscate := args.contains('-obf')
is_repl:=args.contains('-repl')
pref := &Preferences { pref := &Preferences {
is_test: is_test is_test: is_test
is_script: is_script is_script: is_script
@ -827,10 +829,12 @@ fn new_v(args[]string) &V {
show_c_cmd: args.contains('-show_c_cmd') show_c_cmd: args.contains('-show_c_cmd')
translated: args.contains('translated') translated: args.contains('translated')
is_run: args.contains('run') is_run: args.contains('run')
is_repl: args.contains('-repl') is_repl: is_repl
build_mode: build_mode build_mode: build_mode
cflags: cflags cflags: cflags
ccompiler: find_c_compiler() ccompiler: find_c_compiler()
building_v: !is_repl && (dir == 'compiler' ||
dir.contains('v/vlib'))
} }
if pref.is_verbose || pref.is_debug { if pref.is_verbose || pref.is_debug {
println('C compiler=$pref.ccompiler') println('C compiler=$pref.ccompiler')

View File

@ -60,7 +60,6 @@ mut:
attr string attr string
v_script bool // "V bash", import all os functions into global space v_script bool // "V bash", import all os functions into global space
var_decl_name string // To allow declaring the variable so that it can be used in the struct initialization var_decl_name string // To allow declaring the variable so that it can be used in the struct initialization
building_v bool
is_alloc bool // Whether current expression resulted in an allocation is_alloc bool // Whether current expression resulted in an allocation
cur_gen_type string // "App" to replace "T" in current generic function cur_gen_type string // "App" to replace "T" in current generic function
is_vweb bool is_vweb bool
@ -106,8 +105,6 @@ fn (v mut V) new_parser(path string) Parser {
pref: v.pref pref: v.pref
os: v.os os: v.os
vroot: v.vroot vroot: v.vroot
building_v: !v.pref.is_repl && (path.contains('compiler/') ||
path.contains('v/vlib'))
} }
@ -243,7 +240,7 @@ fn (p mut Parser) parse(pass Pass) {
p.comp_time() p.comp_time()
case Token.key_global: case Token.key_global:
if !p.pref.translated && !p.pref.is_live && if !p.pref.translated && !p.pref.is_live &&
!p.builtin_mod && !p.building_v && !os.getwd().contains('/volt') { !p.builtin_mod && !p.pref.building_v && !os.getwd().contains('/volt') {
p.error('__global is only allowed in translated code') p.error('__global is only allowed in translated code')
} }
p.next() p.next()
@ -1056,7 +1053,7 @@ fn (p mut Parser) close_scope() {
// println('breaking. "$v.name" v.scope_level=$v.scope_level') // println('breaking. "$v.name" v.scope_level=$v.scope_level')
break break
} }
if p.building_v && v.is_alloc { if p.pref.building_v && v.is_alloc {
if v.typ.starts_with('array_') { if v.typ.starts_with('array_') {
p.genln('v_array_free($v.name); // close_scope free') p.genln('v_array_free($v.name); // close_scope free')
} }