Changeset 155536 in webkit


Ignore:
Timestamp:
Sep 11, 2013 9:48:20 AM (11 years ago)
Author:
Darin Adler
Message:

Rework CSS parser, eliminating "floating" concept and using %destructor
https://bugs.webkit.org/show_bug.cgi?id=121161

Reviewed by Antti Koivisto.

This is some basic improvement, but there is still room for a lot more
consistent approach and formatting in this file. There is a mix of code that
works by side effects in the CSSParser class and code that works with the
values that bison generates in the union that is more or less random. And
the data structures seem too costly, with too much heap allocation. And the
CSSParser class has grown massive, with a mix of both function for use by
code that wants to trigger parsing, and helper functions called by code in
the grammar file. All of that can benefit from more refinement in the future.

  • css/CSSGrammar.y.in: Made some incremental improvements to the structure

of the grammar file, including:

  • Breaking up the %union so types are declared next to their use
  • Eliminating one shift/reduce conflict caused by two "maybe_space" in a row
  • Breaking the conditional sections out into their own sections instead of scattering them in with the other code.
  • Eliminating unused return values in productions such as charset, ignored_charset, namespace, margin_box, invalid_rule, save_block, invalid_at, and declarations_and_margins.
  • Adding %destructor to productions that return values that need to be deleted or deref'd. This removes the need for CSSParser to separately track these as "floating" to clean up in case of errors.
  • Removing unneeded productions such as media_feature, region_selector, attr_name, and medium.
  • Removing explicit code blocks that just say "$$ = $1" or empty blocks when there is no return type, since those are default.
  • Formatting many productions on single lines since I find them easier to read. Later I think we could make many more CSSParser functions and make even more of the production single lines in the grammar file.
  • Using adoptPtr, adoptRef, delete, deref, leakPtr, and leakRef to put heap allocated values into and out of the union without storage leaks.
  • css/CSSParser.cpp:

(WebCore::CSSParser::~CSSParser): Remove the now-unneeded deleteAllValues for
the various colections of floating things.
(WebCore::CSSParser::createFilterRule): Don't put the rule into m_parsedRules,
just return a PassRefPtr instead.
(WebCore::CSSParser::createImportRule): Ditto.
(WebCore::CSSParser::createMediaRule): Ditto.
(WebCore::CSSParser::createEmptyMediaRule): Ditto.
(WebCore::CSSParser::createSupportsRule): Ditto.
(WebCore::CSSParser::createKeyframesRule): Ditto.
(WebCore::CSSParser::createStyleRule): Ditto.
(WebCore::CSSParser::createFontFaceRule): Ditto.
(WebCore::CSSParser::createHostRule): Ditto.
(WebCore::CSSParser::rewriteSpecifiersWithNamespaceIfNeeded): Got rid of the
unused return value from this function and changed it to to take a reference
instead of a pointer.
(WebCore::CSSParser::rewriteSpecifiersWithElementName): Ditto.
(WebCore::CSSParser::rewriteSpecifiers): Changed this to take and return OwnPtr.
(WebCore::CSSParser::createPageRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.
(WebCore::CSSParser::createSelectorVector): Added. Used to implement the
optimization where we recycle a single selector vector. Not sure we still need
this, or maybe we need more optimizations like it, but for now keep it.
(WebCore::CSSParser::recycleSelectorVector): Ditto.
(WebCore::CSSParser::createRegionRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.
(WebCore::CSSParser::createMarginAtRule): Got rid of unused return value.
When this function is implemented for real, we might add a return value.
(WebCore::CSSParser::createKeyframe): Don't put keyframe into m_parsedKeyframes,
return PassRefPtr instead.
(WebCore::CSSParser::createViewportRule): Don't put rule into m_parsedRules, return
PassRefPtr instead.

  • css/CSSParser.h: Removed many now-needed functions to manage floating items.

Changed rule creation functions to return PassRefPtr. Other changes as mentioned above.

  • css/CSSParserValues.cpp:

(WebCore::destroy): Added.
(WebCore::CSSParserValueList::~CSSParserValueList): Updated to call destroy.

  • css/CSSParserValues.h: Ditto.
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r155534 r155536  
     12013-09-11  Darin Adler  <darin@apple.com>
     2
     3        Rework CSS parser, eliminating "floating" concept and using %destructor
     4        https://bugs.webkit.org/show_bug.cgi?id=121161
     5
     6        Reviewed by Antti Koivisto.
     7
     8        This is some basic improvement, but there is still room for a lot more
     9        consistent approach and formatting in this file. There is a mix of code that
     10        works by side effects in the CSSParser class and code that works with the
     11        values that bison generates in the union that is more or less random. And
     12        the data structures seem too costly, with too much heap allocation. And the
     13        CSSParser class has grown massive, with a mix of both function for use by
     14        code that wants to trigger parsing, and helper functions called by code in
     15        the grammar file. All of that can benefit from more refinement in the future.
     16
     17        * css/CSSGrammar.y.in: Made some incremental improvements to the structure
     18        of the grammar file, including:
     19        - Breaking up the %union so types are declared next to their use
     20        - Eliminating one shift/reduce conflict caused by two "maybe_space" in a row
     21        - Breaking the conditional sections out into their own sections instead of
     22          scattering them in with the other code.
     23        - Eliminating unused return values in productions such as charset,
     24          ignored_charset, namespace, margin_box, invalid_rule, save_block,
     25          invalid_at, and declarations_and_margins.
     26        - Adding %destructor to productions that return values that need to be deleted
     27          or deref'd. This removes the need for CSSParser to separately track these
     28          as "floating" to clean up in case of errors.
     29        - Removing unneeded productions such as media_feature, region_selector,
     30          attr_name, and medium.
     31        - Removing explicit code blocks that just say "$$ = $1" or empty blocks when
     32          there is no return type, since those are default.
     33        - Formatting many productions on single lines since I find them easier to read.
     34          Later I think we could make many more CSSParser functions and make even
     35          more of the production single lines in the grammar file.
     36        - Using adoptPtr, adoptRef, delete, deref, leakPtr, and leakRef to put
     37          heap allocated values into and out of the union without storage leaks.
     38         
     39        * css/CSSParser.cpp:
     40        (WebCore::CSSParser::~CSSParser): Remove the now-unneeded deleteAllValues for
     41        the various colections of floating things.
     42        (WebCore::CSSParser::createFilterRule): Don't put the rule into m_parsedRules,
     43        just return a PassRefPtr instead.
     44        (WebCore::CSSParser::createImportRule): Ditto.
     45        (WebCore::CSSParser::createMediaRule): Ditto.
     46        (WebCore::CSSParser::createEmptyMediaRule): Ditto.
     47        (WebCore::CSSParser::createSupportsRule): Ditto.
     48        (WebCore::CSSParser::createKeyframesRule): Ditto.
     49        (WebCore::CSSParser::createStyleRule): Ditto.
     50        (WebCore::CSSParser::createFontFaceRule): Ditto.
     51        (WebCore::CSSParser::createHostRule): Ditto.
     52        (WebCore::CSSParser::rewriteSpecifiersWithNamespaceIfNeeded): Got rid of the
     53        unused return value from this function and changed it to to take a reference
     54        instead of a pointer.
     55        (WebCore::CSSParser::rewriteSpecifiersWithElementName): Ditto.
     56        (WebCore::CSSParser::rewriteSpecifiers): Changed this to take and return OwnPtr.
     57        (WebCore::CSSParser::createPageRule): Don't put rule into m_parsedRules, return
     58        PassRefPtr instead.
     59        (WebCore::CSSParser::createSelectorVector): Added. Used to implement the
     60        optimization where we recycle a single selector vector. Not sure we still need
     61        this, or maybe we need more optimizations like it, but for now keep it.
     62        (WebCore::CSSParser::recycleSelectorVector): Ditto.
     63        (WebCore::CSSParser::createRegionRule): Don't put rule into m_parsedRules, return
     64        PassRefPtr instead.
     65        (WebCore::CSSParser::createMarginAtRule): Got rid of unused return value.
     66        When this function is implemented for real, we might add a return value.
     67        (WebCore::CSSParser::createKeyframe): Don't put keyframe into m_parsedKeyframes,
     68        return PassRefPtr instead.
     69        (WebCore::CSSParser::createViewportRule): Don't put rule into m_parsedRules, return
     70        PassRefPtr instead.
     71
     72        * css/CSSParser.h: Removed many now-needed functions to manage floating items.
     73        Changed rule creation functions to return PassRefPtr. Other changes as mentioned above.
     74
     75        * css/CSSParserValues.cpp:
     76        (WebCore::destroy): Added.
     77        (WebCore::CSSParserValueList::~CSSParserValueList): Updated to call destroy.
     78        * css/CSSParserValues.h: Ditto.
     79
    1802013-09-11  Mario Sanchez Prada  <mario.prada@samsung.com>
    281
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r153822 r155536  
    2828
    2929%union {
    30     bool boolean;
    31     char character;
    32     int integer;
    3330    double number;
    3431    CSSParserString string;
    35 
    36     StyleRuleBase* rule;
    37     Vector<RefPtr<StyleRuleBase> >* ruleList;
    38     CSSParserSelector* selector;
    39     Vector<OwnPtr<CSSParserSelector> >* selectorList;
    4032    CSSSelector::MarginBoxType marginBox;
    41     CSSSelector::Relation relation;
    42     MediaQuerySet* mediaList;
    43     MediaQuery* mediaQuery;
    44     MediaQuery::Restrictor mediaQueryRestrictor;
    45     MediaQueryExp* mediaQueryExp;
    4633    CSSParserValue value;
    47     CSSParserValueList* valueList;
    48     Vector<OwnPtr<MediaQueryExp> >* mediaQueryExpList;
    49     StyleKeyframe* keyframe;
    50     Vector<RefPtr<StyleKeyframe> >* keyframeRuleList;
    51     float val;
    52     CSSPropertyID id;
    53     CSSParser::Location location;
    5434}
    5535
     
    8969
    9070#if ENABLE_SHADOW_DOM
    91 %expect 32
     71%expect 31
    9272#else
    93 %expect 31
     73%expect 30
    9474#endif
    9575
     
    123103%token PAGE_SYM
    124104%token MEDIA_SYM
    125 #if ENABLE_CSS3_CONDITIONAL_RULES
    126 %token SUPPORTS_SYM
    127 #endif
    128105%token FONT_FACE_SYM
    129 #if ENABLE_SHADOW_DOM
    130 %token HOST_SYM
    131 #endif
    132106%token CHARSET_SYM
    133107%token NAMESPACE_SYM
     
    142116%token WEBKIT_REGION_RULE_SYM
    143117%token WEBKIT_VIEWPORT_RULE_SYM
    144 #if ENABLE_CSS3_CONDITIONAL_RULES
    145 %token WEBKIT_SUPPORTS_CONDITION_SYM
    146 #endif
    147 #if ENABLE_CSS_SHADERS
    148 %token WEBKIT_FILTER_RULE_SYM
    149 #endif
    150118%token <marginBox> TOPLEFTCORNER_SYM
    151119%token <marginBox> TOPLEFT_SYM
     
    171139%token MEDIA_NOT
    172140%token MEDIA_AND
    173 #if ENABLE_CSS3_CONDITIONAL_RULES
    174 %token SUPPORTS_NOT
    175 %token SUPPORTS_AND
    176 %token SUPPORTS_OR
    177 #endif
    178141
    179142%token <number> REMS
     
    212175%token <string> FUNCTION
    213176%token <string> ANYFUNCTION
    214 #if ENABLE_VIDEO_TRACK
    215 %token <string> CUEFUNCTION
    216 #endif
    217177%token <string> NOTFUNCTION
    218178%token <string> CALCFUNCTION
     
    223183%token <string> UNICODERANGE
    224184
     185%union { CSSSelector::Relation relation; }
    225186%type <relation> combinator
    226187
    227 %type <rule> charset
    228 %type <rule> ignored_charset
    229 %type <rule> ruleset
    230 %type <rule> media
    231 %type <rule> import
    232 %type <rule> namespace
    233 %type <rule> page
    234 %type <rule> margin_box
    235 %type <rule> font_face
     188%union { StyleRuleBase* rule; }
     189%type <rule> block_rule block_valid_rule font_face import keyframes media page region rule ruleset valid_rule
     190%destructor { if ($$) $$->deref(); } block_rule block_valid_rule font_face import keyframes media page region rule ruleset valid_rule
     191
     192%union { Vector<RefPtr<StyleRuleBase>>* ruleList; }
     193%type <ruleList> block_rule_list block_valid_rule_list
     194%destructor { delete $$; } block_rule_list block_valid_rule_list
     195
     196%type <string> ident_or_string maybe_ns_prefix namespace_selector string_or_uri
     197
     198%type <marginBox> margin_sym
     199
     200%union { MediaQuerySet* mediaList; }
     201%type <mediaList> media_list maybe_media_list
     202%destructor { if ($$) $$->deref(); } media_list maybe_media_list
     203
     204%union { MediaQuery* mediaQuery; }
     205%type <mediaQuery> media_query
     206%destructor { delete $$; } media_query
     207
     208%union { MediaQuery::Restrictor mediaQueryRestrictor; }
     209%type <mediaQueryRestrictor> maybe_media_restrictor
     210
     211%union { MediaQueryExp* mediaQueryExp; }
     212%type <mediaQueryExp> media_query_exp
     213%destructor { delete $$; } media_query_exp
     214
     215%union { Vector<OwnPtr<MediaQueryExp>>* mediaQueryExpList; }
     216%type <mediaQueryExpList> media_query_exp_list maybe_and_media_query_exp_list
     217%destructor { delete $$; } media_query_exp_list maybe_and_media_query_exp_list
     218
     219%type <string> keyframe_name
     220
     221%union { StyleKeyframe* keyframe; }
     222%type <keyframe> keyframe_rule
     223%destructor { if ($$) $$->deref(); } keyframe_rule
     224
     225%union { Vector<RefPtr<StyleKeyframe>>* keyframeRuleList; }
     226%type <keyframeRuleList> keyframes_rule
     227%destructor { delete $$; } keyframes_rule
     228
     229// These two parser values never need to be destroyed because they are never functions.
     230%type <value> key unary_term
     231
     232// These parser values need to be destroyed because they might be functions.
     233%type <value> calc_func_term calc_function function min_or_max_function term
     234%destructor { destroy($$); } calc_func_term calc_function function min_or_max_function term
     235
     236%union { CSSPropertyID id; }
     237%type <id> property
     238
     239%union { CSSParserSelector* selector; }
     240%type <selector> attrib class page_selector pseudo pseudo_page selector simple_selector specifier specifier_list
     241%destructor { delete $$; } attrib class page_selector pseudo pseudo_page selector simple_selector specifier specifier_list
     242
     243%union { Vector<OwnPtr<CSSParserSelector>>* selectorList; }
     244%type <selectorList> selector_list simple_selector_list
     245%destructor { delete $$; } selector_list simple_selector_list
     246
     247%union { bool boolean; }
     248%type <boolean> declaration declaration_list decl_list priority
     249
     250%union { CSSSelector::Match match; }
     251%type <match> match
     252
     253%union { int integer; }
     254%type <integer> unary_operator maybe_unary_operator
     255
     256%union { char character; }
     257%type <character> operator calc_func_operator
     258
     259%union { CSSParserValueList* valueList; }
     260%type <valueList> calc_func_expr calc_func_expr_list calc_func_paren_expr expr key_list maybe_media_value valid_calc_func_expr valid_expr
     261%destructor { delete $$; } calc_func_expr calc_func_expr_list calc_func_paren_expr expr key_list maybe_media_value valid_calc_func_expr valid_expr
     262
     263%type <string> min_or_max
     264
     265%type <string> element_name
     266
     267%union { CSSParser::Location location; }
     268%type <location> error_location
     269
     270#if ENABLE_CSS3_CONDITIONAL_RULES
     271
     272%token SUPPORTS_AND
     273%token SUPPORTS_NOT
     274%token SUPPORTS_OR
     275%token SUPPORTS_SYM
     276%token WEBKIT_SUPPORTS_CONDITION_SYM
     277
     278%type <rule> supports
     279%destructor { if ($$) $$->deref(); } supports
     280
     281%type <boolean> supports_condition supports_condition_in_parens supports_conjunction supports_declaration_condition supports_disjunction supports_error supports_negation
     282
     283#endif
     284
     285#if ENABLE_CSS_DEVICE_ADAPTATION
     286
     287%type <rule> viewport
     288%destructor { if ($$) $$->deref(); } viewport
     289
     290#endif
     291
     292#if ENABLE_CSS_SHADERS
     293
     294%token WEBKIT_FILTER_RULE_SYM
     295
     296%type <rule> filter
     297%destructor { if ($$) $$->deref(); } filter
     298
     299#endif
     300
    236301#if ENABLE_SHADOW_DOM
     302
     303%token HOST_SYM
     304
    237305%type <rule> host
    238 #endif
    239 %type <rule> keyframes
    240 %type <rule> invalid_rule
    241 %type <rule> save_block
    242 %type <rule> invalid_at
    243 %type <rule> rule
    244 %type <rule> valid_rule
    245 %type <ruleList> block_rule_list
    246 %type <ruleList> region_block_rule_list
    247 %type <rule> block_rule
    248 %type <rule> block_valid_rule
    249 %type <rule> region
    250 #if ENABLE_CSS3_CONDITIONAL_RULES
    251 %type <rule> supports
    252 #endif
    253 #if ENABLE_CSS_DEVICE_ADAPTATION
    254 %type <rule> viewport
    255 #endif
    256 #if ENABLE_CSS_SHADERS
    257 %type <rule> filter
    258 #endif
    259 
    260 %type <string> maybe_ns_prefix
    261 
    262 %type <string> namespace_selector
    263 
    264 %type <string> string_or_uri
    265 %type <string> ident_or_string
    266 %type <string> medium
    267 %type <marginBox> margin_sym
    268 
    269 %type <string> media_feature
    270 %type <mediaList> media_list
    271 %type <mediaList> maybe_media_list
    272 %type <mediaQuery> media_query
    273 %type <mediaQueryRestrictor> maybe_media_restrictor
    274 %type <valueList> maybe_media_value
    275 %type <mediaQueryExp> media_query_exp
    276 %type <mediaQueryExpList> media_query_exp_list
    277 %type <mediaQueryExpList> maybe_and_media_query_exp_list
    278 
    279 #if ENABLE_CSS3_CONDITIONAL_RULES
    280 %type <boolean> supports_condition
    281 %type <boolean> supports_condition_in_parens
    282 %type <boolean> supports_negation
    283 %type <boolean> supports_conjunction
    284 %type <boolean> supports_disjunction
    285 %type <boolean> supports_declaration_condition
    286 %type <boolean> supports_error
    287 #endif
    288 
    289 %type <string> keyframe_name
    290 %type <keyframe> keyframe_rule
    291 %type <keyframeRuleList> keyframes_rule
    292 %type <valueList> key_list
    293 %type <value> key
    294 
    295 %type <id> property
    296 
    297 %type <selector> specifier
    298 %type <selector> specifier_list
    299 %type <selector> simple_selector
    300 %type <selector> selector
    301 %type <selectorList> selector_list
    302 %type <selectorList> simple_selector_list
    303 %type <selectorList> region_selector
    304 %type <selector> selector_with_trailing_whitespace
    305 %type <selector> class
    306 %type <selector> attrib
    307 %type <selector> pseudo
    308 %type <selector> pseudo_page
    309 %type <selector> page_selector
    310 
    311 %type <boolean> declaration_list
    312 %type <boolean> decl_list
    313 %type <boolean> declaration
    314 %type <boolean> declarations_and_margins
    315 
    316 %type <boolean> prio
    317 
    318 %type <integer> match
    319 %type <integer> unary_operator
    320 %type <integer> maybe_unary_operator
    321 %type <character> operator
    322 
    323 %type <valueList> expr
    324 %type <valueList> valid_expr
    325 %type <value> term
    326 %type <value> unary_term
    327 %type <value> function
    328 %type <value> calc_func_term
    329 %type <character> calc_func_operator
    330 %type <valueList> calc_func_expr
    331 %type <valueList> valid_calc_func_expr
    332 %type <valueList> calc_func_expr_list
    333 %type <valueList> calc_func_paren_expr
    334 %type <value> calc_function
    335 %type <string> min_or_max
    336 %type <value> min_or_max_function
    337 
    338 %type <string> element_name
    339 %type <string> attr_name
    340 
    341 %type <location> error_location
     306%destructor { if ($$) $$->deref(); } host
     307
     308#endif
     309
     310#if ENABLE_VIDEO_TRACK
     311
     312%token <string> CUEFUNCTION
     313
     314#endif
    342315
    343316%%
     
    356329  ;
    357330
    358 webkit_rule:
    359     WEBKIT_RULE_SYM '{' maybe_space valid_rule maybe_space '}' {
    360         parser->m_rule = $4;
    361     }
    362 ;
    363 
    364 webkit_keyframe_rule:
    365     WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space '}' {
    366         parser->m_keyframe = $4;
    367     }
    368 ;
    369 
    370 webkit_decls:
    371     WEBKIT_DECLS_SYM '{' maybe_space_before_declaration declaration_list '}' {
    372         /* can be empty */
    373     }
    374 ;
     331webkit_rule: WEBKIT_RULE_SYM '{' maybe_space valid_rule maybe_space '}' { parser->m_rule = $4; } ;
     332
     333webkit_keyframe_rule: WEBKIT_KEYFRAME_RULE_SYM '{' maybe_space keyframe_rule maybe_space '}' { parser->m_keyframe = adoptRef($4); } ;
     334
     335webkit_decls: WEBKIT_DECLS_SYM '{' maybe_space_before_declaration declaration_list '}' ;
    375336
    376337webkit_value:
    377338    WEBKIT_VALUE_SYM '{' maybe_space expr '}' {
    378339        if ($4) {
    379             parser->m_valueList = parser->sinkFloatingValueList($4);
     340            parser->m_valueList = adoptPtr($4);
    380341            int oldParsedProperties = parser->m_parsedProperties.size();
    381342            if (!parser->parseValue(parser->m_id, parser->m_important))
     
    386347;
    387348
    388 webkit_mediaquery:
    389      WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' {
    390          parser->m_mediaQuery = parser->sinkFloatingMediaQuery($4);
    391      }
    392 ;
     349webkit_mediaquery: WEBKIT_MEDIAQUERY_SYM WHITESPACE maybe_space media_query '}' { parser->m_mediaQuery = adoptPtr($4); } ;
    393350
    394351webkit_selector:
     
    397354            if (parser->m_selectorListForParseSelector)
    398355                parser->m_selectorListForParseSelector->adoptSelectorVector(*$4);
     356            parser->recycleSelectorVector(adoptPtr($4));
    399357        }
    400358    }
     
    402360
    403361#if ENABLE_CSS3_CONDITIONAL_RULES
    404 webkit_supports_condition:
    405     WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition '}' {
    406         parser->m_supportsCondition = $4;
    407     }
    408 ;
    409 #endif
    410 
    411 maybe_space:
    412     /* empty */ %prec UNIMPORTANT_TOK
    413   | maybe_space WHITESPACE
    414   ;
    415 
    416 maybe_sgml:
    417     /* empty */
    418   | maybe_sgml SGML_CD
    419   | maybe_sgml WHITESPACE
    420   ;
    421 
    422 maybe_charset:
    423    /* empty */
    424   | charset {
    425   }
    426   ;
    427 
    428 closing_brace:
    429     '}'
    430   | %prec LOWEST_PREC TOKEN_EOF
    431   ;
    432 
    433 closing_parenthesis:
    434     ')'
    435   | %prec LOWEST_PREC TOKEN_EOF
    436   ;
     362
     363webkit_supports_condition: WEBKIT_SUPPORTS_CONDITION_SYM '{' maybe_space supports_condition '}' { parser->m_supportsCondition = $4; } ;
     364
     365#endif
     366
     367maybe_space: /* empty */ %prec UNIMPORTANT_TOK | maybe_space WHITESPACE ;
     368
     369maybe_sgml: /* empty */ | maybe_sgml SGML_CD | maybe_sgml WHITESPACE ;
     370
     371maybe_charset: /* empty */ | charset ;
     372
     373closing_brace: '}' | %prec LOWEST_PREC TOKEN_EOF ;
     374
     375closing_parenthesis: ')' | %prec LOWEST_PREC TOKEN_EOF ;
    437376
    438377charset:
     
    442381     if (parser->isExtractingSourceData() && parser->m_currentRuleDataStack->isEmpty() && parser->m_ruleSourceDataResult)
    443382         parser->addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
    444      $$ = 0;
    445383  }
    446   | CHARSET_SYM error invalid_block {
    447   }
    448   | CHARSET_SYM error ';' {
    449   }
     384  | CHARSET_SYM error invalid_block
     385  | CHARSET_SYM error ';'
    450386;
    451387
    452 ignored_charset:
    453     CHARSET_SYM maybe_space STRING maybe_space ';' {
    454         // Ignore any @charset rule not at the beginning of the style sheet.
    455         $$ = 0;
    456     }
    457     | CHARSET_SYM maybe_space ';' {
    458         $$ = 0;
    459     }
    460 ;
     388// Ignore any @charset rule not at the beginning of the style sheet.
     389ignored_charset: CHARSET_SYM maybe_space STRING maybe_space ';' | CHARSET_SYM maybe_space ';' ;
    461390
    462391rule_list:
    463    /* empty */
    464  | rule_list rule maybe_sgml {
    465      if ($2 && parser->m_styleSheet)
    466          parser->m_styleSheet->parserAppendRule($2);
    467  }
    468  ;
     392    /* empty */
     393    | rule_list rule maybe_sgml {
     394        if (RefPtr<StyleRuleBase> rule = adoptRef($2)) {
     395            if (parser->m_styleSheet)
     396                parser->m_styleSheet->parserAppendRule(rule.release());
     397        }
     398    }
     399    ;
    469400
    470401valid_rule:
     
    474405  | font_face
    475406  | keyframes
    476   | namespace
     407  | namespace { $$ = 0; }
    477408  | import
    478409  | region
     
    493424rule:
    494425    valid_rule {
     426        $$ = $1;
    495427        parser->m_hadSyntacticallyValidCSSRule = true;
    496428    }
    497   | ignored_charset
    498   | invalid_rule
    499   | invalid_at
    500   ;
     429    | ignored_charset { $$ = 0; }
     430    | invalid_rule { $$ = 0; }
     431    | invalid_at { $$ = 0; }
     432    ;
    501433
    502434block_rule_list:
     
    504436  | block_rule_list block_rule maybe_sgml {
    505437      $$ = $1;
    506       if ($2) {
     438      if (RefPtr<StyleRuleBase> rule = adoptRef($2)) {
    507439          if (!$$)
    508               $$ = parser->createRuleList();
    509           $$->append($2);
     440              $$ = new Vector<RefPtr<StyleRuleBase>>;
     441          $$->append(rule.release());
    510442      }
    511443  }
    512444  ;
    513445
    514 region_block_rule_list:
     446block_valid_rule_list:
    515447    /* empty */ { $$ = 0; }
    516   | region_block_rule_list block_valid_rule maybe_sgml {
     448  | block_valid_rule_list block_valid_rule maybe_sgml {
    517449      $$ = $1;
    518       if ($2) {
     450      if (RefPtr<StyleRuleBase> rule = adoptRef($2)) {
    519451          if (!$$)
    520               $$ = parser->createRuleList();
    521           $$->append($2);
     452              $$ = new Vector<RefPtr<StyleRuleBase>>;
     453          $$->append(rule.release());
    522454      }
    523455  }
     
    541473  ;
    542474
    543 block_rule:
    544     block_valid_rule
    545   | invalid_rule
    546   | invalid_at
    547   | namespace
    548   | import
    549   | region
    550   ;
     475block_rule: block_valid_rule | invalid_rule { $$ = 0; } | invalid_at { $$ = 0; } | namespace { $$ = 0; } | import | region ;
    551476
    552477at_import_header_end_maybe_space:
     
    565490import:
    566491    before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list ';' {
    567         $$ = parser->createImportRule($4, $6);
     492        $$ = parser->createImportRule($4, adoptRef($6)).leakRef();
    568493    }
    569494  | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list TOKEN_EOF {
    570         $$ = parser->createImportRule($4, $6);
     495        $$ = parser->createImportRule($4, adoptRef($6)).leakRef();
    571496    }
    572497  | before_import_rule IMPORT_SYM at_import_header_end_maybe_space string_or_uri maybe_space maybe_media_list invalid_block {
    573498        $$ = 0;
    574499        parser->popRuleData();
     500        if ($6)
     501            $6->deref();
    575502    }
    576503  | before_import_rule IMPORT_SYM error ';' {
     
    585512
    586513namespace:
    587 NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' {
    588     parser->addNamespace($3, $4);
    589     $$ = 0;
    590 }
    591 | NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space invalid_block {
    592     $$ = 0;
    593 }
    594 | NAMESPACE_SYM error invalid_block {
    595     $$ = 0;
    596 }
    597 | NAMESPACE_SYM error ';' {
    598     $$ = 0;
    599 }
    600 ;
    601 
    602 maybe_ns_prefix:
    603 /* empty */ { $$.clear(); }
    604 | IDENT maybe_space { $$ = $1; }
    605 ;
    606 
    607 string_or_uri:
    608 STRING
    609 | URI
    610 ;
    611 
    612 media_feature:
    613     IDENT maybe_space {
    614         $$ = $1;
    615     }
    616     ;
    617 
    618 maybe_media_value:
    619     /*empty*/ {
    620         $$ = 0;
    621     }
    622     | ':' maybe_space expr maybe_space {
    623         $$ = $3;
    624     }
    625     ;
     514    NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space ';' { parser->addNamespace($3, $4); }
     515    | NAMESPACE_SYM maybe_space maybe_ns_prefix string_or_uri maybe_space invalid_block
     516    | NAMESPACE_SYM error invalid_block
     517    | NAMESPACE_SYM error ';'
     518    ;
     519
     520maybe_ns_prefix: /* empty */ { $$.clear(); } | IDENT maybe_space;
     521
     522string_or_uri: STRING | URI ;
     523
     524maybe_media_value: /*empty*/ { $$ = 0; } | ':' maybe_space expr maybe_space { $$ = $3; } ;
    626525
    627526media_query_exp:
    628     maybe_media_restrictor maybe_space '(' maybe_space media_feature maybe_space maybe_media_value ')' maybe_space {
     527    maybe_media_restrictor maybe_space '(' maybe_space IDENT maybe_space maybe_media_value ')' maybe_space {
    629528        // If restrictor is specified, media query expression is invalid.
    630529        // Create empty media query expression and continue parsing media query.
     530        OwnPtr<CSSParserValueList> mediaValue = adoptPtr($7);
    631531        if ($1 != MediaQuery::None)
    632             $$ = parser->createFloatingMediaQueryExp("", 0);
     532            $$ = MediaQueryExp::create(emptyString(), nullptr).leakPtr();
    633533        else {
    634534            $5.lower();
    635             $$ = parser->createFloatingMediaQueryExp($5, $7);
     535            $$ = MediaQueryExp::create($5, mediaValue.get()).leakPtr();
    636536        }
    637537    }
     
    640540media_query_exp_list:
    641541    media_query_exp {
    642         $$ = parser->createFloatingMediaQueryExpList();
    643         $$->append(parser->sinkFloatingMediaQueryExp($1));
     542        $$ = new Vector<OwnPtr<MediaQueryExp>>;
     543        $$->append(adoptPtr($1));
    644544    }
    645545    | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
    646546        $$ = $1;
    647         $$->append(parser->sinkFloatingMediaQueryExp($5));
     547        $$->append(adoptPtr($5));
    648548    }
    649549    ;
     
    651551maybe_and_media_query_exp_list:
    652552    /*empty*/ {
    653         $$ = parser->createFloatingMediaQueryExpList();
     553        $$ = new Vector<OwnPtr<MediaQueryExp>>;
    654554    }
    655555    | MEDIA_AND maybe_space media_query_exp_list {
     
    672572media_query:
    673573    media_query_exp_list {
    674         $$ = parser->createFloatingMediaQuery(parser->sinkFloatingMediaQueryExpList($1));
     574        $$ = new MediaQuery(MediaQuery::None, "all", adoptPtr($1));
    675575    }
    676576    |
    677     maybe_media_restrictor maybe_space medium maybe_and_media_query_exp_list {
     577    maybe_media_restrictor maybe_space IDENT maybe_space maybe_and_media_query_exp_list {
    678578        $3.lower();
    679         $$ = parser->createFloatingMediaQuery($1, $3, parser->sinkFloatingMediaQueryExpList($4));
    680     }
    681     ;
    682 
    683 maybe_media_list:
    684      /* empty */ {
    685         $$ = parser->createMediaQuerySet();
    686      }
    687      | media_list
    688      ;
     579        $$ = new MediaQuery($1, $3, adoptPtr($5));
     580    }
     581    ;
     582
     583maybe_media_list: /* empty */ { $$ = MediaQuerySet::create().leakRef(); } | media_list ;
    689584
    690585media_list:
    691586    media_query {
    692         $$ = parser->createMediaQuerySet();
    693         $$->addMediaQuery(parser->sinkFloatingMediaQuery($1));
     587        $$ = MediaQuerySet::create().leakRef();
     588        $$->addMediaQuery(adoptPtr($1));
    694589        parser->updateLastMediaLine($$);
    695590    }
    696591    | media_list ',' maybe_space media_query {
    697592        $$ = $1;
     593        OwnPtr<MediaQuery> mediaQuery = adoptPtr($4);
    698594        if ($$) {
    699             $$->addMediaQuery(parser->sinkFloatingMediaQuery($4));
     595            $$->addMediaQuery(mediaQuery.release());
    700596            parser->updateLastMediaLine($$);
    701597        }
     
    703599    | media_list error {
    704600        $$ = 0;
     601        if ($1)
     602            $1->deref();
    705603    }
    706604    ;
     
    726624media:
    727625    before_media_rule MEDIA_SYM maybe_space media_list at_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
    728         $$ = parser->createMediaRule($4, $9);
     626        $$ = parser->createMediaRule(adoptRef($4), adoptPtr($9).get()).leakRef();
    729627    }
    730628    | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space block_rule_list save_block {
    731         $$ = parser->createEmptyMediaRule($7);
     629        $$ = parser->createEmptyMediaRule(adoptPtr($7).get()).leakRef();
    732630    }
    733631    | before_media_rule MEDIA_SYM at_rule_header_end_maybe_space ';' {
     
    737635    ;
    738636
    739 medium:
    740   IDENT maybe_space {
    741       $$ = $1;
    742   }
    743   ;
    744 
    745637#if ENABLE_CSS3_CONDITIONAL_RULES
     638
    746639supports:
    747640    before_supports_rule SUPPORTS_SYM maybe_space supports_condition at_supports_rule_header_end '{' at_rule_body_start maybe_space block_rule_list save_block {
    748         $$ = parser->createSupportsRule($4, $9);
     641        $$ = parser->createSupportsRule($4, adoptPtr($9).get()).leakRef();
    749642    }
    750643    | before_supports_rule SUPPORTS_SYM supports_error {
     
    755648    ;
    756649
    757 supports_error:
    758     error ';'
    759     | error invalid_block
     650supports_error: error ';' | error invalid_block ;
    760651
    761652before_supports_rule:
     
    773664    ;
    774665
    775 supports_condition:
    776     supports_condition_in_parens
    777     | supports_negation
    778     | supports_conjunction
    779     | supports_disjunction
    780     ;
    781 
    782 supports_negation:
    783     SUPPORTS_NOT maybe_space supports_condition_in_parens {
    784         $$ = !$3;
    785     }
    786     ;
     666supports_condition: supports_condition_in_parens | supports_negation | supports_conjunction | supports_disjunction ;
     667
     668supports_negation: SUPPORTS_NOT maybe_space supports_condition_in_parens { $$ = !$3; } ;
    787669
    788670supports_conjunction:
    789     supports_condition_in_parens SUPPORTS_AND maybe_space supports_condition_in_parens {
    790         $$ = $1 && $4;
    791     }
    792     | supports_conjunction SUPPORTS_AND maybe_space supports_condition_in_parens {
    793         $$ = $1 && $4;
    794     }
     671    supports_condition_in_parens SUPPORTS_AND maybe_space supports_condition_in_parens { $$ = $1 && $4; }
     672    | supports_conjunction SUPPORTS_AND maybe_space supports_condition_in_parens { $$ = $1 && $4; }
    795673    ;
    796674
    797675supports_disjunction:
    798     supports_condition_in_parens SUPPORTS_OR maybe_space supports_condition_in_parens {
    799         $$ = $1 || $4;
    800     }
    801     | supports_disjunction SUPPORTS_OR maybe_space supports_condition_in_parens {
    802         $$ = $1 || $4;
    803     }
     676    supports_condition_in_parens SUPPORTS_OR maybe_space supports_condition_in_parens { $$ = $1 || $4; }
     677    | supports_disjunction SUPPORTS_OR maybe_space supports_condition_in_parens { $$ = $1 || $4; }
    804678    ;
    805679
    806680supports_condition_in_parens:
    807     '(' maybe_space supports_condition ')' maybe_space {
    808         $$ = $3;
    809     }
     681    '(' maybe_space supports_condition ')' maybe_space { $$ = $3; }
    810682    | supports_declaration_condition
    811683    | '(' error ')'
     
    813685
    814686supports_declaration_condition:
    815     '(' maybe_space property ':' maybe_space expr prio ')' maybe_space {
     687    '(' maybe_space property ':' maybe_space expr priority ')' maybe_space {
    816688        $$ = false;
    817689        CSSParser* p = static_cast<CSSParser*>(parser);
    818         if ($3 && $6) {
    819             p->m_valueList = p->sinkFloatingValueList($6);
     690        OwnPtr<CSSParserExpression> propertyValue = adoptPtr($6);
     691        if ($3 && propertyValue) {
     692            p->m_valueList = propertyValue.release();
    820693            int oldParsedProperties = p->m_parsedProperties.size();
    821             $$ = p->parseValue(static_cast<CSSPropertyID>($3), $7);
     694            $$ = p->parseValue($3, $7);
    822695            // We just need to know if the declaration is supported as it is written. Rollback any additions.
    823696            if ($$)
     
    828701    }
    829702    ;
     703
    830704#endif
    831705
     
    838712keyframes:
    839713    before_keyframes_rule WEBKIT_KEYFRAMES_SYM maybe_space keyframe_name at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space keyframes_rule closing_brace {
    840         $$ = parser->createKeyframesRule($4, parser->sinkFloatingKeyframeVector($9));
     714        $$ = parser->createKeyframesRule($4, adoptPtr($9)).leakRef();
    841715    }
    842716    ;
    843717 
    844 keyframe_name:
    845     IDENT
    846     | STRING
    847     ;
     718keyframe_name: IDENT | STRING ;
    848719
    849720keyframes_rule:
    850     /* empty */ { $$ = parser->createFloatingKeyframeVector(); }
     721    /* empty */ { $$ = new Vector<RefPtr<StyleKeyframe>>; }
    851722    | keyframes_rule keyframe_rule maybe_space {
    852723        $$ = $1;
    853         if ($2)
    854             $$->append($2);
    855     }
    856     ;
    857 
    858 keyframe_rule:
    859     key_list maybe_space '{' maybe_space declaration_list closing_brace {
    860         $$ = parser->createKeyframe($1);
    861     }
    862     ;
     724        if (RefPtr<StyleKeyframe> keyframe = adoptRef($2))
     725            $$->append(keyframe.release());
     726    }
     727    ;
     728
     729keyframe_rule: key_list maybe_space '{' maybe_space declaration_list closing_brace { $$ = parser->createKeyframe(*adoptPtr($1)).leakRef(); } ;
    863730
    864731key_list:
    865732    key {
    866         $$ = parser->createFloatingValueList();
    867         $$->addValue(parser->sinkFloatingValue($1));
     733        $$ = new CSSParserValueList;
     734        $$->addValue($1);
    868735    }
    869736    | key_list maybe_space ',' maybe_space key {
    870737        $$ = $1;
     738        ASSERT($5.unit != CSSParserValue::Function); // No need to call destroy.
    871739        if ($$)
    872             $$->addValue(parser->sinkFloatingValue($5));
     740            $$->addValue($5);
    873741    }
    874742    ;
     
    903771    '{' at_rule_body_start maybe_space_before_declaration declarations_and_margins closing_brace {
    904772        if ($4)
    905             $$ = parser->createPageRule(parser->sinkFloatingSelector($4));
     773            $$ = parser->createPageRule(adoptPtr($4)).leakRef();
    906774        else {
    907775            // Clear properties in the invalid @page rule.
     
    913781    }
    914782    | before_page_rule PAGE_SYM error invalid_block {
    915       parser->popRuleData();
    916       $$ = 0;
     783        parser->popRuleData();
     784        $$ = 0;
    917785    }
    918786    | before_page_rule PAGE_SYM error ';' {
    919       parser->popRuleData();
    920       $$ = 0;
     787        parser->popRuleData();
     788        $$ = 0;
    921789    }
    922790    ;
     
    924792page_selector:
    925793    IDENT {
    926         $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
     794        $$ = new CSSParserSelector(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
    927795        $$->setForPage();
    928796    }
     
    940808    }
    941809    | /* empty */ {
    942         $$ = parser->createFloatingSelector();
     810        $$ = new CSSParserSelector;
    943811        $$->setForPage();
    944812    }
    945813    ;
    946814
    947 declarations_and_margins:
    948     declaration_list
    949     | declarations_and_margins margin_box maybe_space declaration_list
    950     ;
     815declarations_and_margins: declaration_list | declarations_and_margins margin_box maybe_space declaration_list ;
    951816
    952817margin_box:
     
    954819        parser->startDeclarationsForMarginBox();
    955820    } maybe_space '{' maybe_space declaration_list closing_brace {
    956         $$ = parser->createMarginAtRule($1);
    957     }
    958     ;
    959 
    960 margin_sym :
     821        parser->createMarginAtRule($1);
     822    }
     823    ;
     824
     825margin_sym:
    961826    TOPLEFTCORNER_SYM {
    962827        $$ = CSSSelector::TopLeftCornerMarginBox;
     
    1016881
    1017882font_face:
    1018     before_font_face_rule FONT_FACE_SYM at_rule_header_end_maybe_space
    1019     '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
    1020         $$ = parser->createFontFaceRule();
     883    before_font_face_rule FONT_FACE_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
     884        $$ = parser->createFontFaceRule().leakRef();
    1021885    }
    1022886    | before_font_face_rule FONT_FACE_SYM error invalid_block {
    1023       $$ = 0;
    1024       parser->popRuleData();
     887        $$ = 0;
     888        parser->popRuleData();
    1025889    }
    1026890    | before_font_face_rule FONT_FACE_SYM error ';' {
    1027       $$ = 0;
    1028       parser->popRuleData();
     891        $$ = 0;
     892        parser->popRuleData();
    1029893    }
    1030894;
    1031895
    1032896#if ENABLE_SHADOW_DOM
     897
    1033898before_host_rule:
    1034899    /* empty */ {
     
    1038903
    1039904host:
    1040     before_host_rule HOST_SYM at_rule_header_end_maybe_space
    1041     '{' at_rule_body_start maybe_space block_rule_list save_block {
    1042         $$ = parser->createHostRule($7);
     905    before_host_rule HOST_SYM at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space block_rule_list save_block {
     906        $$ = parser->createHostRule(adoptPtr($7).get()).leakRef();
    1043907    }
    1044908    | before_host_rule HOST_SYM at_rule_header_end_maybe_space ';' {
     
    1047911    }
    1048912    ;
     913
    1049914#endif
    1050915
    1051916#if ENABLE_CSS_DEVICE_ADAPTATION
     917
    1052918before_viewport_rule:
    1053919    /* empty */ {
     
    1060926    before_viewport_rule WEBKIT_VIEWPORT_RULE_SYM at_rule_header_end_maybe_space
    1061927    '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
    1062         $$ = parser->createViewportRule();
     928        $$ = parser->createViewportRule().leakRef();
    1063929        parser->markViewportRuleBodyEnd();
    1064930    }
     
    1074940    }
    1075941;
    1076 #endif
    1077 
    1078 region_selector:
    1079     selector_list {
    1080         if ($1) {
    1081             parser->setReusableRegionSelectorVector($1);
    1082             $$ = parser->reusableRegionSelectorVector();
    1083         }
    1084         else
    1085             $$ = 0;
    1086     }
    1087 ;
     942
     943#endif
    1088944
    1089945before_region_rule:
     
    1094950
    1095951region:
    1096     before_region_rule WEBKIT_REGION_RULE_SYM WHITESPACE region_selector at_rule_header_end '{' at_rule_body_start maybe_space region_block_rule_list save_block {
     952    before_region_rule WEBKIT_REGION_RULE_SYM WHITESPACE selector_list at_rule_header_end '{' at_rule_body_start maybe_space block_valid_rule_list save_block {
     953        OwnPtr<Vector<RefPtr<StyleRuleBase>>> ruleList = adoptPtr($9);
    1097954        if ($4)
    1098             $$ = parser->createRegionRule($4, $9);
     955            $$ = parser->createRegionRule($4, ruleList.get()).leakRef();
    1099956        else {
    1100957            $$ = 0;
     
    1105962
    1106963#if ENABLE_CSS_SHADERS
     964
    1107965before_filter_rule:
    1108966    /* empty */ {
     
    1113971
    1114972filter:
    1115     before_filter_rule WEBKIT_FILTER_RULE_SYM WHITESPACE IDENT at_rule_header_end_maybe_space
    1116     '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
     973    before_filter_rule WEBKIT_FILTER_RULE_SYM WHITESPACE IDENT at_rule_header_end_maybe_space '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
    1117974        parser->m_inFilterRule = false;
    1118         $$ = parser->createFilterRule($4);
    1119     }
    1120     ;
     975        $$ = parser->createFilterRule($4).leakRef();
     976    }
     977    ;
     978
    1121979#endif
    1122980
     
    1127985  ;
    1128986
    1129 maybe_unary_operator:
    1130     unary_operator { $$ = $1; }
    1131     | { $$ = 1; }
    1132     ;
    1133 
    1134 unary_operator:
    1135     '-' { $$ = -1; }
    1136   | '+' { $$ = 1; }
    1137   ;
    1138 
    1139 maybe_space_before_declaration:
    1140     maybe_space {
    1141         parser->markPropertyStart();
    1142     }
    1143   ;
     987maybe_unary_operator: unary_operator | { $$ = 1; } ;
     988
     989unary_operator: '-' { $$ = -1; } | '+' { $$ = 1; } ;
     990
     991maybe_space_before_declaration: maybe_space { parser->markPropertyStart(); } ;
    1144992
    1145993before_selector_list:
    1146     /* empty */ {
     994    {
    1147995        parser->markRuleHeaderStart(CSSRuleSourceData::STYLE_RULE);
    1148996        parser->markSelectorStart();
     
    1150998  ;
    1151999
    1152 at_rule_header_end:
    1153     /* empty */ {
    1154         parser->markRuleHeaderEnd();
    1155     }
    1156   ;
    1157 
    1158 at_selector_end:
    1159     /* empty */ {
    1160         parser->markSelectorEnd();
    1161     }
    1162   ;
     1000at_rule_header_end: { parser->markRuleHeaderEnd(); } ;
     1001
     1002at_selector_end: { parser->markSelectorEnd(); } ;
    11631003
    11641004ruleset:
    11651005    before_selector_list selector_list at_selector_end at_rule_header_end '{' at_rule_body_start maybe_space_before_declaration declaration_list closing_brace {
    1166         $$ = parser->createStyleRule($2);
    1167     }
    1168   ;
    1169 
    1170 before_selector_group_item:
    1171     /* empty */ {
    1172         parser->markSelectorStart();
    1173     }
     1006        $$ = parser->createStyleRule($2).leakRef();
     1007        parser->recycleSelectorVector(adoptPtr($2));
     1008    }
     1009  ;
     1010
     1011before_selector_group_item: { parser->markSelectorStart(); } ;
    11741012
    11751013selector_list:
    11761014    selector %prec UNIMPORTANT_TOK {
     1015        $$ = 0;
    11771016        if ($1) {
    1178             $$ = parser->reusableSelectorVector();
    1179             $$->shrink(0);
    1180             $$->append(parser->sinkFloatingSelector($1));
     1017            $$ = parser->createSelectorVector().leakPtr();
     1018            $$->append(adoptPtr($1));
    11811019            parser->updateLastSelectorLineAndPosition();
    11821020        }
    11831021    }
    11841022    | selector_list at_selector_end ',' maybe_space before_selector_group_item selector %prec UNIMPORTANT_TOK {
    1185         if ($1 && $6) {
    1186             $$ = $1;
    1187             $$->append(parser->sinkFloatingSelector($6));
     1023        OwnPtr<Vector<OwnPtr<CSSParserSelector>>> selectorList = adoptPtr($1);
     1024        OwnPtr<CSSParserSelector> selector = adoptPtr($6);
     1025        $$ = 0;
     1026        if (selectorList && selector) {
     1027            $$ = selectorList.leakPtr();
     1028            $$->append(selector.release());
    11881029            parser->updateLastSelectorLineAndPosition();
    1189         } else
    1190             $$ = 0;
    1191     }
    1192   | selector_list error {
    1193         $$ = 0;
     1030        }
     1031    }
     1032    | selector_list error {
     1033        $$ = 0;
     1034        delete $1;
    11941035    }
    11951036   ;
    11961037
    1197 selector_with_trailing_whitespace:
    1198     selector WHITESPACE {
    1199         $$ = $1;
    1200     }
    1201     ;
    1202 
    12031038selector:
    1204     simple_selector {
    1205         $$ = $1;
    1206     }
    1207     | selector_with_trailing_whitespace
    1208     {
    1209         $$ = $1;
    1210     }
    1211     | selector_with_trailing_whitespace simple_selector
    1212     {
    1213         $$ = $2;
    1214         if (!$1)
    1215             $$ = 0;
    1216         else if ($$)
    1217             $$->appendTagHistory(CSSSelector::Descendant, parser->sinkFloatingSelector($1));
     1039    simple_selector
     1040    | selector WHITESPACE
     1041    | selector WHITESPACE simple_selector {
     1042        OwnPtr<CSSParserSelector> left = adoptPtr($1);
     1043        OwnPtr<CSSParserSelector> right = adoptPtr($3);
     1044        $$ = 0;
     1045        if (left && right) {
     1046            right->appendTagHistory(CSSSelector::Descendant, left.release());
     1047            $$ = right.leakPtr();
     1048        }
    12181049    }
    12191050    | selector combinator simple_selector {
    1220         $$ = $3;
    1221         if (!$1)
    1222             $$ = 0;
    1223         else if ($$)
    1224             $$->appendTagHistory($2, parser->sinkFloatingSelector($1));
     1051        OwnPtr<CSSParserSelector> left = adoptPtr($1);
     1052        OwnPtr<CSSParserSelector> right = adoptPtr($3);
     1053        $$ = 0;
     1054        if (left && right) {
     1055            right->appendTagHistory($2, left.release());
     1056            $$ = right.leakPtr();
     1057        }
    12251058    }
    12261059    | selector error {
    12271060        $$ = 0;
     1061        delete $1;
    12281062    }
    12291063    ;
    12301064
    12311065namespace_selector:
    1232     /* empty */ '|' { $$.clear(); }
     1066    '|' { $$.clear(); }
    12331067    | '*' '|' { static LChar star = '*'; $$.init(&star, 1); }
    1234     | IDENT '|' { $$ = $1; }
     1068    | IDENT '|'
    12351069;
    1236    
     1070
    12371071simple_selector:
    12381072    element_name {
    1239         $$ = parser->createFloatingSelectorWithTagName(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
     1073        $$ = new CSSParserSelector(QualifiedName(nullAtom, $1, parser->m_defaultNamespace));
    12401074    }
    12411075    | element_name specifier_list {
    12421076        $$ = $2;
    12431077        if ($$)
    1244             $$ = parser->rewriteSpecifiersWithElementName(nullAtom, $1, $$);
     1078            parser->rewriteSpecifiersWithElementName(nullAtom, $1, *$$);
    12451079    }
    12461080    | specifier_list {
    12471081        $$ = $1;
    12481082        if ($$)
    1249             $$ = parser->rewriteSpecifiersWithNamespaceIfNeeded($$);
     1083            parser->rewriteSpecifiersWithNamespaceIfNeeded(*$$);
    12501084    }
    12511085    | namespace_selector element_name {
    1252         $$ = parser->createFloatingSelectorWithTagName(parser->determineNameInNamespace($1, $2));
     1086        $$ = new CSSParserSelector(parser->determineNameInNamespace($1, $2));
    12531087    }
    12541088    | namespace_selector element_name specifier_list {
    12551089        $$ = $3;
    12561090        if ($$)
    1257             $$ = parser->rewriteSpecifiersWithElementName($1, $2, $$);
     1091            parser->rewriteSpecifiersWithElementName($1, $2, *$$);
    12581092    }
    12591093    | namespace_selector specifier_list {
    12601094        $$ = $2;
    12611095        if ($$)
    1262             $$ = parser->rewriteSpecifiersWithElementName($1, starAtom, $$);
     1096            parser->rewriteSpecifiersWithElementName($1, starAtom, *$$);
    12631097    }
    12641098  ;
     
    12661100simple_selector_list:
    12671101    simple_selector %prec UNIMPORTANT_TOK {
     1102        $$ = 0;
    12681103        if ($1) {
    1269             $$ = parser->createFloatingSelectorVector();
    1270             $$->append(parser->sinkFloatingSelector($1));
    1271         } else
    1272             $$ = 0;
     1104            $$ = parser->createSelectorVector().leakPtr();
     1105            $$->append(adoptPtr($1));
     1106        }
    12731107    }
    12741108    | simple_selector_list maybe_space ',' maybe_space simple_selector %prec UNIMPORTANT_TOK {
    1275         if ($1 && $5) {
    1276             $$ = $1;
    1277             $$->append(parser->sinkFloatingSelector($5));
    1278         } else
    1279             $$ = 0;
     1109        OwnPtr<Vector<OwnPtr<CSSParserSelector>>> list = adoptPtr($1);
     1110        OwnPtr<CSSParserSelector> selector = adoptPtr($5);
     1111        $$ = 0;
     1112        if (list && selector) {
     1113            $$ = list.leakPtr();
     1114            $$->append(selector.release());
     1115        }
    12801116    }
    12811117    | simple_selector_list error {
    12821118        $$ = 0;
    1283     }
    1284   ;
     1119        delete $1;
     1120    }
     1121    ;
    12851122
    12861123element_name:
    12871124    IDENT {
    1288         CSSParserString& str = $1;
    12891125        if (parser->m_context.isHTMLDocument)
    1290             str.lower();
    1291         $$ = str;
     1126            $1.lower();
     1127        $$ = $1;
    12921128    }
    12931129    | '*' {
     
    12951131        $$.init(&star, 1);
    12961132    }
    1297   ;
     1133    ;
    12981134
    12991135specifier_list:
    1300     specifier {
    1301         $$ = $1;
    1302     }
     1136    specifier
    13031137    | specifier_list specifier {
    1304         if (!$2)
    1305             $$ = 0;
    1306         else if ($1)
    1307             $$ = parser->rewriteSpecifiers($1, $2);
     1138        OwnPtr<CSSParserSelector> list = adoptPtr($1);
     1139        OwnPtr<CSSParserSelector> specifier = adoptPtr($2);
     1140        $$ = 0;
     1141        if (list && specifier)
     1142            $$ = parser->rewriteSpecifiers(list.release(), specifier.release()).leakPtr();
    13081143    }
    13091144    | specifier_list error {
    13101145        $$ = 0;
     1146        delete $1;
    13111147    }
    13121148;
     
    13141150specifier:
    13151151    IDSEL {
    1316         $$ = parser->createFloatingSelector();
     1152        $$ = new CSSParserSelector;
    13171153        $$->setMatch(CSSSelector::Id);
    13181154        if (parser->m_context.mode == CSSQuirksMode)
     
    13211157    }
    13221158  | HEX {
    1323         if ($1[0] >= '0' && $1[0] <= '9') {
     1159        if ($1[0] >= '0' && $1[0] <= '9')
    13241160            $$ = 0;
    1325         } else {
    1326             $$ = parser->createFloatingSelector();
     1161        else {
     1162            $$ = new CSSParserSelector;
    13271163            $$->setMatch(CSSSelector::Id);
    13281164            if (parser->m_context.mode == CSSQuirksMode)
     
    13381174class:
    13391175    '.' IDENT {
    1340         $$ = parser->createFloatingSelector();
     1176        $$ = new CSSParserSelector;
    13411177        $$->setMatch(CSSSelector::Class);
    13421178        if (parser->m_context.mode == CSSQuirksMode)
     
    13461182  ;
    13471183
    1348 attr_name:
    1349     IDENT maybe_space {
    1350         $$ = $1;
    1351     }
    1352     ;
    1353 
    13541184attrib:
    1355     '[' maybe_space attr_name ']' {
    1356         $$ = parser->createFloatingSelector();
     1185    '[' maybe_space IDENT maybe_space ']' {
     1186        $$ = new CSSParserSelector;
    13571187        $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom), parser->m_context.isHTMLDocument);
    13581188        $$->setMatch(CSSSelector::Set);
    13591189    }
    1360     | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space ']' {
    1361         $$ = parser->createFloatingSelector();
     1190    | '[' maybe_space IDENT maybe_space match maybe_space ident_or_string maybe_space ']' {
     1191        $$ = new CSSParserSelector;
    13621192        $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom), parser->m_context.isHTMLDocument);
    1363         $$->setMatch((CSSSelector::Match)$4);
    1364         $$->setValue($6);
    1365     }
    1366     | '[' maybe_space namespace_selector attr_name ']' {
    1367         $$ = parser->createFloatingSelector();
     1193        $$->setMatch($5);
     1194        $$->setValue($7);
     1195    }
     1196    | '[' maybe_space namespace_selector IDENT maybe_space ']' {
     1197        $$ = new CSSParserSelector;
    13681198        $$->setAttribute(parser->determineNameInNamespace($3, $4), parser->m_context.isHTMLDocument);
    13691199        $$->setMatch(CSSSelector::Set);
    13701200    }
    1371     | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_string maybe_space ']' {
    1372         $$ = parser->createFloatingSelector();
     1201    | '[' maybe_space namespace_selector IDENT maybe_space match maybe_space ident_or_string maybe_space ']' {
     1202        $$ = new CSSParserSelector;
    13731203        $$->setAttribute(parser->determineNameInNamespace($3, $4), parser->m_context.isHTMLDocument);
    1374         $$->setMatch((CSSSelector::Match)$5);
    1375         $$->setValue($7);
     1204        $$->setMatch($6);
     1205        $$->setValue($8);
    13761206    }
    13771207  ;
     
    13981228    ;
    13991229
    1400 ident_or_string:
    1401     IDENT
    1402   | STRING
    1403     ;
     1230ident_or_string: IDENT | STRING ;
    14041231
    14051232pseudo_page:
    14061233    ':' IDENT {
    1407         $$ = parser->createFloatingSelector();
     1234        $$ = new CSSParserSelector;
    14081235        $$->setMatch(CSSSelector::PagePseudoClass);
    14091236        $2.lower();
     
    14161243pseudo:
    14171244    ':' IDENT {
    1418         $$ = parser->createFloatingSelector();
     1245        $$ = new CSSParserSelector;
    14191246        $$->setMatch(CSSSelector::PseudoClass);
    14201247        $2.lower();
     
    14251252    }
    14261253    | ':' ':' IDENT {
    1427         $$ = parser->createFloatingSelector();
     1254        $$ = new CSSParserSelector;
    14281255        $$->setMatch(CSSSelector::PseudoElement);
    14291256        $3.lower();
     
    14371264    // used by ::cue(:past/:future)
    14381265    | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space ')' {
     1266        $$ = 0;
    14391267        if ($5) {
    1440             $$ = parser->createFloatingSelector();
     1268            $$ = new CSSParserSelector;
    14411269            $$->setMatch(CSSSelector::PseudoClass);
    1442             $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($5));
     1270            $$->adoptSelectorVector(*adoptPtr($5));
    14431271            $$->setValue($3);
    14441272            CSSSelector::PseudoType type = $$->pseudoType();
    14451273            if (type != CSSSelector::PseudoCue)
    14461274                $$ = 0;
    1447         } else
    1448             $$ = 0;
     1275        }
    14491276    }
    14501277#endif
     
    14551282    // related discussion with respect to :not.
    14561283    | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space ')' {
     1284        $$ = 0;
    14571285        if ($4) {
    1458             $$ = parser->createFloatingSelector();
     1286            $$ = new CSSParserSelector;
    14591287            $$->setMatch(CSSSelector::PseudoClass);
    1460             $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
     1288            $$->adoptSelectorVector(*adoptPtr($4));
    14611289            $2.lower();
    14621290            $$->setValue($2);
     
    14641292            if (type != CSSSelector::PseudoAny)
    14651293                $$ = 0;
    1466         } else
    1467             $$ = 0;
     1294        }
    14681295    }
    14691296    // used by :nth-*(ax+b)
    14701297    | ':' FUNCTION maybe_space NTH maybe_space ')' {
    1471         $$ = parser->createFloatingSelector();
     1298        $$ = new CSSParserSelector;
    14721299        $$->setMatch(CSSSelector::PseudoClass);
    14731300        $$->setArgument($4);
     
    14791306    // used by :nth-*
    14801307    | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space ')' {
    1481         $$ = parser->createFloatingSelector();
     1308        $$ = new CSSParserSelector;
    14821309        $$->setMatch(CSSSelector::PseudoClass);
    14831310        $$->setArgument(String::number($4 * $5));
     
    14891316    // used by :nth-*(odd/even) and :lang
    14901317    | ':' FUNCTION maybe_space IDENT maybe_space ')' {
    1491         $$ = parser->createFloatingSelector();
     1318        $$ = new CSSParserSelector;
    14921319        $$->setMatch(CSSSelector::PseudoClass);
    14931320        $$->setArgument($4);
     
    15071334    // used by :not
    15081335    | ':' NOTFUNCTION maybe_space simple_selector maybe_space ')' {
    1509         if (!$4 || !$4->isSimple())
    1510             $$ = 0;
    1511         else {
    1512             $$ = parser->createFloatingSelector();
     1336        OwnPtr<CSSParserSelector> selector = adoptPtr($4);
     1337        $$ =0;
     1338        if (selector && selector->isSimple()) {
     1339            $$ = new CSSParserSelector;
    15131340            $$->setMatch(CSSSelector::PseudoClass);
    15141341
    1515             Vector<OwnPtr<CSSParserSelector> > selectorVector;
    1516             selectorVector.append(parser->sinkFloatingSelector($4));
     1342            Vector<OwnPtr<CSSParserSelector>> selectorVector;
     1343            selectorVector.append(selector.release());
    15171344            $$->adoptSelectorVector(selectorVector);
    15181345
     
    15251352declaration_list:
    15261353    /* empty */ { $$ = false; }
    1527     | declaration {
    1528         $$ = $1;
    1529     }
    1530     | decl_list declaration {
    1531         $$ = $1;
    1532         if ( $2 )
    1533             $$ = $2;
    1534     }
    1535     | decl_list {
    1536         $$ = $1;
    1537     }
    1538     | decl_list_recovery {
    1539         $$ = false;
    1540     }
    1541     | decl_list decl_list_recovery {
    1542         $$ = $1;
    1543     }
     1354    | declaration
     1355    | decl_list declaration { $$ = $1 || $2; }
     1356    | decl_list
     1357    | decl_list_recovery { $$ = false; }
     1358    | decl_list decl_list_recovery
    15441359    ;
    15451360
     
    15721387
    15731388declaration:
    1574     VAR_DEFINITION maybe_space ':' maybe_space expr prio {
     1389    VAR_DEFINITION maybe_space ':' maybe_space expr priority {
    15751390#if ENABLE_CSS_VARIABLES
    1576         parser->storeVariableDeclaration($1, parser->sinkFloatingValueList($5), $6);
     1391        parser->storeVariableDeclaration($1, adoptPtr($5), $6);
    15771392        $$ = true;
    15781393        parser->markPropertyEnd($6, true);
    15791394#else
     1395        delete $5;
    15801396        $$ = false;
    15811397#endif
    15821398    }
    1583     |
    1584     property ':' maybe_space expr prio {
     1399    | property ':' maybe_space expr priority {
    15851400        $$ = false;
    15861401        bool isPropertyParsed = false;
    1587         if ($1 && $4) {
    1588             parser->m_valueList = parser->sinkFloatingValueList($4);
     1402        OwnPtr<CSSParserValueList> propertyValue = adoptPtr($4);
     1403        if ($1 && propertyValue) {
     1404            parser->m_valueList = propertyValue.release();
    15891405            int oldParsedProperties = parser->m_parsedProperties.size();
    1590             $$ = parser->parseValue(static_cast<CSSPropertyID>($1), $5);
     1406            $$ = parser->parseValue($1, $5);
    15911407            if (!$$)
    15921408                parser->rollbackLastProperties(parser->m_parsedProperties.size() - oldParsedProperties);
     
    15971413        parser->markPropertyEnd($5, isPropertyParsed);
    15981414    }
    1599     |
    1600     property declaration_recovery {
     1415    | property declaration_recovery { $$ = false; }
     1416    | property ':' maybe_space expr priority declaration_recovery {
     1417        // When we encounter something like p {color: red !important fail;} we should drop the declaration.
     1418        parser->markPropertyEnd(false, false);
     1419        delete $4;
    16011420        $$ = false;
    16021421    }
    1603     |
    1604     property ':' maybe_space expr prio declaration_recovery {
    1605         /* When we encounter something like p {color: red !important fail;} we should drop the declaration */
     1422    | IMPORTANT_SYM maybe_space declaration_recovery {
     1423        // Handle this case -- div { text-align: center; !important } -- by just reducing away the stray !important.
     1424        $$ = false;
     1425    }
     1426    | property ':' maybe_space declaration_recovery {
     1427        // If we come across rules with invalid values like this case: p { weight: *; }, just discard the rule.
    16061428        parser->markPropertyEnd(false, false);
    16071429        $$ = false;
    16081430    }
    1609     |
    1610     IMPORTANT_SYM maybe_space declaration_recovery {
    1611         /* Handle this case: div { text-align: center; !important } Just reduce away the stray !important. */
    1612         $$ = false;
    1613     }
    1614     |
    1615     property ':' maybe_space declaration_recovery {
    1616         /* if we come across rules with invalid values like this case: p { weight: *; }, just discard the rule */
    1617         parser->markPropertyEnd(false, false);
    1618         $$ = false;
    1619     }
    1620   ;
    1621 
    1622 declaration_recovery:
    1623     error error_location error_recovery {
    1624         parser->syntaxError($2);
    1625     }
    1626   ;
    1627 
    1628 property:
    1629     IDENT maybe_space {
    1630         $$ = cssPropertyID($1);
    1631     }
    1632   ;
    1633 
    1634 prio:
    1635     IMPORTANT_SYM maybe_space { $$ = true; }
    1636     | /* empty */ { $$ = false; }
    1637   ;
    1638 
    1639 expr:
    1640     valid_expr
    1641     | valid_expr expr_recovery { $$ = 0; }
    1642   ;
     1431  ;
     1432
     1433declaration_recovery: error error_location error_recovery { parser->syntaxError($2); } ;
     1434
     1435property: IDENT maybe_space { $$ = cssPropertyID($1); } ;
     1436
     1437priority: IMPORTANT_SYM maybe_space { $$ = true; } | /* empty */ { $$ = false; } ;
     1438
     1439expr: valid_expr | valid_expr expr_recovery { $$ = 0; delete $1; } ;
    16431440
    16441441valid_expr:
    16451442    term {
    1646         $$ = parser->createFloatingValueList();
    1647         $$->addValue(parser->sinkFloatingValue($1));
     1443        $$ = new CSSParserValueList;
     1444        $$->addValue($1);
    16481445    }
    16491446    | valid_expr operator term {
    16501447        $$ = $1;
    1651         if ($$) {
     1448        if (!$$)
     1449            destroy($3);
     1450        else {
    16521451            if ($2) {
    16531452                CSSParserValue v;
     
    16571456                $$->addValue(v);
    16581457            }
    1659             $$->addValue(parser->sinkFloatingValue($3));
    1660         }
    1661     }
    1662   ;
    1663 
    1664 expr_recovery:
    1665     error error_location error_recovery
    1666   ;
    1667 
    1668 operator:
    1669     '/' maybe_space {
    1670         $$ = '/';
    1671     }
    1672   | ',' maybe_space {
    1673         $$ = ',';
    1674     }
    1675   | /* empty */ {
    1676         $$ = 0;
    1677   }
    1678   ;
     1458            $$->addValue($3);
     1459        }
     1460    }
     1461  ;
     1462
     1463expr_recovery: error error_location error_recovery ;
     1464
     1465operator: '/' maybe_space { $$ = '/'; } | ',' maybe_space { $$ = ','; } | /* empty */ { $$ = 0; } ;
    16791466
    16801467term:
    1681   unary_term maybe_space { $$ = $1; }
     1468  unary_term maybe_space
    16821469  | unary_operator unary_term maybe_space { $$ = $2; $$.fValue *= $1; }
    16831470  | STRING maybe_space { $$.id = CSSValueInvalid; $$.string = $1; $$.unit = CSSPrimitiveValue::CSS_STRING; }
     
    16991486      $$.string = $3;
    17001487      $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
     1488#else
     1489      $$.id = CSSValueInvalid;
     1490      $$.unit = 0;
    17011491#endif
    17021492  }
    17031493  /* FIXME: according to the specs a function can have a unary_operator in front. I know no case where this makes sense */
    1704   | function maybe_space {
    1705       $$ = $1;
    1706   }
    1707   | calc_function maybe_space {
    1708       $$ = $1;
    1709   }
    1710   | min_or_max_function maybe_space {
    1711       $$ = $1;
    1712   }
     1494  | function maybe_space
     1495  | calc_function maybe_space
     1496  | min_or_max_function maybe_space
    17131497  | '%' maybe_space { /* Handle width: %; */
    17141498      $$.id = CSSValueInvalid; $$.unit = 0;
     
    17561540function:
    17571541    FUNCTION maybe_space expr closing_parenthesis {
    1758         CSSParserFunction* f = parser->createFloatingFunction();
     1542        CSSParserFunction* f = new CSSParserFunction;
    17591543        f->name = $1;
    1760         f->args = parser->sinkFloatingValueList($3);
     1544        f->args = adoptPtr($3);
    17611545        $$.id = CSSValueInvalid;
    17621546        $$.unit = CSSParserValue::Function;
     
    17641548    } |
    17651549    FUNCTION maybe_space closing_parenthesis {
    1766         CSSParserFunction* f = parser->createFloatingFunction();
     1550        CSSParserFunction* f = new CSSParserFunction;
    17671551        f->name = $1;
    1768         CSSParserValueList* valueList = parser->createFloatingValueList();
    1769         f->args = parser->sinkFloatingValueList(valueList);
     1552        f->args = adoptPtr(new CSSParserValueList);
    17701553        $$.id = CSSValueInvalid;
    17711554        $$.unit = CSSParserValue::Function;
     
    17731556    } |
    17741557    FUNCTION maybe_space expr_recovery closing_parenthesis {
    1775         CSSParserFunction* f = parser->createFloatingFunction();
     1558        CSSParserFunction* f = new CSSParserFunction;
    17761559        f->name = $1;
    17771560        f->args = nullptr;
     
    17831566
    17841567calc_func_term:
    1785   unary_term { $$ = $1; }
     1568  unary_term
    17861569  | VARFUNCTION maybe_space IDENT closing_parenthesis {
    17871570#if ENABLE_CSS_VARIABLES
     
    17891572      $$.string = $3;
    17901573      $$.unit = CSSPrimitiveValue::CSS_VARIABLE_NAME;
     1574#else
     1575      $$.id = CSSValueInvalid;
     1576      $$.unit = 0;
    17911577#endif
    17921578  }
     
    18091595  ;
    18101596
    1811 calc_maybe_space:
    1812     /* empty */
    1813     | WHITESPACE
    1814   ;
     1597calc_maybe_space: /* empty */ | WHITESPACE ;
    18151598
    18161599calc_func_paren_expr:
    18171600    '(' maybe_space calc_func_expr calc_maybe_space closing_parenthesis {
     1601        $$ = 0;
    18181602        if ($3) {
    18191603            $$ = $3;
     
    18251609            v.iValue = ')';
    18261610            $$->addValue(v);
    1827         } else
    1828             $$ = 0;
    1829     }
    1830   ;
    1831 
    1832 calc_func_expr:
    1833     valid_calc_func_expr
    1834     | valid_calc_func_expr expr_recovery { $$ = 0; }
    1835   ;
     1611        }
     1612    }
     1613  ;
     1614
     1615calc_func_expr: valid_calc_func_expr | valid_calc_func_expr expr_recovery { $$ = 0; delete $1; } ;
    18361616
    18371617valid_calc_func_expr:
    18381618    calc_func_term {
    1839         $$ = parser->createFloatingValueList();
    1840         $$->addValue(parser->sinkFloatingValue($1));
     1619        $$ = new CSSParserValueList;
     1620        $$->addValue($1);
    18411621    }
    18421622    | calc_func_expr calc_func_operator calc_func_term {
    1843         if ($1 && $2) {
    1844             $$ = $1;
     1623        OwnPtr<CSSParserValueList> expression = adoptPtr($1);
     1624        $$ = 0;
     1625        if (expression && $2) {
     1626            $$ = expression.leakPtr();
    18451627            CSSParserValue v;
    18461628            v.id = CSSValueInvalid;
     
    18481630            v.iValue = $2;
    18491631            $$->addValue(v);
    1850             $$->addValue(parser->sinkFloatingValue($3));
    1851         } else
    1852             $$ = 0;
     1632            $$->addValue($3);
     1633        } else {
     1634            destroy($3);
     1635        }
    18531636
    18541637    }
    18551638    | calc_func_expr calc_func_operator calc_func_paren_expr {
    1856         if ($1 && $2 && $3) {
    1857             $$ = $1;
     1639        OwnPtr<CSSParserValueList> left = adoptPtr($1);
     1640        OwnPtr<CSSParserValueList> right = adoptPtr($3);
     1641        $$ = 0;
     1642        if (left && $2 && right) {
    18581643            CSSParserValue v;
    18591644            v.id = CSSValueInvalid;
    18601645            v.unit = CSSParserValue::Operator;
    18611646            v.iValue = $2;
    1862             $$->addValue(v);
    1863             $$->extend(*($3));
    1864         } else
    1865             $$ = 0;
     1647            left->addValue(v);
     1648            left->extend(*right);
     1649            $$ = left.leakPtr();
     1650        }
    18661651    }
    18671652    | calc_func_paren_expr
     
    18691654
    18701655calc_func_expr_list:
    1871     calc_func_expr calc_maybe_space {
    1872         $$ = $1;
    1873     }
     1656    calc_func_expr calc_maybe_space
    18741657    | calc_func_expr_list ',' maybe_space calc_func_expr calc_maybe_space {
    1875         if ($1 && $4) {
    1876             $$ = $1;
     1658        OwnPtr<CSSParserValueList> list = adoptPtr($1);
     1659        OwnPtr<CSSParserValueList> expression = adoptPtr($4);
     1660        $$ = 0;
     1661        if (list && expression) {
     1662            $$ = list.leakPtr();
    18771663            CSSParserValue v;
    18781664            v.id = CSSValueInvalid;
     
    18801666            v.iValue = ',';
    18811667            $$->addValue(v);
    1882             $$->extend(*($4));
    1883         } else
    1884             $$ = 0;
     1668            $$->extend(*expression);
     1669        }
    18851670    }
    18861671  ;
     
    18881673calc_function:
    18891674    CALCFUNCTION maybe_space calc_func_expr calc_maybe_space closing_parenthesis {
    1890         CSSParserFunction* f = parser->createFloatingFunction();
     1675        CSSParserFunction* f = new CSSParserFunction;
    18911676        f->name = $1;
    1892         f->args = parser->sinkFloatingValueList($3);
     1677        f->args = adoptPtr($3);
    18931678        $$.id = CSSValueInvalid;
    18941679        $$.unit = CSSParserValue::Function;
     
    18961681    }
    18971682    | CALCFUNCTION maybe_space expr_recovery closing_parenthesis {
     1683        $$.id = CSSValueInvalid;
     1684        $$.unit = 0;
    18981685        YYERROR;
    18991686    }
     
    19011688
    19021689
    1903 min_or_max:
    1904     MINFUNCTION {
    1905         $$ = $1;
    1906     }
    1907     | MAXFUNCTION {
    1908         $$ = $1;
    1909     }
    1910     ;
     1690min_or_max: MINFUNCTION | MAXFUNCTION ;
    19111691
    19121692min_or_max_function:
    19131693    min_or_max maybe_space calc_func_expr_list closing_parenthesis {
    1914         CSSParserFunction* f = parser->createFloatingFunction();
     1694        CSSParserFunction* f = new CSSParserFunction;
    19151695        f->name = $1;
    1916         f->args = parser->sinkFloatingValueList($3);
     1696        f->args = adoptPtr($3);
    19171697        $$.id = CSSValueInvalid;
    19181698        $$.unit = CSSParserValue::Function;
     
    19201700    }
    19211701    | min_or_max maybe_space expr_recovery closing_parenthesis {
     1702        $$.id = CSSValueInvalid;
     1703        $$.unit = 0;
    19221704        YYERROR;
    19231705    }
     
    19261708/* error handling rules */
    19271709
    1928 save_block:
    1929     closing_brace {
    1930         $$ = 0;
    1931     }
    1932   | error closing_brace {
    1933         $$ = 0;
    1934     }
    1935     ;
    1936 
    1937 invalid_at:
    1938     ATKEYWORD error invalid_block {
    1939         $$ = 0;
    1940     }
    1941   | ATKEYWORD error ';' {
    1942         $$ = 0;
    1943     }
    1944     ;
    1945 
    1946 invalid_rule:
    1947     error invalid_block {
    1948         $$ = 0;
    1949     }
    1950 
    1951 /*
    1952   Seems like the two rules below are trying too much and violating
    1953   http://www.hixie.ch/tests/evil/mixed/csserrorhandling.html
    1954 
    1955   | error ';' {
    1956         $$ = 0;
    1957     }
    1958   | error '}' {
    1959         $$ = 0;
    1960     }
    1961 */
    1962     ;
    1963 
    1964 invalid_block:
    1965     '{' error_recovery closing_brace {
    1966         parser->invalidBlockHit();
    1967     }
    1968     ;
    1969 
    1970 invalid_square_brackets_block:
    1971     '[' error_recovery ']'
    1972   | '[' error_recovery TOKEN_EOF
    1973     ;
    1974 
    1975 invalid_parentheses_block:
    1976     opening_parenthesis error_recovery closing_parenthesis;
     1710save_block: closing_brace | error closing_brace ;
     1711
     1712invalid_at: ATKEYWORD error invalid_block | ATKEYWORD error ';' ;
     1713
     1714invalid_rule: error invalid_block ;
     1715
     1716invalid_block: '{' error_recovery closing_brace { parser->invalidBlockHit(); } ;
     1717
     1718invalid_square_brackets_block: '[' error_recovery ']' | '[' error_recovery TOKEN_EOF ;
     1719
     1720invalid_parentheses_block: opening_parenthesis error_recovery closing_parenthesis;
    19771721
    19781722opening_parenthesis:
     
    19831727    ;
    19841728
    1985 error_location: {
    1986         $$ = parser->currentLocation();
    1987     }
    1988     ;
     1729error_location: { $$ = parser->currentLocation(); } ;
    19891730
    19901731error_recovery:
     
    19971738
    19981739%%
    1999 
  • trunk/Source/WebCore/css/CSSParser.cpp

    r155496 r155536  
    358358{
    359359    clearProperties();
    360 
    361     deleteAllValues(m_floatingSelectors);
    362     deleteAllValues(m_floatingSelectorVectors);
    363     deleteAllValues(m_floatingValueLists);
    364     deleteAllValues(m_floatingFunctions);
    365360}
    366361
     
    523518#if ENABLE(CSS3_TEXT)
    524519    case CSSPropertyWebkitTextDecorationColor:
    525 #endif // CSS3_TEXT
     520#endif
    526521    case CSSPropertyWebkitTextEmphasisColor:
    527522    case CSSPropertyWebkitTextFillColor:
     
    92389233}
    92399234
    9240 StyleRuleBase* CSSParser::createFilterRule(const CSSParserString& filterName)
     9235PassRefPtr<StyleRuleBase> CSSParser::createFilterRule(const CSSParserString& filterName)
    92419236{
    92429237    RefPtr<StyleRuleFilter> rule = StyleRuleFilter::create(filterName, createStylePropertySet());
    92439238    clearProperties();
    9244     StyleRuleFilter* result = rule.get();
    9245     m_parsedRules.append(rule.release());
    92469239    processAndAddNewRuleToSourceTreeIfNeeded();
    9247     return result;
     9240    return rule.release();
    92489241}
    92499242
     
    1146511458}
    1146611459
    11467 CSSParserSelector* CSSParser::createFloatingSelectorWithTagName(const QualifiedName& tagQName)
    11468 {
    11469     CSSParserSelector* selector = new CSSParserSelector(tagQName);
    11470     m_floatingSelectors.add(selector);
    11471     return selector;
    11472 }
    11473 
    11474 CSSParserSelector* CSSParser::createFloatingSelector()
    11475 {
    11476     CSSParserSelector* selector = new CSSParserSelector;
    11477     m_floatingSelectors.add(selector);
    11478     return selector;
    11479 }
    11480 
    11481 PassOwnPtr<CSSParserSelector> CSSParser::sinkFloatingSelector(CSSParserSelector* selector)
    11482 {
    11483     if (selector) {
    11484         ASSERT(m_floatingSelectors.contains(selector));
    11485         m_floatingSelectors.remove(selector);
    11486     }
    11487     return adoptPtr(selector);
    11488 }
    11489 
    11490 Vector<OwnPtr<CSSParserSelector> >* CSSParser::createFloatingSelectorVector()
    11491 {
    11492     Vector<OwnPtr<CSSParserSelector> >* selectorVector = new Vector<OwnPtr<CSSParserSelector> >;
    11493     m_floatingSelectorVectors.add(selectorVector);
    11494     return selectorVector;
    11495 }
    11496 
    11497 PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > CSSParser::sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectorVector)
    11498 {
    11499     if (selectorVector) {
    11500         ASSERT(m_floatingSelectorVectors.contains(selectorVector));
    11501         m_floatingSelectorVectors.remove(selectorVector);
    11502     }
    11503     return adoptPtr(selectorVector);
    11504 }
    11505 
    11506 CSSParserValueList* CSSParser::createFloatingValueList()
    11507 {
    11508     CSSParserValueList* list = new CSSParserValueList;
    11509     m_floatingValueLists.add(list);
    11510     return list;
    11511 }
    11512 
    11513 PassOwnPtr<CSSParserValueList> CSSParser::sinkFloatingValueList(CSSParserValueList* list)
    11514 {
    11515     if (list) {
    11516         ASSERT(m_floatingValueLists.contains(list));
    11517         m_floatingValueLists.remove(list);
    11518     }
    11519     return adoptPtr(list);
    11520 }
    11521 
    11522 CSSParserFunction* CSSParser::createFloatingFunction()
    11523 {
    11524     CSSParserFunction* function = new CSSParserFunction;
    11525     m_floatingFunctions.add(function);
    11526     return function;
    11527 }
    11528 
    11529 PassOwnPtr<CSSParserFunction> CSSParser::sinkFloatingFunction(CSSParserFunction* function)
    11530 {
    11531     if (function) {
    11532         ASSERT(m_floatingFunctions.contains(function));
    11533         m_floatingFunctions.remove(function);
    11534     }
    11535     return adoptPtr(function);
    11536 }
    11537 
    11538 CSSParserValue& CSSParser::sinkFloatingValue(CSSParserValue& value)
    11539 {
    11540     if (value.unit == CSSParserValue::Function) {
    11541         ASSERT(m_floatingFunctions.contains(value.function));
    11542         m_floatingFunctions.remove(value.function);
    11543     }
    11544     return value;
    11545 }
    11546 
    11547 MediaQueryExp* CSSParser::createFloatingMediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* values)
    11548 {
    11549     m_floatingMediaQueryExp = MediaQueryExp::create(mediaFeature, values);
    11550     return m_floatingMediaQueryExp.get();
    11551 }
    11552 
    11553 PassOwnPtr<MediaQueryExp> CSSParser::sinkFloatingMediaQueryExp(MediaQueryExp* expression)
    11554 {
    11555     ASSERT_UNUSED(expression, expression == m_floatingMediaQueryExp);
    11556     return m_floatingMediaQueryExp.release();
    11557 }
    11558 
    11559 Vector<OwnPtr<MediaQueryExp> >* CSSParser::createFloatingMediaQueryExpList()
    11560 {
    11561     m_floatingMediaQueryExpList = adoptPtr(new Vector<OwnPtr<MediaQueryExp> >);
    11562     return m_floatingMediaQueryExpList.get();
    11563 }
    11564 
    11565 PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > CSSParser::sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >* list)
    11566 {
    11567     ASSERT_UNUSED(list, list == m_floatingMediaQueryExpList);
    11568     return m_floatingMediaQueryExpList.release();
    11569 }
    11570 
    11571 MediaQuery* CSSParser::createFloatingMediaQuery(MediaQuery::Restrictor restrictor, const String& mediaType, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
    11572 {
    11573     m_floatingMediaQuery = adoptPtr(new MediaQuery(restrictor, mediaType, expressions));
    11574     return m_floatingMediaQuery.get();
    11575 }
    11576 
    11577 MediaQuery* CSSParser::createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > expressions)
    11578 {
    11579     return createFloatingMediaQuery(MediaQuery::None, "all", expressions);
    11580 }
    11581 
    11582 PassOwnPtr<MediaQuery> CSSParser::sinkFloatingMediaQuery(MediaQuery* query)
    11583 {
    11584     ASSERT_UNUSED(query, query == m_floatingMediaQuery);
    11585     return m_floatingMediaQuery.release();
    11586 }
    11587 
    11588 Vector<RefPtr<StyleKeyframe> >* CSSParser::createFloatingKeyframeVector()
    11589 {
    11590     m_floatingKeyframeVector = adoptPtr(new Vector<RefPtr<StyleKeyframe> >());
    11591     return m_floatingKeyframeVector.get();
    11592 }
    11593 
    11594 PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > CSSParser::sinkFloatingKeyframeVector(Vector<RefPtr<StyleKeyframe> >* keyframeVector)
    11595 {
    11596     ASSERT_UNUSED(keyframeVector, m_floatingKeyframeVector == keyframeVector);
    11597     return m_floatingKeyframeVector.release();
    11598 }
    11599 
    11600 MediaQuerySet* CSSParser::createMediaQuerySet()
    11601 {
    11602     RefPtr<MediaQuerySet> queries = MediaQuerySet::create();
    11603     MediaQuerySet* result = queries.get();
    11604     m_parsedMediaQuerySets.append(queries.release());
    11605     return result;
    11606 }
    11607 
    11608 StyleRuleBase* CSSParser::createImportRule(const CSSParserString& url, MediaQuerySet* media)
     11460PassRefPtr<StyleRuleBase> CSSParser::createImportRule(const CSSParserString& url, PassRefPtr<MediaQuerySet> media)
    1160911461{
    1161011462    if (!media || !m_allowImportRules) {
     
    1161311465    }
    1161411466    RefPtr<StyleRuleImport> rule = StyleRuleImport::create(url, media);
    11615     StyleRuleImport* result = rule.get();
    11616     m_parsedRules.append(rule.release());
    1161711467    processAndAddNewRuleToSourceTreeIfNeeded();
    11618     return result;
    11619 }
    11620 
    11621 StyleRuleBase* CSSParser::createMediaRule(MediaQuerySet* media, RuleList* rules)
     11468    return rule.release();
     11469}
     11470
     11471PassRefPtr<StyleRuleBase> CSSParser::createMediaRule(PassRefPtr<MediaQuerySet> media, RuleList* rules)
    1162211472{
    1162311473    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1163011480    } else
    1163111481        rule = StyleRuleMedia::create(media, rules ? *rules : emptyRules);
    11632     StyleRuleMedia* result = rule.get();
    11633     m_parsedRules.append(rule.release());
    1163411482    processAndAddNewRuleToSourceTreeIfNeeded();
    11635     return result;
    11636 }
    11637 
    11638 StyleRuleBase* CSSParser::createEmptyMediaRule(RuleList* rules)
    11639 {
    11640     return createMediaRule(MediaQuerySet::create().get(), rules);
     11483    return rule.release();
     11484}
     11485
     11486PassRefPtr<StyleRuleBase> CSSParser::createEmptyMediaRule(RuleList* rules)
     11487{
     11488    return createMediaRule(MediaQuerySet::create(), rules);
    1164111489}
    1164211490
    1164311491#if ENABLE(CSS3_CONDITIONAL_RULES)
    11644 StyleRuleBase* CSSParser::createSupportsRule(bool conditionIsSupported, RuleList* rules)
     11492PassRefPtr<StyleRuleBase> CSSParser::createSupportsRule(bool conditionIsSupported, RuleList* rules)
    1164511493{
    1164611494    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1166411512    }
    1166511513
    11666     StyleRuleSupports* result = rule.get();
    11667     m_parsedRules.append(rule.release());
    1166811514    processAndAddNewRuleToSourceTreeIfNeeded();
    1166911515
    11670     return result;
     11516    return rule.release();
    1167111517}
    1167211518
     
    1170011546
    1170111547#endif
    11702 
    11703 CSSParser::RuleList* CSSParser::createRuleList()
    11704 {
    11705     OwnPtr<RuleList> list = adoptPtr(new RuleList);
    11706     RuleList* listPtr = list.get();
    11707 
    11708     m_parsedRuleLists.append(list.release());
    11709     return listPtr;
    11710 }
    1171111548
    1171211549void CSSParser::processAndAddNewRuleToSourceTreeIfNeeded()
     
    1177411611void CSSParser::logError(const String& message, int lineNumber)
    1177511612{
    11776     // FIXME: <http://webkit.org/b/114313> CSS Parser ConsoleMessage errors should include column numbers
     11613    // FIXME: <http://webkit.org/b/114313> CSS parser console message errors should include column numbers.
    1177711614    PageConsole& console = m_styleSheet->singleOwnerDocument()->page()->console();
    1177811615    console.addMessage(CSSMessageSource, WarningMessageLevel, message, m_styleSheet->baseURL().string(), lineNumber + 1, 0);
    1177911616}
    1178011617
    11781 StyleRuleKeyframes* CSSParser::createKeyframesRule(const String& name, PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > popKeyframes)
    11782 {
    11783     OwnPtr<Vector<RefPtr<StyleKeyframe> > > keyframes = popKeyframes;
     11618PassRefPtr<StyleRuleKeyframes> CSSParser::createKeyframesRule(const String& name, PassOwnPtr<Vector<RefPtr<StyleKeyframe>>> popKeyframes)
     11619{
     11620    OwnPtr<Vector<RefPtr<StyleKeyframe>>> keyframes = popKeyframes;
    1178411621    m_allowImportRules = m_allowNamespaceDeclarations = false;
    1178511622    RefPtr<StyleRuleKeyframes> rule = StyleRuleKeyframes::create();
     
    1178711624        rule->parserAppendKeyframe(keyframes->at(i));
    1178811625    rule->setName(name);
    11789     StyleRuleKeyframes* rulePtr = rule.get();
    11790     m_parsedRules.append(rule.release());
    1179111626    processAndAddNewRuleToSourceTreeIfNeeded();
    11792     return rulePtr;
    11793 }
    11794 
    11795 StyleRuleBase* CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors)
    11796 {
    11797     StyleRule* result = 0;
     11627    return rule.release();
     11628}
     11629
     11630PassRefPtr<StyleRuleBase> CSSParser::createStyleRule(Vector<OwnPtr<CSSParserSelector>>* selectors)
     11631{
     11632    RefPtr<StyleRule> rule;
    1179811633    if (selectors) {
    1179911634        m_allowImportRules = false;
     
    1180111636        if (m_hasFontFaceOnlyValues)
    1180211637            deleteFontFaceOnlyValues();
    11803         RefPtr<StyleRule> rule = StyleRule::create(m_lastSelectorLineNumber, createStylePropertySet());
     11638        rule = StyleRule::create(m_lastSelectorLineNumber, createStylePropertySet());
    1180411639        rule->parserAdoptSelectorVector(*selectors);
    11805         result = rule.get();
    11806         m_parsedRules.append(rule.release());
    1180711640        processAndAddNewRuleToSourceTreeIfNeeded();
    1180811641    } else
    1180911642        popRuleData();
    1181011643    clearProperties();
    11811     return result;
    11812 }
    11813 
    11814 StyleRuleBase* CSSParser::createFontFaceRule()
     11644    return rule.release();
     11645}
     11646
     11647PassRefPtr<StyleRuleBase> CSSParser::createFontFaceRule()
    1181511648{
    1181611649    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1183111664    RefPtr<StyleRuleFontFace> rule = StyleRuleFontFace::create(createStylePropertySet());
    1183211665    clearProperties();
    11833     StyleRuleFontFace* result = rule.get();
    11834     m_parsedRules.append(rule.release());
    1183511666    processAndAddNewRuleToSourceTreeIfNeeded();
    11836     return result;
     11667    return rule.release();
    1183711668}
    1183811669
    1183911670#if ENABLE(SHADOW_DOM)
    11840 StyleRuleBase* CSSParser::createHostRule(RuleList* rules)
     11671PassRefPtr<StyleRuleBase> CSSParser::createHostRule(RuleList* rules)
    1184111672{
    1184211673    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1184811679        rule = StyleRuleHost::create(emptyRules);
    1184911680    }
    11850     StyleRuleHost* result = rule.get();
    11851     m_parsedRules.append(rule.release());
    1185211681    processAndAddNewRuleToSourceTreeIfNeeded();
    11853     return result;
     11682    return rule.release();
    1185411683}
    1185511684#endif
     
    1187211701}
    1187311702
    11874 CSSParserSelector* CSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector* specifiers)
    11875 {
    11876     if (m_defaultNamespace != starAtom || specifiers->isCustomPseudoElement())
    11877         return rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers, /*tagIsForNamespaceRule*/true);
    11878     return specifiers;
    11879 }
    11880 
    11881 CSSParserSelector* CSSParser::rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector* specifiers, bool tagIsForNamespaceRule)
     11703void CSSParser::rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector& specifiers)
     11704{
     11705    if (m_defaultNamespace != starAtom || specifiers.isCustomPseudoElement())
     11706        rewriteSpecifiersWithElementName(nullAtom, starAtom, specifiers, /*tagIsForNamespaceRule*/true);
     11707}
     11708
     11709void CSSParser::rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector& specifiers, bool tagIsForNamespaceRule)
    1188211710{
    1188311711    AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
    1188411712    QualifiedName tag(namespacePrefix, elementName, determinedNamespace);
    1188511713
    11886     if (!specifiers->isCustomPseudoElement()) {
     11714    if (!specifiers.isCustomPseudoElement()) {
    1188711715        if (tag == anyQName())
    11888             return specifiers;
     11716            return;
    1188911717#if ENABLE(VIDEO_TRACK)
    11890         if (!(specifiers->pseudoType() == CSSSelector::PseudoCue))
     11718        if (specifiers.pseudoType() != CSSSelector::PseudoCue)
    1189111719#endif
    11892             specifiers->prependTagSelector(tag, tagIsForNamespaceRule);
    11893         return specifiers;
    11894     }
    11895 
    11896     CSSParserSelector* lastShadowDescendant = specifiers;
    11897     CSSParserSelector* history = specifiers;
     11720            specifiers.prependTagSelector(tag, tagIsForNamespaceRule);
     11721        return;
     11722    }
     11723
     11724    CSSParserSelector* lastShadowDescendant = &specifiers;
     11725    CSSParserSelector* history = &specifiers;
    1189811726    while (history->tagHistory()) {
    1189911727        history = history->tagHistory();
     
    1190511733        if (tag != anyQName())
    1190611734            lastShadowDescendant->tagHistory()->prependTagSelector(tag, tagIsForNamespaceRule);
    11907         return specifiers;
     11735        return;
    1190811736    }
    1190911737
    1191011738    // For shadow-ID pseudo-elements to be correctly matched, the ShadowDescendant combinator has to be used.
    1191111739    // We therefore create a new Selector with that combinator here in any case, even if matching any (host) element in any namespace (i.e. '*').
    11912     OwnPtr<CSSParserSelector> elementNameSelector = adoptPtr(new CSSParserSelector(tag));
    11913     lastShadowDescendant->setTagHistory(elementNameSelector.release());
     11740    lastShadowDescendant->setTagHistory(adoptPtr(new CSSParserSelector(tag)));
    1191411741    lastShadowDescendant->setRelation(CSSSelector::ShadowDescendant);
    11915     return specifiers;
    11916 }
    11917 
    11918 CSSParserSelector* CSSParser::rewriteSpecifiers(CSSParserSelector* specifiers, CSSParserSelector* newSpecifier)
     11742}
     11743
     11744OwnPtr<CSSParserSelector> CSSParser::rewriteSpecifiers(OwnPtr<CSSParserSelector> specifiers, OwnPtr<CSSParserSelector> newSpecifier)
    1191911745{
    1192011746#if ENABLE(VIDEO_TRACK)
     
    1192411750#endif
    1192511751        // Unknown pseudo element always goes at the top of selector chain.
    11926         newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, sinkFloatingSelector(specifiers));
     11752        newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, specifiers.release());
    1192711753        return newSpecifier;
    1192811754    }
    1192911755    if (specifiers->isCustomPseudoElement()) {
    1193011756        // Specifiers for unknown pseudo element go right behind it in the chain.
    11931         specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::ShadowDescendant);
     11757        specifiers->insertTagHistory(CSSSelector::SubSelector, newSpecifier.release(), CSSSelector::ShadowDescendant);
    1193211758        return specifiers;
    1193311759    }
    11934     specifiers->appendTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier));
     11760    specifiers->appendTagHistory(CSSSelector::SubSelector, newSpecifier.release());
    1193511761    return specifiers;
    1193611762}
    1193711763
    11938 StyleRuleBase* CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
     11764PassRefPtr<StyleRuleBase> CSSParser::createPageRule(PassOwnPtr<CSSParserSelector> pageSelector)
    1193911765{
    1194011766    // FIXME: Margin at-rules are ignored.
    1194111767    m_allowImportRules = m_allowNamespaceDeclarations = false;
    11942     StyleRulePage* pageRule = 0;
     11768    RefPtr<StyleRulePage> rule;
    1194311769    if (pageSelector) {
    11944         RefPtr<StyleRulePage> rule = StyleRulePage::create(createStylePropertySet());
    11945         Vector<OwnPtr<CSSParserSelector> > selectorVector;
     11770        rule = StyleRulePage::create(createStylePropertySet());
     11771        Vector<OwnPtr<CSSParserSelector>> selectorVector;
    1194611772        selectorVector.append(pageSelector);
    1194711773        rule->parserAdoptSelectorVector(selectorVector);
    11948         pageRule = rule.get();
    11949         m_parsedRules.append(rule.release());
    1195011774        processAndAddNewRuleToSourceTreeIfNeeded();
    1195111775    } else
    1195211776        popRuleData();
    1195311777    clearProperties();
    11954     return pageRule;
    11955 }
    11956 
    11957 void CSSParser::setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectors)
    11958 {
    11959     if (selectors)
    11960         m_reusableRegionSelectorVector.swap(*selectors);
    11961 }
    11962 
    11963 StyleRuleBase* CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules)
     11778    return rule.release();
     11779}
     11780
     11781OwnPtr<Vector<OwnPtr<CSSParserSelector>>> CSSParser::createSelectorVector()
     11782{
     11783    if (m_recycledSelectorVector) {
     11784        m_recycledSelectorVector->shrink(0);
     11785        return std::move(m_recycledSelectorVector);
     11786    }
     11787    return adoptPtr(new Vector<OwnPtr<CSSParserSelector>>);
     11788}
     11789
     11790void CSSParser::recycleSelectorVector(OwnPtr<Vector<OwnPtr<CSSParserSelector>>> vector)
     11791{
     11792    if (vector && !m_recycledSelectorVector)
     11793        m_recycledSelectorVector = std::move(vector);
     11794}
     11795
     11796PassRefPtr<StyleRuleBase> CSSParser::createRegionRule(Vector<OwnPtr<CSSParserSelector>>* regionSelector, RuleList* rules)
    1196411797{
    1196511798    if (!cssRegionsEnabled() || !regionSelector || !rules) {
     
    1197211805    RefPtr<StyleRuleRegion> regionRule = StyleRuleRegion::create(regionSelector, *rules);
    1197311806
    11974     StyleRuleRegion* result = regionRule.get();
    11975     m_parsedRules.append(regionRule.release());
    1197611807    if (isExtractingSourceData())
    1197711808        addNewRuleToSourceTree(CSSRuleSourceData::createUnknown());
    1197811809
    11979     return result;
    11980 }
    11981 
    11982 StyleRuleBase* CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
     11810    return regionRule.release();
     11811}
     11812
     11813void CSSParser::createMarginAtRule(CSSSelector::MarginBoxType /* marginBox */)
    1198311814{
    1198411815    // FIXME: Implement margin at-rule here, using:
     
    1198811819
    1198911820    endDeclarationsForMarginBox();
    11990     return 0; // until this method is implemented.
    1199111821}
    1199211822
     
    1201511845}
    1201611846
    12017 StyleKeyframe* CSSParser::createKeyframe(CSSParserValueList* keys)
     11847PassRefPtr<StyleKeyframe> CSSParser::createKeyframe(CSSParserValueList& keys)
    1201811848{
    1201911849    // Create a key string from the passed keys
    1202011850    StringBuilder keyString;
    12021     for (unsigned i = 0; i < keys->size(); ++i) {
     11851    for (unsigned i = 0; i < keys.size(); ++i) {
    1202211852        // Just as per the comment below, we ignore keyframes with
    1202311853        // invalid key values (plain numbers or unknown identifiers)
    1202411854        // marked as CSSPrimitiveValue::CSS_UNKNOWN during parsing.
    12025         if (keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_UNKNOWN) {
     11855        if (keys.valueAt(i)->unit == CSSPrimitiveValue::CSS_UNKNOWN) {
    1202611856            clearProperties();
    1202711857            return 0;
    1202811858        }
    1202911859
    12030         ASSERT(keys->valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
    12031         float key = static_cast<float>(keys->valueAt(i)->fValue);
     11860        ASSERT(keys.valueAt(i)->unit == CSSPrimitiveValue::CSS_NUMBER);
     11861        float key = static_cast<float>(keys.valueAt(i)->fValue);
    1203211862        if (key < 0 || key > 100) {
    1203311863            // As per http://www.w3.org/TR/css3-animations/#keyframes,
     
    1204811878    clearProperties();
    1204911879
    12050     StyleKeyframe* keyframePtr = keyframe.get();
    12051     m_parsedKeyframes.append(keyframe.release());
    12052     return keyframePtr;
     11880    return keyframe.release();
    1205311881}
    1205411882
     
    1225812086
    1225912087#if ENABLE(CSS_DEVICE_ADAPTATION)
    12260 StyleRuleBase* CSSParser::createViewportRule()
     12088PassRefPtr<StyleRuleBase> CSSParser::createViewportRule()
    1226112089{
    1226212090    m_allowImportRules = m_allowNamespaceDeclarations = false;
     
    1226512093    clearProperties();
    1226612094
    12267     StyleRuleViewport* result = rule.get();
    12268     m_parsedRules.append(rule.release());
    1226912095    processAndAddNewRuleToSourceTreeIfNeeded();
    1227012096
    12271     return result;
     12097    return rule.release();
    1227212098}
    1227312099
  • trunk/Source/WebCore/css/CSSParser.h

    r154996 r155536  
    176176
    177177    bool parseBasicShape(CSSPropertyID, bool important);
    178     PassRefPtr<CSSBasicShape> parseBasicShapeRectangle(CSSParserValueList* args);
    179     PassRefPtr<CSSBasicShape> parseBasicShapeCircle(CSSParserValueList* args);
    180     PassRefPtr<CSSBasicShape> parseBasicShapeEllipse(CSSParserValueList* args);
    181     PassRefPtr<CSSBasicShape> parseBasicShapePolygon(CSSParserValueList* args);
    182     PassRefPtr<CSSBasicShape> parseBasicShapeInsetRectangle(CSSParserValueList* args);
     178    PassRefPtr<CSSBasicShape> parseBasicShapeRectangle(CSSParserValueList*);
     179    PassRefPtr<CSSBasicShape> parseBasicShapeCircle(CSSParserValueList*);
     180    PassRefPtr<CSSBasicShape> parseBasicShapeEllipse(CSSParserValueList*);
     181    PassRefPtr<CSSBasicShape> parseBasicShapePolygon(CSSParserValueList*);
     182    PassRefPtr<CSSBasicShape> parseBasicShapeInsetRectangle(CSSParserValueList*);
    183183
    184184    bool parseFont(bool important);
     
    283283#if ENABLE(CSS3_TEXT)
    284284    bool parseTextUnderlinePosition(bool important);
    285 #endif // CSS3_TEXT
     285#endif
    286286
    287287    PassRefPtr<CSSValue> parseTextIndent();
     
    301301    bool parseFontVariantLigatures(bool important);
    302302
    303     CSSParserSelector* createFloatingSelector();
    304     CSSParserSelector* createFloatingSelectorWithTagName(const QualifiedName&);
    305     PassOwnPtr<CSSParserSelector> sinkFloatingSelector(CSSParserSelector*);
    306 
    307     Vector<OwnPtr<CSSParserSelector> >* createFloatingSelectorVector();
    308     PassOwnPtr<Vector<OwnPtr<CSSParserSelector> > > sinkFloatingSelectorVector(Vector<OwnPtr<CSSParserSelector> >*);
    309 
    310     CSSParserValueList* createFloatingValueList();
    311     PassOwnPtr<CSSParserValueList> sinkFloatingValueList(CSSParserValueList*);
    312 
    313     CSSParserFunction* createFloatingFunction();
    314     PassOwnPtr<CSSParserFunction> sinkFloatingFunction(CSSParserFunction*);
    315 
    316     CSSParserValue& sinkFloatingValue(CSSParserValue&);
    317 
    318     MediaQuerySet* createMediaQuerySet();
    319     StyleRuleBase* createImportRule(const CSSParserString&, MediaQuerySet*);
    320     StyleKeyframe* createKeyframe(CSSParserValueList*);
    321     StyleRuleKeyframes* createKeyframesRule(const String&, PassOwnPtr<Vector<RefPtr<StyleKeyframe> > >);
    322 
    323     typedef Vector<RefPtr<StyleRuleBase> > RuleList;
    324     StyleRuleBase* createMediaRule(MediaQuerySet*, RuleList*);
    325     StyleRuleBase* createEmptyMediaRule(RuleList*);
    326     RuleList* createRuleList();
    327     StyleRuleBase* createStyleRule(Vector<OwnPtr<CSSParserSelector> >* selectors);
    328     StyleRuleBase* createFontFaceRule();
    329     StyleRuleBase* createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
    330     StyleRuleBase* createRegionRule(Vector<OwnPtr<CSSParserSelector> >* regionSelector, RuleList* rules);
    331     StyleRuleBase* createMarginAtRule(CSSSelector::MarginBoxType);
     303    // Faster than doing a new/delete each time since it keeps one vector.
     304    OwnPtr<Vector<OwnPtr<CSSParserSelector>>> createSelectorVector();
     305    void recycleSelectorVector(OwnPtr<Vector<OwnPtr<CSSParserSelector>>>);
     306
     307    PassRefPtr<StyleRuleBase> createImportRule(const CSSParserString&, PassRefPtr<MediaQuerySet>);
     308    PassRefPtr<StyleKeyframe> createKeyframe(CSSParserValueList&);
     309    PassRefPtr<StyleRuleKeyframes> createKeyframesRule(const String&, PassOwnPtr<Vector<RefPtr<StyleKeyframe>>>);
     310
     311    typedef Vector<RefPtr<StyleRuleBase>> RuleList;
     312    PassRefPtr<StyleRuleBase> createMediaRule(PassRefPtr<MediaQuerySet>, RuleList*);
     313    PassRefPtr<StyleRuleBase> createEmptyMediaRule(RuleList*);
     314    PassRefPtr<StyleRuleBase> createStyleRule(Vector<OwnPtr<CSSParserSelector>>* selectors);
     315    PassRefPtr<StyleRuleBase> createFontFaceRule();
     316    PassRefPtr<StyleRuleBase> createPageRule(PassOwnPtr<CSSParserSelector> pageSelector);
     317    PassRefPtr<StyleRuleBase> createRegionRule(Vector<OwnPtr<CSSParserSelector>>* regionSelector, RuleList* rules);
     318    void createMarginAtRule(CSSSelector::MarginBoxType);
    332319#if ENABLE(CSS3_CONDITIONAL_RULES)
    333     StyleRuleBase* createSupportsRule(bool conditionIsSupported, RuleList*);
     320    PassRefPtr<StyleRuleBase> createSupportsRule(bool conditionIsSupported, RuleList*);
    334321    void markSupportsRuleHeaderStart();
    335322    void markSupportsRuleHeaderEnd();
     
    337324#endif
    338325#if ENABLE(SHADOW_DOM)
    339     StyleRuleBase* createHostRule(RuleList* rules);
     326    PassRefPtr<StyleRuleBase> createHostRule(RuleList*);
    340327#endif
    341328#if ENABLE(CSS_SHADERS)
    342     StyleRuleBase* createFilterRule(const CSSParserString&);
     329    PassRefPtr<StyleRuleBase> createFilterRule(const CSSParserString&);
    343330#endif
    344331
     
    346333    void endDeclarationsForMarginBox();
    347334
    348     MediaQueryExp* createFloatingMediaQueryExp(const AtomicString&, CSSParserValueList*);
    349     PassOwnPtr<MediaQueryExp> sinkFloatingMediaQueryExp(MediaQueryExp*);
    350     Vector<OwnPtr<MediaQueryExp> >* createFloatingMediaQueryExpList();
    351     PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > > sinkFloatingMediaQueryExpList(Vector<OwnPtr<MediaQueryExp> >*);
    352     MediaQuery* createFloatingMediaQuery(MediaQuery::Restrictor, const String&, PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
    353     MediaQuery* createFloatingMediaQuery(PassOwnPtr<Vector<OwnPtr<MediaQueryExp> > >);
    354     PassOwnPtr<MediaQuery> sinkFloatingMediaQuery(MediaQuery*);
    355 
    356     Vector<RefPtr<StyleKeyframe> >* createFloatingKeyframeVector();
    357     PassOwnPtr<Vector<RefPtr<StyleKeyframe> > > sinkFloatingKeyframeVector(Vector<RefPtr<StyleKeyframe> >*);
    358 
    359335    void addNamespace(const AtomicString& prefix, const AtomicString& uri);
    360336    QualifiedName determineNameInNamespace(const AtomicString& prefix, const AtomicString& localName);
    361337
    362     CSSParserSelector* rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector*, bool isNamespacePlaceholder = false);
    363     CSSParserSelector* rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector*);
    364     CSSParserSelector* rewriteSpecifiers(CSSParserSelector*, CSSParserSelector*);
     338    void rewriteSpecifiersWithElementName(const AtomicString& namespacePrefix, const AtomicString& elementName, CSSParserSelector&, bool isNamespacePlaceholder = false);
     339    void rewriteSpecifiersWithNamespaceIfNeeded(CSSParserSelector&);
     340    OwnPtr<CSSParserSelector> rewriteSpecifiers(OwnPtr<CSSParserSelector>, OwnPtr<CSSParserSelector>);
    365341
    366342    void invalidBlockHit();
    367 
    368     Vector<OwnPtr<CSSParserSelector> >* reusableSelectorVector() { return &m_reusableSelectorVector; }
    369 
    370     void setReusableRegionSelectorVector(Vector<OwnPtr<CSSParserSelector> >* selectors);
    371     Vector<OwnPtr<CSSParserSelector> >* reusableRegionSelectorVector() { return &m_reusableRegionSelectorVector; }
    372343
    373344    void updateLastSelectorLineAndPosition();
     
    443414    void markViewportRuleBodyStart() { m_inViewport = true; }
    444415    void markViewportRuleBodyEnd() { m_inViewport = false; }
    445     StyleRuleBase* createViewportRule();
     416    PassRefPtr<StyleRuleBase> createViewportRule();
    446417#endif
    447418
     
    614585    int (CSSParser::*m_lexFunc)(void*);
    615586
    616     Vector<RefPtr<StyleRuleBase> > m_parsedRules;
    617     Vector<RefPtr<StyleKeyframe> > m_parsedKeyframes;
    618     Vector<RefPtr<MediaQuerySet> > m_parsedMediaQuerySets;
    619     Vector<OwnPtr<RuleList> > m_parsedRuleLists;
    620     HashSet<CSSParserSelector*> m_floatingSelectors;
    621     HashSet<Vector<OwnPtr<CSSParserSelector> >*> m_floatingSelectorVectors;
    622     HashSet<CSSParserValueList*> m_floatingValueLists;
    623     HashSet<CSSParserFunction*> m_floatingFunctions;
    624 
    625     OwnPtr<MediaQuery> m_floatingMediaQuery;
    626     OwnPtr<MediaQueryExp> m_floatingMediaQueryExp;
    627     OwnPtr<Vector<OwnPtr<MediaQueryExp> > > m_floatingMediaQueryExpList;
    628 
    629     OwnPtr<Vector<RefPtr<StyleKeyframe> > > m_floatingKeyframeVector;
    630 
    631     Vector<OwnPtr<CSSParserSelector> > m_reusableSelectorVector;
    632     Vector<OwnPtr<CSSParserSelector> > m_reusableRegionSelectorVector;
     587    OwnPtr<Vector<OwnPtr<CSSParserSelector>>> m_recycledSelectorVector;
    633588
    634589    RefPtr<CSSCalcValue> m_parsedCalculation;
  • trunk/Source/WebCore/css/CSSParserValues.cpp

    r155195 r155536  
    3434using namespace WTF;
    3535
     36void destroy(const CSSParserValue& value)
     37{
     38    if (value.unit == CSSParserValue::Function)
     39        delete value.function;
     40}
     41
    3642CSSParserValueList::~CSSParserValueList()
    3743{
    38     size_t numValues = m_values.size();
    39     for (size_t i = 0; i < numValues; i++) {
    40         if (m_values[i].unit == CSSParserValue::Function)
    41             delete m_values[i].function;
    42     }
     44    for (size_t i = 0, size = m_values.size(); i < size; i++)
     45        destroy(m_values[i]);
    4346}
    4447
  • trunk/Source/WebCore/css/CSSParserValues.h

    r153631 r155536  
    126126    int unit;
    127127
    128 
    129128    PassRefPtr<CSSValue> createCSSValue();
    130129};
     130
     131void destroy(const CSSParserValue&);
    131132
    132133class CSSParserValueList {
Note: See TracChangeset for help on using the changeset viewer.