Break functionality out of analyzeTypedef
This commit is contained in:
parent
65af9d7f3c
commit
e104da363c
|
@ -49,24 +49,36 @@ func (this *Tree) analyzeTypedef (
|
|||
definition.Type, definition, false)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
// assemble constant map
|
||||
definition, err = this.assembleTypedefConstantMap(definition)
|
||||
// analyze constants
|
||||
err = this.analyzeConstantDeclarations(definition)
|
||||
if err != nil { return nil, err }
|
||||
|
||||
return definition, nil
|
||||
}
|
||||
|
||||
func (this *Tree) analyzeConstantDeclarations (
|
||||
definition *entity.Typedef,
|
||||
) (
|
||||
error,
|
||||
) {
|
||||
// assemble constant map
|
||||
err := this.assembleTypedefConstantMap(definition)
|
||||
if err != nil { return err }
|
||||
|
||||
// analyze constants
|
||||
fillerValue := 0
|
||||
for index, constant := range definition.Constants {
|
||||
constant, err := this.analyzeConstantDeclaration(constant, definition.Type)
|
||||
if err != nil { return nil, err }
|
||||
if err != nil { return err }
|
||||
if constant.Value == nil {
|
||||
if !isNumeric(definition.Type) {
|
||||
return nil, errors.Errorf (
|
||||
return errors.Errorf (
|
||||
constant.Position(),
|
||||
"cannot fill in constant value for non-numeric type %v",
|
||||
definition.Name)
|
||||
}
|
||||
constant.Value = &entity.LiteralInt {
|
||||
Pos: pos,
|
||||
Pos: constant.Position(),
|
||||
Value: fillerValue,
|
||||
Ty: definition.Type,
|
||||
}
|
||||
|
@ -77,8 +89,7 @@ func (this *Tree) analyzeTypedef (
|
|||
definition.ConstantOrder[index] = constant.Name
|
||||
definition.Constants[index] = constant
|
||||
}
|
||||
|
||||
return definition, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *Tree) analyzeConstantDeclaration (
|
||||
|
@ -368,14 +379,13 @@ func (this *Tree) analyzeBehavior (behavior *entity.Signature) (*entity.Signatur
|
|||
func (this *Tree) assembleTypedefConstantMap (
|
||||
typedef *entity.Typedef,
|
||||
) (
|
||||
*entity.Typedef,
|
||||
error,
|
||||
) {
|
||||
typedef.ConstantMap = make(map[string] *entity.ConstantDeclaration)
|
||||
typedef.ConstantOrder = make([]string, len(typedef.Constants))
|
||||
for index, constant := range typedef.Constants {
|
||||
if previous, exists := typedef.ConstantMap[constant.Name]; exists {
|
||||
return nil, errors.Errorf (
|
||||
return errors.Errorf (
|
||||
constant.Position(), "%s already defined at %v",
|
||||
constant.Name, previous.Position())
|
||||
}
|
||||
|
@ -383,5 +393,5 @@ func (this *Tree) assembleTypedefConstantMap (
|
|||
typedef.ConstantOrder[index] = constant.Name
|
||||
typedef.Constants [index] = constant
|
||||
}
|
||||
return typedef, nil
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue