A stack property can refer to other stack types. For example: properties: gateway: type: aws/ec2/internetGateway ... In such cases, we need to validate the property during binding, in addition to binding it to an actual type so that we can later validate callers who are constructing instances of this stack and providing property values that we must typecheck. Note that this binding is subtly different than existing stack type binding. All the name validation, resolution, and so forth are the same. However, notice that in this case we are not actually supplying any property setters. That is, internetGateway is not an "expanded" type, in that we have not processed any of its templates. An analogy might help: this is sort of akin referring to an uninstantiated generic type in a traditional programming language, versus its instantiated form. In this case, certain properties aren't available to us, however we can still use it for type identity, etc.
36 lines
985 B
Go
36 lines
985 B
Go
// Copyright 2016 Marapongo, Inc. All rights reserved.
|
|
|
|
package compiler
|
|
|
|
import (
|
|
"github.com/marapongo/mu/pkg/ast"
|
|
)
|
|
|
|
// Symbol is a named entity that can be referenced and bound to.
|
|
type Symbol struct {
|
|
Kind SymbolKind // the kind of symbol.
|
|
Name ast.Name // the symbol's unique name.
|
|
Node *ast.Node // the Node part of the payload data structure.
|
|
Real interface{} // the real part of the payload (i.e., the whole structure).
|
|
}
|
|
|
|
// SymbolKind indicates the kind of symbol being registered (e.g., Stack, Service, etc).
|
|
type SymbolKind int
|
|
|
|
const (
|
|
SymKindService SymbolKind = iota
|
|
SymKindStack
|
|
SymKindStackRef
|
|
)
|
|
|
|
func NewServiceSymbol(nm ast.Name, svc *ast.Service) *Symbol {
|
|
return &Symbol{SymKindService, nm, &svc.Node, svc}
|
|
}
|
|
|
|
func NewStackSymbol(nm ast.Name, stack *ast.Stack) *Symbol {
|
|
return &Symbol{SymKindStack, nm, &stack.Node, stack}
|
|
}
|
|
|
|
func NewStackRefSymbol(nm ast.Name, ref *ast.StackRef) *Symbol {
|
|
return &Symbol{SymKindStackRef, nm, &ref.Node, ref}
|
|
}
|