Bug 1298756 - Use uint8_t/uint16_t as underlying type for enums from webidl. r=bz

MozReview-Commit-ID: 3uS9s5ZrPFd

--HG--
extra : rebase_source : ff64b4468ee99ba08fd8638298a27711b7fb6393
This commit is contained in:
Xidorn Quan 2017-01-12 12:23:37 +11:00
Родитель cea9ab4dfb
Коммит a8e64a94e1
14 изменённых файлов: 31 добавлений и 25 удалений

Просмотреть файл

@ -48,8 +48,8 @@ class GlobalObject;
class OwningElementOrCSSPseudoElement; class OwningElementOrCSSPseudoElement;
class UnrestrictedDoubleOrKeyframeAnimationOptions; class UnrestrictedDoubleOrKeyframeAnimationOptions;
class UnrestrictedDoubleOrKeyframeEffectOptions; class UnrestrictedDoubleOrKeyframeEffectOptions;
enum class IterationCompositeOperation : uint32_t; enum class IterationCompositeOperation : uint8_t;
enum class CompositeOperation : uint32_t; enum class CompositeOperation : uint8_t;
struct AnimationPropertyDetails; struct AnimationPropertyDetails;
} }

Просмотреть файл

@ -115,7 +115,7 @@ class DocGroup;
class External; class External;
class Function; class Function;
class Gamepad; class Gamepad;
enum class ImageBitmapFormat : uint32_t; enum class ImageBitmapFormat : uint8_t;
class IdleRequest; class IdleRequest;
class IdleRequestCallback; class IdleRequestCallback;
class Location; class Location;

Просмотреть файл

@ -149,7 +149,7 @@ class MediaQueryList;
class GlobalObject; class GlobalObject;
class NodeFilter; class NodeFilter;
class NodeIterator; class NodeIterator;
enum class OrientationType : uint32_t; enum class OrientationType : uint8_t;
class ProcessingInstruction; class ProcessingInstruction;
class Promise; class Promise;
class StyleSheetList; class StyleSheetList;
@ -3037,9 +3037,10 @@ protected:
#ifdef MOZILLA_INTERNAL_API #ifdef MOZILLA_INTERNAL_API
// Our visibility state // Our visibility state
mozilla::dom::VisibilityState mVisibilityState; mozilla::dom::VisibilityState mVisibilityState;
static_assert(sizeof(mozilla::dom::VisibilityState) == sizeof(uint32_t), "Error size of mVisibilityState and mDummy"); static_assert(sizeof(mozilla::dom::VisibilityState) == sizeof(uint8_t),
"Error size of mVisibilityState and mDummy");
#else #else
uint32_t mDummy; uint8_t mDummy;
#endif #endif
// True if BIDI is enabled. // True if BIDI is enabled.

Просмотреть файл

@ -9625,15 +9625,25 @@ class CGEnum(CGThing):
def nEnumStrings(self): def nEnumStrings(self):
return len(self.enum.values()) + 1 return len(self.enum.values()) + 1
def underlyingType(self):
count = self.nEnumStrings()
if count <= 256:
return "uint8_t"
if count <= 65536:
return "uint16_t"
raise ValueError("Enum " + self.enum.identifier.name +
" has more than 65536 values")
def declare(self): def declare(self):
decl = fill( decl = fill(
""" """
enum class ${name} : uint32_t { enum class ${name} : ${ty} {
$*{enums} $*{enums}
EndGuard_ EndGuard_
}; };
""", """,
name=self.enum.identifier.name, name=self.enum.identifier.name,
ty=self.underlyingType(),
enums=",\n".join(map(getEnumValueName, self.enum.values())) + ",\n") enums=",\n".join(map(getEnumValueName, self.enum.values())) + ",\n")
strings = CGNamespace(self.stringsNamespace(), strings = CGNamespace(self.stringsNamespace(),
CGGeneric(declare="extern const EnumEntry %s[%d];\n" CGGeneric(declare="extern const EnumEntry %s[%d];\n"

2
dom/cache/CacheStorage.h поставляемый
Просмотреть файл

@ -28,7 +28,7 @@ namespace ipc {
namespace dom { namespace dom {
enum class CacheStorageNamespace : uint32_t; enum class CacheStorageNamespace : uint8_t;
class Promise; class Promise;
namespace workers { namespace workers {

Просмотреть файл

@ -15,7 +15,7 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
enum class CanvasWindingRule : uint32_t; enum class CanvasWindingRule : uint8_t;
class SVGMatrix; class SVGMatrix;
class CanvasPath final : class CanvasPath final :

Просмотреть файл

@ -52,7 +52,7 @@ class File;
class HTMLCanvasElement; class HTMLCanvasElement;
class HTMLImageElement; class HTMLImageElement;
class HTMLVideoElement; class HTMLVideoElement;
enum class ImageBitmapFormat : uint32_t; enum class ImageBitmapFormat : uint8_t;
class ImageData; class ImageData;
class ImageUtils; class ImageUtils;
template<typename T> class MapDataIntoBufferSource; template<typename T> class MapDataIntoBufferSource;

Просмотреть файл

@ -21,7 +21,7 @@ class ErrorResult;
namespace dom { namespace dom {
struct ChannelPixelLayout; struct ChannelPixelLayout;
enum class ImageBitmapFormat : uint32_t; enum class ImageBitmapFormat : uint8_t;
typedef nsTArray<ChannelPixelLayout> ImagePixelLayout; typedef nsTArray<ChannelPixelLayout> ImagePixelLayout;

Просмотреть файл

@ -22,8 +22,8 @@ struct BrowserElementDownloadOptions;
struct BrowserElementExecuteScriptOptions; struct BrowserElementExecuteScriptOptions;
class BrowserElementNextPaintEventCallback; class BrowserElementNextPaintEventCallback;
class DOMRequest; class DOMRequest;
enum class BrowserFindCaseSensitivity: uint32_t; enum class BrowserFindCaseSensitivity: uint8_t;
enum class BrowserFindDirection: uint32_t; enum class BrowserFindDirection: uint8_t;
} // namespace dom } // namespace dom
class ErrorResult; class ErrorResult;

Просмотреть файл

@ -42,7 +42,7 @@ class AudioNodeStream;
namespace dom { namespace dom {
enum class AudioContextState : uint32_t; enum class AudioContextState : uint8_t;
class AnalyserNode; class AnalyserNode;
class AudioBuffer; class AudioBuffer;
class AudioBufferSourceNode; class AudioBufferSourceNode;
@ -71,7 +71,7 @@ class WaveShaperNode;
class PeriodicWave; class PeriodicWave;
struct PeriodicWaveConstraints; struct PeriodicWaveConstraints;
class Promise; class Promise;
enum class OscillatorType : uint32_t; enum class OscillatorType : uint8_t;
// This is addrefed by the OscillatorNodeEngine on the main thread // This is addrefed by the OscillatorNodeEngine on the main thread
// and then used from the MSG thread. // and then used from the MSG thread.

Просмотреть файл

@ -350,11 +350,6 @@ AudioNodeStream::SetChannelMixingParametersImpl(uint32_t aNumberOfChannels,
ChannelCountMode aChannelCountMode, ChannelCountMode aChannelCountMode,
ChannelInterpretation aChannelInterpretation) ChannelInterpretation aChannelInterpretation)
{ {
// Make sure that we're not clobbering any significant bits by fitting these
// values in 16 bits.
MOZ_ASSERT(int(aChannelCountMode) < INT16_MAX);
MOZ_ASSERT(int(aChannelInterpretation) < INT16_MAX);
mNumberOfInputChannels = aNumberOfChannels; mNumberOfInputChannels = aNumberOfChannels;
mChannelCountMode = aChannelCountMode; mChannelCountMode = aChannelCountMode;
mChannelInterpretation = aChannelInterpretation; mChannelInterpretation = aChannelInterpretation;

Просмотреть файл

@ -23,7 +23,7 @@ class Console;
class Crypto; class Crypto;
class Function; class Function;
class IDBFactory; class IDBFactory;
enum class ImageBitmapFormat : uint32_t; enum class ImageBitmapFormat : uint8_t;
class Performance; class Performance;
class Promise; class Promise;
class RequestOrUSVString; class RequestOrUSVString;

Просмотреть файл

@ -21,8 +21,8 @@ namespace layers {
class PTextureParent; class PTextureParent;
} }
namespace dom { namespace dom {
enum class GamepadMappingType : uint32_t; enum class GamepadMappingType : uint8_t;
enum class GamepadHand : uint32_t; enum class GamepadHand : uint8_t;
struct GamepadPoseState; struct GamepadPoseState;
} }
namespace gfx { namespace gfx {

Просмотреть файл

@ -314,8 +314,8 @@ enum class StyleOrient : uint8_t {
// See AnimationEffectReadOnly.webidl // See AnimationEffectReadOnly.webidl
// and mozilla/dom/AnimationEffectReadOnlyBinding.h // and mozilla/dom/AnimationEffectReadOnlyBinding.h
namespace dom { namespace dom {
enum class PlaybackDirection : uint32_t; enum class PlaybackDirection : uint8_t;
enum class FillMode : uint32_t; enum class FillMode : uint8_t;
} }
// See nsStyleDisplay // See nsStyleDisplay