Changeset 200859 in webkit


Ignore:
Timestamp:
May 13, 2016, 9:16:51 AM (9 years ago)
Author:
beidson@apple.com
Message:

Protector Ref/RefPtrs should have a specified naming style.
https://bugs.webkit.org/show_bug.cgi?id=157591

Reviewed by Darin Adler.

Tools:

  • Scripts/webkitpy/style/checkers/cpp.py:

(check_identifier_name_in_declaration):
(CppChecker):

  • Scripts/webkitpy/style/checkers/cpp_unittest.py:

(WebKitStyleTest.test_names):

Websites/webkit.org:

  • code-style.md:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r200747 r200859  
     12016-05-13  Brady Eidson  <beidson@apple.com>
     2
     3        Protector Ref/RefPtrs should have a specified naming style.
     4        https://bugs.webkit.org/show_bug.cgi?id=157591
     5
     6        Reviewed by Darin Adler.
     7
     8        * Scripts/webkitpy/style/checkers/cpp.py:
     9        (check_identifier_name_in_declaration):
     10        (CppChecker):
     11        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
     12        (WebKitStyleTest.test_names):
     13
    1142016-05-12  Csaba Osztrogonác  <ossy@webkit.org>
    215
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py

    r200059 r200859  
    32923292        return
    32933293
     3294    # Make sure Ref/RefPtrs used as protectors are named correctly, and do this before we start stripping things off the input.
     3295    ref_regexp = r'^\s*Ref(Ptr)?<([\w_]|::)+> (?P<protector_name>[\w_]+)\((\*|&)*(m_)?(?P<protected_name>[\w_]+)\);'
     3296    ref_check = match(ref_regexp, line)
     3297    if ref_check:
     3298        protector_name = ref_check.group('protector_name')
     3299        protected_name = ref_check.group('protected_name')
     3300        cap_protected_name = protected_name[0].upper() + protected_name[1:]
     3301        expected_protector_name = 'protected' + cap_protected_name
     3302        if protected_name == 'this' and protector_name != 'protectedThis':
     3303            error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protectedThis\'.")
     3304        elif protector_name == expected_protector_name or protector_name == 'protector':
     3305            return
     3306        else:
     3307            error(line_number, 'readability/naming/protected', 4, "\'" + protector_name + "\' is incorrectly named. It should be named \'protector\' or \'" + expected_protector_name + "\'.")
     3308
    32943309    # Basically, a declaration is a type name followed by whitespaces
    32953310    # followed by an identifier. The type name can be complicated
     
    38473862        'readability/parameter_name',
    38483863        'readability/naming',
     3864        'readability/naming/protected',
    38493865        'readability/naming/underscores',
    38503866        'readability/null',
  • trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py

    r200059 r200859  
    51805180                         '_fillRule' + name_underscore_error_message)
    51815181
     5182        # Valid protector RefPtr/Ref variable names.
     5183        self.assert_lint('RefPtr<Node> protectedThis(this);', '')
     5184        self.assert_lint('Ref<Node> protectedThis(*this);', '')
     5185        self.assert_lint('RefPtr<Node> protectedNode(node);', '')
     5186        self.assert_lint('RefPtr<Node> protectedNode(&node);', '')
     5187        self.assert_lint('RefPtr<Node> protector(node);', '')
     5188        self.assert_lint('RefPtr<Node> protector(&node);', '')
     5189        self.assert_lint('Ref<Node> protectedNode(node);', '')
     5190        self.assert_lint('Ref<Node> protectedNode(*node);', '')
     5191        self.assert_lint('Ref<Node> protector(node);', '')
     5192        self.assert_lint('Ref<Node> protector(*node);', '')
     5193        self.assert_lint('RefPtr<Node> protectedOtherNode(otherNode);', '')
     5194        self.assert_lint('RefPtr<Node> protectedOtherNode(&otherNode);', '')
     5195        self.assert_lint('Ref<Node> protectedOtherNode(otherNode);', '')
     5196        self.assert_lint('Ref<Node> protectedOtherNode(*otherNode);', '')
     5197        self.assert_lint('RefPtr<Widget> protectedWidget(m_widget);', '')
     5198        self.assert_lint('RefPtr<Widget> protectedWidget(&m_widget);', '')
     5199        self.assert_lint('Ref<Widget> protectedWidget(m_widget);', '')
     5200        self.assert_lint('Ref<Widget> protectedWidget(*m_widget);', '')
     5201        self.assert_lint('RefPtr<Widget> protector(m_widget);', '')
     5202        self.assert_lint('RefPtr<Widget> protector(&m_widget);', '')
     5203        self.assert_lint('Ref<Widget> protector(m_widget);', '')
     5204        self.assert_lint('Ref<Widget> protector(*m_widget);', '')
     5205        self.assert_lint('RefPtr<SomeNamespace::Node> protectedThis(this);', '')
     5206        self.assert_lint('RefPtr<SomeClass::InternalClass::Node> protectedThis(this);', '')
     5207
     5208        # Invalid protector RefPtr/Ref variable names.
     5209        self.assert_lint('RefPtr<Node> protector(this);', "'protector' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]")
     5210        self.assert_lint('Ref<Node> protector(*this);', "'protector' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]")
     5211        self.assert_lint('RefPtr<Node> self(this);', "'self' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]")
     5212        self.assert_lint('Ref<Node> self(*this);', "'self' is incorrectly named. It should be named 'protectedThis'.  [readability/naming/protected] [4]")
     5213        self.assert_lint('RefPtr<Node> protectedThis(node);', "'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5214        self.assert_lint('RefPtr<Node> protectedThis(&node);', "'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5215        self.assert_lint('Ref<Node> protectedThis(node);', "'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5216        self.assert_lint('Ref<Node> protectedThis(*node);', "'protectedThis' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5217        self.assert_lint('RefPtr<Node> protectedNode(otherNode);', "'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]")
     5218        self.assert_lint('RefPtr<Node> protectedNode(&otherNode);', "'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]")
     5219        self.assert_lint('Ref<Node> protectedNode(otherNode);', "'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]")
     5220        self.assert_lint('Ref<Node> protectedNode(*otherNode);', "'protectedNode' is incorrectly named. It should be named 'protector' or 'protectedOtherNode'.  [readability/naming/protected] [4]")
     5221        self.assert_lint('RefPtr<Node> nodeRef(node);', "'nodeRef' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5222        self.assert_lint('Ref<Node> nodeRef(*node);', "'nodeRef' is incorrectly named. It should be named 'protector' or 'protectedNode'.  [readability/naming/protected] [4]")
     5223
     5224        # Lines that look like a protector variable declaration but aren't.
     5225        self.assert_lint('static RefPtr<Widget> doSomethingWith(widget);', '')
     5226        self.assert_lint('RefPtr<Widget> create();', '')
     5227
    51825228    def test_parameter_names(self):
    51835229        # Leave meaningless variable names out of function declarations.
  • trunk/Websites/webkit.org/ChangeLog

    r200082 r200859  
     12016-05-13  Brady Eidson  <beidson@apple.com>
     2
     3        Protector Ref/RefPtrs should have a specified naming style.
     4        https://bugs.webkit.org/show_bug.cgi?id=157591
     5
     6        Reviewed by Darin Adler.
     7
     8        * code-style.md:
     9
    1102016-04-26  Timothy Hatcher  <timothy@apple.com>
    211
  • trunk/Websites/webkit.org/code-style.md

    r197643 r200859  
    712712#ifndef _HTML_DOCUMENT_H_
    713713#define _HTML_DOCUMENT_H_
     714```
     715
     716[](#names-protectors-this) Ref and RefPtr objects meant to protect `this` from deletion should be named "protectedThis".
     717
     718###### Right:
     719
     720```cpp
     721RefPtr<Node> protectedThis(this);
     722Ref<Element> protectedThis(*this);
     723```
     724
     725###### Wrong:
     726
     727```cpp
     728RefPtr<Node> protector(this);
     729RefPtr<Widget> self(this);
     730Ref<Element> elementRef(*this);
     731```
     732
     733[](#names-protectors) Ref and RefPtr objects meant to protect variables other than `this` from deletion should be named either "protector", or "protected" combined with the capitalized form of the variable name.
     734
     735###### Right:
     736
     737```cpp
     738RefPtr<Element> protector(&element);
     739RefPtr<Node> protectedNode(node);
     740RefPtr<Widget> protectedMainWidget(m_mainWidget);
     741```
     742
     743###### Wrong:
     744
     745```cpp
     746RefPtr<Node> nodeRef(&rootNode);
     747Ref<Element> protect(*element);
     748RefPtr<Widget> protected(widget);
     749RefPtr<Node> protectorNode(node);
    714750```
    715751
Note: See TracChangeset for help on using the changeset viewer.