types.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2021 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mk2rbc
  15. import "fmt"
  16. // Starlark expression types we use
  17. type starlarkType int
  18. const (
  19. // Variable types. Initially we only know the types of the product
  20. // configuration variables that are lists, and the types of some
  21. // hardwired variables. The remaining variables are first entered as
  22. // having an unknown type and treated as strings, but sometimes we
  23. // can infer variable's type from the value assigned to it.
  24. starlarkTypeUnknown starlarkType = iota
  25. starlarkTypeList starlarkType = iota
  26. starlarkTypeString starlarkType = iota
  27. starlarkTypeInt starlarkType = iota
  28. starlarkTypeBool starlarkType = iota
  29. starlarkTypeVoid starlarkType = iota
  30. )
  31. func (t starlarkType) String() string {
  32. switch t {
  33. case starlarkTypeList:
  34. return "list"
  35. case starlarkTypeString:
  36. return "string"
  37. case starlarkTypeInt:
  38. return "int"
  39. case starlarkTypeBool:
  40. return "bool"
  41. case starlarkTypeVoid:
  42. return "void"
  43. case starlarkTypeUnknown:
  44. return "unknown"
  45. default:
  46. panic(fmt.Sprintf("Unknown starlark type %d", t))
  47. }
  48. }
  49. type hiddenArgType int
  50. const (
  51. // Some functions have an implicitly emitted first argument, which may be
  52. // a global ('g') or configuration ('cfg') variable.
  53. hiddenArgNone hiddenArgType = iota
  54. hiddenArgGlobal hiddenArgType = iota
  55. hiddenArgConfig hiddenArgType = iota
  56. )
  57. type varClass int
  58. const (
  59. VarClassConfig varClass = iota
  60. VarClassSoong varClass = iota
  61. VarClassLocal varClass = iota
  62. )
  63. type variableRegistrar interface {
  64. NewVariable(name string, varClass varClass, valueType starlarkType)
  65. }
  66. // ScopeBase is a placeholder implementation of the mkparser.Scope.
  67. // All our scopes are read-only and resolve only simple variables.
  68. type ScopeBase struct{}
  69. func (s ScopeBase) Set(_, _ string) {
  70. panic("implement me")
  71. }
  72. func (s ScopeBase) Call(_ string, _ []string) []string {
  73. panic("implement me")
  74. }
  75. func (s ScopeBase) SetFunc(_ string, _ func([]string) []string) {
  76. panic("implement me")
  77. }
  78. // Used to find all makefiles in the source tree
  79. type MakefileFinder interface {
  80. Find(root string) []string
  81. }