Browse Source

Change the flags from arrays to slices

Leaves the flag no-arrays for backwards compatibility but marks it as deprecated
content-update
Augusto 4 years ago committed by xpetit
parent
commit
02ed96cadf
  1. 14
      go/tests/rc/rc.go
  2. 21
      go/tests/rc/rc_test.go

14
go/tests/rc/rc.go

@ -62,8 +62,9 @@ var (
allowedRep = make(map[string]int)
// Flags
noArrays bool
noSlices bool
noRelativeImports bool
noTheseArrays strBoolMap
noTheseSlices strBoolMap
casting bool
noFor bool
noLit regexpFlag
@ -81,7 +82,7 @@ func (i *illegal) String() string {
}
func init() {
flag.Var(&noTheseArrays, "no-these-arrays", "Disallowes the array types passed in the flag as a list separeted by comma with out spaces\nLike so: -no-these-arrays=int,string,bool")
flag.Var(&noTheseSlices, "no-these-slices", "Disallowes the slice types passed in the flag as a comma-separated list without spaces\nLike so: -no-these-slices=int,string,bool")
flag.Var(&noLit, "no-lit",
`The use of basic literals (strings or characters) matching the pattern -no-lit="{PATTERN}"
passed to the program would not be allowed`,
@ -89,7 +90,8 @@ passed to the program would not be allowed`,
flag.BoolVar(&noRelativeImports, "no-relative-imports", false, `Disallowes the use of relative imports`)
flag.BoolVar(&noFor, "no-for", false, `The "for" instruction is not allowed`)
flag.BoolVar(&casting, "cast", false, "Allowes casting")
flag.BoolVar(&noArrays, "no-arrays", false, "Disallowes all array types")
flag.BoolVar(&noArrays, "no-arrays", false, "Deprecated use no-slices")
flag.BoolVar(&noSlices, "no-slices", false, "Disallowes all slice types")
flag.BoolVar(&allowBuiltin, "allow-builtin", false, "Allowes all builtin functions and casting")
sort.Sort(sort.StringSlice(os.Args[1:]))
}
@ -544,7 +546,7 @@ func analyseProgram(filename, path string, load loadedSource) *info {
}
info.illegals = append(info.illegals, analyseLoops(info.fors, noFor)...)
info.illegals = append(info.illegals, analyseArrayTypes(info.arrays, noArrays, noTheseArrays)...)
info.illegals = append(info.illegals, analyseArrayTypes(info.arrays, noArrays || noSlices, noTheseSlices)...)
info.illegals = append(info.illegals, analyseLits(info.lits, noLit)...)
info.illegals = append(info.illegals, analyseRepetition(info.callRep, allowedRep)...)
info.illegals = removeRepetitions(info.illegals)
@ -694,10 +696,10 @@ func analyseLits(litOccu []*occurrence, noLit regexpFlag) []*illegal {
return illegals
}
func analyseArrayTypes(arrays []*occurrence, noArrays bool, noTheseArrays map[string]bool) []*illegal {
func analyseArrayTypes(arrays []*occurrence, noArrays bool, noTheseSlices map[string]bool) []*illegal {
var illegals []*illegal
for _, v := range arrays {
if noArrays || noTheseArrays[v.name] {
if noArrays || noTheseSlices[v.name] {
il := &illegal{
T: "illegal-slice",
Name: v.name,

21
go/tests/rc/rc_test.go

@ -77,7 +77,26 @@ Cheating:
illegal-slice rune tests/printalphabet/printalphabet.go:9:18
illegal-slice rune tests/printalphabet/printalphabet.go:16:7
`,
"-no-these-arrays=int,rune tests/printalphabet/printalphabet.go": `Parsing:
"-no-slices tests/printalphabet/printalphabet.go": `Parsing:
Ok
Cheating:
TYPE: NAME: LOCATION:
illegal-import fmt tests/printalphabet/printalphabet.go:4:2
illegal-import github.com/01-edu/z01 tests/printalphabet/printalphabet.go:6:2
illegal-call append tests/printalphabet/printalphabet.go:11:7
illegal-definition fillArray tests/printalphabet/printalphabet.go:9:1
illegal-call int tests/printalphabet/printalphabet.go:17:7
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:19:3
illegal-access z01.PrintRune tests/printalphabet/printalphabet.go:21:2
illegal-definition main tests/printalphabet/printalphabet.go:15:1
illegal-access fmt.Println tests/printalphabet/printalphabet.go:26:3
illegal-definition defFun tests/printalphabet/printalphabet.go:25:2
illegal-call defFun tests/printalphabet/printalphabet.go:28:2
illegal-definition testingScope tests/printalphabet/printalphabet.go:24:1
illegal-slice rune tests/printalphabet/printalphabet.go:9:18
illegal-slice rune tests/printalphabet/printalphabet.go:16:7
`,
"-no-these-slices=int,rune tests/printalphabet/printalphabet.go": `Parsing:
Ok
Cheating:
TYPE: NAME: LOCATION:

Loading…
Cancel
Save