mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
map: allow array values
This commit is contained in:
@ -67,8 +67,8 @@ pub fn(graph mut ModDepGraph) add(mod string, deps []string) {
|
||||
}
|
||||
|
||||
pub fn(graph &ModDepGraph) resolve() *ModDepGraph {
|
||||
mut node_names := map[string]ModDepGraphNode{}
|
||||
mut node_deps := map[string]DepSet{}
|
||||
mut node_names := map[string]ModDepGraphNode
|
||||
mut node_deps := map[string]DepSet
|
||||
|
||||
for _, node in graph.nodes {
|
||||
node_names[node.name] = node
|
||||
|
@ -883,8 +883,8 @@ fn (p mut Parser) get_type() string {
|
||||
p.error('maps only support string keys for now')
|
||||
}
|
||||
p.check(.rsbr)
|
||||
val_type := p.check_name()
|
||||
typ= 'map_$val_type'
|
||||
val_type := p.get_type()// p.check_name()
|
||||
typ = 'map_$val_type'
|
||||
p.register_map(typ)
|
||||
return typ
|
||||
}
|
||||
@ -2603,15 +2603,19 @@ fn (p mut Parser) map_init() string {
|
||||
p.error('only string key maps allowed for now')
|
||||
}
|
||||
p.check(.rsbr)
|
||||
val_type = p.check_name()
|
||||
if !p.table.known_type(val_type) {
|
||||
p.error('map init unknown type "$val_type"')
|
||||
}
|
||||
val_type = p.get_type()/// p.check_name()
|
||||
//if !p.table.known_type(val_type) {
|
||||
//p.error('map init unknown type "$val_type"')
|
||||
//}
|
||||
typ := 'map_$val_type'
|
||||
p.register_map(typ)
|
||||
p.gen('new_map(1, sizeof($val_type))')
|
||||
p.check(.lcbr)
|
||||
p.check(.rcbr)
|
||||
if p.tok == .lcbr {
|
||||
p.check(.lcbr)
|
||||
p.check(.rcbr)
|
||||
println('warning: $p.file_name:$p.scanner.line_nr ' +
|
||||
'initializaing maps no longer requires `{}`')
|
||||
}
|
||||
return typ
|
||||
}
|
||||
|
||||
|
@ -137,8 +137,8 @@ fn is_primitive_type(typ string) bool {
|
||||
|
||||
fn new_table(obfuscate bool) *Table {
|
||||
mut t := &Table {
|
||||
obf_ids: map[string]int{}
|
||||
fns: map[string]Fn{}
|
||||
obf_ids: map[string]int
|
||||
fns: map[string]Fn
|
||||
//generic_fns: map[string]GenTable{}
|
||||
generic_fns: []GenTable
|
||||
obfuscate: obfuscate
|
||||
@ -818,7 +818,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string {
|
||||
fn new_file_import_table(file_path string) *FileImportTable {
|
||||
return &FileImportTable{
|
||||
file_path: file_path
|
||||
imports: map[string]string{}
|
||||
imports: map[string]string
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ enum Token {
|
||||
// build_keys genereates a map with keywords' string values:
|
||||
// Keywords['return'] == .key_return
|
||||
fn build_keys() map[string]int {
|
||||
mut res := map[string]int{}
|
||||
mut res := map[string]int
|
||||
for t := int(Token.keyword_beg) + 1; t < int(Token.keyword_end); t++ {
|
||||
key := TokenStr[t]
|
||||
res[key] = int(t)
|
||||
@ -127,11 +127,11 @@ fn build_token_str() []string {
|
||||
mut s := [''; NrTokens]
|
||||
s[Token.keyword_beg] = ''
|
||||
s[Token.keyword_end] = ''
|
||||
s[Token.eof] = '.eof'
|
||||
s[Token.name] = '.name'
|
||||
s[Token.number] = '.number'
|
||||
s[Token.eof] = 'eof'
|
||||
s[Token.name] = 'name'
|
||||
s[Token.number] = 'number'
|
||||
s[Token.str] = 'STR'
|
||||
s[Token.chartoken] = '.chartoken'
|
||||
s[Token.chartoken] = 'char'
|
||||
s[Token.plus] = '+'
|
||||
s[Token.minus] = '-'
|
||||
s[Token.mul] = '*'
|
||||
@ -198,7 +198,6 @@ fn build_token_str() []string {
|
||||
s[Token.key_type] = 'type'
|
||||
s[Token.key_for] = 'for'
|
||||
s[Token.key_switch] = 'switch'
|
||||
//Tokens[MATCH] = 'match'
|
||||
s[Token.key_case] = 'case'
|
||||
s[Token.func] = 'fn'
|
||||
s[Token.key_true] = 'true'
|
||||
@ -207,7 +206,7 @@ fn build_token_str() []string {
|
||||
s[Token.key_break] = 'break'
|
||||
s[Token.key_import] = 'import'
|
||||
s[Token.key_embed] = 'embed'
|
||||
//Tokens[TYP.eof] = 'typeof'
|
||||
//Tokens[key_typeof] = 'typeof'
|
||||
s[Token.key_default] = 'default'
|
||||
s[Token.key_enum] = 'enum'
|
||||
s[Token.key_interface] = 'interface'
|
||||
|
Reference in New Issue
Block a user