• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15package mk2rbc
16
17import "fmt"
18
19// Starlark expression types we use
20type starlarkType int
21
22const (
23	// Variable types. Initially we only know the types of the  product
24	// configuration variables that are lists, and the types of some
25	// hardwired variables. The remaining variables are first entered as
26	// having an unknown type and treated as strings, but sometimes we
27	//  can infer variable's type from the value assigned to it.
28	starlarkTypeUnknown starlarkType = iota
29	starlarkTypeList    starlarkType = iota
30	starlarkTypeString  starlarkType = iota
31	starlarkTypeInt     starlarkType = iota
32	starlarkTypeBool    starlarkType = iota
33	starlarkTypeVoid    starlarkType = iota
34)
35
36func (t starlarkType) String() string {
37	switch t {
38	case starlarkTypeList:
39		return "list"
40	case starlarkTypeString:
41		return "string"
42	case starlarkTypeInt:
43		return "int"
44	case starlarkTypeBool:
45		return "bool"
46	case starlarkTypeVoid:
47		return "void"
48	case starlarkTypeUnknown:
49		return "unknown"
50	default:
51		panic(fmt.Sprintf("Unknown starlark type %d", t))
52	}
53}
54
55type hiddenArgType int
56
57const (
58	// Some functions have an implicitly emitted first argument, which may be
59	// a global ('g') or configuration ('cfg') variable.
60	hiddenArgNone   hiddenArgType = iota
61	hiddenArgGlobal hiddenArgType = iota
62	hiddenArgConfig hiddenArgType = iota
63)
64
65type varClass int
66
67const (
68	VarClassConfig varClass = iota
69	VarClassSoong  varClass = iota
70	VarClassLocal  varClass = iota
71)
72
73type variableRegistrar interface {
74	NewVariable(name string, varClass varClass, valueType starlarkType)
75}
76
77// ScopeBase is a placeholder implementation of the mkparser.Scope.
78// All our scopes are read-only and resolve only simple variables.
79type ScopeBase struct{}
80
81func (s ScopeBase) Set(_, _ string) {
82	panic("implement me")
83}
84
85func (s ScopeBase) Call(_ string, _ []string) []string {
86	panic("implement me")
87}
88
89func (s ScopeBase) SetFunc(_ string, _ func([]string) []string) {
90	panic("implement me")
91}
92
93// Used to find all makefiles in the source tree
94type MakefileFinder interface {
95	Find(root string) []string
96}
97