class EnumDecl is partial inherits Container implements IBoxMember, INameSpaceMember # TODO: defaultAccessLevel = 'public' var _attribs as AttributeList var _storageTypeNode as ITypeProxy? var _storageType as IType? var _nativeType as NativeType? var _needScanNativeType as bool cue init(parent as IParentSpace?, token as IToken, idToken as IToken, name as String, isNames as List, attribs as AttributeList, storageTypeNode as ITypeProxy?, docString as String, enumMembers as List) base.init(parent, token, name, isNames, docString) _idToken = idToken _attribs = attribs _storageTypeNode = storageTypeNode for em in enumMembers .addDecl(em) em.enumDecl = this cue init(parent as IParentSpace?, nativeType as NativeType, isNames as List, docString as String?) base.init(parent, TokenFix.empty, nativeType.name, isNames, docString) _idToken = Token.empty _attribs = AttributeList() _nativeType = nativeType assert .compiler .backEnd.setUnderlyingType(this) # sets _storageTypeNode #_storageTypeNode = ClrTypeProxy(Enum.getUnderlyingType((_nativeType to ClrNativeType).backEndType)) # TODO: fix native _needScanNativeType = true def _scanNativeType assert .compiler .backEnd.scanNativeType(this) get attributes as AttributeList is override return _attribs get canDeclNamesDifferOnlyByCase as bool is override return _nativeType is not nil def cobraSourceSignature as String return .idString get defaultAccessLevel as String is override return 'public' get englishName as String is override return 'enumeration type' get idToken from var as IToken def isDescendantOf(type as IType) as bool is override or require .nativeType if .nativeType and not .didBindInh, .bindInh return type is this get isFromBinaryLibrary as bool return _nativeType is not nil get isShared as bool is override return true get isReference as bool is override # enums are not reference types return false pro isUsed as bool get return base.isUsed set base.isUsed = value if _needScanNativeType, _scanNativeType get nativeType from var get typeForIdentifier as IType is override return .compiler.typeType get typeForReceiver as IType is override return this def _bindInt is override base._bindInt for attrib in .attributes, attrib.bindInt if _storageTypeNode _storageType = _storageTypeNode.realType if not _storageType.isDescendantOf(.compiler.anyIntType) .throwError('The enumeration storage type must be a primitive integer type such as int8, uint8, int16, uint16, int, uint, int64 or uint64.') if _needScanNativeType, _scanNativeType def _bindImp is override base._bindImp for attrib in .attributes, attrib.bindImp # the storage type is always a primitive type like `int` so no _bindImp is necessary def extensionMemberFor(box as Box, name as String) as IMember? return nil def mangleName(name as String) as String return name def memberForName(name as String) as IMember? if _needScanNativeType, _scanNativeType m = base.memberForName(name) if m is nil objClass = .compiler.objectType return objClass.memberForName(name) return m def mergedIntoPartialBox(newBox as Box) require newBox is not .parentBox newBox.name == .parentBox.name body _parentBox = newBox class EnumMember is partial inherits NamedNode implements IMember """ Holds the name and (optionally) value of a member of an EnumDecl. """ var _value as int? var _enumDecl as EnumDecl? cue init(token as IToken, value as int?) require token.which=='ID' base.init(token, token.text) _value = value cue init(name as String, value as int) base.init(name) _value = value def addMinFields is override base.addMinFields .addField('value', _value) get attributes as AttributeList return AttributeList() pro enumDecl from var get isCallable as bool return false get isShared as bool return true get englishName as String return 'enumeration value' pro parentNameSpace as NameSpace? get return nil set throw NotSupportedException() get requiresThis as bool # This property probably doesn't make much sense for an enum member which must always # be accessed via its containg enum type. return false get resultType as IType require .enumDecl return _enumDecl to ! get typeForIdentifier as IType is override return _enumDecl to ! get typeForReceiver as IType is override return _enumDecl to ! get value from var def unNilReturnType # TODO: can this be axed when IMember gets broken up? pass