Convert calc-related enums to 8-bit enum classes
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 19:19:33 +0000 (19:19 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Aug 2018 19:19:33 +0000 (19:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188215

Reviewed by Zalan Bujtas.

This shrinks CSSCalcOperation from 48 to 32 bytes.

* css/CSSCalculationValue.cpp:
(WebCore::unitCategory):
(WebCore::determineCategory):
(WebCore::resolvedTypeForMinOrMax):
(WebCore::isIntegerResult):
(WebCore::CSSCalcExpressionNodeParser::parseValue):
(WebCore::CSSCalcExpressionNodeParser::parseValueMultiplicativeExpression):
(WebCore::CSSCalcExpressionNodeParser::parseAdditiveValueExpression):
(WebCore::CSSCalcExpressionNodeParser::parseMinMaxExpression):
(WebCore::createBlendHalf):
(WebCore::createCSS):
* css/CSSCalculationValue.h:
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::primitiveType const):
* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::convertTo100PercentMinusLength):
* css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::CalcParser::consumeNumberRaw):
(WebCore::CSSPropertyParserHelpers::CalcParser::consumePositiveIntegerRaw):
(WebCore::CSSPropertyParserHelpers::consumeInteger):
(WebCore::CSSPropertyParserHelpers::consumePositiveIntegerRaw):
(WebCore::CSSPropertyParserHelpers::consumeNumberRaw):
(WebCore::CSSPropertyParserHelpers::consumeNumber):
(WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):
(WebCore::CSSPropertyParserHelpers::consumeLength):
(WebCore::CSSPropertyParserHelpers::consumePercent):
(WebCore::CSSPropertyParserHelpers::canConsumeCalcValue):
(WebCore::CSSPropertyParserHelpers::consumeLengthOrPercent):
(WebCore::CSSPropertyParserHelpers::consumeAngle):
(WebCore::CSSPropertyParserHelpers::consumeAngleOrPercent):
(WebCore::CSSPropertyParserHelpers::consumeTime):
* platform/CalculationValue.cpp:
(WebCore::CalcExpressionNumber::operator== const):
(WebCore::CalcExpressionOperation::evaluate const):
(WebCore::CalcExpressionOperation::operator== const):
(WebCore::CalcExpressionOperation::dump const):
(WebCore::CalcExpressionLength::operator== const):
(WebCore::CalcExpressionBlendLength::CalcExpressionBlendLength):
(WebCore::CalcExpressionBlendLength::operator== const):
(WebCore::operator<<):
* platform/CalculationValue.h:
(WebCore::CalcExpressionNumber::CalcExpressionNumber):
(WebCore::toCalcExpressionNumber):
(WebCore::CalcExpressionLength::CalcExpressionLength):
(WebCore::toCalcExpressionLength):
(WebCore::CalcExpressionOperation::CalcExpressionOperation):
(WebCore::toCalcExpressionOperation):
(WebCore::toCalcExpressionBlendLength):
* platform/Length.cpp:
(WebCore::convertTo100PercentMinusLength):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@234506 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/css/CSSCalculationValue.cpp
Source/WebCore/css/CSSCalculationValue.h
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/StyleBuilderConverter.h
Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
Source/WebCore/platform/CalculationValue.cpp
Source/WebCore/platform/CalculationValue.h
Source/WebCore/platform/Length.cpp

index ce2f9e0..dc77635 100644 (file)
@@ -1,3 +1,63 @@
+2018-08-02  Simon Fraser  <simon.fraser@apple.com>
+
+        Convert calc-related enums to 8-bit enum classes
+        https://bugs.webkit.org/show_bug.cgi?id=188215
+
+        Reviewed by Zalan Bujtas.
+
+        This shrinks CSSCalcOperation from 48 to 32 bytes.
+
+        * css/CSSCalculationValue.cpp:
+        (WebCore::unitCategory):
+        (WebCore::determineCategory):
+        (WebCore::resolvedTypeForMinOrMax):
+        (WebCore::isIntegerResult):
+        (WebCore::CSSCalcExpressionNodeParser::parseValue):
+        (WebCore::CSSCalcExpressionNodeParser::parseValueMultiplicativeExpression):
+        (WebCore::CSSCalcExpressionNodeParser::parseAdditiveValueExpression):
+        (WebCore::CSSCalcExpressionNodeParser::parseMinMaxExpression):
+        (WebCore::createBlendHalf):
+        (WebCore::createCSS):
+        * css/CSSCalculationValue.h:
+        * css/CSSPrimitiveValue.cpp:
+        (WebCore::CSSPrimitiveValue::primitiveType const):
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::convertTo100PercentMinusLength):
+        * css/parser/CSSPropertyParserHelpers.cpp:
+        (WebCore::CSSPropertyParserHelpers::CalcParser::consumeNumberRaw):
+        (WebCore::CSSPropertyParserHelpers::CalcParser::consumePositiveIntegerRaw):
+        (WebCore::CSSPropertyParserHelpers::consumeInteger):
+        (WebCore::CSSPropertyParserHelpers::consumePositiveIntegerRaw):
+        (WebCore::CSSPropertyParserHelpers::consumeNumberRaw):
+        (WebCore::CSSPropertyParserHelpers::consumeNumber):
+        (WebCore::CSSPropertyParserHelpers::consumeFontWeightNumber):
+        (WebCore::CSSPropertyParserHelpers::consumeLength):
+        (WebCore::CSSPropertyParserHelpers::consumePercent):
+        (WebCore::CSSPropertyParserHelpers::canConsumeCalcValue):
+        (WebCore::CSSPropertyParserHelpers::consumeLengthOrPercent):
+        (WebCore::CSSPropertyParserHelpers::consumeAngle):
+        (WebCore::CSSPropertyParserHelpers::consumeAngleOrPercent):
+        (WebCore::CSSPropertyParserHelpers::consumeTime):
+        * platform/CalculationValue.cpp:
+        (WebCore::CalcExpressionNumber::operator== const):
+        (WebCore::CalcExpressionOperation::evaluate const):
+        (WebCore::CalcExpressionOperation::operator== const):
+        (WebCore::CalcExpressionOperation::dump const):
+        (WebCore::CalcExpressionLength::operator== const):
+        (WebCore::CalcExpressionBlendLength::CalcExpressionBlendLength):
+        (WebCore::CalcExpressionBlendLength::operator== const):
+        (WebCore::operator<<):
+        * platform/CalculationValue.h:
+        (WebCore::CalcExpressionNumber::CalcExpressionNumber):
+        (WebCore::toCalcExpressionNumber):
+        (WebCore::CalcExpressionLength::CalcExpressionLength):
+        (WebCore::toCalcExpressionLength):
+        (WebCore::CalcExpressionOperation::CalcExpressionOperation):
+        (WebCore::toCalcExpressionOperation):
+        (WebCore::toCalcExpressionBlendLength):
+        * platform/Length.cpp:
+        (WebCore::convertTo100PercentMinusLength):
+
 2018-08-02  Charlie Turner  <cturner@igalia.com>
 
         Handle zero-sized ISOMP4 boxes appropriately
index b758301..815c492 100644 (file)
@@ -56,7 +56,7 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type)
 {
     switch (type) {
     case CSSPrimitiveValue::CSS_NUMBER:
-        return CalcNumber;
+        return CalculationCategory::Number;
     case CSSPrimitiveValue::CSS_EMS:
     case CSSPrimitiveValue::CSS_EXS:
     case CSSPrimitiveValue::CSS_PX:
@@ -71,22 +71,22 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type)
     case CSSPrimitiveValue::CSS_VH:
     case CSSPrimitiveValue::CSS_VMIN:
     case CSSPrimitiveValue::CSS_VMAX:
-        return CalcLength;
+        return CalculationCategory::Length;
     case CSSPrimitiveValue::CSS_PERCENTAGE:
-        return CalcPercent;
+        return CalculationCategory::Percent;
     case CSSPrimitiveValue::CSS_DEG:
     case CSSPrimitiveValue::CSS_RAD:
     case CSSPrimitiveValue::CSS_GRAD:
     case CSSPrimitiveValue::CSS_TURN:
-        return CalcAngle;
+        return CalculationCategory::Angle;
     case CSSPrimitiveValue::CSS_MS:
     case CSSPrimitiveValue::CSS_S:
-        return CalcTime;
+        return CalculationCategory::Time;
     case CSSPrimitiveValue::CSS_HZ:
     case CSSPrimitiveValue::CSS_KHZ:
-        return CalcFrequency;
+        return CalculationCategory::Frequency;
     default:
-        return CalcOther;
+        return CalculationCategory::Other;
     }
 }
 
@@ -219,21 +219,21 @@ private:
     std::unique_ptr<CalcExpressionNode> createCalcExpression(const CSSToLengthConversionData& conversionData) const final
     {
         switch (category()) {
-        case CalcNumber:
+        case CalculationCategory::Number:
             return std::make_unique<CalcExpressionNumber>(m_value->floatValue());
-        case CalcLength:
+        case CalculationCategory::Length:
             return std::make_unique<CalcExpressionLength>(Length(m_value->computeLength<float>(conversionData), WebCore::Fixed));
-        case CalcPercent:
-        case CalcPercentLength: {
+        case CalculationCategory::Percent:
+        case CalculationCategory::PercentLength: {
             return std::make_unique<CalcExpressionLength>(m_value->convertToLength<FixedFloatConversion | PercentConversion>(conversionData));
         }
         // Only types that could be part of a Length expression can be converted
-        // to a CalcExpressionNode. CalcPercentNumber makes no sense as a Length.
-        case CalcPercentNumber:
-        case CalcAngle:
-        case CalcTime:
-        case CalcFrequency:
-        case CalcOther:
+        // to a CalcExpressionNode. CalculationCategory::PercentNumber makes no sense as a Length.
+        case CalculationCategory::PercentNumber:
+        case CalculationCategory::Angle:
+        case CalculationCategory::Time:
+        case CalculationCategory::Frequency:
+        case CalculationCategory::Other:
             ASSERT_NOT_REACHED();
         }
         ASSERT_NOT_REACHED();
@@ -251,17 +251,17 @@ private:
     double computeLengthPx(const CSSToLengthConversionData& conversionData) const final
     {
         switch (category()) {
-        case CalcLength:
+        case CalculationCategory::Length:
             return m_value->computeLength<double>(conversionData);
-        case CalcPercent:
-        case CalcNumber:
+        case CalculationCategory::Percent:
+        case CalculationCategory::Number:
             return m_value->doubleValue();
-        case CalcPercentLength:
-        case CalcPercentNumber:
-        case CalcAngle:
-        case CalcTime:
-        case CalcFrequency:
-        case CalcOther:
+        case CalculationCategory::PercentLength:
+        case CalculationCategory::PercentNumber:
+        case CalculationCategory::Angle:
+        case CalculationCategory::Time:
+        case CalculationCategory::Frequency:
+        case CalculationCategory::Other:
             ASSERT_NOT_REACHED();
             break;
         }
@@ -293,84 +293,84 @@ private:
     Ref<CSSPrimitiveValue> m_value;
 };
 
-static const CalculationCategory addSubtractResult[CalcAngle][CalcAngle] = {
-//    CalcNumber         CalcLength         CalcPercent        CalcPercentNumber  CalcPercentLength
-    { CalcNumber,        CalcOther,         CalcPercentNumber, CalcPercentNumber, CalcOther }, //         CalcNumber
-    { CalcOther,         CalcLength,        CalcPercentLength, CalcOther,         CalcPercentLength }, // CalcLength
-    { CalcPercentNumber, CalcPercentLength, CalcPercent,       CalcPercentNumber, CalcPercentLength }, // CalcPercent
-    { CalcPercentNumber, CalcOther,         CalcPercentNumber, CalcPercentNumber, CalcOther }, //         CalcPercentNumber
-    { CalcOther,         CalcPercentLength, CalcPercentLength, CalcOther,         CalcPercentLength }, // CalcPercentLength
+static const CalculationCategory addSubtractResult[static_cast<unsigned>(CalculationCategory::Angle)][static_cast<unsigned>(CalculationCategory::Angle)] = {
+//    CalculationCategory::Number         CalculationCategory::Length         CalculationCategory::Percent        CalculationCategory::PercentNumber  CalculationCategory::PercentLength
+    { CalculationCategory::Number,        CalculationCategory::Other,         CalculationCategory::PercentNumber, CalculationCategory::PercentNumber, CalculationCategory::Other }, //         CalculationCategory::Number
+    { CalculationCategory::Other,         CalculationCategory::Length,        CalculationCategory::PercentLength, CalculationCategory::Other,         CalculationCategory::PercentLength }, // CalculationCategory::Length
+    { CalculationCategory::PercentNumber, CalculationCategory::PercentLength, CalculationCategory::Percent,       CalculationCategory::PercentNumber, CalculationCategory::PercentLength }, // CalculationCategory::Percent
+    { CalculationCategory::PercentNumber, CalculationCategory::Other,         CalculationCategory::PercentNumber, CalculationCategory::PercentNumber, CalculationCategory::Other }, //         CalculationCategory::PercentNumber
+    { CalculationCategory::Other,         CalculationCategory::PercentLength, CalculationCategory::PercentLength, CalculationCategory::Other,         CalculationCategory::PercentLength }, // CalculationCategory::PercentLength
 };
 
 static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSide, const CSSCalcExpressionNode& rightSide, CalcOperator op)
 {
     CalculationCategory leftCategory = leftSide.category();
     CalculationCategory rightCategory = rightSide.category();
-    ASSERT(leftCategory < CalcOther);
-    ASSERT(rightCategory < CalcOther);
+    ASSERT(leftCategory < CalculationCategory::Other);
+    ASSERT(rightCategory < CalculationCategory::Other);
 
     switch (op) {
-    case CalcAdd:
-    case CalcSubtract:
-        if (leftCategory < CalcAngle && rightCategory < CalcAngle)
-            return addSubtractResult[leftCategory][rightCategory];
+    case CalcOperator::Add:
+    case CalcOperator::Subtract:
+        if (leftCategory < CalculationCategory::Angle && rightCategory < CalculationCategory::Angle)
+            return addSubtractResult[static_cast<unsigned>(leftCategory)][static_cast<unsigned>(rightCategory)];
         if (leftCategory == rightCategory)
             return leftCategory;
-        return CalcOther;
-    case CalcMultiply:
-        if (leftCategory != CalcNumber && rightCategory != CalcNumber)
-            return CalcOther;
-        return leftCategory == CalcNumber ? rightCategory : leftCategory;
-    case CalcDivide:
-        if (rightCategory != CalcNumber || rightSide.isZero())
-            return CalcOther;
+        return CalculationCategory::Other;
+    case CalcOperator::Multiply:
+        if (leftCategory != CalculationCategory::Number && rightCategory != CalculationCategory::Number)
+            return CalculationCategory::Other;
+        return leftCategory == CalculationCategory::Number ? rightCategory : leftCategory;
+    case CalcOperator::Divide:
+        if (rightCategory != CalculationCategory::Number || rightSide.isZero())
+            return CalculationCategory::Other;
         return leftCategory;
-    case CalcMin:
-    case CalcMax:
+    case CalcOperator::Min:
+    case CalcOperator::Max:
         ASSERT_NOT_REACHED();
-        return CalcOther;
+        return CalculationCategory::Other;
     }
 
     ASSERT_NOT_REACHED();
-    return CalcOther;
+    return CalculationCategory::Other;
 }
 
 static CalculationCategory resolvedTypeForMinOrMax(CalculationCategory category, CalculationCategory destinationCategory)
 {
     switch (category) {
-    case CalcNumber:
-    case CalcLength:
-    case CalcPercentNumber:
-    case CalcPercentLength:
-    case CalcAngle:
-    case CalcTime:
-    case CalcFrequency:
-    case CalcOther:
+    case CalculationCategory::Number:
+    case CalculationCategory::Length:
+    case CalculationCategory::PercentNumber:
+    case CalculationCategory::PercentLength:
+    case CalculationCategory::Angle:
+    case CalculationCategory::Time:
+    case CalculationCategory::Frequency:
+    case CalculationCategory::Other:
         return category;
 
-    case CalcPercent:
-        if (destinationCategory == CalcLength)
-            return CalcPercentLength;
-        if (destinationCategory == CalcNumber)
-            return CalcPercentNumber;
+    case CalculationCategory::Percent:
+        if (destinationCategory == CalculationCategory::Length)
+            return CalculationCategory::PercentLength;
+        if (destinationCategory == CalculationCategory::Number)
+            return CalculationCategory::PercentNumber;
         return category;
     }
 
-    return CalcOther;
+    return CalculationCategory::Other;
 }
 
 static inline bool isIntegerResult(CalcOperator op, const CSSCalcExpressionNode& leftSide, const CSSCalcExpressionNode& rightSide)
 {
     // Performs W3C spec's type checking for calc integers.
     // http://www.w3.org/TR/css3-values/#calc-type-checking
-    return op != CalcDivide && leftSide.isInteger() && rightSide.isInteger();
+    return op != CalcOperator::Divide && leftSide.isInteger() && rightSide.isInteger();
 }
 
 static inline bool isIntegerResult(CalcOperator op, const Vector<Ref<CSSCalcExpressionNode>>& nodes)
 {
     // Performs W3C spec's type checking for calc integers.
     // http://www.w3.org/TR/css3-values/#calc-type-checking
-    if (op == CalcDivide)
+    if (op == CalcOperator::Divide)
         return false;
 
     for (auto& node : nodes) {
@@ -394,11 +394,11 @@ public:
         if (!leftSide || !rightSide)
             return nullptr;
 
-        ASSERT(leftSide->category() < CalcOther);
-        ASSERT(rightSide->category() < CalcOther);
+        ASSERT(leftSide->category() < CalculationCategory::Other);
+        ASSERT(rightSide->category() < CalculationCategory::Other);
 
         auto newCategory = determineCategory(*leftSide, *rightSide, op);
-        if (newCategory == CalcOther)
+        if (newCategory == CalculationCategory::Other)
             return nullptr;
 
         return adoptRef(new CSSCalcOperation(newCategory, op, leftSide.releaseNonNull(), rightSide.releaseNonNull()));
@@ -406,26 +406,26 @@ public:
 
     static RefPtr<CSSCalcOperation> createMinOrMax(CalcOperator op, Vector<Ref<CSSCalcExpressionNode>>&& values, CalculationCategory destinationCategory)
     {
-        ASSERT(op == CalcMin || op == CalcMax);
+        ASSERT(op == CalcOperator::Min || op == CalcOperator::Max);
 
         std::optional<CalculationCategory> category = std::nullopt;
         for (auto& value : values) {
             auto valueCategory = resolvedTypeForMinOrMax(value->category(), destinationCategory);
 
-            ASSERT(valueCategory < CalcOther);
+            ASSERT(valueCategory < CalculationCategory::Other);
             if (!category) {
-                if (valueCategory == CalcOther)
+                if (valueCategory == CalculationCategory::Other)
                     return nullptr;
                 category = valueCategory;
             }
 
             if (category != valueCategory) {
-                if (isSamePair(category.value(), valueCategory, CalcLength, CalcPercentLength)) {
-                    category = CalcPercentLength;
+                if (isSamePair(category.value(), valueCategory, CalculationCategory::Length, CalculationCategory::PercentLength)) {
+                    category = CalculationCategory::PercentLength;
                     continue;
                 }
-                if (isSamePair(category.value(), valueCategory, CalcNumber, CalcPercentNumber)) {
-                    category = CalcPercentNumber;
+                if (isSamePair(category.value(), valueCategory, CalculationCategory::Number, CalculationCategory::PercentNumber)) {
+                    category = CalculationCategory::PercentNumber;
                     continue;
                 }
                 return nullptr;
@@ -442,19 +442,19 @@ public:
 
         auto leftCategory = leftSide->category();
         auto rightCategory = rightSide->category();
-        ASSERT(leftCategory < CalcOther);
-        ASSERT(rightCategory < CalcOther);
+        ASSERT(leftCategory < CalculationCategory::Other);
+        ASSERT(rightCategory < CalculationCategory::Other);
 
         bool isInteger = isIntegerResult(op, *leftSide, *rightSide);
 
         // Simplify numbers.
-        if (leftCategory == CalcNumber && rightCategory == CalcNumber) {
+        if (leftCategory == CalculationCategory::Number && rightCategory == CalculationCategory::Number) {
             CSSPrimitiveValue::UnitType evaluationType = CSSPrimitiveValue::CSS_NUMBER;
             return CSSCalcPrimitiveValue::create(evaluateOperator(op, { leftSide->doubleValue(), rightSide->doubleValue() }), evaluationType, isInteger);
         }
 
         // Simplify addition and subtraction between same types.
-        if (op == CalcAdd || op == CalcSubtract) {
+        if (op == CalcOperator::Add || op == CalcOperator::Subtract) {
             if (leftCategory == rightSide->category()) {
                 CSSPrimitiveValue::UnitType leftType = leftSide->primitiveType();
                 if (hasDoubleValue(leftType)) {
@@ -474,18 +474,18 @@ public:
             }
         } else {
             // Simplify multiplying or dividing by a number for simplifiable types.
-            ASSERT(op == CalcMultiply || op == CalcDivide);
+            ASSERT(op == CalcOperator::Multiply || op == CalcOperator::Divide);
             auto* numberSide = getNumberSide(*leftSide, *rightSide);
             if (!numberSide)
                 return create(op, leftSide.releaseNonNull(), rightSide.releaseNonNull());
-            if (numberSide == leftSide && op == CalcDivide)
+            if (numberSide == leftSide && op == CalcOperator::Divide)
                 return nullptr;
             auto& otherSide = leftSide == numberSide ? *rightSide : *leftSide;
 
             double number = numberSide->doubleValue();
             if (!std::isfinite(number))
                 return nullptr;
-            if (op == CalcDivide && !number)
+            if (op == CalcOperator::Divide && !number)
                 return nullptr;
 
             auto otherType = otherSide.primitiveType();
@@ -537,10 +537,10 @@ private:
         StringBuilder result;
         result.append('(');
         switch (op) {
-        case CalcAdd:
-        case CalcSubtract:
-        case CalcMultiply:
-        case CalcDivide:
+        case CalcOperator::Add:
+        case CalcOperator::Subtract:
+        case CalcOperator::Multiply:
+        case CalcOperator::Divide:
             ASSERT(childExpressions.size() == 2);
             result.append(childExpressions[0]);
             result.append(' ');
@@ -548,10 +548,10 @@ private:
             result.append(' ');
             result.append(childExpressions[1]);
             break;
-        case CalcMin:
-        case CalcMax:
+        case CalcOperator::Min:
+        case CalcOperator::Max:
             ASSERT(!childExpressions.isEmpty());
-            const char* functionName = op == CalcMin ? "min(" : "max(";
+            const char* functionName = op == CalcOperator::Min ? "min(" : "max(";
             result.append(functionName);
             result.append(childExpressions[0]);
             for (size_t i = 1; i < childExpressions.size(); ++i) {
@@ -596,20 +596,20 @@ private:
     CSSPrimitiveValue::UnitType primitiveType() const final
     {
         switch (category()) {
-        case CalcNumber:
+        case CalculationCategory::Number:
 #if !ASSERT_DISABLED
             for (auto& child : m_children)
-                ASSERT(child->category() == CalcNumber);
+                ASSERT(child->category() == CalculationCategory::Number);
 #endif
             return CSSPrimitiveValue::CSS_NUMBER;
-        case CalcLength:
-        case CalcPercent: {
+        case CalculationCategory::Length:
+        case CalculationCategory::Percent: {
             if (m_children.isEmpty())
                 return CSSPrimitiveValue::CSS_UNKNOWN;
             if (m_children.size() == 2) {
-                if (m_children[0]->category() == CalcNumber)
+                if (m_children[0]->category() == CalculationCategory::Number)
                     return m_children[1]->primitiveType();
-                if (m_children[1]->category() == CalcNumber)
+                if (m_children[1]->category() == CalculationCategory::Number)
                     return m_children[0]->primitiveType();
             }
             CSSPrimitiveValue::UnitType firstType = m_children[0]->primitiveType();
@@ -619,15 +619,15 @@ private:
             }
             return firstType;
         }
-        case CalcAngle:
+        case CalculationCategory::Angle:
             return CSSPrimitiveValue::CSS_DEG;
-        case CalcTime:
+        case CalculationCategory::Time:
             return CSSPrimitiveValue::CSS_MS;
-        case CalcFrequency:
+        case CalculationCategory::Frequency:
             return CSSPrimitiveValue::CSS_HZ;
-        case CalcPercentLength:
-        case CalcPercentNumber:
-        case CalcOther:
+        case CalculationCategory::PercentLength:
+        case CalculationCategory::PercentNumber:
+        case CalculationCategory::Other:
             return CSSPrimitiveValue::CSS_UNKNOWN;
         }
         ASSERT_NOT_REACHED();
@@ -644,16 +644,16 @@ private:
 
     CSSCalcOperation(CalculationCategory category, CalcOperator op, Vector<Ref<CSSCalcExpressionNode>>&& children)
         : CSSCalcExpressionNode(category, isIntegerResult(op, children))
-        , m_children(WTFMove(children))
         , m_operator(op)
+        , m_children(WTFMove(children))
     {
     }
 
     static CSSCalcExpressionNode* getNumberSide(CSSCalcExpressionNode& leftSide, CSSCalcExpressionNode& rightSide)
     {
-        if (leftSide.category() == CalcNumber)
+        if (leftSide.category() == CalculationCategory::Number)
             return &leftSide;
-        if (rightSide.category() == CalcNumber)
+        if (rightSide.category() == CalculationCategory::Number)
             return &rightSide;
         return nullptr;
     }
@@ -666,21 +666,21 @@ private:
     static double evaluateOperator(CalcOperator op, const Vector<double>& children)
     {
         switch (op) {
-        case CalcAdd:
+        case CalcOperator::Add:
             ASSERT(children.size() == 2);
             return children[0] + children[1];
-        case CalcSubtract:
+        case CalcOperator::Subtract:
             ASSERT(children.size() == 2);
             return children[0] - children[1];
-        case CalcMultiply:
+        case CalcOperator::Multiply:
             ASSERT(children.size() == 2);
             return children[0] * children[1];
-        case CalcDivide:
+        case CalcOperator::Divide:
             ASSERT(children.size() == 1 || children.size() == 2);
             if (children.size() == 1)
                 return std::numeric_limits<double>::quiet_NaN();
             return children[0] / children[1];
-        case CalcMin: {
+        case CalcOperator::Min: {
             if (children.isEmpty())
                 return std::numeric_limits<double>::quiet_NaN();
             double minimum = children[0];
@@ -688,7 +688,7 @@ private:
                 minimum = std::min(minimum, child);
             return minimum;
         }
-        case CalcMax: {
+        case CalcOperator::Max: {
             if (children.isEmpty())
                 return std::numeric_limits<double>::quiet_NaN();
             double maximum = children[0];
@@ -701,8 +701,8 @@ private:
         return 0;
     }
 
-    Vector<Ref<CSSCalcExpressionNode>> m_children;
     const CalcOperator m_operator;
+    Vector<Ref<CSSCalcExpressionNode>> m_children;
 };
 
 static ParseState checkDepthAndIndex(int* depth, CSSParserTokenRange tokens)
@@ -754,7 +754,7 @@ private:
             return false;
         
         CSSPrimitiveValue::UnitType type = token.unitType();
-        if (unitCategory(type) == CalcOther)
+        if (unitCategory(type) == CalculationCategory::Other)
             return false;
         
         bool isInteger = token.numericValueType() == IntegerValueType || (token.numericValueType() == NumberValueType && token.numericValue() == trunc(token.numericValue()));
@@ -797,7 +797,7 @@ private:
         
         while (!tokens.atEnd()) {
             char operatorCharacter = operatorValue(tokens.peek());
-            if (operatorCharacter != CalcMultiply && operatorCharacter != CalcDivide)
+            if (operatorCharacter != static_cast<char>(CalcOperator::Multiply) && operatorCharacter != static_cast<char>(CalcOperator::Divide))
                 break;
             tokens.consumeIncludingWhitespace();
             
@@ -824,7 +824,7 @@ private:
         
         while (!tokens.atEnd()) {
             char operatorCharacter = operatorValue(tokens.peek());
-            if (operatorCharacter != CalcAdd && operatorCharacter != CalcSubtract)
+            if (operatorCharacter != static_cast<char>(CalcOperator::Add) && operatorCharacter != static_cast<char>(CalcOperator::Subtract))
                 break;
             if ((&tokens.peek() - 1)->type() != WhitespaceToken)
                 return false; // calc(1px+ 2px) is invalid
@@ -850,7 +850,7 @@ private:
         if (checkDepthAndIndex(&depth, tokens) != OK)
             return false;
 
-        CalcOperator op = (minMaxFunction == CSSValueMin) ? CalcMin : CalcMax;
+        CalcOperator op = (minMaxFunction == CSSValueMin) ? CalcOperator::Min : CalcOperator::Max;
 
         Value value;
         if (!parseValueExpression(tokens, depth, &value))
@@ -885,24 +885,24 @@ private:
 
 static inline RefPtr<CSSCalcOperation> createBlendHalf(const Length& length, const RenderStyle& style, float progress)
 {
-    return CSSCalcOperation::create(CalcMultiply, createCSS(length, style),
+    return CSSCalcOperation::create(CalcOperator::Multiply, createCSS(length, style),
         CSSCalcPrimitiveValue::create(CSSPrimitiveValue::create(progress, CSSPrimitiveValue::CSS_NUMBER), !progress || progress == 1));
 }
 
 static RefPtr<CSSCalcExpressionNode> createCSS(const CalcExpressionNode& node, const RenderStyle& style)
 {
     switch (node.type()) {
-    case CalcExpressionNodeNumber: {
+    case CalcExpressionNodeType::Number: {
         float value = toCalcExpressionNumber(node).value();
         return CSSCalcPrimitiveValue::create(CSSPrimitiveValue::create(value, CSSPrimitiveValue::CSS_NUMBER), value == std::trunc(value));
     }
-    case CalcExpressionNodeLength:
+    case CalcExpressionNodeType::Length:
         return createCSS(toCalcExpressionLength(node).length(), style);
-    case CalcExpressionNodeOperation: {
+    case CalcExpressionNodeType::Operation: {
         auto& operationNode = toCalcExpressionOperation(node);
         auto& operationChildren = operationNode.children();
         CalcOperator op = operationNode.getOperator();
-        if (op == CalcMin || op == CalcMax) {
+        if (op == CalcOperator::Min || op == CalcOperator::Max) {
             Vector<Ref<CSSCalcExpressionNode>> values;
             values.reserveInitialCapacity(operationChildren.size());
             for (auto& child : operationChildren) {
@@ -911,7 +911,7 @@ static RefPtr<CSSCalcExpressionNode> createCSS(const CalcExpressionNode& node, c
                     return nullptr;
                 values.uncheckedAppend(*cssNode);
             }
-            return CSSCalcOperation::createMinOrMax(operationNode.getOperator(), WTFMove(values), CalcOther);
+            return CSSCalcOperation::createMinOrMax(operationNode.getOperator(), WTFMove(values), CalculationCategory::Other);
         }
 
         if (operationChildren.size() == 2)
@@ -919,13 +919,13 @@ static RefPtr<CSSCalcExpressionNode> createCSS(const CalcExpressionNode& node, c
 
         return nullptr;
     }
-    case CalcExpressionNodeBlendLength: {
+    case CalcExpressionNodeType::BlendLength: {
         // FIXME: (http://webkit.org/b/122036) Create a CSSCalcExpressionNode equivalent of CalcExpressionBlendLength.
         auto& blend = toCalcExpressionBlendLength(node);
         float progress = blend.progress();
-        return CSSCalcOperation::create(CalcAdd, createBlendHalf(blend.from(), style, 1 - progress), createBlendHalf(blend.to(), style, progress));
+        return CSSCalcOperation::create(CalcOperator::Add, createBlendHalf(blend.from(), style, 1 - progress), createBlendHalf(blend.to(), style, progress));
     }
-    case CalcExpressionNodeUndefined:
+    case CalcExpressionNodeType::Undefined:
         ASSERT_NOT_REACHED();
     }
     return nullptr;
index 90eb9cd..9f3d709 100644 (file)
@@ -39,16 +39,16 @@ class CSSParserTokenRange;
 class CSSToLengthConversionData;
 class RenderStyle;
 
-enum CalculationCategory {
-    CalcNumber = 0,
-    CalcLength,
-    CalcPercent,
-    CalcPercentNumber,
-    CalcPercentLength,
-    CalcAngle,
-    CalcTime,
-    CalcFrequency,
-    CalcOther
+enum class CalculationCategory : uint8_t {
+    Number = 0,
+    Length,
+    Percent,
+    PercentNumber,
+    PercentLength,
+    Angle,
+    Time,
+    Frequency,
+    Other
 };
 
 class CSSCalcExpressionNode : public RefCounted<CSSCalcExpressionNode> {
index a761276..c60d1b4 100644 (file)
@@ -248,21 +248,21 @@ unsigned short CSSPrimitiveValue::primitiveType() const
         return m_primitiveUnitType;
 
     switch (m_value.calc->category()) {
-    case CalcNumber:
+    case CalculationCategory::Number:
         return CSSPrimitiveValue::CSS_NUMBER;
-    case CalcLength:
+    case CalculationCategory::Length:
         return CSSPrimitiveValue::CSS_PX;
-    case CalcPercent:
+    case CalculationCategory::Percent:
         return CSSPrimitiveValue::CSS_PERCENTAGE;
-    case CalcPercentNumber:
+    case CalculationCategory::PercentNumber:
         return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_NUMBER;
-    case CalcPercentLength:
+    case CalculationCategory::PercentLength:
         return CSSPrimitiveValue::CSS_CALC_PERCENTAGE_WITH_LENGTH;
-    case CalcAngle:
-    case CalcTime:
-    case CalcFrequency:
+    case CalculationCategory::Angle:
+    case CalculationCategory::Time:
+    case CalculationCategory::Frequency:
         return m_value.calc->primitiveType();
-    case CalcOther:
+    case CalculationCategory::Other:
         return CSSPrimitiveValue::CSS_UNKNOWN;
     }
     return CSSPrimitiveValue::CSS_UNKNOWN;
index 481c458..60a24bc 100644 (file)
@@ -326,7 +326,7 @@ inline Length StyleBuilderConverter::convertTo100PercentMinusLength(const Length
     lengths.reserveInitialCapacity(2);
     lengths.uncheckedAppend(std::make_unique<CalcExpressionLength>(Length(100, Percent)));
     lengths.uncheckedAppend(std::make_unique<CalcExpressionLength>(length));
-    auto op = std::make_unique<CalcExpressionOperation>(WTFMove(lengths), CalcSubtract);
+    auto op = std::make_unique<CalcExpressionOperation>(WTFMove(lengths), CalcOperator::Subtract);
     return Length(CalculationValue::create(WTFMove(op), ValueRangeAll));
 }
 
index a44a526..98ffc21 100644 (file)
@@ -106,7 +106,7 @@ public:
 
     bool consumeNumberRaw(double& result)
     {
-        if (!m_calcValue || m_calcValue->category() != CalcNumber)
+        if (!m_calcValue || m_calcValue->category() != CalculationCategory::Number)
             return false;
         m_sourceRange = m_range;
         result = m_calcValue->doubleValue();
@@ -115,7 +115,7 @@ public:
     
     bool consumePositiveIntegerRaw(int& result)
     {
-        if (!m_calcValue || m_calcValue->category() != CalcNumber || !m_calcValue->isInt())
+        if (!m_calcValue || m_calcValue->category() != CalculationCategory::Number || !m_calcValue->isInt())
             return false;
         result = static_cast<int>(m_calcValue->doubleValue());
         if (result < 1)
@@ -138,9 +138,9 @@ RefPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRange& range, double mini
             return nullptr;
         return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitType::CSS_NUMBER);
     }
-    CalcParser calcParser(range, CalcNumber);
+    CalcParser calcParser(range, CalculationCategory::Number);
     if (const CSSCalcValue* calculation = calcParser.value()) {
-        if (calculation->category() != CalcNumber || !calculation->isInt())
+        if (calculation->category() != CalculationCategory::Number || !calculation->isInt())
             return nullptr;
         double value = calculation->doubleValue();
         if (value < minimumValue)
@@ -164,7 +164,7 @@ bool consumePositiveIntegerRaw(CSSParserTokenRange& range, int& result)
         result = range.consumeIncludingWhitespace().numericValue();
         return true;
     }
-    CalcParser calcParser(range, CalcNumber);
+    CalcParser calcParser(range, CalculationCategory::Number);
     return calcParser.consumePositiveIntegerRaw(result);
 }
     
@@ -174,7 +174,7 @@ bool consumeNumberRaw(CSSParserTokenRange& range, double& result)
         result = range.consumeIncludingWhitespace().numericValue();
         return true;
     }
-    CalcParser calcParser(range, CalcNumber, ValueRangeAll);
+    CalcParser calcParser(range, CalculationCategory::Number, ValueRangeAll);
     return calcParser.consumeNumberRaw(result);
 }
 
@@ -187,11 +187,11 @@ RefPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRange& range, ValueRange v
             return nullptr;
         return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), token.unitType());
     }
-    CalcParser calcParser(range, CalcNumber, ValueRangeAll);
+    CalcParser calcParser(range, CalculationCategory::Number, ValueRangeAll);
     if (const CSSCalcValue* calculation = calcParser.value()) {
         // FIXME: Calcs should not be subject to parse time range checks.
         // spec: https://drafts.csswg.org/css-values-3/#calc-range
-        if (calculation->category() != CalcNumber || (valueRange == ValueRangeNonNegative && calculation->isNegative()))
+        if (calculation->category() != CalculationCategory::Number || (valueRange == ValueRangeNonNegative && calculation->isNegative()))
             return nullptr;
         return calcParser.consumeNumber();
     }
@@ -217,7 +217,7 @@ RefPtr<CSSPrimitiveValue> consumeFontWeightNumber(CSSParserTokenRange& range)
         return consumeNumber(range, ValueRangeAll);
 
     // "[For calc()], the used value resulting from an expression must be clamped to the range allowed in the target context."
-    CalcParser calcParser(range, CalcNumber, ValueRangeAll);
+    CalcParser calcParser(range, CalculationCategory::Number, ValueRangeAll);
     double result;
     if (calcParser.consumeNumberRaw(result)
 #if !ENABLE(VARIATION_FONTS)
@@ -279,8 +279,8 @@ RefPtr<CSSPrimitiveValue> consumeLength(CSSParserTokenRange& range, CSSParserMod
         CSSPrimitiveValue::UnitType unitType = CSSPrimitiveValue::UnitType::CSS_PX;
         return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), unitType);
     }
-    CalcParser calcParser(range, CalcLength, valueRange);
-    if (calcParser.value() && calcParser.value()->category() == CalcLength)
+    CalcParser calcParser(range, CalculationCategory::Length, valueRange);
+    if (calcParser.value() && calcParser.value()->category() == CalculationCategory::Length)
         return calcParser.consumeValue();
     return nullptr;
 }
@@ -293,9 +293,9 @@ RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange& range, ValueRange
             return nullptr;
         return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitType::CSS_PERCENTAGE);
     }
-    CalcParser calcParser(range, CalcPercent, valueRange);
+    CalcParser calcParser(range, CalculationCategory::Percent, valueRange);
     if (const CSSCalcValue* calculation = calcParser.value()) {
-        if (calculation->category() == CalcPercent)
+        if (calculation->category() == CalculationCategory::Percent)
             return calcParser.consumeValue();
     }
     return nullptr;
@@ -303,13 +303,13 @@ RefPtr<CSSPrimitiveValue> consumePercent(CSSParserTokenRange& range, ValueRange
 
 static bool canConsumeCalcValue(CalculationCategory category, CSSParserMode cssParserMode)
 {
-    if (category == CalcLength || category == CalcPercent || category == CalcPercentLength)
+    if (category == CalculationCategory::Length || category == CalculationCategory::Percent || category == CalculationCategory::PercentLength)
         return true;
 
     if (cssParserMode != SVGAttributeMode)
         return false;
 
-    if (category == CalcNumber || category == CalcPercentNumber)
+    if (category == CalculationCategory::Number || category == CalculationCategory::PercentNumber)
         return true;
 
     return false;
@@ -322,7 +322,7 @@ RefPtr<CSSPrimitiveValue> consumeLengthOrPercent(CSSParserTokenRange& range, CSS
         return consumeLength(range, cssParserMode, valueRange, unitless);
     if (token.type() == PercentageToken)
         return consumePercent(range, valueRange);
-    CalcParser calcParser(range, CalcLength, valueRange);
+    CalcParser calcParser(range, CalculationCategory::Length, valueRange);
     if (const CSSCalcValue* calculation = calcParser.value()) {
         if (canConsumeCalcValue(calculation->category(), cssParserMode))
             return calcParser.consumeValue();
@@ -348,9 +348,9 @@ RefPtr<CSSPrimitiveValue> consumeAngle(CSSParserTokenRange& range, CSSParserMode
         return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), CSSPrimitiveValue::UnitType::CSS_DEG);
     }
 
-    CalcParser calcParser(range, CalcAngle, ValueRangeAll);
+    CalcParser calcParser(range, CalculationCategory::Angle, ValueRangeAll);
     if (const CSSCalcValue* calculation = calcParser.value()) {
-        if (calculation->category() == CalcAngle)
+        if (calculation->category() == CalculationCategory::Angle)
             return calcParser.consumeValue();
     }
     return nullptr;
@@ -375,9 +375,9 @@ static RefPtr<CSSPrimitiveValue> consumeAngleOrPercent(CSSParserTokenRange& rang
     if (token.type() == PercentageToken)
         return consumePercent(range, valueRange);
 
-    CalcParser calcParser(range, CalcAngle, valueRange);
+    CalcParser calcParser(range, CalculationCategory::Angle, valueRange);
     if (const CSSCalcValue* calculation = calcParser.value()) {
-        if (calculation->category() == CalcAngle)
+        if (calculation->category() == CalculationCategory::Angle)
             return calcParser.consumeValue();
     }
     return nullptr;
@@ -398,9 +398,9 @@ RefPtr<CSSPrimitiveValue> consumeTime(CSSParserTokenRange& range, CSSParserMode
             return CSSValuePool::singleton().createValue(range.consumeIncludingWhitespace().numericValue(), unit);
         return nullptr;
     }
-    CalcParser calcParser(range, CalcTime, valueRange);
+    CalcParser calcParser(range, CalculationCategory::Time, valueRange);
     if (const CSSCalcValue* calculation = calcParser.value()) {
-        if (calculation->category() == CalcTime)
+        if (calculation->category() == CalculationCategory::Time)
             return calcParser.consumeValue();
     }
     return nullptr;
index e5ac4b2..67e92b0 100644 (file)
@@ -55,7 +55,7 @@ void CalcExpressionNumber::dump(TextStream& ts) const
 
 bool CalcExpressionNumber::operator==(const CalcExpressionNode& other) const
 {
-    return other.type() == CalcExpressionNodeNumber && *this == toCalcExpressionNumber(other);
+    return other.type() == CalcExpressionNodeType::Number && *this == toCalcExpressionNumber(other);
 }
 
 float CalculationValue::evaluate(float maxValue) const
@@ -71,25 +71,25 @@ float CalculationValue::evaluate(float maxValue) const
 float CalcExpressionOperation::evaluate(float maxValue) const
 {
     switch (m_operator) {
-    case CalcAdd: {
+    case CalcOperator::Add: {
         ASSERT(m_children.size() == 2);
         float left = m_children[0]->evaluate(maxValue);
         float right = m_children[1]->evaluate(maxValue);
         return left + right;
     }
-    case CalcSubtract: {
+    case CalcOperator::Subtract: {
         ASSERT(m_children.size() == 2);
         float left = m_children[0]->evaluate(maxValue);
         float right = m_children[1]->evaluate(maxValue);
         return left - right;
     }
-    case CalcMultiply: {
+    case CalcOperator::Multiply: {
         ASSERT(m_children.size() == 2);
         float left = m_children[0]->evaluate(maxValue);
         float right = m_children[1]->evaluate(maxValue);
         return left * right;
     }
-    case CalcDivide: {
+    case CalcOperator::Divide: {
         ASSERT(m_children.size() == 1 || m_children.size() == 2);
         if (m_children.size() == 1)
             return std::numeric_limits<float>::quiet_NaN();
@@ -97,7 +97,7 @@ float CalcExpressionOperation::evaluate(float maxValue) const
         float right = m_children[1]->evaluate(maxValue);
         return left / right;
     }
-    case CalcMin: {
+    case CalcOperator::Min: {
         if (m_children.isEmpty())
             return std::numeric_limits<float>::quiet_NaN();
         float minimum = m_children[0]->evaluate(maxValue);
@@ -105,7 +105,7 @@ float CalcExpressionOperation::evaluate(float maxValue) const
             minimum = std::min(minimum, child->evaluate(maxValue));
         return minimum;
     }
-    case CalcMax: {
+    case CalcOperator::Max: {
         if (m_children.isEmpty())
             return std::numeric_limits<float>::quiet_NaN();
         float maximum = m_children[0]->evaluate(maxValue);
@@ -120,7 +120,7 @@ float CalcExpressionOperation::evaluate(float maxValue) const
 
 bool CalcExpressionOperation::operator==(const CalcExpressionNode& other) const
 {
-    return other.type() == CalcExpressionNodeOperation && *this == toCalcExpressionOperation(other);
+    return other.type() == CalcExpressionNodeType::Operation && *this == toCalcExpressionOperation(other);
 }
 
 bool operator==(const CalcExpressionOperation& a, const CalcExpressionOperation& b)
@@ -139,7 +139,7 @@ bool operator==(const CalcExpressionOperation& a, const CalcExpressionOperation&
 
 void CalcExpressionOperation::dump(TextStream& ts) const
 {
-    if (m_operator == CalcMin || m_operator == CalcMax) {
+    if (m_operator == CalcOperator::Min || m_operator == CalcOperator::Max) {
         ts << m_operator << "(";
         size_t childrenCount = m_children.size();
         for (size_t i = 0; i < childrenCount; i++) {
@@ -159,7 +159,7 @@ float CalcExpressionLength::evaluate(float maxValue) const
 
 bool CalcExpressionLength::operator==(const CalcExpressionNode& other) const
 {
-    return other.type() == CalcExpressionNodeLength && *this == toCalcExpressionLength(other);
+    return other.type() == CalcExpressionNodeType::Length && *this == toCalcExpressionLength(other);
 }
 
 void CalcExpressionLength::dump(TextStream& ts) const
@@ -168,16 +168,16 @@ void CalcExpressionLength::dump(TextStream& ts) const
 }
 
 CalcExpressionBlendLength::CalcExpressionBlendLength(Length from, Length to, float progress)
-    : CalcExpressionNode(CalcExpressionNodeBlendLength)
+    : CalcExpressionNode(CalcExpressionNodeType::BlendLength)
     , m_from(from)
     , m_to(to)
     , m_progress(progress)
 {
     // Flatten nesting of CalcExpressionBlendLength as a speculative fix for rdar://problem/30533005.
     // CalcExpressionBlendLength is only used as a result of animation and they don't nest in normal cases.
-    if (m_from.isCalculated() && m_from.calculationValue().expression().type() == CalcExpressionNodeBlendLength)
+    if (m_from.isCalculated() && m_from.calculationValue().expression().type() == CalcExpressionNodeType::BlendLength)
         m_from = toCalcExpressionBlendLength(m_from.calculationValue().expression()).from();
-    if (m_to.isCalculated() && m_to.calculationValue().expression().type() == CalcExpressionNodeBlendLength)
+    if (m_to.isCalculated() && m_to.calculationValue().expression().type() == CalcExpressionNodeType::BlendLength)
         m_to = toCalcExpressionBlendLength(m_to.calculationValue().expression()).to();
 }
 
@@ -188,7 +188,7 @@ float CalcExpressionBlendLength::evaluate(float maxValue) const
 
 bool CalcExpressionBlendLength::operator==(const CalcExpressionNode& other) const
 {
-    return other.type() == CalcExpressionNodeBlendLength && *this == toCalcExpressionBlendLength(other);
+    return other.type() == CalcExpressionNodeType::BlendLength && *this == toCalcExpressionBlendLength(other);
 }
 
 void CalcExpressionBlendLength::dump(TextStream& ts) const
@@ -199,12 +199,12 @@ void CalcExpressionBlendLength::dump(TextStream& ts) const
 TextStream& operator<<(TextStream& ts, CalcOperator op)
 {
     switch (op) {
-    case CalcAdd: ts << "+"; break;
-    case CalcSubtract: ts << "-"; break;
-    case CalcMultiply: ts << "*"; break;
-    case CalcDivide: ts << "/"; break;
-    case CalcMin: ts << "max"; break;
-    case CalcMax: ts << "min"; break;
+    case CalcOperator::Add: ts << "+"; break;
+    case CalcOperator::Subtract: ts << "-"; break;
+    case CalcOperator::Multiply: ts << "*"; break;
+    case CalcOperator::Divide: ts << "/"; break;
+    case CalcOperator::Min: ts << "max"; break;
+    case CalcOperator::Max: ts << "min"; break;
     }
     return ts;
 }
index 4ae3211..616cb13 100644 (file)
@@ -28,8 +28,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef CalculationValue_h
-#define CalculationValue_h
+#pragma once
 
 #include "Length.h"
 #include <memory>
@@ -43,27 +42,28 @@ class TextStream;
 
 namespace WebCore {
 
-enum CalcOperator {
-    CalcAdd = '+',
-    CalcSubtract = '-',
-    CalcMultiply = '*',
-    CalcDivide = '/',
-    CalcMin = 0,
-    CalcMax = 1,
+// Don't change these values; parsing uses them.
+enum class CalcOperator : uint8_t {
+    Add = '+',
+    Subtract = '-',
+    Multiply = '*',
+    Divide = '/',
+    Min = 0,
+    Max = 1,
 };
 
-enum CalcExpressionNodeType {
-    CalcExpressionNodeUndefined,
-    CalcExpressionNodeNumber,
-    CalcExpressionNodeLength,
-    CalcExpressionNodeOperation,
-    CalcExpressionNodeBlendLength,
+enum class CalcExpressionNodeType : uint8_t {
+    Undefined,
+    Number,
+    Length,
+    Operation,
+    BlendLength,
 };
 
 class CalcExpressionNode {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    explicit CalcExpressionNode(CalcExpressionNodeType = CalcExpressionNodeUndefined);
+    explicit CalcExpressionNode(CalcExpressionNodeType = CalcExpressionNodeType::Undefined);
     virtual ~CalcExpressionNode() = default;
 
     CalcExpressionNodeType type() const { return m_type; }
@@ -171,7 +171,7 @@ inline bool operator==(const CalculationValue& a, const CalculationValue& b)
 }
 
 inline CalcExpressionNumber::CalcExpressionNumber(float value)
-    : CalcExpressionNode(CalcExpressionNodeNumber)
+    : CalcExpressionNode(CalcExpressionNodeType::Number)
     , m_value(value)
 {
 }
@@ -183,12 +183,12 @@ inline bool operator==(const CalcExpressionNumber& a, const CalcExpressionNumber
 
 inline const CalcExpressionNumber& toCalcExpressionNumber(const CalcExpressionNode& value)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeNumber);
+    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeType::Number);
     return static_cast<const CalcExpressionNumber&>(value);
 }
 
 inline CalcExpressionLength::CalcExpressionLength(Length length)
-    : CalcExpressionNode(CalcExpressionNodeLength)
+    : CalcExpressionNode(CalcExpressionNodeType::Length)
     , m_length(length)
 {
 }
@@ -200,12 +200,12 @@ inline bool operator==(const CalcExpressionLength& a, const CalcExpressionLength
 
 inline const CalcExpressionLength& toCalcExpressionLength(const CalcExpressionNode& value)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeLength);
+    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeType::Length);
     return static_cast<const CalcExpressionLength&>(value);
 }
 
 inline CalcExpressionOperation::CalcExpressionOperation(Vector<std::unique_ptr<CalcExpressionNode>>&& children, CalcOperator op)
-    : CalcExpressionNode(CalcExpressionNodeOperation)
+    : CalcExpressionNode(CalcExpressionNodeType::Operation)
     , m_children(WTFMove(children))
     , m_operator(op)
 {
@@ -215,7 +215,7 @@ bool operator==(const CalcExpressionOperation&, const CalcExpressionOperation&);
 
 inline const CalcExpressionOperation& toCalcExpressionOperation(const CalcExpressionNode& value)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeOperation);
+    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeType::Operation);
     return static_cast<const CalcExpressionOperation&>(value);
 }
 
@@ -226,7 +226,7 @@ inline bool operator==(const CalcExpressionBlendLength& a, const CalcExpressionB
 
 inline const CalcExpressionBlendLength& toCalcExpressionBlendLength(const CalcExpressionNode& value)
 {
-    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeBlendLength);
+    ASSERT_WITH_SECURITY_IMPLICATION(value.type() == CalcExpressionNodeType::BlendLength);
     return static_cast<const CalcExpressionBlendLength&>(value);
 }
 
@@ -235,5 +235,3 @@ WTF::TextStream& operator<<(WTF::TextStream&, const CalcExpressionNode&);
 WTF::TextStream& operator<<(WTF::TextStream&, CalcOperator);
 
 } // namespace WebCore
-
-#endif // CalculationValue_h
index d26364b..2982852 100644 (file)
@@ -295,7 +295,7 @@ Length convertTo100PercentMinusLength(const Length& length)
     lengths.reserveInitialCapacity(2);
     lengths.uncheckedAppend(std::make_unique<CalcExpressionLength>(Length(100, Percent)));
     lengths.uncheckedAppend(std::make_unique<CalcExpressionLength>(length));
-    auto op = std::make_unique<CalcExpressionOperation>(WTFMove(lengths), CalcSubtract);
+    auto op = std::make_unique<CalcExpressionOperation>(WTFMove(lengths), CalcOperator::Subtract);
     return Length(CalculationValue::create(WTFMove(op), ValueRangeAll));
 }