Add constants to entity
This commit is contained in:
@@ -622,3 +622,25 @@ func (this *Assignment) HasExplicitType () bool { return false }
|
||||
func (this *Assignment) String () string {
|
||||
return fmt.Sprint(this.Location, "=", this.Value)
|
||||
}
|
||||
|
||||
var _ Expression = &Constant { }
|
||||
// Constant access allows accessing an enumerated constant defined as part of a
|
||||
// type. It can be assigned to a type matching the constant declaration's type.
|
||||
// Since it contains inherent type information, it may be directly assigned to
|
||||
// an interface.
|
||||
type Constant struct {
|
||||
// Syntax
|
||||
Pos errors.Position
|
||||
TypeName string
|
||||
Name string
|
||||
|
||||
// Semantics
|
||||
Ty Type
|
||||
}
|
||||
func (*Constant) expression(){}
|
||||
func (this *Constant) Position () errors.Position { return this.Pos }
|
||||
func (this *Constant) Type () Type { return this.Ty }
|
||||
func (this *Constant) HasExplicitType () bool { return true }
|
||||
func (this *Constant) String () string {
|
||||
return fmt.Sprint(this.TypeName, ".", this.Name)
|
||||
}
|
||||
|
||||
@@ -252,3 +252,19 @@ func Quote (in string) string {
|
||||
}
|
||||
return out + "'"
|
||||
}
|
||||
|
||||
// ConstantDeclaration declares an enumerated constant as part of a Typedef.
|
||||
type ConstantDeclaration struct {
|
||||
// Syntax
|
||||
Pos errors.Position
|
||||
Name string
|
||||
Value Expression
|
||||
|
||||
// Semantics
|
||||
Ty Type
|
||||
}
|
||||
func (this *ConstantDeclaration) Position () errors.Position { return this.Pos }
|
||||
func (this *ConstantDeclaration) Type () Type { return this.Ty }
|
||||
func (this *ConstantDeclaration) String () string {
|
||||
return fmt.Sprint("| ", this.Name, " ", this.Value)
|
||||
}
|
||||
|
||||
+11
-6
@@ -24,14 +24,16 @@ var _ TopLevel = &Typedef { }
|
||||
// Typedef binds a type to a global identifier.
|
||||
type Typedef struct {
|
||||
// Syntax
|
||||
Pos errors.Position
|
||||
Acc Access
|
||||
Name string
|
||||
Type Type
|
||||
Pos errors.Position
|
||||
Acc Access
|
||||
Name string
|
||||
Type Type
|
||||
Constants []*ConstantDeclaration
|
||||
|
||||
// Semantics
|
||||
Unt uuid.UUID
|
||||
Methods map[string] *Method
|
||||
Unt uuid.UUID
|
||||
Methods map[string] *Method
|
||||
ConstantsMap map[string] *ConstantDeclaration
|
||||
}
|
||||
func (*Typedef) topLevel(){}
|
||||
func (this *Typedef) Position () errors.Position { return this.Pos }
|
||||
@@ -41,6 +43,9 @@ func (this *Typedef) String () string {
|
||||
output := ""
|
||||
output += fmt.Sprint(this.Acc, " ")
|
||||
output += fmt.Sprint(this.Name, ": ", this.Type)
|
||||
for _, constant := range this.Constants {
|
||||
output += fmt.Sprint("\n", constant)
|
||||
}
|
||||
if this.Methods != nil {
|
||||
for _, method := range this.Methods {
|
||||
output += fmt.Sprint("\n", method)
|
||||
|
||||
Reference in New Issue
Block a user