srcanamdw/codescanner/codescanner.py
author noe\swadi
Thu, 18 Feb 2010 12:29:02 +0530
changeset 1 22878952f6e2
permissions -rw-r--r--
Committing the CodeScanner Core tool This component has been moved from the StaticAnaApps package. BUG : 5889 (http://developer.symbian.org/webbugs/show_bug.cgi?id=5889).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     1
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     3
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     4
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     5
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     6
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     7
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     8
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
     9
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    10
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    11
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    12
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    13
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    14
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    15
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    16
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    17
# linescanner.py - the main body of CodeScanner
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
import base64
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
import datetime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
import encodings
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
import getopt
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
import os
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
import os.path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
import psyco
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
import re
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
import sys
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
import xml.dom.minidom
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
import zlib
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
# Ignore flags
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
KIgnoreNothing = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
KIgnoreComments = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
KIgnoreCommentsAndQuotes = 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
KIgnoreQuotes = 3
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
# Severities for the scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
KSeverityHigh = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
KSeverityMedium = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
KSeverityLow = 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
# The names used in the XML configuration file for severity element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
KSeverityConfigMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
			KSeverityHigh		: "high",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
			KSeverityMedium		: "medium",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
			KSeverityLow		: "low"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
# The names used in the HTML summary file for severity element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
KSeverityHTMLMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
			KSeverityHigh		: "High",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
			KSeverityMedium		: "Medium",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
			KSeverityLow		: "Low"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
# Categories for the scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
KCategoryLegal = "Legal Code" 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
KCategoryDefinitePanic = "Always Panic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
KCategoryCanPanic = "Can Panic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
KCategoryWrongFunctionality = "Wrong Functionality"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
KCategoryLocalisation = "Localisation"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
KCategoryPerformance = "Performance"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
KCategoryCodingStandards = "Coding Standard"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
KCategoryDocumentation = "Documentation"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
KCategoryCodeReviewGuides = "Code Review Guide"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
KCategoryOther = "Other"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
KCategoryHtmlDisplayOrder = [KCategoryLegal,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
	KCategoryDefinitePanic,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
	KCategoryCanPanic,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
	KCategoryWrongFunctionality,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
	KCategoryLocalisation,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
	KCategoryPerformance,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
	KCategoryCodingStandards,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
	KCategoryDocumentation,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
	KCategoryCodeReviewGuides,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
	KCategoryOther]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    79
# The names used in the XML configuration file for category element names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    80
KCategoryConfigMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    81
			KCategoryLegal				:	"legal", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    82
			KCategoryDefinitePanic		:	"panic", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    83
			KCategoryCanPanic			:	"canpanic", 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    84
			KCategoryWrongFunctionality	:	"functionality",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    85
			KCategoryLocalisation		:	"localisation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    86
			KCategoryPerformance		:	"performance",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    87
			KCategoryCodingStandards	:	"codingstandards",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    88
			KCategoryDocumentation		:	"documentation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    89
			KCategoryCodeReviewGuides	:	"codereview",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    90
			KCategoryOther				:	"other"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    91
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    92
#Custom rule keyword types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    93
KKeywordBaseClass = "baseclass"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    94
KKeywordCall = "call"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    95
KKeywordClassName = "class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    96
KKeywordComment = "comment"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    97
KKeywordGeneric = "generic"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    98
KKeywordLocal = "local"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    99
KKeywordMacro = "macro"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   100
KKeywordMember = "member"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   101
KKeywordMethod = "method"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   102
KKeywordParameter = "parameter"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   103
KKeywordUnknown = "unknown"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   104
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   105
#The names used in the XML configuration file for custom rule keyword types.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   106
KCustomRuleKeywordMap = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   107
			KKeywordBaseClass           :   "baseclass",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   108
			KKeywordCall                :   "call",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   109
			KKeywordClassName           :   "class",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   110
			KKeywordComment             :   "comment",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   111
			KKeywordGeneric             :   "generic",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   112
			KKeywordLocal               :   "local",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   113
			KKeywordMacro               :   "macro",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   114
			KKeywordMember              :   "member",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   115
			KKeywordMethod              :   "method",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   116
			KKeywordParameter           :   "parameter",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   117
			KKeywordUnknown             :   "unknown"}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   118
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   119
KVersion = "Nokia CodeScanner version 2.1.4"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   120
KCopyrightLine1 = "Copyright (c) 2007-2009. Nokia Corporation. All rights reserved."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   121
KCopyrightLine1Html = "Copyright © 2007-2009. Nokia Corporation. All rights reserved."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   122
KCopyrightLine2 = "For product and support information, visit www.forum.nokia.com."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   123
KWww = "www.forum.nokia.com"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   124
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   125
stringPool = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   126
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   127
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   128
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   129
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   130
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   131
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   132
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   133
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   134
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   135
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   136
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   137
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   138
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   139
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   140
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   141
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   142
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   143
# English.loc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   144
# localised string for Script accessArrayElementWithoutCheck
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   145
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   146
stringPool[ "accessArrayElementWithoutCheck!title" ]       = "Array element accessed by At() function without checking index is within array range"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   147
stringPool[ "accessArrayElementWithoutCheck!description" ] = "Whenever an element in an array is accessed, the index should be checked to ensure that it is less than array.Count(). CodeScanner checks for explicit calls to a Count() function; so if the array index is checked in a different way, it gives false positives. Accessing an invalid index can cause a panic."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   148
stringPool[ "accessArrayElementWithoutCheck!ideTitle" ]    = "array element accessed by At() function without checking index is within array range"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   149
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   150
# localised string for Script accessArrayElementWithoutCheck2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   151
stringPool[ "accessArrayElementWithoutCheck2!title" ]       = "Array element accessed by [] without checking range"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   152
stringPool[ "accessArrayElementWithoutCheck2!description" ] = "Whenever an element in an array is accessed, the index should first be checked to ensure that it is within range. CodeScanner checks for explicit calls to a Count() or Length() function; so if the array index is checked in a different way, it gives false positives. Accessing an invalid index can cause a panic."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   153
stringPool[ "accessArrayElementWithoutCheck2!ideTitle" ]    = "array element accessed by [] without checking range"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   154
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   155
# localised string for Script activestart
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   156
stringPool[ "activestart!title" ]       = "Using CActiveScheduler::Start"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   157
stringPool[ "activestart!description" ] = "Using CActiveScheduler::Start() can mean that something asynchronous is being made synchronous. Instead, use active objects correctly in an asynchronous way."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   158
stringPool[ "activestart!ideTitle" ]    = "using CActiveScheduler::Start"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   159
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   160
# localised string for Script activestop
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   161
stringPool[ "activestop!title" ]       = "Using CActiveScheduler::Stop"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   162
stringPool[ "activestop!description" ] = "Using CActiveScheduler::Stop() can mean that something asynchronous is being made synchronous. Instead, use active objects correctly in an asynchronous way."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   163
stringPool[ "activestop!ideTitle" ]    = "using CActiveScheduler::Stop"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   164
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   165
# localised string for Script arraypassing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   166
stringPool[ "arraypassing!title" ]       = "Passing arrays by value rather than reference"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   167
stringPool[ "arraypassing!description" ] = "Passing arrays by value causes the array to be copied needlessly, which takes up time and memory. For efficiency, references should be used."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   168
stringPool[ "arraypassing!ideTitle" ]    = "passing arrays by value rather than reference"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   169
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   170
# localised string for Script arrayptrcleanup
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   171
stringPool[ "arrayptrcleanup!title" ]       = "Using local CArrayPtr classes without cleanup items"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   172
stringPool[ "arrayptrcleanup!description" ] = "It is not enough to push a local CArrayPtr class onto the cleanup stack. A TCleanupItem and callback function must be used to avoid leaking the elements."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   173
stringPool[ "arrayptrcleanup!ideTitle" ]    = "using local CArrayPtr classes without cleanup items"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   174
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   175
# localised string for Script assertdebuginvariant
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   176
stringPool[ "assertdebuginvariant!title" ]       = "__ASSERT_DEBUG with User::Invariant"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   177
stringPool[ "assertdebuginvariant!description" ] = "Replace __ASSERT_DEBUG(<condition>, User::Invariant()) with ASSERT(<condition>), because it is easier to read."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   178
stringPool[ "assertdebuginvariant!ideTitle" ]    = "__ASSERT_DEBUG with User::Invariant"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   179
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   180
# localised string for Script baddefines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   181
stringPool[ "baddefines!title" ]       = "Lowercase definition names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   182
stringPool[ "baddefines!description" ] = "Badly-named definitions makes the code harder to maintain and can lead to defects."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   183
stringPool[ "baddefines!ideTitle" ]    = "lowercase definition names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   184
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   185
# localised string for Script baseconstruct
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   186
stringPool[ "baseconstruct!title" ]       = "Leaving function called before BaseConstructL()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   187
stringPool[ "baseconstruct!description" ] = "If a leave occurs before BaseConstructL() is called, the system can panic because it is trying to clean up an application that has not been fully initialised."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   188
stringPool[ "baseconstruct!ideTitle" ]    = "leaving method called before BaseConstructL"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   189
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   190
# localised string for Script callActiveObjectWithoutCheckingOrStopping
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   191
stringPool[ "callActiveObjectWithoutCheckingOrStopping!title" ]       = "Active object called without checking whether it is active or canceling it first"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   192
stringPool[ "callActiveObjectWithoutCheckingOrStopping!description" ] = "If an active object is started twice, a panic occurs. CodeScanner picks out places where there is a call to a Start(), Queue(), or After() function on a member variable, without a previous call to IsActive(), Cancel(), or Stop(). In general, if starting a timer, there should at least be a call to IsActive() to ensure that the timer is not already running."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   193
stringPool[ "callActiveObjectWithoutCheckingOrStopping!ideTitle" ]    = "active object called without checking whether it is active or canceling it first"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   194
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   195
# localised string for Script changenotification
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   196
stringPool[ "changenotification!title" ]       = "Using RSAVarChangeNotify to see System Agent changes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   197
stringPool[ "changenotification!description" ] = "When watching for System Agent changes, use RSystemAgent rather than RSAVarChangeNotify, which can fail."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   198
stringPool[ "changenotification!ideTitle" ]    = "using RSAVarChangeNotify to see System Agent changes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   199
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   200
# localised string for Script cleanup
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   201
stringPool[ "cleanup!title" ]       = "CleanupStack::Pop(AndDestroy) parameters"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   202
stringPool[ "cleanup!description" ] = "These functions should be called with explicit variable parameters to avoid misalignment."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   203
stringPool[ "cleanup!ideTitle" ]    = "missing CleanupStack::Pop parameter"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   205
# localised string for Script commentcode
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   206
stringPool[ "commentcode!title" ]       = "Commented-out code"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   207
stringPool[ "commentcode!description" ] = "Instances of code that are commented out make the code hard to maintain and to interpret clearly. The commented out code should be removed. Any requirement to rediscover old code should be made through source control and not by trawling through commented-out code."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   208
stringPool[ "commentcode!ideTitle" ]    = "commented-out code"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   209
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   210
# localised string for Script connect
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   211
stringPool[ "connect!title" ]       = "Ignoring Connect() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   212
stringPool[ "connect!description" ] = "Ignoring the error returned from Connect() functions means that if the Connect() function fails due to OOM or other problems, the next access to the resource will panic."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   213
stringPool[ "connect!ideTitle" ]    = "ignoring Connect() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   214
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   215
# localised string for Script ConnectAndDontCloseMemberVariable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   216
stringPool[ "ConnectAndDontCloseMemberVariable!title" ]       = "Calling Connect() or Open() on a member variable without calling Close() in the destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   217
stringPool[ "ConnectAndDontCloseMemberVariable!description" ] = "If Connect() or Open() is called on any member variable, then Close() must be called in the destructor."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   218
stringPool[ "ConnectAndDontCloseMemberVariable!ideTitle" ]    = "calling Connect() or Open() on a member variable without calling Close() in the destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   219
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   220
# localised string for Script constnames
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   221
stringPool[ "constnames!title" ]       = "Badly-named constants"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   222
stringPool[ "constnames!description" ] = "Badly-named constant will make the source code harder to maintain and make defects more likely."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   223
stringPool[ "constnames!ideTitle" ]    = "badly-named constant"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   224
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   225
# localised string for Script consttdescptr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   226
stringPool[ "consttdescptr!title" ]       = "Const descriptor pointer as argument"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   227
stringPool[ "consttdescptr!description" ] = "Use \"const TDesC&\" instead of \"const TDesC*\"."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   228
stringPool[ "consttdescptr!ideTitle" ]    = "const descriptor pointer as argument"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   229
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   230
# localised string for Script controlornull
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   231
stringPool[ "controlornull!title" ]       = "Accessing return value of ControlOrNull()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   232
stringPool[ "controlornull!description" ] = "The return value might be NULL, so it should be checked before access."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   233
stringPool[ "controlornull!ideTitle" ]    = "accessing return value of ControlOrNull()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   234
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   235
# localised string for Script crepository
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   236
stringPool[ "crepository!title" ]       = "Ignoring CRepository::get() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   237
stringPool[ "crepository!description" ] = "Independent application cannot assume that the Central Repository is set up fully. This means the return value of CRepository::get() cannot be ignored."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   238
stringPool[ "crepository!ideTitle" ]    = "ignoring CRepository::get() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   239
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   240
# localised string for Script ctltargettype
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   241
stringPool[ "ctltargettype!title" ]       = "Use of targettype ctl"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   242
stringPool[ "ctltargettype!description" ] = "The ctl target type should not be used. Instead, use DLL and explicitly refer to the Control Panel's DEF file. Note: Code that causes this issue only needs attention if it is found in code developed for Nokia Series 90 code that has extra exports for resetting the Control Panel item's data."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   243
stringPool[ "ctltargettype!ideTitle" ]    = "use of targettype ctl"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   244
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   245
# localised string for Script customizableicons
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   246
stringPool[ "customizableicons!title" ]       = "Use of customizable icons"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   247
stringPool[ "customizableicons!description" ] = "Due to device customization requirements, independent application must not remove any customization done by the variant team. This means independent application cannot include customizable icons."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   248
stringPool[ "customizableicons!ideTitle" ]    = "use of customizable icons"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   249
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   250
# localised string for Script debugrom
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   251
stringPool[ "debugrom!title" ]       = "Debug components in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   252
stringPool[ "debugrom!description" ] = "Debug versions of components in the ROM could mean that ROM space is being taken up with debugging information or that logging is being put out. Release versions should be in the ROM unless there is a good reason why they are not."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   253
stringPool[ "debugrom!ideTitle" ]    = "debug components in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   254
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   255
# localised string for Script declarename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   256
stringPool[ "declarename!title" ]       = "Use of __DECLARE_NAME"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   257
stringPool[ "declarename!description" ] = "The __DECLARE_NAME macro is historical and serves no purpose anymore and should be removed."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   258
stringPool[ "declarename!ideTitle" ]    = "use of __DECLARE_NAME"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   259
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   260
# localised string for Script deleteMemberVariable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   261
stringPool[ "deleteMemberVariable!title" ]       = "Member variable deleted incorrectly"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   262
stringPool[ "deleteMemberVariable!description" ] = "When a member variable is deleted, it should be assigned either to NULL or to another value. This prevents accidental access of the deleted object. If a NewL() or other leaving function is called to reassign the member variable, it should first be assigned to NULL in case that function leaves."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   263
stringPool[ "deleteMemberVariable!ideTitle" ]    = "member variable deleted incorrectly"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   264
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   265
# localised string for Script destructor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   266
stringPool[ "destructor!title" ]       = "Pointer access in destructors"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   267
stringPool[ "destructor!description" ] = "Accessing pointers to objects in destructors without checking whether they are not NULL could result in a panic because they may not have been constructed. The pointers should be checked to determine whether they are owned objects. If they are not owned, they should really be references rather than pointers."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   268
stringPool[ "destructor!ideTitle" ]    = "destructor is accessing/dereferencing data member"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   269
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   270
# localised string for Script doubleSemiColon
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   271
stringPool[ "doubleSemiColon!title" ]       = "Use of double semicolon"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   272
stringPool[ "doubleSemiColon!description" ] = "Double semicolons at the end of a line are not necessary and cause a CodeWarrior compiler error."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   273
stringPool[ "doubleSemiColon!ideTitle" ]    = "use of double semicolon"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   274
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   275
# localised string for Script driveletters
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   276
stringPool[ "driveletters!title" ]       = "Hard-coded drive letters"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   277
stringPool[ "driveletters!description" ] = "Drive letters should not be hard-coded."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   278
stringPool[ "driveletters!ideTitle" ]    = "hard-coded drive letters"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   279
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   280
# localised string for Script eikbuttons
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   281
stringPool[ "eikbuttons!title" ]       = "Checks that the R_EIK_BUTTONS_* resources are not being used"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   282
stringPool[ "eikbuttons!description" ] = "R_EIK_BUTTONS_* resources will not be internationalised, and should not be used. Instead, create your own button resource. No button resource (or indeed, rls string) should be used in more than one location. Note: This issue is only relevant for development on Nokia platforms."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   283
stringPool[ "eikbuttons!ideTitle" ]    = "use of R_EIK_BUTTONS_ resources"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   284
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   285
# localised string for Script eikonenvstatic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   286
stringPool[ "eikonenvstatic!title" ]       = "Using CEikonEnv::Static"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   287
stringPool[ "eikonenvstatic!description" ] = "CEikonEnv::Static() calls should be kept to a minimum, because this involves TLS. All applications, controls, and dialogs already have a pointer to the singleton instance of CEikonEnv as a member variable and so do not need to find it again. If a class does not have access to a CEikonEnv and needs to use it repeatedly, then it should store one."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   288
stringPool[ "eikonenvstatic!ideTitle" ]    = "using CEikonEnv::Static"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   289
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   290
# localised string for Script enummembers
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   291
stringPool[ "enummembers!title" ]       = "Enums with badly-named members"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   292
stringPool[ "enummembers!description" ] = "Enums with badly-named members make the code harder to maintain and may cause defects."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   293
stringPool[ "enummembers!ideTitle" ]    = "enum with badly-named member"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   294
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   295
# localised string for Script enumnames
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   296
stringPool[ "enumnames!title" ]       = "Badly-named enums"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   297
stringPool[ "enumnames!description" ] = "Badly-named enums make the code harder to maintain and may cause defects."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   298
stringPool[ "enumnames!ideTitle" ]    = "badly-named enum"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   299
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   300
# localised string for Script exportinline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   301
stringPool[ "exportinline!title" ]       = "Exporting inline functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   302
stringPool[ "exportinline!description" ] = "Inline functions should not be exported because this can cause those that link to the DLL to fail to build. Exporting functions limits the changes that can be made in the future due to considerations of binary-compatibility."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   303
stringPool[ "exportinline!ideTitle" ]    = "exporting inline functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   304
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   305
# localised string for Script exportpurevirtual
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   306
stringPool[ "exportpurevirtual!title" ]       = "Exporting pure virtual functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   307
stringPool[ "exportpurevirtual!description" ] = "Symbian recommends against the exportation of pure virtual functions."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   308
stringPool[ "exportpurevirtual!ideTitle" ]    = "exporting pure virtual functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   309
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   310
# localised string for Script externaldriveletters
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   311
# stringPool[ "externaldriveletters!title" ]       = "Hard-coded external drive letters"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   312
# stringPool[ "externaldriveletters!description" ] = "External drive letters should not be hard-coded as the external drive may change between platforms and releases. This may cause confusion over ownership leading to classes being deleted erroneously and leaks occurring."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   313
# stringPool[ "externaldriveletters!ideTitle" ]    = "hard-coded external drive letter"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   314
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   315
# localised string for Script flags
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   316
stringPool[ "flags!title" ]       = "Use of R&D flags or feature flags"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   317
stringPool[ "flags!description" ] = "Independent application must not use R&D flags nor feature flags via preprocessor statements in the source code. This means bld*.hrh and productvariant.hrh should not be used."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   318
stringPool[ "flags!ideTitle" ]    = "use of R&D flags or feature flags"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   319
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   320
# localised string for Script foff
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   321
stringPool[ "foff!title" ]       = "Use of _FOFF"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   322
stringPool[ "foff!description" ] = "_FOFF allows access to data in classes that were not intended for public access. This may cause problems, especially when the location of the data changes."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   323
stringPool[ "foff!ideTitle" ]    = "use of _FOFF"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   324
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   325
# localised string for Script forbiddenwords
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   326
stringPool[ "forbiddenwords!title" ]       = "Use of forbidden words in header files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   327
stringPool[ "forbiddenwords!description" ] = "Some words should not be used in header files; especially those header files destined for external release. Some words may be forbidden for legal reasons or for platform consistency. Where they exist, alternative allowed words should be used. For example, \"NMP\" and \"Nokia Mobile Phones\" should be replaced by \"Nokia\"."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   328
stringPool[ "forbiddenwords!ideTitle" ]    = "use of forbidden words in header files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   329
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   330
# localised string for Script forgottoputptroncleanupstack
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   331
stringPool[ "forgottoputptroncleanupstack!title" ]       = "Neglected to put variable on cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   332
stringPool[ "forgottoputptroncleanupstack!description" ] = "If a variable is not put on the cleanup stack and a leaving function or ELeave is called, a memory leak occurs. CodeScanner occasionally gives false positives for this issue. Individual cases should be investigated."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   333
stringPool[ "forgottoputptroncleanupstack!ideTitle" ]    = "neglected to put variable on cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   334
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   335
# localised string for Script friend
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   336
stringPool[ "friend!title" ]       = "Use of friends"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   337
stringPool[ "friend!description" ] = "The friend directive is often misused and can indicate problems in the OO design."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   338
stringPool[ "friend!ideTitle" ]    = "use of friends"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   339
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   340
# localised string for Script goto
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   341
stringPool[ "goto!title" ]       = "Use of goto"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   342
stringPool[ "goto!description" ] = "Goto should not be used if it can be avoided because it makes the program flow more difficult to follow."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   343
stringPool[ "goto!ideTitle" ]    = "use of goto"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   344
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   345
# localised string for Script ifassignments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   346
stringPool[ "ifassignments!title" ]       = "Assignment in an If statement"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   347
stringPool[ "ifassignments!description" ] = "Assignments inside an If statement often indicate that the assignment was not intended. Even if the assignment was intended, it is clearer to separate out the assignment from the conditional. The script that detects such occurrences has a few false positives when the action statements are on the same line as the conditional check. However, this is also against the coding standards and the action should be on a separate line."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   348
stringPool[ "ifassignments!ideTitle" ]    = "assignment in an If statement"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   349
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   350
# localised string for Script ifpreprocessor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   351
stringPool[ "ifpreprocessor!title" ]       = "Use of #if in .h files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   352
stringPool[ "ifpreprocessor!description" ] = "#if in header files should only be used before the main include guards and not around #include statements or around functional blocks in class definitions. The reason for the latter is to aid readability and to make BC breaks more difficult."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   353
stringPool[ "ifpreprocessor!ideTitle" ]    = "use of #if in .h files (not as main include guards)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   354
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   355
# localised string for Script inheritanceorder
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   356
stringPool[ "inheritanceorder!title" ]       = "Incorrect inheritance order of M and C classes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   357
stringPool[ "inheritanceorder!description" ] = "If a C class inherits first from an M class and then a C class, a panic can occur when trying to pop a CBase pointer pointing to such a class from the cleanup stack when in fact a pointer pointing to the first predecessor, the mixin class, was popped instead."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   358
stringPool[ "inheritanceorder!ideTitle" ]    = "incorrect inheritance order of M and C classes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   359
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   360
# localised string for Script intleaves
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   361
stringPool[ "intleaves!title" ]       = "Methods that leave AND return a TInt error"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   362
stringPool[ "intleaves!description" ] = "Returning an error code as well as being able to leave is problematical for the caller. It is preferable to adhere to one method of returning the error. Note: CodeScanner is likely to return false positives for this situation, because some returned TInt values will not be error codes."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   363
stringPool[ "intleaves!ideTitle" ]    = "methods that leave AND return a TInt error"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   364
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   365
# localised string for Script jmp
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   366
stringPool[ "jmp!title" ]       = "Use of setjmp and/or longjmp"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   367
stringPool[ "jmp!description" ] = "Using setjmp and/or longjmp makes code less maintainable."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   368
stringPool[ "jmp!ideTitle" ]    = "use of setjmp and/or longjmp"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   369
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   370
# localised string for Script leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   371
stringPool[ "leave!title" ]       = "Leaving functions called in non-leaving functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   372
stringPool[ "leave!description" ] = "Non-leaving functions should not call leaving functions. Note: Operator functions are considered to be able to leave when scanning the code inside them."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   373
stringPool[ "leave!ideTitle" ]    = "leaving function called in non-leaving function"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   374
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   375
# localised string for Script LeaveNoError
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   376
stringPool[ "LeaveNoError!title" ]       = "Leaving with KErrNone"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   377
stringPool[ "LeaveNoError!description" ] = "Leaving with KErrNone usually indicates that there is a makeshift way around a design issue rather than a true and proper fix to the architecture."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   378
stringPool[ "LeaveNoError!ideTitle" ]    = "leaving with KErrNone"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   379
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   380
# localised string for Script leavingoperators
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   381
stringPool[ "leavingoperators!title" ]       = "Leaving functions called in operator functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   382
stringPool[ "leavingoperators!description" ] = "It is not obvious that operator functions can leave. Calling leaving functions in operator functions should be considered carefully."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   383
stringPool[ "leavingoperators!ideTitle" ]    = "leaving functions called in operator functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   384
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   385
# localised string for Script LFunctionCantLeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   386
stringPool[ "LFunctionCantLeave!title" ]       = "L-functions that cannot leave"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   387
stringPool[ "LFunctionCantLeave!description" ] = "A function should not be named with an 'L' if it cannot leave. The only exception is in virtual functions where the function name is defined in the base class so the L cannot be removed. For example, RunL()."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   388
stringPool[ "LFunctionCantLeave!ideTitle" ]    = "L-functions that cannot leave"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   389
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   390
# localised string for Script longlines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   391
stringPool[ "longlines!title" ]       = "Overly long lines of code"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   392
stringPool[ "longlines!description" ] = "Lines longer than about 100 characters can indicate messy or badly-structured code that is hard to maintain."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   393
stringPool[ "longlines!ideTitle" ]    = "overly long line of code"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   394
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   395
# localised string for Script magicnumbers
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   396
stringPool[ "magicnumbers!title" ]       = "Use of magic numbers"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   397
stringPool[ "magicnumbers!description" ] = "Magic numbers - that is, numbers that are hard-coded into the source code and instead of being presented as constants - make code difficult to maintain and give no indication of why a calculation is the way it is. Magic numbers should be replaced with named constants."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   398
stringPool[ "magicnumbers!ideTitle" ]    = "use of magic numbers"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   399
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   400
# localised string for Script mclassdestructor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   401
stringPool[ "mclassdestructor!title" ]       = "M class has destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   402
stringPool[ "mclassdestructor!description" ] = "M classes should not contain a destructor."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   403
stringPool[ "mclassdestructor!ideTitle" ]    = "M class has destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   404
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   405
# localised string for Script memberlc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   406
stringPool[ "memberlc!title" ]       = "Assigning LC methods to member variables"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   407
stringPool[ "memberlc!description" ] = "Objects on the cleanup stack should not be assigned to member variables"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   408
stringPool[ "memberlc!ideTitle" ]    = "LC method assigned to data member"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   409
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   410
# localised string for Script membervariablecallld
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   411
stringPool[ "membervariablecallld!title" ]       = "Calling LD function on member variable"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   412
stringPool[ "membervariablecallld!description" ] = "LD functions should not be called on a member variable because ownership can be unclear and may lead to double deletes."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   413
stringPool[ "membervariablecallld!ideTitle" ]    = "calling LD function on member variable"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   414
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   415
# localised string for Script missingcancel
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   416
stringPool[ "missingcancel!title" ]       = "Cancel() not called in active object's destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   417
stringPool[ "missingcancel!description" ] = "Cancel() should always be called in active object's destructor to cancel an outstanding request if there is one. If there is no request pending then Cancel() just does nothing, but if we do not call Cancel() when having an outstanding request a panic will be raised. CodeScanner occasionally gives false positives for this issue. Individual cases should be investigated."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   418
stringPool[ "missingcancel!ideTitle" ]    = "Cancel() not called in active object's destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   419
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   420
# localised string for Script missingcclass
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   421
stringPool[ "missingcclass!title" ]       = "C class not inheriting from another C class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   422
stringPool[ "missingcclass!description" ] = "All C classes should inherit from another C class to ensure that all data members are zeroed."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   423
stringPool[ "missingcclass!ideTitle" ]    = "C class not inheriting from another C class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   424
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   425
# localised string for Script mmpsourcepath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   426
stringPool[ "mmpsourcepath!title" ]       = "Use of absolute path names in MMP files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   427
stringPool[ "mmpsourcepath!description" ] = "Use of absolute paths in MMP files makes it impossible to relocate the source. Relative paths should be used instead."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   428
stringPool[ "mmpsourcepath!ideTitle" ]    = "use of absolute path names in MMP files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   429
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   430
# localised string for Script multilangrsc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   431
stringPool[ "multilangrsc!title" ]       = "Not using BaflUtils::NearestLanguageFile() when loading a resource file"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   432
stringPool[ "multilangrsc!description" ] = "If AddResourceFileL() is used without first using BaflUtils::NearestLanguageFile(), then not all language versions of resources will be picked up."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   433
stringPool[ "multilangrsc!ideTitle" ]    = "not using BaflUtils::NearestLanguageFile() when loading a resource file"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   434
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   435
# localised string for Script multipledeclarations
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   436
stringPool[ "multipledeclarations!title" ]       = "Multiple declarations on one line"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   437
stringPool[ "multipledeclarations!description" ] = "Multiple declarations on one line can be confusing. Separate them out so that each declaration is on its own separate line."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   438
stringPool[ "multipledeclarations!ideTitle" ]    = "multiple declarations on one line"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   439
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   440
# localised string for Script multipleinheritance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   441
stringPool[ "multipleinheritance!title" ]       = "Non M-class multiple inheritance"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   442
stringPool[ "multipleinheritance!description" ] = "It is bad Symbian OS practice to derive from two classes that have implemented functions. Complex behaviour that was not intended can result."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   443
stringPool[ "multipleinheritance!ideTitle" ]    = "multiple inheritance from non M-classes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   444
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   445
# localised string for Script mydocs
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   446
stringPool[ "mydocs!title" ]       = "Hard-coded mydocs directory strings"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   447
stringPool[ "mydocs!description" ] = "The mydocs directory is subject to change so should not be referenced directly. Note: @	This issue will only occur in code developed for the Nokia Series 90 platform."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   448
stringPool[ "mydocs!ideTitle" ]    = "hard-coded mydocs directory strings"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   449
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   450
# localised string for Script namespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   451
stringPool[ "namespace!title" ]       = "Use of namespace"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   452
stringPool[ "namespace!description" ] = "Namespaces are often used to work around a poor naming convention."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   453
stringPool[ "namespace!ideTitle" ]    = "use of namespace"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   454
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   455
# localised string for Script newlreferences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   456
stringPool[ "newlreferences!title" ]       = "NewL() returning a reference"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   457
stringPool[ "newlreferences!description" ] = "NewL() and NewLC() functions should return a pointer to an object created on the heap."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   458
stringPool[ "newlreferences!ideTitle" ]    = "NewL() returning a reference"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   459
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   460
# localised string for Script noleavetrap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   461
stringPool[ "noleavetrap!title" ]       = "TRAP used with no leaving functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   462
stringPool[ "noleavetrap!description" ] = "A TRAP is unnecessary if there are no leaving functions."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   463
stringPool[ "noleavetrap!ideTitle" ]    = "TRAP contains no leaving functions"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   464
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   465
# localised string for Script nonconsthbufc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   466
stringPool[ "nonconsthbufc!title" ]       = "Non-const HBufC* parameter passing"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   467
stringPool[ "nonconsthbufc!description" ] = "HBufC* parameters should almost always be passed as a const pointer."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   468
stringPool[ "nonconsthbufc!ideTitle" ]    = "non-const HBufC* parameter passing"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   469
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   470
# localised string for Script nonconsttdesc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   471
stringPool[ "nonconsttdesc!title" ]       = "Non-const TDesC& parameter passing"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   472
stringPool[ "nonconsttdesc!description" ] = "TDesC& parameters should be passed as a const. If it is not, it may indicate that the coder does not understand descriptors, for example, passing descriptors by value."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   473
stringPool[ "nonconsttdesc!ideTitle" ]    = "non-const TDesC& parameter passing"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   474
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   475
# localised string for Script nonleavenew
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   476
stringPool[ "nonleavenew!title" ]       = "Use of new without (ELeave)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   477
stringPool[ "nonleavenew!description" ] = "Using new without (ELeave) is only used in special circumstances. The leaving variant should typically be used in preference. A common exception is for application creation, where NULL is returned for failed creation."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   478
stringPool[ "nonleavenew!ideTitle" ]    = "new used without (ELeave)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   479
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   480
# localised string for Script nonunicodeskins
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   481
stringPool[ "nonunicodeskins!title" ]       = "Non-Unicode skins"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   482
stringPool[ "nonunicodeskins!description" ] = "Skin definition files (SKN, SKE) must be Unicode. Note: Code that causes this issue only needs attention if it is found in code developed for Nokia Series 90 code."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   483
stringPool[ "nonunicodeskins!ideTitle" ]    = "non-Unicode skins"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   484
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   485
# localised string for Script null
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   486
stringPool[ "null!title" ]       = "NULL equality check"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   487
stringPool[ "null!description" ] = "There is no need to compare pointer variables to NULL. Use If(ptr)."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   488
stringPool[ "null!ideTitle" ]    = "NULL equality check"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   489
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   490
# localised string for Script open
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   491
stringPool[ "open!title" ]       = "Ignoring Open() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   492
stringPool[ "open!description" ] = "Ignoring the return value from Open() functions (due to OOM, etc.) means that when the resource is accessed next, a panic will result."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   493
stringPool[ "open!ideTitle" ]    = "ignoring Open() return value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   494
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   495
# localised string for Script pointertoarrays
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   496
stringPool[ "pointertoarrays!title" ]       = "Pointer to arrays as members of a C class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   497
stringPool[ "pointertoarrays!description" ] = "In C classes, there is no need to use pointers to arrays as data members. Instead, use the arrays themselves. Using pointers leads to obscure notation like \"(*array)[n]\" for the more usual \"array[n]\". It also makes it necessary to explicitly delete the arrays in the destructor. Using the arrays themselves also simplifies notation, reduces indirection, and reduces heap fragmentation."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   498
stringPool[ "pointertoarrays!ideTitle" ]    = "pointer to arrays as members of a C class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   499
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   500
# localised string for Script pragmadisable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   501
stringPool[ "pragmadisable!title" ]       = "Use of #pragma warning"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   502
stringPool[ "pragmadisable!description" ] = "Disabling warnings can lead to problems, because the warnings are probably there for a reason."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   503
stringPool[ "pragmadisable!ideTitle" ]    = "use of #pragma warning"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   504
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   505
# localised string for Script pragmamessage
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   506
stringPool[ "pragmamessage!title" ]       = "Use of #pragma message"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   507
stringPool[ "pragmamessage!description" ] = "#pragma messages during the build stage can interfere with the build log parsing."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   508
stringPool[ "pragmamessage!ideTitle" ]    = "use of #pragma message"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   509
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   510
# localised string for Script pragmaother
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   511
stringPool[ "pragmaother!title" ]       = "Use of #pragma other than warning and message"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   512
stringPool[ "pragmaother!description" ] = "#pragma directives should only be used in very edge cases (for example, functions consisting of inline assembler without explicit return statements) because, typically, their usage masks valid build warnings and error messages."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   513
stringPool[ "pragmaother!ideTitle" ]    = "use of #pragma other than warning and message"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   514
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   515
# localised string for Script privateinheritance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   516
stringPool[ "privateinheritance!title" ]       = "Use of private inheritance"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   517
stringPool[ "privateinheritance!description" ] = "Classes should not be inherited privately. If public or protected inheritance is not appropriate, consider using an amalgamation; that is, have an object of that type as a member variable."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   518
stringPool[ "privateinheritance!ideTitle" ]    = "use of private inheritance"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   519
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   520
# localised string for Script pushaddrvar
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   521
stringPool[ "pushaddrvar!title" ]       = "Pushing address of a variable onto the cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   522
stringPool[ "pushaddrvar!description" ] = "If the variable is owned by the code pushing it, it should be stored as a pointer. If it is not, it should not be pushed onto the cleanup stack."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   523
stringPool[ "pushaddrvar!ideTitle" ]    = "pushing address of a variable onto the cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   525
# localised string for Script pushmember
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   526
stringPool[ "pushmember!title" ]       = "Pushing data members onto the cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   527
stringPool[ "pushmember!description" ] = "Pushing member variables is likely to lead to double deletes or leakage in certain circumstances and so should be avoided. Even if no panic can result, it is bad practice and makes maintenance more difficult."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   528
stringPool[ "pushmember!ideTitle" ]    = "data member pushed to cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   529
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   530
# localised string for Script readresource
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   531
stringPool[ "readresource!title" ]       = "Using ReadResource() instead of ReadResourceL()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   532
stringPool[ "readresource!description" ] = "ReadResourceL() should always be used in preference to ReadResource() because in an error scenario ReadResource() effectively fails silently. If no check is performed on the resulting descriptor afterwards, unexpected states can ensue. These states are often characterized by buffer overflows."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   533
stringPool[ "readresource!ideTitle" ]    = "Using ReadResource() instead of ReadResourceL()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   534
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   535
# localised string for Script resourcenotoncleanupstack
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   536
stringPool[ "resourcenotoncleanupstack!title" ]       = "Neglected to put resource objects on cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   537
stringPool[ "resourcenotoncleanupstack!description" ] = "If a stack-based resource object is not put on the cleanup stack with CleanupResetAndDestroyPushL() or CleanupClosePushL(), and a leaving function or ELeave is called, a memory leak occurs. CodeScanner occasionally gives false positives for this issue. Individual cases should be investigated."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   538
stringPool[ "resourcenotoncleanupstack!ideTitle" ]    = "neglected to put resource objects on cleanup stack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   539
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   540
# localised string for Script resourcesonheap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   541
stringPool[ "resourcesonheap!title" ]       = "Resource objects on the heap"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   542
stringPool[ "resourcesonheap!description" ] = "There is very rarely any real need to put R classes on the heap (unless they are not real R classes!).  Doing so can lead to inefficiency and cleanup stack problems."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   543
stringPool[ "resourcesonheap!ideTitle" ]    = "resource objects on the heap"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   544
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   545
# localised string for Script returndescriptoroutofscope
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   546
stringPool[ "returndescriptoroutofscope!title" ]       = "Return descriptor out of scope"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   547
stringPool[ "returndescriptoroutofscope!description" ] = "Returning a TBuf descriptor that is declared locally takes it out of scope. This can cause a crash on WINSCW, although not on WINS."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   548
stringPool[ "returndescriptoroutofscope!ideTitle" ]    = "return descriptor out of scope"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   549
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   550
# localised string for Script rfs
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   551
stringPool[ "rfs!title" ]       = "Use of non-pointer/reference RFs"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   552
stringPool[ "rfs!description" ] = "Connecting to an RFs is a time-consuming operation. (It can take approximately 0.1 seconds on some devices.) To minimise wasted time and resources, use the already-connected one in EikonEnv or elsewhere, if possible."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   553
stringPool[ "rfs!ideTitle" ]    = "use of non-pointer/reference RFs"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   554
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   555
# localised string for Script rssnames
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   556
stringPool[ "rssnames!title" ]       = "Duplicate RSS names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   557
stringPool[ "rssnames!description" ] = "Resource files with clashing NAME fields can cause the wrong resource file to be accessed. This can lead to incorrect functionality or panics."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   558
stringPool[ "rssnames!ideTitle" ]    = "duplicate RSS names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   559
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   560
# localised string for Script stringliterals
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   561
stringPool[ "stringliterals!title" ]       = "Use of _L string literals"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   562
stringPool[ "stringliterals!description" ] = "_L() string literals should be replaced by the _LIT() macro."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   563
stringPool[ "stringliterals!ideTitle" ]    = "use of _L string literals"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   564
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   565
# localised string for Script stringsinresourcefiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   566
stringPool[ "stringsinresourcefiles!title" ]       = "Strings in RSS or RA files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   567
stringPool[ "stringsinresourcefiles!description" ] = "Strings should not be defined in RSS or RA files. Instead, they should be put in RLS or other localisable files."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   568
stringPool[ "stringsinresourcefiles!ideTitle" ]    = "strings in RSS or RA files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   569
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   570
# localised string for Script struct
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   571
stringPool[ "struct!title" ]       = "Use of struct"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   572
stringPool[ "struct!description" ] = "C-style structs should not generally be used. The correct idiom is to use a class with public members. A permissible use of a C-style struct is if it is used to group non-semantically related entities together for convenience, and if a class-related hierarchy would be too heavy-weight."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   573
stringPool[ "struct!ideTitle" ]    = "use of struct"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   574
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   575
# localised string for Script tcclasses
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   576
stringPool[ "tcclasses!title" ]       = "T classes inheriting from C classes"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   577
stringPool[ "tcclasses!description" ] = "T classes that are derived from C classes may have a complex constructor and so need to be handled differently. It is better to make the T class into a C class, which will make the code easier to maintain."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   578
stringPool[ "tcclasses!ideTitle" ]    = "T class inherits from C class"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   579
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   580
# localised string for Script tclassdestructor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   581
stringPool[ "tclassdestructor!title" ]       = "T class has destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   582
stringPool[ "tclassdestructor!description" ] = "T classes should not have a destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   583
stringPool[ "tclassdestructor!ideTitle" ]    = "T class has destructor"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   584
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   585
# localised string for Script todocomments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   586
stringPool[ "todocomments!title" ]       = "\"To do\" comments"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   587
stringPool[ "todocomments!description" ] = "\"To do\" comments in code suggest that it is not finished."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   588
stringPool[ "todocomments!ideTitle" ]    = "\"To do\" comment"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   589
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   590
# localised string for Script trapcleanup
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   591
stringPool[ "trapcleanup!title" ]       = "Use of LC function in TRAPs"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   592
stringPool[ "trapcleanup!description" ] = "You cannot trap something that leaves something on the cleanup stack because it will panic."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   593
stringPool[ "trapcleanup!ideTitle" ]    = "LC function used in TRAP"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   594
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   595
# localised string for Script trapeleave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   596
stringPool[ "trapeleave!title" ]       = "Trapping new(ELeave)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   597
stringPool[ "trapeleave!description" ] = "The trapping of a \"new(ELeave) CXxx\" call is redundant and wasteful as the code to support TRAP is surprisingly large. If the instantiation process really needs not to leave, use \"new CXxx\" and check for NULL."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   598
stringPool[ "trapeleave!ideTitle" ]    = "trapping new(ELeave)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   599
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   600
# localised string for Script traprunl
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   601
stringPool[ "traprunl!title" ]       = "Trapping of (Do)RunL() rather than using RunError()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   602
stringPool[ "traprunl!description" ] = "The RunError() function should be used rather than the CActive derivative using its own TRAPD solution within a RunL()."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   603
stringPool[ "traprunl!ideTitle" ]    = "trapping of (Do)RunL() rather than using RunError()"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   604
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   605
# localised string for Script trspassing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   606
stringPool[ "trspassing!title" ]       = "Passing TRequestStatus parameters by value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   607
stringPool[ "trspassing!description" ] = "TRequestStatus parameters should be passed by reference. If TRequestStatus is just being used as an error code, then convert it to a TInt."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   608
stringPool[ "trspassing!ideTitle" ]    = "passing TRequestStatus parameters by value"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   609
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   610
# localised string for Script uids
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   611
stringPool[ "uids!title" ]       = "Duplicate UIDs"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   612
stringPool[ "uids!description" ] = "UIDs must be unique."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   613
stringPool[ "uids!ideTitle" ]    = "duplicate UIDs"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   614
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   615
# localised string for Script uncompressedaif
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   616
stringPool[ "uncompressedaif!title" ]       = "Uncompressed AIFs in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   617
stringPool[ "uncompressedaif!description" ] = "AIF files should be referenced as \"AIF=\" rather than \"data=\" or \"file=\" otherwise they can bloat the ROM size and slow down application loading."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   618
stringPool[ "uncompressedaif!ideTitle" ]    = "uncompressed AIFs in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   619
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   620
# localised string for Script uncompressedbmp
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   621
stringPool[ "uncompressedbmp!title" ]       = "Uncompressed bitmaps in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   622
stringPool[ "uncompressedbmp!description" ] = "Using uncompressed bitmaps can significantly bloat the size of ROM images. All occurrences of \"bitmap=\" in iby/hby files should be replaced with \"auto-bitmap=\". Also, including bitmaps using \"data=\" or \"file=\" causes bloat and load-speed reductions."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   623
stringPool[ "uncompressedbmp!ideTitle" ]    = "uncompressed bitmaps in ROM"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   624
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   625
# localised string for Script unicodesource
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   626
stringPool[ "unicodesource!title" ]       = "Unicode source files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   627
stringPool[ "unicodesource!description" ] = "Having Unicode source files (CPP, H, RLS, LOC, RSS, and RA) will break most build systems."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   628
stringPool[ "unicodesource!ideTitle" ]    = "Unicode source files"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   629
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   630
# localised string for Script userafter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   631
stringPool[ "userafter!title" ]       = "Use of User::After"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   632
stringPool[ "userafter!description" ] = "Generally, User::After() functions are used to skirt around timing problems. Typically, they should be removed and the defects fixed properly: that is, by waiting for the correct event to continue execution."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   633
stringPool[ "userafter!ideTitle" ]    = "use of User::After"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   634
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   635
# localised string for Script userfree
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   636
stringPool[ "userfree!title" ]       = "Using User::Free directly"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   637
stringPool[ "userfree!description" ] = "User::Free() should never be called, because all objects free their memory on deletion; their destructors are not called and further resources cannot be freed or closed. This function should be removed and replaced by explicit deletes."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   638
stringPool[ "userfree!ideTitle" ]    = "using User::Free directly"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   639
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   640
# localised string for Script userWaitForRequest
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   641
stringPool[ "userWaitForRequest!title" ]       = "Use of User::WaitForRequest"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   642
stringPool[ "userWaitForRequest!description" ] = "User::WaitForRequest() should not generally be used in UI code because the UI will not respond to redraw events while its thread is stopped."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   643
stringPool[ "userWaitForRequest!ideTitle" ]    = "use of User::WaitForRequest"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   644
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   645
# localised string for Script variablenames
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   646
stringPool[ "variablenames!title" ]       = "Local variables with member/argument names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   647
stringPool[ "variablenames!description" ] = "Local variable names should be of the form localVariable and not aLocalVar or iLocalVar. Badly-named variables can be misleading and cause maintenance and coding errors."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   648
stringPool[ "variablenames!ideTitle" ]    = "local variables with member/argument names"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   649
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   650
# localised string for Script voidparameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   651
stringPool[ "voidparameter!title" ]       = "Void parameter explicitly declared"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   652
stringPool[ "voidparameter!description" ] = "Declaring a void parameter is unnecessary. A function declared as DoSomething(void) may as well be declared as DoSomething(). Void casts are also unnecessary."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   653
stringPool[ "voidparameter!ideTitle" ]    = "void parameter explicitly declared"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   654
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   655
# localised string for Script worryingcomments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   656
stringPool[ "worryingcomments!title" ]       = "Worrying comments"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   657
stringPool[ "worryingcomments!description" ] = "Typically, exclamation and question marks in comments indicate that something odd is in the code or that it is unfinished or not understood fully."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   658
stringPool[ "worryingcomments!ideTitle" ]    = "worrying comments"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   659
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   660
#!LOCALISEHERE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   661
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   662
def Usage(code, msg=""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   663
	print msg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   664
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   665
	print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   666
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   667
	print "Usage: CodeScanner [options] <source dir> [<output dir>]"	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   668
	print "   or: CodeScanner [options] <source file> [<output dir>]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   669
	print 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   670
	print "options:"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   671
	print "    -h - display command help"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   672
	print "    -v - display verbose messages"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   673
	print "    -c <config file> - use specified configuration file"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   674
	print "    -i <source dir/file> - specify additional directory/file to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   675
	print "    -l <log file> - create debug log with specified filename"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   676
	print "    -o html|xml|std - specify output format : HTML, XML or StdOut; default is HTML"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   677
	print "    -x url to lxr site"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   678
	print "    -r lxr version"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   679
	print "    -t on/off - create a time-stamped directory for results, default is on"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   680
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   681
	print "<source dir> is the directory containing the source code to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   682
	print "<source file> is the single file containing the source code to scan"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   683
	print "<output dir> is the directory in which to produce the output"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   684
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   685
	print "Notes:"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   686
	print "<source dir> and <output dir> cannot be identical"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   687
	print "<output dir> cannot be the root of a drive"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   688
	print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   689
	print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   690
	print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   691
	if scanner.iLog <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   692
		scanner.iLog.Write("usage(): exiting with code " + str(code))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   693
		scanner.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   694
	sys.exit(code)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   695
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   696
def DefaultCompare(aLines, aCurrentline, aRematch, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   697
	if aRematch.search(aLines[aCurrentline]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   698
		return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   699
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   700
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   701
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   702
def DefaultFuncParamCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   703
	# distinguish local declaration from function parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   704
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   705
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   706
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   707
        isFuncParam = (line.find(")") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   708
        isLocal = (line.find(";") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   709
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   710
        while (not isFuncParam) and (not isLocal) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   711
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   712
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   713
            isFuncParam = (line.find(")") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   714
            isLocal = (line.find(";") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   715
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   716
        if isFuncParam:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   717
            return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   718
        elif isLocal:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   719
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   720
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   721
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   722
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   723
def ScanDirOrFile(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   724
	if os.path.isdir(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   725
		scanner.iComponentManager.SetRoot(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   726
		scanner.TraverseDirectory(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   727
	elif os.path.isfile(argument):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   728
		parentDir = os.path.dirname(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   729
		scanner.iComponentManager.SetRoot(parentDir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   730
		scanner.iComponentManager.BeginDirectory(parentDir)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   731
		numberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   732
		numberOfLinesScanned += scanner.ScanFile(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   733
		scanner.iComponentManager.EndDirectory(parentDir, numberOfLinesScanned)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   734
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   735
		print "Unable to open specified source file: " + argument
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   736
		sys.exit(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   737
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   738
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   739
class CScript:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   740
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   741
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   742
	# CScript - a test script
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   743
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   744
	def __init__(self, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   745
		self.iScriptName = aScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   746
		self.iCompare = DefaultCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   747
		self.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   748
		self.iReMatch = re.compile("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   749
		self.iTitle = stringPool[aScriptName + "!title"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   750
		self.iIdeTitle = stringPool[aScriptName + "!ideTitle"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   751
		self.iFileExts = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   752
		self.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   753
		self.iDescription = stringPool[aScriptName + "!description"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   754
		self.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   755
		self.iBaseClass = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   756
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   757
	def ScriptConfig(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   758
		if (scanner.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   759
			for scriptsNode in scanner.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   760
				for scriptNode in scriptsNode.getElementsByTagName(self.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   761
					return scriptNode
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   762
		return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   763
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   764
	def DefaultInheritanceCompare(self, lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   765
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   766
		if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   767
			inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   768
			# check for inheritance list spanning multiple lines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   769
			i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   770
			while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   771
				if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   772
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   773
				inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   774
				i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   775
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   776
			# construct inheritance class list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   777
			inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   778
			reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   779
			classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   780
			for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   781
				match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   782
				if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   783
					inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   784
					colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   785
					if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   786
						inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   787
					classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   788
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   789
			# search for inheritance class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   790
			for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   791
				if classname == self.iBaseClass:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   792
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   793
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   794
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   795
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   796
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   797
class CCustomScript(CScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   798
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   799
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   800
	# CScript - a test script based on a custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   801
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   802
	def __init__(self, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   803
		self.iScriptName = aScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   804
		self.iCompare = DefaultCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   805
		self.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   806
		self.iTitle = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   807
		self.iIdeTitle = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   808
		self.iFileExts = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   809
		self.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   810
		self.iDescription = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   811
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   812
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   813
class CCategorisedScripts:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   814
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   815
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   816
	# CCategorisedScripts - a collection of scripts sorted
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   817
	# by script category (panic, can panic, etc.)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   818
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   819
	def AddScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   820
		# do we have a category for this already?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   821
		category = aScript.iCategory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   822
		if (not self.iScripts.has_key(category)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   823
			# no, create a linear array here
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   824
			self.iScripts[category] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   825
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   826
		# append to the correct category
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   827
		self.iScripts[category].append(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   828
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   829
		# compile the reg-ex otherwise will get continuous hits
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   830
		aScript.iReMatch = re.compile(aScript.iReString, re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   831
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   832
	def AllScripts(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   833
		result = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   834
		for scripts in self.iScripts.values():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   835
			result += scripts
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   836
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   837
		return result
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   838
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   839
	def PrintListOfTestScripts(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   840
		for category in self.iScripts.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   841
			print(category + "\n----------------------------------")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   842
			for script in self.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   843
				print("\t" + script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   844
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   845
		print("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   846
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   847
	# iScripts is a 2D array, 1st level is a hash of categories
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   848
	#                         2nd level is linear array
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   849
	iScripts = {}        
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   850
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   851
class CLogger:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   852
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   853
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   854
	# CLogger
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   855
	# a simple log file interface
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   856
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   857
	def __init__(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   858
		if aFilename != None and len(aFilename) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   859
			self.iFile = file(aFilename, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   860
			self.iFile.write(KVersion + " started at " + datetime.datetime.now().ctime() + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   861
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   862
			self.iFile = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   863
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   864
	def Write(self, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   865
		if self.iFile <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   866
			self.iFile.write(str(datetime.datetime.now().time())+":"+aText+"\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   867
			self.iFile.flush()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   868
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   869
	def Close(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   870
		if self.iFile <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   871
			self.iFile.write(KVersion + " ended at " + datetime.datetime.now().ctime() + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   872
			self.iFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   873
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   874
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   875
class CRendererBase:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   876
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   877
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   878
	# CRendererBase - base class for renderers
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   879
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   880
	def RegisterSelf(self, aName, aDescription, aRendererManager):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   881
		self.iName = aName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   882
		self.iDescription = aDescription
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   883
		aRendererManager.AddRenderer(self)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   884
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   885
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   886
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   887
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   888
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   889
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   890
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   891
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   892
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   893
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   894
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   895
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   896
class CStdOutRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   897
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   898
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   899
	# CStdOutRenderer - renderer for Standard Console Output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   900
	# Output goes to standard output; when run in Carbide, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   901
	# this shows up in the output window. Correctly formatted 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   902
	# lines can then be selected, automatically selecting 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   903
	# the corresponding line of the associated source file. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   904
	# The format is:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   905
	#   <filename>(<line>) : <comment>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   906
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   907
	def __init__(self, aRendererManager):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   908
		self.RegisterSelf("stdout", "StdOut renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   909
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   910
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   911
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   912
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   913
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   914
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   915
		self.iErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   916
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   917
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   918
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   919
		self.iErrorCount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   920
		if (aScript.iSeverity == KSeverityLow):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   921
			msgType = "info"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   922
		elif (aScript.iSeverity == KSeverityMedium):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   923
			msgType = "warning"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   924
		elif (aScript.iSeverity == KSeverityHigh):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   925
			msgType = "error"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   926
		print(aLineContext.iFileName + "(" + str(aLineContext.iLineNumber) + ") : " + msgType + ": " + aScript.iScriptName + ": " + KSeverityConfigMap[aScript.iSeverity] + ": " + KCategoryConfigMap[aScript.iCategory] + ": " + aScript.iIdeTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   927
		if len(scanner.iRendererManager.iAnnotation)>0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   928
			print scanner.iRendererManager.iAnnotation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   929
			scanner.iRendererManager.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   930
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   931
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   932
		scanner.ReportAction("Total problems found in file: " + str(self.iErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   933
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   934
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   935
		scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   936
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   937
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   938
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   939
class CXmlComponentSummaryFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   940
	# #########################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   941
	# CXmlComponentSummaryFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   942
	# Encapsulates the script (problem) summary for XML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   943
	# For each script, there is a listing for occurrences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   944
	# of that script's problem and location of each occurrence.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   945
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   946
	def CreateSummary(self, aXmlRenderer):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   947
		try:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   948
			outputPath = os.path.normpath(os.path.join(aXmlRenderer.iOutputDirectory, "problemIndex.xml"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   949
			outputFile = file(outputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   950
		except IOError:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   951
			scanner.ReportError("IOError : Unable to create output file " + outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   952
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   953
			errors = aXmlRenderer.iErrors
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   954
			level = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   955
			indent = "   "
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   956
			outputFile.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   957
			outputFile.write(level * indent + "<problemIndex>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   958
			level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   959
			for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   960
				found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   961
				if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   962
					for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   963
						if errors.has_key(script.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   964
							found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   965
							break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   966
					if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   967
						outputFile.write(level * indent + "<category")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   968
						outputFile.write(" name=\"" + KCategoryConfigMap[category] + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   969
						level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   970
						for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   971
							if errors.has_key(script.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   972
								outputFile.write(level * indent + "<problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   973
								outputFile.write(" name=\"" + script.iScriptName + "\"")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   974
								outputFile.write(" severity=\"" + KSeverityConfigMap[script.iSeverity] + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   975
								level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   976
								for fileName, lines in errors[script.iScriptName].items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   977
									outputFile.write(level * indent + "<file")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   978
									outputFile.write(" path=\"" + fileName + "\">\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   979
									level += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   980
									for lineNo in lines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   981
										outputFile.write(level * indent + str(lineNo) + "\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   982
									level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   983
									outputFile.write(level * indent + "</file>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   984
								level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   985
								outputFile.write(level * indent + "</problem>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   986
						level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   987
						outputFile.write(level * indent + "</category>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   988
			level -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   989
			outputFile.write(level * indent + "</problemIndex>\n")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   990
			outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   991
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   992
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   993
class CXmlRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   994
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   995
	# ########################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   996
	# CXmlRenderer - a renderer for XML output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   997
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   998
	def __init__(self, aRendererManager, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   999
		self.RegisterSelf("xml", "XML renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1000
		self.iOutputDirectory = aOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1001
		if os.path.isdir(self.iOutputDirectory) != True :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1002
			os.makedirs(self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1003
		self.iErrors = {} 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1004
		print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1005
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1006
		print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1007
		print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1008
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1009
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1010
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1011
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1012
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1013
		self.iFilename = aFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1014
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1015
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1016
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1017
		scriptName = aScript.iScriptName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1018
		fileName = aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1019
		lineNumber = aLineContext.iLineNumber
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1020
		if (not self.iErrors.has_key(scriptName)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1021
			self.iErrors[scriptName] = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1022
		if (not self.iErrors[scriptName].has_key(fileName)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1023
			self.iErrors[scriptName][fileName] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1024
		self.iErrors[scriptName][fileName].append(lineNumber)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1025
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1026
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1027
		#tbd
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1028
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1029
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1030
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1031
		relativeComponentName = scanner.iComponentManager.RelativeComponentName(aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1032
		if len(relativeComponentName) < 1:	# root component - final component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1033
			scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1034
			componentSummaryFile = CXmlComponentSummaryFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1035
			componentSummaryFile.CreateSummary(self)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1036
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1037
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1038
class CHtmlOutputFileBase:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1039
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1040
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1041
	# CHtmlOutputFileBase - base class for HTML output files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1042
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1043
	def WriteHeader(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1044
		aOutputFile.write("<html><body>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1045
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1046
	def Write(self, aOutputFile, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1047
		aOutputFile.write(aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1048
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1049
	def WriteLink(self, aOutputFile, aHref, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1050
		aHref = self.CleanupLink(aHref)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1051
		aOutputFile.write("<a href=\"" + aHref + "\">" + aText + "</a>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1052
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1053
	def WriteElement(self, aOutputFile, aElementName, aElementValue):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1054
		aOutputFile.write("<"+aElementName+">"+aElementValue+"</"+aElementName+">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1055
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1056
	def WriteBreak(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1057
		aOutputFile.write("<br>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1058
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1059
	def WriteFooter(self, aOutputFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1060
		aOutputFile.write("<br><hr><center><h5>"+KCopyrightLine1Html+"</h5>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1061
		aOutputFile.write("<h5>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1062
		CHtmlOutputFileBase.WriteLink(self, aOutputFile, "http://"+KWww, KWww)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1063
		aOutputFile.write("</h5></center></body></html>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1064
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1065
	def CleanupLink(self, aHref):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1066
		# Mozilla Firefox does not handle link with the '#' character correctly, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1067
		# so we need to replace it with the equivalent URL encoding "%23"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1068
		aHref = aHref.replace("#", "%23")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1069
		# Mozilla Firefox sometimes does not handle link with '\' correctly,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1070
		# so we need to replace it with '/'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1071
		aHref = aHref.replace('\\', '/')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1072
		return aHref
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1073
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1074
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1075
class CHtmlOutputFile(CHtmlOutputFileBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1076
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1077
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1078
	# CHtmlOutputFile - simplified access to HTML output file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1079
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1080
	def __init__(self, aOutputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1081
		if not os.path.isdir(os.path.dirname(aOutputPath)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1082
			os.makedirs(os.path.dirname(aOutputPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1083
		self.iOutputFile = file(aOutputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1084
		self.WriteHeader(self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1085
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1086
	def Write(self, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1087
		CHtmlOutputFileBase.Write(self, self.iOutputFile, aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1088
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1089
	def WriteLink(self, aHref, aText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1090
		CHtmlOutputFileBase.WriteLink(self, self.iOutputFile, aHref, aText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1091
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1092
	def WriteElement(self, aElementName, aElementValue):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1093
		CHtmlOutputFileBase.WriteElement(self, self.iOutputFile, aElementName, aElementValue)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1094
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1095
	def WriteBreak(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1096
		CHtmlOutputFileBase.WriteBreak(self, self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1097
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1098
	def Close(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1099
		self.WriteFooter(self.iOutputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1100
		self.iOutputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1101
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1102
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1103
class CHtmlComponentSummaryFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1104
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1105
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1106
	# CHtmlComponentSummaryFiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1107
	# Encapsulates the component summary files for HTML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1108
	# For each component, there is a component report file listing the number 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1109
	# of occurrences of each problem type. There is also a single index or 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1110
	# summary file with links to each of the component report files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1111
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1112
	def CreateSummaries(self, aHtmlRenderer, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1113
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1114
		outputPath = os.path.normpath(os.path.join(aOutputDirectory, "componentIndex.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1115
		componentSummaryFile = CHtmlOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1116
		componentSummaryFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1117
		componentSummaryFile.WriteElement("h2", "Component Summary")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1118
		componentSummaryFile.Write("Source: "+scanner.iSource)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1119
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1120
		componentSummaryFile.Write("Scan started at:   " + scanner.iStartTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1121
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1122
		componentSummaryFile.Write("Scan completed at: " + scanner.iEndTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1123
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1124
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1125
		componentSummaryFile.WriteLink("problemIndex.html", "View problems by type")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1126
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1127
		componentSummaryFile.Write("<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1128
		componentSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1129
		componentSummaryFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1130
		componentSummaryFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1131
		componentSummaryFile.WriteElement("th width=\"75%\"", "Component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1132
		componentSummaryFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1133
		componentSummaryFile.WriteElement("th", "Lines of Code")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1134
		componentSummaryFile.WriteElement("th", "Possible Defects/KLOC")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1135
		componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1136
		for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1137
			componentName = scanner.iComponentManager.ComponentName(component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1138
			outputPath = os.path.normpath(os.path.join(aOutputDirectory, "byComponent"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1139
			outputPath = os.path.normpath(os.path.join(outputPath, componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1140
			outputPath = os.path.normpath(os.path.join(outputPath, "componentSummary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1141
			errorCount = self.WriteComponentReport(aHtmlRenderer, outputPath, component.iFullPath, componentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1142
			if (errorCount > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1143
				totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1144
				numberOfLinesScanned = component.iNumberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1145
				if (numberOfLinesScanned > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1146
					defectsPerKLOC = int((1000.0 / numberOfLinesScanned) * errorCount)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1147
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1148
					defectsPerKLOC = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1149
				componentSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1150
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1151
				relOutputPath = os.path.normpath(os.path.join("byComponent", componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1152
				relOutputPath = os.path.normpath(os.path.join(relOutputPath, "componentSummary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1153
				componentSummaryFile.WriteLink(relOutputPath, component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1154
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1155
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1156
				componentSummaryFile.WriteElement("center",str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1157
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1158
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1159
				componentSummaryFile.WriteElement("center",str(numberOfLinesScanned))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1160
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1161
				componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1162
				componentSummaryFile.WriteElement("center",str(defectsPerKLOC))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1163
				componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1164
				componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1165
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1166
		componentSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1167
		componentSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1168
		componentSummaryFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1169
		componentSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1170
		componentSummaryFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1171
		componentSummaryFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1172
		componentSummaryFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1173
		componentSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1174
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1175
		componentSummaryFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1176
		componentSummaryFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1177
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1178
	def WriteComponentReport(self, aHtmlRenderer, aOutputPath, aComponentFullPath, aComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1179
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1180
		componentReportFile = CHtmlOutputFile(aOutputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1181
		componentReportFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1182
		componentReportFile.WriteElement("h2", "Component Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1183
		componentReportFile.WriteElement("h3", "Component: "+aComponentFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1184
		componentReportFile.Write("<font face=verdana color=black>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1185
		found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1186
		for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1187
			if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1188
				for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1189
					errorCount = scanner.iComponentManager.ScriptComponentErrorCount(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1190
					if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1191
						found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1192
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1193
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1194
		if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1195
			componentReportFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1196
			componentReportFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1197
			componentReportFile.WriteElement("th width=\"75%\"", "Problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1198
			componentReportFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1199
			componentReportFile.WriteElement("th", "Severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1200
			componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1201
			for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1202
				if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1203
					for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1204
						errorCount = scanner.iComponentManager.ScriptComponentErrorCount(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1205
						if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1206
							componentReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1207
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1208
							#scriptComponentPath = aHtmlRenderer.ScriptComponentPath(aComponentFullPath, script.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1209
							#componentReportFile.WriteLink(scriptComponentPath, script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1210
							componentReportFile.WriteLink(script.iScriptName+".html", script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1211
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1212
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1213
							componentReportFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1214
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1215
							componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1216
							componentReportFile.WriteElement("center", KSeverityHTMLMap[script.iSeverity])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1217
							componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1218
							componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1219
							totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1220
			componentReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1221
			componentReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1222
			componentReportFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1223
			componentReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1224
			componentReportFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1225
			componentReportFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1226
			componentReportFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1227
			componentReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1228
			componentReportFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1229
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1230
			componentReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1231
			componentReportFile.WriteElement("i", "There are no items to report for this component.")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1232
			componentReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1233
		componentReportFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1234
		return totalErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1235
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1236
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1237
class CHtmlScriptSummaryFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1238
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1239
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1240
	# CHtmlScriptSummaryFiles
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1241
	# Encapsulates the script (problem) summary files for HTML output.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1242
	# For each script, there is a file listing the number of occurrences
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1243
	# of that script's problem for each component. There is also a single
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1244
	# index or summary file with links to each of the problem report file.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1245
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1246
	def CreateSummaries(self, aHtmlRenderer, aOutputDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1247
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1248
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1249
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1250
		outputPath = os.path.normpath(os.path.join(aOutputDirectory, "problemIndex.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1251
		scriptSummaryFile = CHtmlOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1252
		scriptSummaryFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1253
		scriptSummaryFile.WriteElement("h2", "Problem Summary")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1254
		scriptSummaryFile.Write("Source: "+scanner.iSource)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1255
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1256
		scriptSummaryFile.Write("Scan started at:   " + scanner.iStartTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1257
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1258
		scriptSummaryFile.Write("Scan completed at: " + scanner.iEndTime)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1259
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1260
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1261
		scriptSummaryFile.WriteLink("componentIndex.html", "View problems by component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1262
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1263
		scriptSummaryFile.Write("<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1264
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1265
		for category in KCategoryHtmlDisplayOrder:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1266
			if scanner.iCategoriedScripts.iScripts.has_key(category):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1267
				scriptSummaryFile.WriteElement("h3", "Category: "+category)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1268
				scriptSummaryFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1269
				scriptSummaryFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1270
				scriptSummaryFile.WriteElement("th width=\"75%\"", "Problem")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1271
				scriptSummaryFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1272
				scriptSummaryFile.WriteElement("th", "Severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1273
				scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1274
				categoryErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1275
				for script in scanner.iCategoriedScripts.iScripts[category]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1276
					outputPath = os.path.normpath(os.path.join(aOutputDirectory, "byProblem"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1277
					outputPath = os.path.normpath(os.path.join(outputPath, script.iScriptName+"Summary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1278
					errorCount = self.WriteScriptReport(aHtmlRenderer, outputPath, script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1279
					categoryErrorCount = categoryErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1280
					scriptSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1281
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1282
					relOutputPath = os.path.normpath(os.path.join("byProblem", script.iScriptName+"Summary.html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1283
					scriptSummaryFile.WriteLink(relOutputPath, script.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1284
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1285
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1286
					scriptSummaryFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1287
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1288
					scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1289
					scriptSummaryFile.WriteElement("center", KSeverityHTMLMap[script.iSeverity])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1290
					scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1291
					scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1292
				totalErrorCount = totalErrorCount + categoryErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1293
				scriptSummaryFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1294
				scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1295
				scriptSummaryFile.WriteElement("b", "Category Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1296
				scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1297
				scriptSummaryFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1298
				scriptSummaryFile.WriteElement("center", "<b>"+str(categoryErrorCount)+"</b>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1299
				scriptSummaryFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1300
				scriptSummaryFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1301
				scriptSummaryFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1302
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1303
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1304
		scriptSummaryFile.WriteElement("b", "Total: " + str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1305
		scriptSummaryFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1306
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1307
		scriptSummaryFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1308
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1309
	def WriteScriptReport(self, aHtmlRenderer, aOutputPath, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1310
		totalErrorCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1311
		scriptReportFile = CHtmlOutputFile(aOutputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1312
		scriptReportFile.Write("<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1313
		scriptReportFile.WriteElement("h2", "Problem Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1314
		scriptReportFile.WriteElement("h3", "Problem: " + aScript.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1315
		scriptReportFile.Write(aScript.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1316
		scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1317
		scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1318
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1319
		found = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1320
		for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1321
			errorCount = scanner.iComponentManager.ScriptComponentErrorCount(component.iFullPath, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1322
			if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1323
				found = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1324
				break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1325
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1326
		if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1327
			scriptReportFile.Write("<table border=\"1\" width=\"100%\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1328
			scriptReportFile.Write("<tr bgcolor=\"#0099ff\">")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1329
			scriptReportFile.WriteElement("th width=\"80%\"", "Component")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1330
			scriptReportFile.WriteElement("th", "Items Found")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1331
			scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1332
			for component in scanner.iComponentManager.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1333
				errorCount = scanner.iComponentManager.ScriptComponentErrorCount(component.iFullPath, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1334
				if errorCount > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1335
					scriptReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1336
					scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1337
					scriptComponentPath = aHtmlRenderer.ScriptComponentPath(component.iFullPath, aScript.iScriptName, "..")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1338
					scriptReportFile.WriteLink(scriptComponentPath, component.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1339
					scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1340
					scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1341
					scriptReportFile.WriteElement("center", str(errorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1342
					scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1343
					scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1344
					totalErrorCount = totalErrorCount + errorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1345
			scriptReportFile.Write("<tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1346
			scriptReportFile.Write("<td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1347
			scriptReportFile.WriteElement("b", "Total")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1348
			scriptReportFile.Write("</td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1349
			scriptReportFile.Write("<td><center>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1350
			scriptReportFile.WriteElement("b", str(totalErrorCount))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1351
			scriptReportFile.Write("</center></td>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1352
			scriptReportFile.Write("</tr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1353
			scriptReportFile.Write("</table>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1354
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1355
			scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1356
			scriptReportFile.WriteElement("i", "There are no items of this problem type to report.")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1357
			scriptReportFile.WriteBreak()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1358
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1359
		scriptReportFile.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1360
		return totalErrorCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1361
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1362
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1363
class CHtmlScriptComponentFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1364
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1365
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1366
	# CHtmlScriptComponentFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1367
	# Encapsulates access to the HTML output files with the greatest amount of detail.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1368
	# Each of these files is for a specific problem (script) and for a specific component.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1369
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1370
	# The file handle is closed between each call to avoid exhausting the system
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1371
	# limit for open file handles. Many of these files may be open at one time,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1372
	# and the number of open files is dependent on both the directory structure
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1373
	# being traversed and the number of types of problems found.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1374
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1375
	def __init__(self, aLxrUrl, aLxrVersion):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1376
		self.iLxrUrl = aLxrUrl
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1377
		self.iLxrVersion = aLxrVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1378
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1379
	def BeginOutputFile(self, aOutputPath, aScript, aComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1380
		if not os.path.isdir(os.path.dirname(aOutputPath)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1381
			os.makedirs(os.path.dirname(aOutputPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1382
		outputFile = file(aOutputPath, "w")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1383
		self.iScriptComponentFile = CHtmlOutputFileBase()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1384
		self.iScriptComponentFile.Write(outputFile, "<font face=verdana>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1385
		self.iScriptComponentFile.WriteHeader(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1386
		self.iScriptComponentFile.WriteElement(outputFile, "h2", "Detailed Problem Report")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1387
		self.iScriptComponentFile.WriteElement(outputFile, "h3", "Component: "+aComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1388
		self.iScriptComponentFile.WriteElement(outputFile, "h3", "Problem: "+aScript.iTitle)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1389
		self.iScriptComponentFile.Write(outputFile, aScript.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1390
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1391
		self.iScriptComponentFile.Write(outputFile, "<hr>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1392
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1393
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1394
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1395
	def ReportError(self, aOutputPath, aLineContext):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1396
		outputFile = file(aOutputPath, "a")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1397
		if self.iLxrUrl == None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1398
			# Mozilla Firefox cannot open links to local files, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1399
			# so it is necessary to convert local file path
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1400
			filePath = "file:///" + aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1401
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1402
			# generate link to LXR server instead of local file system
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1403
			filePath = self.iLxrUrl + aLineContext.iFileName[len(scanner.iComponentManager.iRootPath):]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1404
			if self.iLxrVersion <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1405
				filePath = filePath + "?v="+self.iLxrVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1406
			filePath = filePath + '#%03d'%aLineContext.iLineNumber
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1407
		self.iScriptComponentFile.WriteLink(outputFile, filePath, self.TrimFileName(aLineContext))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1408
		self.iScriptComponentFile.Write(outputFile, "(" + str(aLineContext.iLineNumber) + ") ")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1409
		self.iScriptComponentFile.Write(outputFile, aLineContext.iClassName+"::"+aLineContext.iMethodName+" ")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1410
		self.iScriptComponentFile.Write(outputFile, "<code><font color=red>"+self.CleanUpText(aLineContext.iLineText))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1411
		self.iScriptComponentFile.Write(outputFile, "</font></code>")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1412
		self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1413
		if len(scanner.iRendererManager.iAnnotation)>0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1414
			self.iScriptComponentFile.Write(outputFile, scanner.iRendererManager.iAnnotation)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1415
			self.iScriptComponentFile.WriteBreak(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1416
			scanner.iRendererManager.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1417
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1418
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1419
	def EndOutputFile(self, aOutputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1420
		outputFile = file(aOutputPath, "a")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1421
		self.iScriptComponentFile.WriteFooter(outputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1422
		outputFile.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1423
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1424
	def TrimFileName(self, aLineContext):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1425
		filename = aLineContext.iFileName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1426
		componentNameLen = len(aLineContext.iComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1427
		if len(filename) > componentNameLen:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1428
			if filename[0:componentNameLen] == aLineContext.iComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1429
				filename = filename[componentNameLen:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1430
				if filename[0] == os.path.sep:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1431
					filename = filename[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1432
		return filename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1433
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1434
	def CleanUpText(self, aLineText):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1435
		# check for sub-strings that look like HTML tags and preform clean up if needed
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1436
		reTag = re.compile(r"""(<.+>)""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1437
		foundTag = reTag.search(aLineText)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1438
		if foundTag:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1439
			aNewLineText = aLineText.replace("<", "&lt;")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1440
			aNewLineText = aNewLineText.replace(">", "&gt;")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1441
			return aNewLineText
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1442
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1443
			return aLineText		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1444
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1445
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1446
def ComponentCompare(a, b):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1447
	return cmp(os.path.normcase(a.iFullPath), os.path.normcase(b.iFullPath))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1448
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1449
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1450
class CHtmlRenderer(CRendererBase):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1451
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1452
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1453
	# CHtmlRenderer - a renderer for HTML output
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1454
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1455
	# I have nothing to offer but blood, toil, tears and sweat. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1456
	#  - Winston Churchill, 1940 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1457
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1458
	def __init__(self, aRendererManager, aOutputDirectory, aLxrUrl, aLxrVersion):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1459
		self.RegisterSelf("html", "HTML renderer", aRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1460
		self.iOutputDirectory = aOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1461
		if os.path.isdir(self.iOutputDirectory) != True :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1462
			os.makedirs(self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1463
		self.iScriptComponentFile = CHtmlScriptComponentFile(aLxrUrl, aLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1464
		self.iScriptComponentFilePaths = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1465
		print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1466
		print KVersion
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1467
		print KCopyrightLine1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1468
		print KCopyrightLine2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1469
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1470
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1471
		self.iFilename = aFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1472
		scanner.ReportAction("Scanning file " + aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1473
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1474
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1475
		outputPath = self.ScriptComponentPath(aLineContext.iComponentName, aScript.iScriptName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1476
		if not os.path.isfile(outputPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1477
			self.iScriptComponentFilePaths[aLineContext.iComponentName].append(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1478
			self.iScriptComponentFile.BeginOutputFile(outputPath, aScript, aLineContext.iComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1479
		self.iScriptComponentFile.ReportError(outputPath, aLineContext)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1480
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1481
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1482
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1483
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1484
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1485
		self.iScriptComponentFilePaths[aComponent.iFullPath] = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1486
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1487
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1488
		if self.iScriptComponentFilePaths.has_key(aComponent.iFullPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1489
			for outputPath in self.iScriptComponentFilePaths[aComponent.iFullPath]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1490
				self.iScriptComponentFile.EndOutputFile(outputPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1491
			del self.iScriptComponentFilePaths[aComponent.iFullPath]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1492
		relativeComponentName = scanner.iComponentManager.RelativeComponentName(aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1493
		if len(relativeComponentName) < 1:	# root component - final component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1494
			scanner.iEndTime = datetime.datetime.now().ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1495
			scanner.iComponentManager.iCompletedComponents.sort(ComponentCompare)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1496
			scriptSummaryFiles = CHtmlScriptSummaryFiles()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1497
			scriptSummaryFiles.CreateSummaries(self, self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1498
			componentSummaryFiles = CHtmlComponentSummaryFiles()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1499
			componentSummaryFiles.CreateSummaries(self, self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1500
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1501
	def ScriptComponentPath(self, aComponentName, aScriptName, aRel=None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1502
		componentName = scanner.iComponentManager.ComponentName(aComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1503
		if aRel==None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1504
			aRel = self.iOutputDirectory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1505
		outputPath = os.path.normpath(os.path.join(aRel, "byComponent"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1506
		outputPath = os.path.normpath(os.path.join(outputPath, componentName))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1507
		outputPath = os.path.normpath(os.path.join(outputPath, aScriptName+".html"))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1508
		return outputPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1509
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1510
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1511
class CRendererManager:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1512
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1513
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1514
	# CRendererManager
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1515
	# this class handles all the renderers 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1516
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1517
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1518
		# declare associative list of renderers: iRendererList[name]=renderer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1519
		self.iRendererList = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1520
		self.iAnnotation = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1521
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1522
	def AddRenderer(self, aRenderer):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1523
		self.iRendererList[aRenderer.iName.lower()] = aRenderer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1525
	def PrintListOfRenderers(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1526
		print("Renderers:")        
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1527
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1528
			print("\t" + name + "\t" + renderer.iDescription)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1529
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1530
		print("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1531
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1532
	def BeginFile(self, aFilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1533
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1534
			renderer.BeginFile(aFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1535
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1536
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1537
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1538
			renderer.ReportError(aLineContext, aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1539
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1540
	def ReportAnnotation(self, aAnnotation):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1541
		self.iAnnotation = aAnnotation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1542
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1543
	def EndFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1544
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1545
			renderer.EndFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1546
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1547
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1548
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1549
			renderer.BeginComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1550
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1551
	def EndComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1552
		for name, renderer in self.iRendererList.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1553
			renderer.EndComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1554
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1555
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1556
class CComponent:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1557
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1558
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1559
	# CComponent - a single component, identified by the
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1560
	# directory path to its source code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1561
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1562
	def __init__(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1563
		self.iFullPath = aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1564
		self.iScriptErrorCounts = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1565
		self.iHasGroupDir = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1566
		self.iNumberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1567
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1568
	def appendComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1569
		for scriptName in aComponent.iScriptErrorCounts.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1570
			if self.iScriptErrorCounts.has_key(scriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1571
				self.iScriptErrorCounts[scriptName] += aComponent.iScriptErrorCounts[scriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1572
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1573
				self.iScriptErrorCounts[scriptName] = aComponent.iScriptErrorCounts[scriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1574
		self.iNumberOfLinesScanned += aComponent.iNumberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1575
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1576
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1577
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1578
class CComponentManager:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1579
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1580
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1581
	# CComponentManager - controls access to components
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1582
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1583
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1584
		self.iComponentStack = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1585
		self.iCompletedComponents = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1586
		self.iRootComponent = CComponent("")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1587
		self.iUseFullComponentPath = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1588
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1589
	def SetRoot(self, aRootPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1590
		# set the list of root directories - used to left-trim component names
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1591
		self.iRootPath = self.SanitizePath(aRootPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1592
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1593
	def BeginDirectory(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1594
		aPath = self.SanitizePath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1595
		if os.path.isdir(aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1596
			newComponent = CComponent(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1597
			contents = os.listdir(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1598
			for entry in contents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1599
				if (entry.upper() == "GROUP"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1600
					entryPath = os.path.normpath(os.path.join(aPath, entry))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1601
					if os.path.isdir(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1602
						newComponent.iHasGroupDir = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1603
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1604
			if len(self.iComponentStack) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1605
				topComponent = self.iComponentStack[len(self.iComponentStack)-1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1606
				if (newComponent.iHasGroupDir or (not topComponent.iHasGroupDir)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1607
					self.BeginComponent(newComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1608
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1609
					scanner.iLog.Write(aPath + " taken as part of " + topComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1610
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1611
				self.BeginComponent(newComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1612
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1613
			scanner.iLog.Write("ERROR: CComponentManager::BeginDirectory: bad path "+aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1614
		return aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1615
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1616
	def EndDirectory(self, aPath, numberOfLinesScanned):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1617
		aPath = self.SanitizePath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1618
		if len(self.iComponentStack) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1619
			topComponent = self.iComponentStack[len(self.iComponentStack)-1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1620
			topComponent.iNumberOfLinesScanned += numberOfLinesScanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1621
			if (topComponent.iFullPath == aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1622
				self.EndComponent()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1623
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1624
	def ReportError(self, aLineContext, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1625
		scanner.iRendererManager.ReportError(aLineContext, aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1626
		for component in self.iComponentStack:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1627
			if component.iFullPath == aLineContext.iComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1628
				if component.iScriptErrorCounts.has_key(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1629
					component.iScriptErrorCounts[aScript.iScriptName] = component.iScriptErrorCounts[aScript.iScriptName] + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1630
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1631
					component.iScriptErrorCounts[aScript.iScriptName] = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1632
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1633
	def ScriptComponentErrorCount(self, aComponentName, aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1634
		for component in self.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1635
			if component.iFullPath == aComponentName:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1636
				if component.iScriptErrorCounts.has_key(aScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1637
					return component.iScriptErrorCounts[aScriptName]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1638
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1639
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1640
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1641
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1642
	def BeginComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1643
		scanner.iRendererManager.BeginComponent(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1644
		scanner.ReportAction("Begin component: " + aComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1645
		self.iComponentStack.append(aComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1646
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1647
	def EndComponent(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1648
		previousComponent = self.iComponentStack.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1649
		matchingComponent = self.MatchingComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1650
		if (matchingComponent <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1651
			matchingComponent.appendComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1652
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1653
			self.iCompletedComponents.append(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1654
		scanner.ReportAction("End component: " + previousComponent.iFullPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1655
		scanner.iRendererManager.EndComponent(previousComponent)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1656
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1657
	def MatchingComponent(self, aComponent):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1658
		for component in self.iCompletedComponents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1659
			if (ComponentCompare(component, aComponent) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1660
				return component
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1661
		return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1662
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1663
	def CurrentComponentName(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1664
		if len(self.iComponentStack) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1665
			return None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1666
		return self.iComponentStack[len(self.iComponentStack)-1].iFullPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1667
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1668
	def SanitizePath(self, aPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1669
		# Translate an unspecified or relative pathname into an absolute pathname
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1670
		if len(aPath) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1671
			aPath = "."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1672
		aPath = os.path.normpath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1673
		# translate "." and ".." into absolute paths
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1674
		aPath = os.path.abspath(aPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1675
		return aPath
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1676
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1677
	def ComponentName(self, aFullComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1678
		if (self.iUseFullComponentPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1679
			(unused, componentName) = os.path.splitdrive(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1680
			if len(componentName) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1681
				if componentName[0] == os.path.sep and len(componentName) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1682
					componentName = componentName[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1683
			return componentName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1684
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1685
			return self.RelativeComponentName(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1686
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1687
	def RelativeComponentName(self, aFullComponentName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1688
		# Remove the root path from the specified component name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1689
		rootLen = len(self.iRootPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1690
		if aFullComponentName[0:rootLen] == self.iRootPath:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1691
			relativeComponentName = aFullComponentName[rootLen:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1692
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1693
			# this case is unexpected...but we'll try to make the best of it
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1694
			(unused, relativeComponentName) = os.path.splitdrive(aFullComponentName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1695
		# trim leading path separator, if present
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1696
		if len(relativeComponentName) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1697
			if relativeComponentName[0] == os.path.sep and len(relativeComponentName) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1698
				relativeComponentName = relativeComponentName[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1699
		return relativeComponentName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1700
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1701
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1702
class CLineContext:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1703
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1704
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1705
	# CLineContext
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1706
	# A description of the line of source code currently being scanned
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1707
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1708
	iComponentName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1709
	iFileName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1710
	iLineNumber = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1711
	iClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1712
	iMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1713
	iLineText = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1714
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1715
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1716
class CCodeScanner:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1717
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1718
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1719
	# CCodeScanner - main application class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1720
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1721
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1722
		self.iCategoriedScripts = CCategorisedScripts()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1723
		self.iRendererManager   = CRendererManager()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1724
		self.iComponentManager = CComponentManager()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1725
		self.iLineContext = CLineContext()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1726
		self.iDomConfig = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1727
		self.iVerbose = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1728
		self.iLog = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1729
		self.iSource = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1730
		self.iEncodedFileList = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1731
		self.iOutputDirectory = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1732
		self.iStartTimeObj = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1733
		self.iStartTime = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1734
		self.iEndTime = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1735
		self.iLxrUrl = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1736
		self.iLxrVersion = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1737
		self.iConfigFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1738
		self.iInputFilenames = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1739
		self.iLogFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1740
		self.iOutputFormat = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1741
		self.iTimeStampedOutput = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1742
		self.iReMethod = re.compile(r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1743
			((?P<class>\w+)::~?)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1744
			(?P<method>[A-Za-z0-9<>=!*\-+/]+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1745
			[\s\n]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1746
			\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1747
			[^;]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1748
			$
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1749
			""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1750
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1751
	def ReportError(self, aErrorMsg):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1752
		self.iLog.Write(aErrorMsg)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1753
		print aErrorMsg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1754
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1755
	def ReportAction(self, aAction):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1756
		self.iLog.Write(aAction)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1757
		if self.iVerbose:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1758
			print aAction
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1759
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1760
	def ReportInfo(self, aInfoMsg):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1761
		self.iLog.Write(aInfoMsg)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1762
		print aInfoMsg
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1763
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1764
	def CleanOutputDirectory(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1765
		self.iLog.Write("Deleting existing contents of output directory " + self.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1766
		for root, dirs, files in os.walk(self.iOutputDirectory, topdown = False):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1767
			for name in files:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1768
				os.remove(os.path.join(root, name))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1769
			for name in dirs:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1770
				os.rmdir(os.path.join(root, name))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1771
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1772
	def CheckSourceIncluded(self, aSourceFileName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1773
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1774
			for sourceNode in self.iDomConfig.getElementsByTagName("sources"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1775
				for excludeSourceNode in sourceNode.getElementsByTagName("exclude"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1776
					reExcludeSourceStr = excludeSourceNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1777
					reExcludeSource = re.compile(reExcludeSourceStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1778
					if reExcludeSource.search(aSourceFileName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1779
						self.ReportInfo("Note: excluding " + aSourceFileName + " : " + reExcludeSourceStr)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1780
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1781
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1782
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1783
	def CheckScriptEnabled(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1784
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1785
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1786
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1787
					enabledAttr = scriptNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1788
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1789
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1790
			for severitiesNode in self.iDomConfig.getElementsByTagName("severities"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1791
				for severityNode in severitiesNode.getElementsByTagName(KSeverityConfigMap[aScript.iSeverity]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1792
					enabledAttr = severityNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1793
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1794
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1795
			for categoriesNode in self.iDomConfig.getElementsByTagName("categories"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1796
				for categoryNode in categoriesNode.getElementsByTagName(KCategoryConfigMap[aScript.iCategory]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1797
					enabledAttr = categoryNode.getAttribute("enable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1798
					if (enabledAttr.lower() == "false"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1799
						return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1800
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1801
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1802
	def UpdateScriptCategory(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1803
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1804
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1805
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1806
					if scriptNode.hasAttribute("category"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1807
						newCategory = scriptNode.getAttribute("category").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1808
						if (newCategory <> KCategoryConfigMap[aScript.iCategory]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1809
							for name, value in KCategoryConfigMap.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1810
								if (newCategory == value):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1811
									return name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1812
		# no update needed, return original category
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1813
		return aScript.iCategory
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1814
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1815
	def UpdateScriptSeverity(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1816
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1817
			for scriptsNode in self.iDomConfig.getElementsByTagName("scripts"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1818
				for scriptNode in scriptsNode.getElementsByTagName(aScript.iScriptName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1819
					if scriptNode.hasAttribute("severity"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1820
						newSeverity = scriptNode.getAttribute("severity").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1821
						if (newSeverity <> KSeverityConfigMap[aScript.iSeverity]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1822
							for name, value in KSeverityConfigMap.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1823
								if (newSeverity == value):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1824
									return name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1825
		# no update needed, return original severity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1826
		return aScript.iSeverity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1827
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1828
	def ScanFile(self, aSourceFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1829
		self.iLineContext.iFileName = aSourceFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1830
		self.iLineContext.iLineNumber = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1831
		self.iLineContext.iClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1832
		self.iLineContext.iMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1833
		self.iLineContext.iComponentName = self.iComponentManager.CurrentComponentName()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1834
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1835
		self.iRendererManager.BeginFile(aSourceFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1836
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1837
		# note source file extension - used for filtering later on
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1838
		(unused, sourceFileExt) = os.path.splitext(aSourceFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1839
		if len(sourceFileExt) > 0 and sourceFileExt[0] == '.':
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1840
			sourceFileExt = sourceFileExt[1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1841
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1842
		# open, read, and preparse source file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1843
		inputFileHandle = file(aSourceFile, "r")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1844
		inputFileLines = inputFileHandle.readlines()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1845
		inputFileHandle.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1846
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1847
		(noQuoteFileLines, noCommentFileLines, noCommentOrQuoteFileLines, csCommands) = self.PreParseSourceFile(inputFileLines)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1848
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1849
		# bundle all the filtered versions of the file contents into
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1850
		# a hash to re-factor code
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1851
		fileContentsToTest = { KIgnoreNothing           : inputFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1852
							   KIgnoreComments          : noCommentFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1853
							   KIgnoreQuotes            : noQuoteFileLines,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1854
							   KIgnoreCommentsAndQuotes : noCommentOrQuoteFileLines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1855
							   }
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1856
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1857
		# now apply test scripts to source file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1858
		iBraceCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1859
		iBraceCountList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1860
		newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1861
		newCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1862
		self.iCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1863
		self.iCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1864
		self.iCurrentMethodStart = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1865
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1866
		totalNumberOfLines = len(inputFileLines)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1867
		reConstant = re.compile(r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1868
			^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1869
			(static\s+)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1870
			const
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1871
			\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1872
			\w+		# type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1873
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1874
			[\*&]?	# reference or pointer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1875
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1876
			\w+		# name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1877
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1878
			(=|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1879
			""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1880
		reInheritance = re.compile("[\s:]*(public|protected|private)\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1881
		rePreprocessorIf = re.compile("^\s*\#(el)*if(.*)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1882
		rePreprocessorElse = re.compile("^\s*\#else")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1883
		rePreprocessorEnd = re.compile("^\s*\#endif")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1884
		reTypedef = re.compile("^\s*typedef")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1885
		i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1886
		while (i < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1887
			# for extra open braces in #if blocks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1888
			if (rePreprocessorIf.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1889
				iBraceCountList.append(iBraceCount)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1890
			if (rePreprocessorElse.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1891
				if (len(iBraceCountList) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1892
					iBraceCount = iBraceCountList.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1893
			if (rePreprocessorEnd.search(noCommentOrQuoteFileLines[i])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1894
				if (len(iBraceCountList) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1895
					iBraceCountList.pop()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1896
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1897
			if (newCurrentMethodName == ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1898
				methodString = noCommentOrQuoteFileLines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1899
				currentLine = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1900
				m = self.iReMethod.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1901
				if not m and (i + 1 < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1902
					currentLine = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1903
					methodString += noCommentOrQuoteFileLines[currentLine]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1904
					m = self.iReMethod.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1905
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1906
				if m and (iBraceCount == 0) and (methodString.find("#") == -1) and (methodString.find("_LIT") == -1):	# must be at root level and not a preprocessor directive or a _LIT
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1907
					if not reTypedef.match(methodString) and not reConstant.match(methodString):  # must not be typedef or constant declaration 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1908
						# check for cases where macros are used to declare a class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1909
						# by searching for the inheritance part
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1910
						# eg. NONSHARABLE_CLASS(CMyClass) : public CBase
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1911
						isClass = reInheritance.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1912
						if not isClass and (currentLine + 1 < totalNumberOfLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1913
							methodString += noCommentOrQuoteFileLines[currentLine + 1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1914
							isClass = reInheritance.search(methodString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1915
						if not isClass:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1916
							newCurrentMethodName = m.group('method')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1917
							if m.group('class'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1918
								newCurrentClassName = m.group('class')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1919
							else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1920
								newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1921
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1922
			iBraceCount += noCommentOrQuoteFileLines[i].count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1923
			if (iBraceCount > 0) and (newCurrentMethodName <> ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1924
				self.iCurrentClassName = newCurrentClassName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1925
				self.iCurrentMethodName = newCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1926
				self.iCurrentMethodStart = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1927
				newCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1928
				newCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1929
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1930
			self.iLineContext.iLineNumber = i+1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1931
			self.iLineContext.iClassName = self.iCurrentClassName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1932
			self.iLineContext.iMethodName = self.iCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1933
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1934
			# perform all test scripts onto source file									   
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1935
			for script in self.iCategoriedScripts.AllScripts():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1936
				if (script.iFileExts.count(sourceFileExt) > 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1937
				    and fileContentsToTest[script.iIgnore][i] != "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1938
					and	script.iCompare(fileContentsToTest[script.iIgnore], i, script.iReMatch, aSourceFile)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1939
					# skip any script that has been disabled via CodeScanner command(s) in sources
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1940
					if script.iScriptName.lower() in csCommands[i].lower():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1941
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1942
					self.iLineContext.iLineText = fileContentsToTest[script.iIgnore][i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1943
					self.iComponentManager.ReportError(self.iLineContext, script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1944
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1945
			iBraceCount -= noCommentOrQuoteFileLines[i].count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1946
			if (iBraceCount < 0):	# for extra close braces in #if blocks
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1947
				iBraceCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1948
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1949
			if (iBraceCount == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1950
				self.iCurrentClassName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1951
				self.iCurrentMethodName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1952
				self.iCurrentMethodStart = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1953
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1954
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1955
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1956
		self.iRendererManager.EndFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1957
		return totalNumberOfLines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1958
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1959
	def TraverseDirectory(self, aDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1960
		# skip folders marked to be excluded in configuration file
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1961
		aPath = self.iComponentManager.SanitizePath(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1962
		if (not self.CheckSourceIncluded(aPath)) or (not self.CheckSourceIncluded(aPath + os.path.sep)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1963
			return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1964
		aDirectory = self.iComponentManager.BeginDirectory(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1965
		contents = os.listdir(aDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1966
		numberOfLinesScanned = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1967
		for entry in contents:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1968
			entryPath = os.path.normpath(os.path.join(aDirectory, entry))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1969
			if os.path.isdir(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1970
				self.TraverseDirectory(entryPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1971
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1972
				if self.CheckSourceIncluded(entryPath):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1973
					numberOfLinesScanned += self.ScanFile(entryPath)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1974
		self.iComponentManager.EndDirectory(aDirectory, numberOfLinesScanned)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1975
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1976
	def AddScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1977
		enabled = self.CheckScriptEnabled(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1978
		if enabled:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1979
			aScript.iCategory = self.UpdateScriptCategory(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1980
			aScript.iSeverity = self.UpdateScriptSeverity(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1981
			self.iCategoriedScripts.AddScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1982
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1983
			self.ReportInfo("Note: script '" + aScript.iScriptName + "' DISABLED")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1984
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1985
	def AddCustomScript(self, aScript):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1986
		self.ReportInfo("Note: custom rule '" + aScript.iScriptName + "' ADDED")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1987
		self.iCategoriedScripts.AddScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1988
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1989
	def PreParseSourceFile(self, aLines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1990
		# it provides 3 versions of input:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1991
		# 	1. without quotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1992
		# 	2. without comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1993
		# 	3. without quotes and without comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1994
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1995
		inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1996
		noQuoteLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1997
		noCommentLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1998
		noCommentOrQuoteLines = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  1999
		csCommands = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2000
		reCSCommand = re.compile("codescanner((::\w+)+)") # CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2001
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2002
		for line in aLines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2003
			noQuoteLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2004
			noCommentLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2005
			noCommentOrQuoteLine = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2006
			csCommand = "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2007
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2008
			i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2009
			startQuote = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2010
			b = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2011
			escCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2012
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2013
			while i < len(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2014
				# skip quotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2015
				if not inCommentBlock and ((line[i] == "\"") or (line[i] == "\'")):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2016
					startQuote = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2017
					i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2018
					while (i < len(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2019
						endIndex = line[i:].find(line[startQuote])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2020
						if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2021
							b = i + endIndex - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2022
							escCount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2023
							while (line[b] == "\\"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2024
								escCount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2025
								b -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2026
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2027
							i += endIndex + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2028
							if (escCount % 2 == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2029
								noQuoteLine += "\"\""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2030
								noCommentOrQuoteLine += "\"\""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2031
								noCommentLine += line[startQuote:i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2032
								break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2033
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2034
							#	print "Unterminated quote : " + line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2035
							break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2036
					continue	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2037
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2038
				# parse comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2039
				if not inCommentBlock:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2040
					if (line[i] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2041
						if (i < (len(line)-1)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2042
							if (line[i + 1] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2043
								noCommentLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2044
								noCommentOrQuoteLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2045
								noQuoteLine += line[i:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2046
								# look for CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2047
								m = reCSCommand.search(line[i:])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2048
								if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2049
									csCommand = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2050
								break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2051
							elif (line[i + 1] == "*"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2052
								inCommentBlock = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2053
								i += 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2054
								noQuoteLine += "/*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2055
								continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2056
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2057
					noCommentLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2058
					noCommentOrQuoteLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2059
					noQuoteLine += line[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2060
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2061
					# look for CodeScanner command(s) in comments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2062
					m = reCSCommand.search(line[i:])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2063
					if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2064
						csCommand = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2065
					endIndex = line[i:].find("*/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2066
					if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2067
						inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2068
						noQuoteLine += line[i:i + endIndex + 2]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2069
						i += endIndex + 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2070
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2071
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2072
						noCommentLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2073
						noCommentOrQuoteLine += "\n"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2074
						noQuoteLine = line[i:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2075
						break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2076
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2077
				i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2078
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2079
			noCommentLines.append(noCommentLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2080
			noCommentOrQuoteLines.append(noCommentOrQuoteLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2081
			noQuoteLines.append(noQuoteLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2082
			csCommands.append(csCommand)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2083
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2084
		return [noQuoteLines, noCommentLines, noCommentOrQuoteLines, csCommands]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2085
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2086
	def ReadConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2087
		if self.iConfigFilename <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2088
			if (os.path.isfile(self.iConfigFilename)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2089
				self.iDomConfig = xml.dom.minidom.parse(self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2090
				if self.iVerbose:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2091
					print "Note: using configuration file " + self.iConfigFilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2092
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2093
				self.ReportInfo("Unable to open specified configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2094
				self.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2095
				sys.exit(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2096
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2097
	def ReadArgumentsFromConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2098
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2099
			for argumentsNode in self.iDomConfig.getElementsByTagName("arguments"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2100
				# read input file names
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2101
				for inputFileNode in argumentsNode.getElementsByTagName("input"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2102
					self.iInputFilenames += inputFileNode.firstChild.nodeValue + "::"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2103
				# read output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2104
				for outputFormatNode in argumentsNode.getElementsByTagName("outputformat"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2105
					self.iOutputFormat += outputFormatNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2106
				# read lxr URL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2107
				for lxrURLNode in argumentsNode.getElementsByTagName("lxr"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2108
					self.iLxrUrl = lxrURLNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2109
				# read lxr version
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2110
				for lxrVersionNode in argumentsNode.getElementsByTagName("lxrversion"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2111
					self.iLxrVersion = lxrVersionNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2112
				# read time stamped output option
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2113
				for timeStampedOutputNode in argumentsNode.getElementsByTagName("timestampedoutput"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2114
					self.iTimeStampedOutput = timeStampedOutputNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2115
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2116
	def ReadCustomRulesFromConfigFile(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2117
		if (self.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2118
			for customRulesNode in self.iDomConfig.getElementsByTagName("customrules"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2119
				for customRuleNode in customRulesNode.getElementsByTagName("customrule"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2120
					ignoreComments = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2121
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2122
					# read the name of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2123
					ruleName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2124
					for ruleNameNode in customRuleNode.getElementsByTagName("name"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2125
						if (ruleNameNode == None) or (ruleNameNode.firstChild == None) or (ruleNameNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2126
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2127
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2128
							ruleName = ruleNameNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2129
					if len(ruleName) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2130
						self.ReportError("Missing custom rule name in configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2131
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2132
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2133
					# read the keywords associated with the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2134
					keywordList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2135
					badKeywordElement = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2136
					for keywordNode in customRuleNode.getElementsByTagName("keyword"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2137
						# read keyword content
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2138
						if (keywordNode == None) or (keywordNode.firstChild == None) or (keywordNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2139
							badKeywordElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2140
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2141
						newKeyword = CCustomRuleKeyword()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2142
						newKeyword.iContent = keywordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2143
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2144
						# read keyword type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2145
						if not keywordNode.hasAttribute("type"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2146
							badKeywordElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2147
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2148
						type = keywordNode.getAttribute("type").lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2149
						if type in KCustomRuleKeywordMap.values():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2150
							if type == KKeywordComment:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2151
								ignoreComments = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2152
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2153
							type = KCustomRuleKeywordMap[KKeywordUnknown]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2154
						newKeyword.iType = type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2155
						keywordList.append(newKeyword)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2156
					if (len(keywordList) == 0) or (badKeywordElement == True):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2157
						self.ReportBadCustomRuleElement(ruleName, "keyword")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2158
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2159
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2160
					# read the file types associated with the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2161
					fileTypeList = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2162
					badFileTypeElement = False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2163
					for fileTypeNode in customRuleNode.getElementsByTagName("filetype"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2164
						if (fileTypeNode == None) or (fileTypeNode.firstChild == None) or (fileTypeNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2165
							badFileTypeElement = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2166
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2167
						newFileType = fileTypeNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2168
						fileTypeList.append(newFileType.lower())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2169
					if (len(fileTypeList) == 0) or (badFileTypeElement == True):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2170
						self.ReportBadCustomRuleElement(ruleName, "file type")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2171
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2172
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2173
					# read the severity level of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2174
					severity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2175
					for severityNode in customRuleNode.getElementsByTagName("severity"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2176
						if (severityNode == None) or (severityNode.firstChild == None) or (severityNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2177
							self.ReportBadCustomRuleElement(ruleName, "severity")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2178
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2179
						severityValue = severityNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2180
						for severityKey in KSeverityConfigMap.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2181
							if severityValue == KSeverityConfigMap[severityKey]:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2182
								severity = severityKey
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2183
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2184
					# read the tile of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2185
					title = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2186
					for titleNode in customRuleNode.getElementsByTagName("title"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2187
						if (titleNode == None) or (titleNode.firstChild == None) or (titleNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2188
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2189
						title = titleNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2190
					if len(title) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2191
						self.ReportBadCustomRuleElement(ruleName, "title")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2192
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2193
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2194
					# read the description of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2195
					description = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2196
					for descriptionNode in customRuleNode.getElementsByTagName("description"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2197
						if (descriptionNode == None) or (descriptionNode.firstChild == None) or (descriptionNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2198
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2199
						description = descriptionNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2200
					if len(description) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2201
						self.ReportBadCustomRuleElement(ruleName, "description")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2202
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2203
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2204
					# read the optional link of the rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2205
					link = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2206
					for linkNode in customRuleNode.getElementsByTagName("link"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2207
						if (linkNode == None) or (linkNode.firstChild == None) or (linkNode.firstChild.nodeValue == None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2208
							self.ReportBadCustomRuleElement(ruleName, "link")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2209
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2210
						link = linkNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2211
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2212
					# create the RE string for the custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2213
					keywordMap = self.ConstructCustomRuleKeywordMap(keywordList)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2214
					reString = self.ConstructCustomRuleREString(keywordMap)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2215
					if len(reString) == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2216
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2217
					
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2218
					# create a script based on the custom rule
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2219
					aScript = CCustomScript(ruleName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2220
					aScript.iReString = reString
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2221
					aScript.iReMatch = re.compile(reString)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2222
					aScript.iFileExts = fileTypeList
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2223
					aScript.iCategory = KCategoryOther
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2224
					if keywordMap.has_key(KKeywordBaseClass):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2225
						aScript.iBaseClass = keywordMap[KKeywordBaseClass]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2226
						aScript.iCompare = aScript.DefaultInheritanceCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2227
					if ignoreComments:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2228
						aScript.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2229
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2230
						aScript.iIgnore = KIgnoreQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2231
					aScript.iSeverity = severity
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2232
					aScript.iTitle = title
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2233
					aScript.iIdeTitle = title
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2234
					aScript.iDescription = description
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2235
					if link <> None:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2236
						aScript.iLink = link
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2237
					self.AddCustomScript(aScript)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2238
		return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2239
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2240
	def ReportBadCustomRuleElement(self, name, element):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2241
		self.ReportError("<customrule> element '" + name + "' has bad <" + element + "> child element in configuration file: " + self.iConfigFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2242
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2243
	def ConstructCustomRuleKeywordMap(self, keywordList):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2244
		reString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2245
		keywordMap = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2246
		for keyword in keywordList:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2247
			if keywordMap.has_key(keyword.iType):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2248
				keywordMap[keyword.iType] = keywordMap[keyword.iType] + "|" + keyword.iContent
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2249
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2250
				keywordMap[keyword.iType] = keyword.iContent
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2251
		return keywordMap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2252
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2253
	def ConstructCustomRuleREString(self, keywordMap):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2254
		# generate RE string based on the keyword types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2255
		if keywordMap.has_key(KKeywordBaseClass):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2256
			reString = "^\s*class\s+(\w+::)?(\w+)\s*:(.*)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2257
		elif keywordMap.has_key(KKeywordCall):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2258
			reString = "(" + keywordMap[KKeywordCall] + ")\s*\(.*\)\s*;"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2259
		elif keywordMap.has_key(KKeywordClassName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2260
			if keywordMap.has_key(KKeywordMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2261
				reString = "([A-Za-z0-9]+\s+" + keywordMap[KKeywordClassName] + "::)?(" + keywordMap[KKeywordMethod] + ")\s*\(.*\)\s*[^;]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2262
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2263
				reString = "^\s*class\s+(\w+::)?(" + keywordMap[KKeywordClassName] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2264
		elif keywordMap.has_key(KKeywordComment):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2265
			reString = "/(/|\*).*(" + keywordMap[KKeywordComment] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2266
		elif keywordMap.has_key(KKeywordGeneric):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2267
			reString = "(" + keywordMap[KKeywordGeneric] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2268
		elif keywordMap.has_key(KKeywordLocal):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2269
			reString = "^\s*[A-Z]\w*\s*[\*&\s]\s*(" + keywordMap[KKeywordLocal] + ")\w*\s*[;\(=]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2270
		elif keywordMap.has_key(KKeywordMacro):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2271
			reString = "^\s*\#define\s+(" + keywordMap[KKeywordMacro] + ")"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2272
		elif keywordMap.has_key(KKeywordMember):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2273
			reString = "^\s*[A-Z]\w*\s*[\*&\s]\s*(" + keywordMap[KKeywordMember] + ")\w*\s*[;\(=]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2274
		elif keywordMap.has_key(KKeywordMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2275
			reString = "[A-Za-z0-9]+\s+[C|T|R][A-Za-z0-9]+::(" + keywordMap[KKeywordMethod] + ")\s*\(.*\)\s*[^;]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2276
		elif keywordMap.has_key(KKeywordParameter):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2277
			reString = "({)*\s*(" + keywordMap[KKeywordParameter] + ")\s*=\s*(.*);"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2278
		return reString
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2279
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2280
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2281
class CCustomRuleKeyword:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2282
	# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2283
	# CCustomRuleKeyword - keyword associated with custom rules
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2284
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2285
	def __init__(self):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2286
		iContent = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2287
		iType = "unknown"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2288
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2289
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2290
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2291
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2292
class CEncodedFile:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2293
    def Extract(self, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2294
        outputFileHandle = open(os.path.join(aBaseDirectory, self.iFilename), 'wb')
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2295
        outputFileBinary = zlib.decompress(base64.decodestring(self.iFileBody))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2296
        outputFileHandle.write(outputFileBinary)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2297
        outputFileHandle.close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2298
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2299
	iFilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2300
	iFileBody = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2301
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2302
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2303
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2304
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2305
class CEncodedFileList:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2306
	def AddEncodedFile(self, aEncodedFile):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2307
		self.iEncodedFileList[aEncodedFile.iFilename.lower()] = aEncodedFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2308
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2309
	def ExtractEncodedFile(self, aFilename, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2310
		# look for the filename in our list of files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2311
		filename = aFilename.lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2312
		if (self.iEncodedFileList.has_key(filename)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2313
			self.iEncodedFileList[filename].Extract(aBaseDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2314
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2315
			scanner.iLog.Write("Missing "+filename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2316
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2317
	def ExtractAllEncodedFiles(self, aBaseDirectory):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2318
		# run through associative array and extract everything
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2319
		for filename in self.iEncodedFileList.keys():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2320
			self.ExtractEncodedFile(filename, aBaseDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2321
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2322
	# declare iEncodedFileList is an associative array
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2323
	iEncodedFileList = {}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2324
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2325
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2326
# #######################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2327
# main()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2328
scanner = CCodeScanner()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2329
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2330
# process command line arguments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2331
opts, args = getopt.getopt(sys.argv[1:], "hvc:i:l:o:x:r:t:", ["help", "verbose", "config=", "input=", "logfile=", "outputformat=", "lxr=", "lxrversion=", "timestampedoutput="])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2332
for o, a in opts:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2333
	if o in ("-h", "--help"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2334
		Usage(0)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2335
	if o in ("-v", "--verbose"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2336
		scanner.iVerbose = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2337
	if o in ("-c", "--config"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2338
		scanner.iConfigFilename = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2339
	if o in ("-i", "--input"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2340
		scanner.iInputFilenames += a + "::"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2341
	if o in ("-l", "--logfile"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2342
		scanner.iLogFilename = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2343
	if o in ("-o", "--outputformat"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2344
		scanner.iOutputFormat += a			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2345
	if o in ("-x", "--lxr"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2346
		scanner.iLxrUrl = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2347
	if o in ("-r", "--lxrversion"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2348
		scanner.iLxrVersion = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2349
	if o in ("-t", "--timestampedoutput"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2350
		scanner.iTimeStampedOutput = a
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2351
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2352
if len(args) < 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2353
	Usage(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2354
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2355
scanner.iLog = CLogger(scanner.iLogFilename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2356
scanner.iLog.Write("Command line: " + str(sys.argv[1:]))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2357
scanner.iLog.Write("Current working directory: " + os.getcwd())
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2358
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2359
scanner.ReadConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2360
scanner.ReadArgumentsFromConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2361
scanner.ReadCustomRulesFromConfigFile()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2362
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2363
scanner.iSource = args[0]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2364
scanner.iEncodedFileList = CEncodedFileList()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2365
scanner.iStartTimeObj = datetime.datetime.now()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2366
scanner.iStartTime = scanner.iStartTimeObj.ctime()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2367
scanner.iOutputDirectory = scanner.iStartTimeObj.strftime("%a-%b-%d-%H-%M-%S-%Y")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2368
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2369
# invoke the pysco module to improve performance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2370
psyco.full()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2371
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2372
# choose renderer based on command line arguments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2373
if len(args) > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2374
	if ("off" in scanner.iTimeStampedOutput.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2375
		scanner.iOutputDirectory = args[1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2376
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2377
		scanner.iOutputDirectory = os.path.normpath(os.path.join(args[1], scanner.iOutputDirectory))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2378
	scanner.CleanOutputDirectory()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2379
	if scanner.iOutputFormat <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2380
	#user specified output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2381
		if ("xml" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2382
			CXmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2383
		if ("html" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2384
			CHtmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory, scanner.iLxrUrl, scanner.iLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2385
		if ("std" in scanner.iOutputFormat.lower()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2386
			CStdOutRenderer(scanner.iRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2387
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2388
	#default output format
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2389
		CHtmlRenderer(scanner.iRendererManager, scanner.iOutputDirectory, scanner.iLxrUrl, scanner.iLxrVersion)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2390
else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2391
	CStdOutRenderer(scanner.iRendererManager)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2392
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2393
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2394
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2395
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2396
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2397
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2398
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2399
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2400
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2401
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2402
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2403
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2404
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2405
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2406
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2407
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2408
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2409
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2410
# accessArrayElementWithoutCheck.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2411
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2412
# Checks : Array element accessed by At() function without checking 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2413
# index is within array range.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2414
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2415
# Reason : Whenever an element in an array is accessed, the index 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2416
# should be checked to ensure that it is less than array.Count(). 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2417
# CodeScanner checks for explicit calls to a Count() function; so 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2418
# if the array index is checked in a different way, it gives 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2419
# false positives. Accessing an invalid index can cause a panic.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2420
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2421
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2422
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2423
script = CScript("accessArrayElementWithoutCheck")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2424
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2425
	(->|\.)		# pointer/instance of array
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2426
	\s*			# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2427
	At
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2428
	\s*			# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2429
	\(			# opening bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2430
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2431
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2432
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2433
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2434
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2435
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2436
accessArrayCountFn = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2437
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2438
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2439
	Count
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2440
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2441
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2442
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2443
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2444
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2445
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2446
accessArrayDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2447
	\w+			# array type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2448
	[0-9<>*& ]*	# optional array element
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2449
	\w+			# array name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2450
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2451
	\[
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2452
	.*			# array size
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2453
	\]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2454
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2455
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2456
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2457
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2458
def isTimerObject(lines, currentline, varname):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2459
	if (varname.lower().find("array") <> -1) or (varname.lower().find("list") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2460
		return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2461
	if (varname.lower().find("heartbeat") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2462
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2463
	if (varname.lower().find("periodic") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2464
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2465
	if (varname.lower().find("timer") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2466
		return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2467
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2468
	vartype = GetLocalVariableType(lines, currentline, varname)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2469
	if (len(vartype) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2470
		if (vartype.lower().find("array") <> -1) or (vartype.lower().find("list") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2471
			return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2472
		if (vartype.lower().find("heartbeat") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2473
			return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2474
		if (vartype.lower().find("periodic") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2475
			return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2476
		if (vartype.lower().find("timer") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2477
			return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2478
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2479
	return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2480
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2481
def arrayAccessCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2482
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2483
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2484
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2485
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2486
		if (line.count("At") == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2487
			openBracketPos = line.find("At")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2488
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2489
			openBracketPos = line.find("At(")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2490
		cutLine = line[openBracketPos+1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2491
		closeBracketPos = cutLine.find(")") + len(line) - len(cutLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2492
		if (closeBracketPos > openBracketPos) and (openBracketPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2493
			variable = line[openBracketPos+3:closeBracketPos]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2494
			variable = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2495
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2496
			if (len(variable) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2497
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2498
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2499
			# if a constant index assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2500
			if (variable[0] == "E") or (variable[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2501
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2502
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2503
			variableIsNumeric = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2504
			varPos = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2505
			while (varPos < len(variable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2506
				if (variable[varPos] < '0') or (variable[varPos] > '9'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2507
					variableIsNumeric = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2508
					break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2509
				varPos = varPos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2510
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2511
			linePos = openBracketPos - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2512
			while (linePos > 0) and (isNonAlpha(line[linePos])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2513
				linePos = linePos - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2514
			arrayNameEnd = linePos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2515
			while (linePos >= 0) and (isNonAlpha(line[linePos]) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2516
				linePos = linePos - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2517
			arrayNameStart = linePos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2518
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2519
			arrayName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2520
			if (arrayNameStart >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2521
				arrayName = line[arrayNameStart:arrayNameEnd]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2522
				arrayName = TrimVariableName(arrayName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2523
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2524
				if (len(arrayName) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2525
					# if a constant array assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2526
					if (arrayName[0] == "E") or (arrayName[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2527
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2528
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2529
					# ignore any heartbeat/periodic/timer object that is not an array or list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2530
					if isTimerObject(lines, currentline, arrayName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2531
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2532
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2533
			if (variableIsNumeric):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2534
				if (len(arrayName) > 2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2535
					if (arrayName[0] == "i") and (arrayName[1] >= 'A') and (arrayName[1] <= 'Z'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2536
						return 0 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2537
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2538
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2539
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2540
			while (i >= 0) and (i >= scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2541
				line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2542
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2543
				# check to see if index is compared to array size
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2544
				if (len(arrayName) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2545
					arrayNamePos = line.find(arrayName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2546
					if (arrayNamePos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2547
						cutLine = line[arrayNamePos + len(arrayName):]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2548
						if (accessArrayCountFn.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2549
							return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2550
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2551
					if (variableIsNumeric == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2552
						if (accessArrayDeclaration.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2553
							openBracketPos = line.find("[")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2554
							cutLine = line[openBracketPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2555
							closeBracketPos = cutLine.find("]") + len(line) - len(cutLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2556
							if (closeBracketPos > openBracketPos) and (openBracketPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2557
								declVariable = line[openBracketPos:closeBracketPos]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2558
								declVariable = TrimVariableName(declVariable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2559
								if (len(declVariable) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2560
									# if a constant index assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2561
									if (declVariable[0] == "E") or (declVariable[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2562
										return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2563
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2564
								declVariableIsNumeric = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2565
								varPos = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2566
								while (varPos < len(declVariable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2567
									if (declVariable[varPos] < '0') or (declVariable[varPos] > '9'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2568
										declVariableIsNumeric = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2569
										break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2570
									varPos = varPos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2571
								if (declVariableIsNumeric == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2572
									if (int(variable) < int(declVariable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2573
										return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2574
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2575
				i = i - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2576
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2577
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2578
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2579
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2580
script.iCompare	= arrayAccessCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2581
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2582
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2583
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2584
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2585
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2586
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2587
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2588
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2589
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2590
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2591
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2592
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2593
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2594
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2595
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2596
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2597
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2598
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2599
# accessArrayElementWithoutCheck2.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2600
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2601
# Checks : Array element accessed by [] without checking range.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2602
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2603
# Reason : Whenever an element in an array is accessed, the index 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2604
# should first be checked to ensure that it is within range. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2605
# CodeScanner checks for explicit calls to a Count() or Length() 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2606
# function; so if the array index is checked in a different way, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2607
# it gives false positives. Accessing an invalid index can cause 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2608
# a panic.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2609
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2610
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2611
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2612
script = CScript("accessArrayElementWithoutCheck2")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2613
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2614
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2615
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2616
	\)*		# optional closing bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2617
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2618
	\[
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2619
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2620
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2621
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2622
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2623
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2624
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2625
accessArrayCountFn = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2626
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2627
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2628
	Count
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2629
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2630
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2631
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2632
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2633
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2634
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2635
accessArrayLengthFn = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2636
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2637
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2638
	Length
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2639
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2640
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2641
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2642
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2643
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2644
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2645
accessArrayDeclareNew = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2646
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2647
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2648
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2649
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2650
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2651
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2652
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2653
bufferArrayDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2654
	\w+		# array type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2655
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2656
	<
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2657
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2658
	[0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2659
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2660
	>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2661
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2662
	\w+		# array name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2663
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2664
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2665
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2666
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2667
accessArrayDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2668
	\w+		# array type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2669
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2670
	(\*|&)*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2671
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2672
	\[
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2673
	.*		# array size
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2674
	\]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2675
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2676
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2677
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2678
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2679
constArrayDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2680
	\w+		# array type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2681
	[0-9<>*& ]*	# optional array element
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2682
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2683
	\w+		# array name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2684
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2685
	\[
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2686
	.*		# array size
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2687
	\]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2688
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2689
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2690
	[^=]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2691
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2692
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2693
def arrayAccessCompare2(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2694
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2695
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2696
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2697
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2698
		if (accessArrayDeclareNew.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2699
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2700
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2701
		if (accessArrayDeclaration.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2702
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2703
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2704
		if (constArrayDeclaration.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2705
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2706
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2707
		openBracketPos = line.find("[")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2708
		cutLine = line[openBracketPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2709
		closeBracketPos = cutLine.find("]") + len(line) - len(cutLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2710
		if (closeBracketPos > openBracketPos) and (openBracketPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2711
			variable = line[openBracketPos:closeBracketPos]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2712
			variable = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2713
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2714
			if (len(variable) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2715
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2716
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2717
			# if a constant index assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2718
			if (variable[0] == "E") or (variable[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2719
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2720
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2721
			variableIsNumeric = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2722
			varPos = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2723
			while (varPos < len(variable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2724
				if (variable[varPos] < '0') or (variable[varPos] > '9'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2725
					variableIsNumeric = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2726
					break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2727
				varPos = varPos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2728
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2729
			linePos = openBracketPos
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2730
			while (linePos > 0) and (isNonAlpha(line[linePos])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2731
				linePos = linePos - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2732
			arrayNameEnd = linePos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2733
			while (linePos >= 0) and (isNonAlpha(line[linePos]) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2734
				linePos = linePos - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2735
			arrayNameStart = linePos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2736
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2737
			arrayName = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2738
			if (arrayNameStart >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2739
				arrayName = line[arrayNameStart:arrayNameEnd]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2740
				arrayName = TrimVariableName(arrayName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2741
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2742
				if (len(arrayName) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2743
					# if a constant array assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2744
					if (arrayName[0] == "E") or (arrayName[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2745
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2746
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2747
			if (variableIsNumeric):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2748
				if (len(arrayName) > 2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2749
					if (arrayName[0] == "i") and (arrayName[1] >= 'A') and (arrayName[1] <= 'Z'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2750
						return 0 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2751
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2752
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2753
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2754
			while (i >= 0) and (i >= scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2755
				line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2756
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2757
				# check to see if index is compared to array size
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2758
				if (len(arrayName) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2759
					arrayNamePos = line.find(arrayName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2760
					if (arrayNamePos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2761
						cutLine = line[arrayNamePos + len(arrayName):]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2762
						if (accessArrayCountFn.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2763
							return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2764
						if (accessArrayLengthFn.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2765
							return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2766
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2767
					if (variableIsNumeric == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2768
						doCheck = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2769
						if (accessArrayDeclaration.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2770
							openBracketPos = line.find("[")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2771
							cutLine = line[openBracketPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2772
							closeBracketPos = cutLine.find("]") + len(line) - len(cutLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2773
							if (closeBracketPos > openBracketPos) and (openBracketPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2774
								declVariable = line[openBracketPos:closeBracketPos]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2775
								declVariable = TrimVariableName(declVariable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2776
								if (len(declVariable) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2777
									doCheck = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2778
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2779
						if (bufferArrayDeclaration.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2780
							openBracketPos = line.find("<")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2781
							cutLine = line[openBracketPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2782
							closeBracketPos = cutLine.find(">") + len(line) - len(cutLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2783
							if (closeBracketPos > openBracketPos) and (openBracketPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2784
								declVariable = line[openBracketPos:closeBracketPos]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2785
								declVariable = TrimVariableName(declVariable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2786
								if (len(declVariable) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2787
									doCheck = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2788
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2789
						if (doCheck == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2790
							# if a constant index assume it's going to be ok!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2791
							if (declVariable[0] == "E") or (declVariable[0] == "K"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2792
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2793
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2794
							declVariableIsNumeric = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2795
							varPos = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2796
							while (varPos < len(declVariable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2797
								if (declVariable[varPos] < '0') or (declVariable[varPos] > '9'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2798
									declVariableIsNumeric = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2799
									break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2800
								varPos = varPos + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2801
							if (declVariableIsNumeric == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2802
								if (int(variable) < int(declVariable)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2803
									return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2804
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2805
				i = i - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2806
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2807
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2808
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2809
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2810
script.iCompare	= arrayAccessCompare2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2811
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2812
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2813
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2814
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2815
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2816
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2817
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2818
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2819
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2820
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2821
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2822
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2823
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2824
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2825
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2826
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2827
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2828
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2829
# activestart.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2830
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2831
# Checks : Using CActiveScheduler::Start.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2832
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2833
# Reason : Using CActiveScheduler::Start() can mean that something 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2834
# asynchronous is being made synchronous. Instead, use active 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2835
# objects correctly in an asynchronous way.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2836
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2837
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2838
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2839
script = CScript("activestart")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2840
script.iReString = "CActiveScheduler::Start"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2841
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2842
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2843
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2844
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2845
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2846
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2847
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2848
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2849
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2850
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2851
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2852
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2853
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2854
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2855
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2856
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2857
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2858
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2859
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2860
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2861
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2862
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2863
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2864
# activestop.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2865
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2866
# Checks : Using CActiveScheduler::Stop.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2867
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2868
# Reason : Using CActiveScheduler::Stop() can mean that something 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2869
# asynchronous is being made synchronous. Instead, use active 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2870
# objects correctly in an asynchronous way.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2871
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2872
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2873
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2874
script = CScript("activestop")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2875
script.iReString = "CActiveScheduler::Stop"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2876
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2877
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2878
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2879
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2880
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2881
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2882
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2883
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2884
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2885
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2886
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2887
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2888
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2889
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2890
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2891
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2892
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2893
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2894
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2895
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2896
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2897
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2898
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2899
# arraypassing.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2900
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2901
# Checks : Passing arrays by value rather than reference.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2902
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2903
# Reason : Passing arrays by value causes the array to be copied 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2904
# needlessly, which takes up time and memory. For efficiency, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2905
# references should be used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2906
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2907
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2908
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2909
script = CScript("arraypassing")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2910
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2911
    (\(|,)?         # open bracket or preceeding comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2912
    \s*             # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2913
	(R|C)\w*Array	# skip to a parameter type containing "R...Array..." or "C...Array..."
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2914
    \s*				# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2915
	(<.*>)?			# optional class in angle brackets
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2916
	\s+				# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2917
	(\w+)			# parameter name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2918
    (=|\w|\s)*      # optional parameter initialization or whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2919
    (\)|,)			# close bracket or trailing comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2920
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2921
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2922
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2923
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2924
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2925
script.iCompare = DefaultFuncParamCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2926
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2927
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2928
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2929
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2930
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2931
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2932
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2933
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2934
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2935
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2936
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2937
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2938
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2939
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2940
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2941
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2942
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2943
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2944
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2945
# arrayptrcleanup.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2946
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2947
# Checks : Using local CArrayPtr classes without cleanup items.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2948
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2949
# Reason : It is not enough to push a local CArrayPtr class onto 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2950
# the cleanup stack. A TCleanupItem and callback function must be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2951
# used to avoid leaking the elements.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2952
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2953
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2954
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2955
script = CScript("arrayptrcleanup")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2956
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2957
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2958
	(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2959
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2960
	)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2961
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2962
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2963
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2964
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2965
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2966
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2967
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2968
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2969
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2970
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2971
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2972
	CArrayPtr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2973
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2974
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2975
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2976
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2977
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2978
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2979
def arrayptrcleanupcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2980
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2981
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2982
		varName = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2983
		if (len(varName) == 1) or (varName[0] not in "ai") or varName[1].islower():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2984
			for i in range(currentline, currentline + 10):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2985
				if i >= len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2986
					break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2987
				elif (lines[i].find("TCleanupItem") <> -1) and (lines[i].find(varName) <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2988
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2989
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2990
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2991
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2992
script.iCompare = arrayptrcleanupcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2993
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2994
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2995
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2996
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2997
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2998
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  2999
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3000
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3001
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3002
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3003
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3004
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3005
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3006
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3007
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3008
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3009
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3010
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3011
# assertdebuginvariant.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3012
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3013
# Checks : __ASSERT_DEBUG with User::Invariant.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3014
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3015
# Reason : Replace __ASSERT_DEBUG(<condition>, User::Invariant()) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3016
# with ASSERT(<condition>), because it is easier to read.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3017
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3018
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3019
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3020
script = CScript("assertdebuginvariant")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3021
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3022
script.iReString = "__ASSERT_DEBUG\s*\(\w*\s*,\s*User::Invariant\s*\(\s*\)\s*\)\s*;"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3023
script.iFileExts = ["h", "cpp", ".inl", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3024
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3025
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3026
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3027
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3028
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3029
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3030
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3031
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3032
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3033
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3034
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3035
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3036
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3037
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3038
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3039
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3040
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3041
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3042
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3043
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3044
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3045
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3046
# baddefines.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3047
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3048
# Checks : Lowercase definition names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3049
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3050
# Reason : Badly-named definitions makes the code harder to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3051
# maintain and can lead to defects.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3052
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3053
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3054
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3055
script = CScript("baddefines")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3056
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3057
	\#define
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3058
	\s+					# at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3059
	[A-Z0-9_]*[a-z]+	# find a lower case character
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3060
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3061
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3062
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3063
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3064
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3065
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3066
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3067
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3068
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3069
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3070
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3071
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3072
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3073
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3074
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3075
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3076
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3077
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3078
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3079
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3080
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3081
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3082
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3083
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3084
# baseconstruct.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3085
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3086
# Checks : Leaving function called before BaseConstructL().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3087
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3088
# Reason : If a leave occurs before BaseConstructL() is called, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3089
# the system can panic because it is trying to clean up an 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3090
# application that has not been fully initialised.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3091
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3092
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3093
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3094
script = CScript("baseconstruct")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3095
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3096
	^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3097
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3098
	BaseConstructL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3099
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3100
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3101
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3102
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3103
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3104
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3105
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3106
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3107
def baseconstructcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3108
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3109
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3110
		if scanner.iCurrentMethodStart >= 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3111
			for i in range(scanner.iCurrentMethodStart, currentline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3112
				line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3113
				n = KReLeavingLine.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3114
				if n:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3115
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3116
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3117
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3118
script.iCompare = baseconstructcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3119
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3120
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3121
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3122
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3123
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3124
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3125
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3126
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3127
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3128
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3129
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3130
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3131
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3132
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3133
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3134
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3135
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3136
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3137
# callActiveObjectWithoutCheckingOrStopping.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3138
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3139
# Checks : Active object called without checking whether it is 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3140
# active or canceling it first.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3141
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3142
# Reason : If an active object is started twice, a panic occurs. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3143
# CodeScanner picks out places where there is a call to a Start(), 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3144
# Queue(), or After() function on a member variable, without a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3145
# previous call to IsActive(), Cancel(), or Stop(). In general, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3146
# if starting a timer, there should at least be a call to IsActive() 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3147
# to ensure that the timer is not already running.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3148
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3149
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3150
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3151
script = CScript("callActiveObjectWithoutCheckingOrStopping")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3152
script.iReString = r"""\("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3153
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3154
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3155
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3156
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3157
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3158
activeObjectIsActive = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3159
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3160
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3161
	IsActive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3162
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3163
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3164
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3165
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3166
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3168
activeObjectCancel = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3169
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3170
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3171
	Cancel
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3172
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3173
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3174
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3175
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3176
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3177
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3178
activeObjectStop = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3179
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3180
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3181
	Stop
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3182
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3183
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3184
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3185
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3186
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3187
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3188
activeObjectCreate = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3189
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3190
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3191
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3192
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3193
	New
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3194
	\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3195
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3196
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3197
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3198
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3199
activeObjectCreate2 = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3200
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3201
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3202
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3203
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3204
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3205
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3206
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3207
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3208
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3209
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3210
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3211
activeObjectStart = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3212
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3213
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3214
	Start
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3215
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3216
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3217
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3218
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3219
activeObjectQueue = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3220
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3221
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3222
	Queue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3223
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3224
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3225
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3226
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3227
activeObjectAfter = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3228
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3229
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3230
	After
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3231
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3232
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3233
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3234
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3235
# RTimer::After() takes 2 arguments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3236
rtimerObjectAfter = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3237
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3238
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3239
	After
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3240
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3241
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3242
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3243
	\w+			# first argument
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3244
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3245
	,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3246
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3247
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3248
# Non-active types with After(), Queue() or Start() function
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3249
KNonActiveTypes = {
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3250
	"KAnimation"					: "Animation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3251
	"KAnimator"						: "Animator",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3252
	"KClockSourcePeriodicUtility"	: "ClockSourcePeriodicUtility",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3253
	"KCodecWrapper"					: "CodecWrapper",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3254
	"KCommTimer"					: "CommTimer",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3255
	"KEmbeddedStore"				: "EmbeddedStore",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3256
	"KFormulaTextLexer"				: "FormulaTextLexer",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3257
	"KObexServer"					: "ObexServer",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3258
	"KSpriteAnimation"				: "SpriteAnimation",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3259
	"KRConnection"					: "RConnection",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3260
	"KRSubConnection"				: "RSubConnection",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3261
	"KRTest"						: "RTest",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3262
	"KRTimer"						: "RTimer",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3263
	"KValidityPeriod"				: "ValidityPeriod",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3264
	"KVideoPlayHwDevice"			: "VideoPlayHwDevice",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3265
	"KVideoRecordHwDevice"			: "VideoRecordHwDevice",
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3266
}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3267
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3268
def isNonActiveObject(variable):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3269
	for name, value in KNonActiveTypes.items():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3270
		if (variable.lower().find(value.lower()) <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3271
			return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3272
	return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3273
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3274
def activeObjectCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3275
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3276
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3277
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3278
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3279
		if (scanner.iCurrentMethodName == "Start"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3280
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3281
		if (scanner.iCurrentMethodName == "Queue"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3282
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3283
		if (scanner.iCurrentMethodName == "After"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3284
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3285
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3286
		checkForIsActive = 0	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3287
		if (activeObjectStart.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3288
			checkForIsActive = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3289
		if (activeObjectQueue.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3290
			checkForIsActive = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3291
		if (activeObjectAfter.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3292
			# make sure we are not dealing with RTimer::After()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3293
			if (not rtimerObjectAfter.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3294
				checkForIsActive = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3295
		if (checkForIsActive == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3296
			varEnd = line.find("->")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3297
			if (varEnd < 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3298
				varEnd = line.find(".")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3299
			if (varEnd < 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3300
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3301
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3302
			variable = TrimVariableName(line[:varEnd])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3303
			if (len(variable) == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3304
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3305
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3306
			# if a local variable then unlikely to have been started already
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3307
			if (len(variable) > 2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3308
				if (variable[0] != 'i'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3309
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3310
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3311
					if (variable[1] < 'A') or (variable[1] > 'Z'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3312
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3313
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3314
			# ignore non-active object
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3315
			if isNonActiveObject(variable):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3316
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3317
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3318
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3319
			while (i > scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3320
				line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3321
				varPos = line.find(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3322
				if (varPos >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3323
					cutLine = line[varPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3324
					if (activeObjectIsActive.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3325
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3326
					if (activeObjectCancel.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3327
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3328
					if (activeObjectStop.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3329
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3330
					if (activeObjectCreate.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3331
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3332
					if (activeObjectCreate2.search(cutLine)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3333
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3334
				i = i - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3335
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3336
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3337
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3338
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3339
script.iCompare	= activeObjectCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3340
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3341
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3342
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3343
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3344
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3345
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3346
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3347
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3348
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3349
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3350
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3351
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3352
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3353
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3354
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3355
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3356
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3357
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3358
# changenotification.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3359
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3360
# Checks : Using RSAVarChangeNotify to see System Agent changes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3361
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3362
# Reason : When watching for System Agent changes, use RSystemAgent 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3363
# rather than RSAVarChangeNotify, which can fail.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3364
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3365
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3366
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3367
script = CScript("changenotification")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3368
script.iReString = "RSAVarChangeNotify"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3369
script.iFileExts = ["cpp", "h", "inl", "hpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3370
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3371
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3372
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3373
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3374
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3375
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3376
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3377
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3378
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3379
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3380
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3381
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3382
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3383
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3384
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3385
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3386
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3387
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3388
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3389
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3390
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3391
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3392
# cleanup.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3393
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3394
# Checks : CleanupStack::Pop(AndDestroy) parameters.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3395
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3396
# Reason : These functions should be called with explicit variable 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3397
# parameters to avoid misalignment.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3398
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3399
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3400
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3401
script = CScript("cleanup")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3402
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3403
	CleanupStack::Pop(AndDestroy)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3404
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3405
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3406
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3407
	([0-9]+\s*\)|\))
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3408
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3409
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3410
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3411
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3412
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3413
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3414
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3415
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3416
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3417
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3418
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3419
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3420
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3421
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3422
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3423
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3424
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3425
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3426
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3427
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3428
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3429
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3430
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3431
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3432
# commentcode.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3433
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3434
# Checks : Commented-out code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3435
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3436
# Reason : Instances of code that are commented out make the code 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3437
# hard to maintain and to interpret clearly. The commented out code 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3438
# should be removed. Any requirement to rediscover old code 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3439
# should be made through source control and not by trawling through 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3440
# commented-out code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3441
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3442
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3443
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3444
script = CScript("commentcode")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3445
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3446
	/(/|\*)			# "//" or "/*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3447
	(.*);			# skip to semicolon
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3448
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3449
	(//.*)?			# optional comment
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3450
	$				# end of line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3451
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3452
script.iFileExts = ["h","cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3453
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3454
script.iIgnore = KIgnoreQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3455
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3456
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3457
reDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3458
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3459
	[A-Z][\w<>*&]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3460
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3461
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3462
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3463
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3464
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3465
def commentcodecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3466
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3467
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3468
		if ((m.group(2)[-1:] == ")") or (m.group(2).find("=") <> -1)) or (reDeclaration.match(m.group(2))):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3469
			line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3470
			i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3471
			inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3472
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3473
			while i < len(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3474
				if not inCommentBlock:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3475
					if (line[i] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3476
						if (line[i + 1] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3477
							return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3478
						elif (line[i + 1] == "*"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3479
							inCommentBlock = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3480
							i += 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3481
							continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3482
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3483
					endIndex = line[i:].find("*/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3484
					if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3485
						inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3486
						if line[i:i + endIndex + 2].find(";") <> -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3487
							return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3488
						i += endIndex + 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3489
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3490
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3491
						return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3492
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3493
				i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3494
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3495
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3496
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3497
script.iCompare = commentcodecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3498
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3499
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3500
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3501
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3502
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3503
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3504
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3505
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3506
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3507
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3508
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3509
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3510
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3511
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3512
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3513
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3514
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3515
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3516
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3517
# CommonFunctions.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3518
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3519
# Some commonly used functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3520
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3521
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3522
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3523
KReStringLeavingLine = "(\w*[a-z]\w*L(C*|D|P))\s*\(|ELeave|User::Leave|tream\s+<<|tream\s+>>"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3524
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3525
KReLeavingLine = re.compile(KReStringLeavingLine, re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3526
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3527
def isNonAlpha(char):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3528
	if (char >= 'A'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3529
		if (char <= 'Z'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3530
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3531
	if (char >= 'a'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3532
		if (char <= 'z'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3533
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3534
	if (char >= '0'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3535
		if (char <= '9'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3536
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3537
	return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3538
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3539
def TrimVariableName(var):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3540
	while (len(var) > 0) and (isNonAlpha(var[0])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3541
		var = var[1:len(var)]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3542
	while (len(var) > 0) and (isNonAlpha(var[len(var)-1])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3543
		var = var[0:len(var)-1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3544
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3545
	if (len(var) > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3546
		spaceIndex = var.find(" ")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3547
		if (spaceIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3548
			cutVar = var[spaceIndex:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3549
			return TrimVariableName(cutVar)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3550
	return var
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3552
def GetBracketDepth(lines, currentline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3553
	i = scanner.iCurrentMethodStart
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3554
	bracketdepth = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3555
	while (i < currentline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3556
		thisline = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3557
		commentBegin = thisline.find("//")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3558
		if (commentBegin != -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3559
			thisline = thisline[:commentBegin]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3560
		bracketdepth += thisline.count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3561
		bracketdepth -= thisline.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3562
		i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3563
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3564
	return bracketdepth	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3565
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3566
varDeclaration = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3567
	\s*					# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3568
	([A-Z]\w*)			# variable type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3569
	\s*             	# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3570
	(<.*>)?				# optional class in angle brackets
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3571
	\s*[\*&\s]\s*		# optional "*" or "&" plus at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3572
	(\w+)				# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3573
	\s*             	# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3574
	[;\(=]				# ";" or "(" or "="
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3575
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3576
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3577
def GetLocalVariableType(lines, currentline, varname):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3578
	# skip non-local object
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3579
	if (len(varname) > 2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3580
		if (varname[0] == 'i'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3581
			return ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3582
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3583
	# lookup type of local variable or function parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3584
	if (scanner.iCurrentMethodStart <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3585
		i = scanner.iCurrentMethodStart
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3586
		while (i < currentline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3587
			line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3588
			if (line.find(varname) <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3589
				# look up variable declaration
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3590
				m = varDeclaration.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3591
				if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3592
					# return variable type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3593
					return m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3594
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3595
	return ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3596
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3597
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3598
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3599
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3600
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3601
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3602
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3603
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3604
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3605
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3606
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3607
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3608
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3609
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3610
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3611
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3612
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3613
# connect.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3614
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3615
# Checks : Ignoring Connect() return value.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3616
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3617
# Reason : Ignoring the error returned from Connect() functions 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3618
# means that if the Connect() function fails due to OOM or 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3619
# other problems, the next access to the resource will panic.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3620
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3621
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3622
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3623
script = CScript("connect")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3624
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3625
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3626
	\w+					# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3627
	(\.|->)				# "." or "->"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3628
	Connect\s*\(\s*\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3629
	\s*;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3630
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3631
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3632
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3633
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3634
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3635
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3636
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3637
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3638
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3639
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3640
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3641
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3642
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3643
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3644
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3645
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3646
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3647
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3648
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3649
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3650
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3651
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3652
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3653
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3654
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3655
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3656
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3657
# ConnectAndDontCloseMemberVariable.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3658
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3659
# Checks : Calling Connect() or Open() on a member variable without 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3660
# calling Close() in the destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3661
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3662
# Reason : If Connect() or Open() is called on any member variable, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3663
# then Close() must be called in the destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3664
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3665
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3666
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3667
script = CScript("ConnectAndDontCloseMemberVariable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3668
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3669
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3670
	i[A-Z]\w+			# member variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3671
	(\.|->)				# "." or "->"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3672
	(Connect|Open)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3673
	\s*\(\s*\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3674
	\s*;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3675
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3676
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3677
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3678
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3679
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3680
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3681
ConnectAndDontCloseLeavingFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3682
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3683
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3684
	(C|D|P)*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3685
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3686
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3687
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3688
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3689
def ConnectNotCloseCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3690
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3691
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3692
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3693
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3694
		# get the variable name, between the '*' and the '='
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3695
		startindex = line.find("i")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3696
		if (startindex == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3697
			startindex = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3698
		endindex = line.find("Connect")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3699
		if (endindex == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3700
			endindex = line.find("Open")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3701
		variable = line[startindex:endindex]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3702
		if (len(variable) < 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3703
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3704
		variable = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3705
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3706
		# see if variable is closed within this function before a Leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3707
		i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3708
		bracketdepth = GetBracketDepth(lines, i)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3709
		while (i < len(lines)) and (bracketdepth  > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3710
			line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3711
			if (line.find(variable) >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3712
				if (line.find("Close") >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3713
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3714
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3715
			bracketdepth += line.count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3716
			bracketdepth -= line.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3717
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3718
			if (line.find("User::Leave") >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3719
				bracketdepth = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3720
			if (line.find("ELeave") >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3721
				bracketdepth = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3722
			if (ConnectAndDontCloseLeavingFunction.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3723
				bracketdepth = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3724
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3725
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3726
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3727
		# look for destructor and see if variable is closed there
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3728
		stringToFind = "~" + scanner.iCurrentClassName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3729
		i = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3730
		foundDestructor = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3731
		bracketdepth = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3732
		while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3733
			thisLine = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3734
			if (thisLine.find(stringToFind) >= 0) and (foundDestructor == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3735
				while (i < len(lines)) and (foundDestructor == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3736
					thisLine = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3737
					if (thisLine.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3738
						foundDestructor = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3739
					else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3740
						i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3741
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3742
			if (foundDestructor):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3743
				bracketdepth += thisLine.count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3744
				bracketdepth -= thisLine.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3745
				if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3746
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3747
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3748
				if (thisLine.find(variable) >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3749
					if (thisLine.find("Close") >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3750
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3751
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3752
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3753
		if (foundDestructor):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3754
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3755
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3756
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3757
script.iCompare	= ConnectNotCloseCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3758
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3759
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3760
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3761
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3762
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3763
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3764
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3765
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3766
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3767
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3768
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3769
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3770
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3771
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3772
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3773
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3774
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3775
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3776
# constnames.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3777
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3778
# Checks : Badly-named constants.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3779
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3780
# Reason : Badly-named constant will make the source code harder to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3781
# maintain and make defects more likely.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3782
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3783
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3784
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3785
script = CScript("constnames")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3786
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3787
	^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3788
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3789
	const
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3790
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3791
	\w+		# type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3792
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3793
	[\*&]?	# reference or pointer
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3794
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3795
	[^K\s]	# name initial letter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3796
	\w+		# name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3797
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3798
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3799
	[^()]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3800
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3801
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3802
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3803
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3804
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3805
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3806
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3807
def constnamescompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3808
	if (scanner.iCurrentMethodName == ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3809
		if rematch.search(lines[currentline]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3810
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3811
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3812
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3813
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3814
script.iCompare = constnamescompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3815
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3816
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3817
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3818
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3819
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3820
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3821
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3822
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3823
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3824
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3825
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3826
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3827
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3828
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3829
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3830
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3831
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3832
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3833
# consttdescptr.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3834
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3835
# Checks : Const descriptor pointer as argument.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3836
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3837
# Reason : Use "const TDesC&" instead of "const TDesC*".
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3838
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3839
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3840
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3841
script = CScript("consttdescptr")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3842
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3843
    (\(|,)?        # open bracket or preceeding comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3844
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3845
	const
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3846
    \s+            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3847
	TDesC
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3848
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3849
	\*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3850
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3851
    (=|\w|\s)*     # optional parameter name, parameter initialization or whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3852
    (\)|,)         # close bracket or trailing comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3853
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3854
script.iFileExts = ["h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3855
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3856
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3857
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3858
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3859
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3860
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3861
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3862
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3863
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3864
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3865
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3866
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3867
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3868
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3869
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3870
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3871
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3872
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3873
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3874
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3875
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3876
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3877
# controlornull.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3878
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3879
# Checks : Accessing return value of ControlOrNull().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3880
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3881
# Reason : The return value might be NULL, so it should be checked 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3882
# before access.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3883
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3884
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3885
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3886
script = CScript("controlornull")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3887
script.iReString = "(\.|->)ControlOrNull\(.*\)->"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3888
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3889
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3890
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3891
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3892
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3893
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3894
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3895
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3896
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3897
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3898
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3899
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3900
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3901
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3902
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3903
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3904
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3905
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3906
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3907
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3908
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3909
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3910
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3911
# crepository.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3912
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3913
# Checks : Ignoring CRepository::get() return value.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3914
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3915
# Reason : Independent application cannot assume that the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3916
# Central Repository is set up fully. This means the return value 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3917
# of CRepository::get() cannot be ignored.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3918
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3919
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3920
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3921
script = CScript("crepository")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3922
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3923
    ^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3924
    (\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3925
    (\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3926
    (G|g)et\s*\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3927
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3928
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3929
script.iCategory = KCategoryOther
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3930
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3931
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3932
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3933
reCRepositoryAssignStr = "=\s+$"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3934
reCRepositoryAssign = re.compile(reCRepositoryAssignStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3935
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3936
reCRepositoryConditionalStr = "(if|while)\s+\($"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3937
reCRepositoryConditional = re.compile(reCRepositoryConditionalStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3938
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3939
def crepositorycompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3940
    m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3941
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3942
        objectName = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3943
        objectType = GetLocalVariableType(lines, currentline, objectName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3944
        if (objectType.find("CRepository") == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3945
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3946
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3947
        # look for handler of CRepository::get() return value on a different line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3948
        i = currentline - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3949
        if (i > 0) and (i >= scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3950
            line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3951
            bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3952
            if (bracketCount > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3953
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3954
            r1 = reCRepositoryAssign.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3955
            if r1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3956
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3957
            r2 = reCRepositoryConditional.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3958
            if r2:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3959
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3960
        return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3961
    else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3962
        return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3963
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3964
script.iCompare = crepositorycompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3965
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3966
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3967
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3968
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3969
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3970
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3971
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3972
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3973
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3974
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3975
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3976
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3977
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3978
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3979
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3980
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3981
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3982
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3983
# ctltargettype.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3984
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3985
# Checks : Use of targettype ctl.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3986
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3987
# Reason : The ctl target type should not be used. Instead, use DLL 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3988
# and explicitly refer to the Control Panel's DEF file. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3989
# Note: Code that causes this issue only needs attention if it is 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3990
# found in code developed for Nokia Series 90 code that has extra 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3991
# exports for resetting the Control Panel item's data.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3992
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3993
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3994
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3995
script = CScript("ctltargettype")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3996
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3997
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3998
	[Tt][Aa][Rr][Gg][Ee][Tt][Tt][Yy][Pp][Ee]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  3999
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4000
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4001
script.iFileExts = ["mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4002
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4003
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4004
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4005
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4006
reTargetPath = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4007
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4008
	[Tt][Aa][Rr][Gg][Ee][Tt][Pp][Aa][Tt][Hh]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4009
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4010
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4011
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4012
reDefFile = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4013
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4014
	[Dd][Ee][Ff][Ff][Ii][Ll][Ee]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4015
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4016
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4017
def ctltargettypecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4018
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4019
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4020
		if lines[currentline].upper().find("CTL") <> -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4021
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4022
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4023
		if lines[currentline].upper().find("DLL") <> -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4024
			foundDefFile = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4025
			foundSystemControls = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4026
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4027
			for line in lines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4028
				if reTargetPath.search(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4029
					if line.upper().find("SYSTEM\\CONTROLS") <> -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4030
						foundSystemControls = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4031
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4032
				if reDefFile.search(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4033
					if line.upper().find("CTRL.DEF") <> -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4034
						foundDefFile = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4035
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4036
				if (foundSystemControls == 1) and (foundDefFile == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4037
					break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4038
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4039
			if (foundSystemControls == 1) and (foundDefFile <> 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4040
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4041
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4042
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4043
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4044
script.iCompare	= ctltargettypecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4045
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4046
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4047
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4048
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4049
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4050
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4051
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4052
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4053
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4054
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4055
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4056
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4057
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4058
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4059
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4060
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4061
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4062
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4063
# customizableicons.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4064
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4065
# Checks : Use of customizable icons.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4066
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4067
# Reason : Due to device customization requirements, independent 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4068
# application must not remove any customization done by the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4069
# variant team. This means independent application cannot include 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4070
# customizable icons.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4071
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4072
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4073
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4074
script = CScript("customizableicons")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4075
script.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4076
script.iFileExts = ["mk", "mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4077
script.iCategory = KCategoryOther
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4078
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4079
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4080
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4081
reCustomizableIconsStr = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4082
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4083
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4084
    for wordNode in scriptNode.getElementsByTagName("iconsRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4085
        reCustomizableIconsStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4086
        print "Note: 'customizable icons' pattern configured as:  " + reCustomizableIconsStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4087
        break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4088
if len(reCustomizableIconsStr) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4089
    reCustomizableIcons = re.compile(reCustomizableIconsStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4090
else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4091
    reCustomizableIcons = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4092
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4093
def customizableIconsCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4094
    if reCustomizableIcons:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4095
        return reCustomizableIcons.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4096
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4097
script.iCompare = customizableIconsCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4098
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4099
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4100
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4101
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4102
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4103
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4104
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4105
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4106
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4107
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4108
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4109
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4110
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4111
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4112
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4113
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4114
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4115
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4116
# debugrom.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4117
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4118
# Checks : Debug components in ROM.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4119
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4120
# Reason : Debug versions of components in the ROM could mean that 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4121
# ROM space is being taken up with debugging information or that 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4122
# logging is being put out. Release versions should be in the ROM 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4123
# unless there is a good reason why they are not.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4124
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4125
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4126
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4127
script = CScript("debugrom")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4128
script.iReString = "DEBUG_DIR|\\udeb\\\\"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4129
script.iFileExts = ["iby", "hby"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4130
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4131
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4132
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4133
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4134
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4135
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4136
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4137
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4138
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4139
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4140
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4141
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4142
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4143
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4144
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4145
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4146
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4147
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4148
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4149
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4150
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4151
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4152
# declarename.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4153
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4154
# Checks : Use of __DECLARE_NAME.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4155
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4156
# Reason : The __DECLARE_NAME macro is historical and serves 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4157
# no purpose anymore and should be removed.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4158
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4159
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4160
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4161
script = CScript("declarename")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4162
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4163
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4164
	__DECLARE_NAME
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4165
	\s*					# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4166
	\(					# open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4167
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4168
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4169
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4170
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4171
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4172
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4173
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4174
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4175
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4176
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4177
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4178
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4179
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4180
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4181
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4182
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4183
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4184
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4185
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4186
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4187
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4188
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4189
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4190
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4191
# deleteMemberVariable.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4192
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4193
# Checks : Member variable deleted incorrectly.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4194
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4195
# Reason : When a member variable is deleted, it should be assigned 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4196
# either to NULL or to another value. This prevents accidental 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4197
# access of the deleted object. If a NewL() or other leaving 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4198
# function is called to reassign the member variable, it should 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4199
# first be assigned to NULL in case that function leaves.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4200
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4201
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4202
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4203
script = CScript("deleteMemberVariable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4204
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4205
	delete		# delete command
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4206
	\s*			# optional space
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4207
	\(*			# optional open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4208
	\s*			# optional space
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4209
	i[A-Z]		# member variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4210
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4211
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4212
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4213
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4214
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4215
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4216
deleteMemberVariableLeavingFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4217
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4218
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4219
	(C|D)*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4220
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4221
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4222
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4223
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4224
deleteMemberVariableNewELeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4225
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4226
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4227
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4228
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4229
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4230
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4231
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4232
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4233
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4234
deleteMemberVariableLeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4235
	User::Leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4236
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4237
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4238
deleteMemberVariableArrayDeletion = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4239
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4240
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4241
	Delete
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4242
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4243
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4244
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4245
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4246
deleteMemberVariableArrayDeletion2 = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4247
	(\.|->)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4248
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4249
	Remove
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4250
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4251
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4252
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4253
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4254
def deleteMemberVariableCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4255
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4256
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4257
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4258
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4259
		if (scanner.iCurrentMethodName.find(scanner.iCurrentClassName) > -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4260
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4261
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4262
		deletingArrayMember = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4263
		if (line.find("[")):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4264
			deletingArrayMember = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4265
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4266
		# get the variable name, between the 'delete' and the ';'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4267
		endindex = line.find(";")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4268
		if (endindex == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4269
			endindex = len(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4270
		startindex = line.find("delete")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4271
		variable = line[startindex+6:endindex]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4272
		variable2 = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4273
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4274
		bracketdepth = GetBracketDepth(lines, currentline)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4275
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4276
		i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4277
		while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4278
			nextLine = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4279
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4280
			if deleteMemberVariableLeavingFunction.search(nextLine):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4281
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4282
			if deleteMemberVariableLeave.search(nextLine):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4283
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4284
			if deleteMemberVariableNewELeave.search(nextLine):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4285
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4286
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4287
			if (deletingArrayMember == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4288
				if (nextLine.find(variable2)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4289
					if deleteMemberVariableArrayDeletion.search(nextLine):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4290
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4291
					if deleteMemberVariableArrayDeletion2.search(nextLine):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4292
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4293
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4294
			foundAssignment = nextLine.find("=")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4295
			if (foundAssignment > -1 and nextLine[foundAssignment+1] != "="):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4296
				assigned = nextLine[:foundAssignment]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4297
				if (assigned.find(variable2)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4298
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4299
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4300
			if (nextLine.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4301
				bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4302
			if (nextLine.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4303
				bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4304
				if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4305
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4306
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4307
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4308
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4309
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4310
script.iCompare	= deleteMemberVariableCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4311
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4312
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4313
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4314
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4315
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4316
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4317
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4318
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4319
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4320
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4321
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4322
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4323
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4324
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4325
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4326
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4327
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4328
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4329
# destructor.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4330
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4331
# Checks : Pointer access in destructors.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4332
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4333
# Reason : Accessing pointers to objects in destructors without 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4334
# checking whether they are not NULL could result in a panic, since
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4335
# they may not have been constructed. The pointers should be
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4336
# checked to determine whether they are owned objects. If they are
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4337
# not owned, they should really be references rather than pointers.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4338
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4339
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4340
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4341
script = CScript("destructor")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4342
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4343
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4344
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4345
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4346
	::~
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4347
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4348
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4349
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4350
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4351
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4352
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4353
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4354
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4355
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4356
remember = re.compile("(i[A-Z]\w*)(.+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4357
reguard = re.compile("^\s*(if|while)(.*)({|$)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4358
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4359
def findguard(lines, currentline, destructorstartline, membername):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4360
	i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4361
	line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4362
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4363
	while (i > destructorstartline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4364
		line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4365
		m = reguard.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4366
		if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4367
			index = m.group(2).find(membername)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4368
			if (index <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4369
				if (line[index - 1:index] <> "*") and (line[index + len(membername):index + len(membername) + 2] <> "->"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4370
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4371
		i = i - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4372
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4373
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4374
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4375
def destructorcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4376
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4377
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4378
		openbracecount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4379
		closebracecount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4380
		checkline = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4381
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4382
		while (checkline < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4383
			line = lines[checkline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4384
			openbracecount += line.count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4385
			closebracecount += line.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4386
			member = remember.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4387
			if member and ((member.group(2)[:2] == "->") or (line[member.start()-1:member.start()] == "*" and member.group(2)[:1] <> ".")):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4388
				membername = member.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4389
				if (membername.upper()[-3:] == "ENV") or findguard(lines, checkline, currentline, membername) <> 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4390
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4391
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4392
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4393
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4394
			if (openbracecount and (openbracecount - closebracecount == 0)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4395
				break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4396
			checkline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4397
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4398
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4399
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4400
script.iCompare	= destructorcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4401
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4402
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4403
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4404
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4405
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4406
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4407
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4408
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4409
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4410
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4411
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4412
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4413
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4414
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4415
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4416
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4417
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4418
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4419
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4420
# doubleSemiColon.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4421
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4422
# Checks : Use of double semicolon.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4423
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4424
# Reason : Double semicolons at the end of a line are not necessary 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4425
# and cause a CodeWarrior compiler error.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4426
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4427
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4428
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4429
script = CScript("doubleSemiColon")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4430
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4431
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4432
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4433
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4434
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4435
	$
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4436
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4437
script.iFileExts = ["cpp", "h", "inl"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4438
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4439
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4440
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4441
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4442
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4443
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4444
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4445
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4446
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4447
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4448
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4449
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4450
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4451
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4452
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4453
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4454
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4455
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4456
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4457
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4458
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4459
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4460
# driveletters.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4461
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4462
# Checks : Hard-coded drive letters.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4463
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4464
# Reason : Drive letters should not be hard-coded.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4465
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4466
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4467
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4468
script = CScript("driveletters")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4469
script.iReString = r"""[a-zA-Z]:\\\\"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4470
script.iFileExts = ["cpp", "h", "rss", "rls", "loc", "ra"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4471
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4472
script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4473
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4474
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4475
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4476
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4477
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4478
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4479
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4480
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4481
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4482
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4483
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4484
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4485
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4486
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4487
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4488
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4489
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4490
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4491
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4492
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4493
# eikbuttons.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4494
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4495
# Checks : Checks that the R_EIK_BUTTONS_* resources are not being 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4496
# used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4497
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4498
# Reason : R_EIK_BUTTONS_* resources will not be internationalised, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4499
# and should not be used. Instead, create your own button resource. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4500
# No button resource (or indeed, rls string) should be used in 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4501
# more than one location. Note: This issue is only relevant for 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4502
# development on Nokia platforms.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4503
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4504
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4505
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4506
script = CScript("eikbuttons")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4507
script.iReString = "R_EIK_BUTTONS_.*?"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4508
script.iFileExts = ["rss", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4509
script.iCategory = KCategoryLocalisation
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4510
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4511
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4512
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4513
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4514
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4515
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4516
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4517
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4518
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4519
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4520
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4521
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4522
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4523
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4524
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4525
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4526
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4527
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4528
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4529
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4530
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4531
# eikonenvstatic.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4532
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4533
# Checks : Using CEikonEnv::Static.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4534
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4535
# Reason : CEikonEnv::Static() calls should be kept to a minimum, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4536
# because this involves TLS. All applications, controls, and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4537
# dialogs already have a pointer to the singleton instance of 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4538
# CEikonEnv as a member variable and so don't need to find it again. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4539
# If a class does not have access to a CEikonEnv and needs to use 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4540
# it repeatedly, then it should store one.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4541
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4542
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4543
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4544
script = CScript("eikonenvstatic")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4545
script.iReString = "CEikonEnv::Static"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4546
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4547
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4548
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4549
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4550
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4552
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4553
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4554
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4555
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4556
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4557
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4558
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4559
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4560
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4561
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4562
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4563
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4564
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4565
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4566
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4567
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4568
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4569
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4570
# enummembers.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4571
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4572
# Checks : Badly-named enum members.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4573
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4574
# Reason : Badly-named enum members make the code harder to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4575
# maintain and may cause defects.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4576
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4577
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4578
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4579
script = CScript("enummembers")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4580
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4581
			^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4582
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4583
			enum
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4584
			((\s+\w+)|(\s+\w+\s*::\s*\w+))?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4585
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4586
			({|$)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4587
			"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4588
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4589
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4590
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4591
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4592
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4593
reMember = re.compile("^\s*(\w+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4594
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4595
def enummemberscompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4596
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4597
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4598
		startline = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4599
		openbraceindex = lines[startline].find("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4600
		while (openbraceindex == -1) and (startline < len(lines)) and (lines[startline].find(";") == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4601
			startline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4602
			openbraceindex = lines[startline].find("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4603
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4604
		if openbraceindex == -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4605
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4606
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4607
		endline = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4608
		closebraceindex = lines[endline].find("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4609
		while (closebraceindex == -1) and (endline < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4610
			endline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4611
			closebraceindex = lines[endline].find("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4612
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4613
		enumcontents = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4614
		if (startline == endline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4615
			enumcontents = lines[startline][openbraceindex + 1:closebraceindex - 1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4616
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4617
			enumcontents = lines[startline][openbraceindex + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4618
			line = startline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4619
			while (line < len(lines)) and (line < endline):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4620
				enumcontents = enumcontents + lines[line]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4621
				line += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4622
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4623
			enumcontents = enumcontents + lines[endline][:closebraceindex - 1]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4624
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4625
		# check contents
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4626
		members = enumcontents.split("\n\r,")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4627
		for member in members:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4628
			m2 = reMember.search(member)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4629
			if m2 and (m2.group(1)[:1] <> "E"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4630
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4631
									
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4632
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4633
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4634
script.iCompare = enummemberscompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4635
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4636
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4637
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4638
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4639
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4640
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4641
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4642
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4643
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4644
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4645
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4646
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4647
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4648
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4649
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4650
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4651
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4652
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4653
# enumnames.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4654
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4655
# Checks : Badly-named enums.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4656
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4657
# Reason : Badly-named enums make the code harder to maintain and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4658
# may cause defects.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4659
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4660
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4661
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4662
script = CScript("enumnames")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4663
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4664
			^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4665
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4666
			enum
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4667
			\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4668
			(\w+\s*::\s*)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4669
			(\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4670
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4671
			({|$)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4672
			"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4673
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4674
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4675
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4676
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4677
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4678
def enumnamescompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4679
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4680
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4681
		if m.group(2)[:1] <> "T":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4682
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4683
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4684
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4685
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4686
script.iCompare = enumnamescompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4687
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4688
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4689
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4690
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4691
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4692
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4693
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4694
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4695
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4696
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4697
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4698
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4699
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4700
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4701
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4702
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4703
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4704
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4705
# exportinline.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4706
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4707
# Checks : Exporting inline functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4708
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4709
# Reason : Inline functions should not be exported because this can 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4710
# cause those that link to the DLL to fail to build. Exporting 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4711
# functions limits the changes that can be made in the future 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4712
# due to considerations of binary-compatibility.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4713
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4714
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4715
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4716
script = CScript("exportinline")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4717
script.iReString = "IMPORT_C\s+.*inline\s+.+\("
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4718
script.iFileExts = ["cpp", "h", "hpp", "inl", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4719
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4720
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4721
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4722
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4723
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4724
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4725
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4726
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4727
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4728
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4729
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4730
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4731
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4732
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4733
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4734
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4735
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4736
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4737
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4738
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4739
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4740
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4741
# exportpurevirtual.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4742
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4743
# Checks : Exporting pure virtual functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4744
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4745
# Reason : Symbian recommends against the exportation of 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4746
# pure virtual functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4747
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4748
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4749
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4750
script = CScript("exportpurevirtual")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4751
script.iReString = "IMPORT_C\s+.*\)\s*=\s*0\s*;$"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4752
script.iFileExts = ["cpp", "h", "hpp", "inl", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4753
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4754
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4755
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4756
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4757
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4758
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4759
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4760
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4761
# This script is duplicate of driveletters.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4762
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4763
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4764
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4765
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4766
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4767
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4768
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4769
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4770
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4771
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4772
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4773
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4774
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4775
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4776
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4777
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4778
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4779
# externaldriveletters.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4780
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4781
# Checks : Hard-coded external drive letters.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4782
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4783
# Reason : External drive letters should not be hard-coded as the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4784
# external drive may change between platforms and releases. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4785
# This may cause confusion over ownership leading to classes being 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4786
# deleted erroneously and leaks occurring.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4787
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4788
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4789
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4790
#script = CScript("externaldriveletters")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4791
#script.iReString = """"[abd-yABD-Y]:\\\\"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4792
#script.iFileExts = ["cpp", "h", "rss", "rls", "loc", "ra"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4793
#script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4794
#script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4795
#script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4796
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4797
#scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4798
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4799
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4800
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4801
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4802
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4803
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4804
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4805
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4806
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4807
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4808
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4809
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4810
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4811
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4812
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4813
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4814
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4815
# flags.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4816
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4817
# Checks : Use of R&D flags or feature flags.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4818
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4819
# Reason : Independent application must not use R&D flags nor 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4820
# feature flags via preprocessor statements in the source code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4821
# This means bld*.hrh and productvariant.hrh should not be used.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4822
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4823
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4824
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4825
script = CScript("flags")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4826
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4827
    ^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4828
    \#include
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4829
    \s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4830
    ("|<)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4831
    ((bld\w+|productvariant)\.hrh)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4832
    ("|>)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4833
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4834
script.iFileExts = ["cpp", "h", "hrh", "mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4835
script.iCategory = KCategoryOther
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4836
script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4837
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4838
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4839
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4840
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4841
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4842
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4843
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4844
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4845
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4846
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4847
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4848
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4849
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4850
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4851
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4852
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4853
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4854
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4855
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4856
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4857
# foff.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4858
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4859
# Checks : Use of _FOFF.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4860
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4861
# Reason : _FOFF allows access to data in classes that were not 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4862
# intended for public access. This may cause problems, especially 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4863
# when the location of the data changes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4864
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4865
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4866
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4867
script = CScript("foff")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4868
script.iReString = "_FOFF"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4869
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4870
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4871
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4872
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4873
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4874
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4875
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4876
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4877
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4878
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4879
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4880
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4881
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4882
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4883
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4884
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4885
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4886
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4887
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4888
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4889
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4890
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4891
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4892
# forbiddenwords.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4893
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4894
# Checks : Use of forbidden words in header files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4895
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4896
# Reason : Some words should not be used in header files; 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4897
# especially those header files destined for external release. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4898
# Some words may be forbidden for legal reasons or for platform 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4899
# consistency. Where they exist, alternative allowed words should 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4900
# be used. For example, \"NMP\" and \"Nokia Mobile Phones\" should 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4901
# be replaced by \"Nokia\".
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4902
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4903
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4904
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4905
script = CScript("forbiddenwords")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4906
script.iReString = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4907
script.iFileExts = ["h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4908
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4909
script.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4910
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4911
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4912
reForbiddenWordsStr = "(Typhoon|Hurricane|Calypso|Rubik|Epoc\\|Nokia Mobile Phones|NMP|Mobile Innovation|(^|\s)S90|(^|\s)S80)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4913
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4914
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4915
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4916
	for wordNode in scriptNode.getElementsByTagName("wordsRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4917
		reForbiddenWordsStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4918
		print "Note: 'forbidden words' pattern configured as: " + reForbiddenWordsStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4919
		break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4920
reForbiddenWords = re.compile(reForbiddenWordsStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4921
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4922
def forbiddenwordcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4923
	return reForbiddenWords.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4924
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4925
script.iCompare = forbiddenwordcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4926
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4927
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4928
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4929
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4930
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4931
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4932
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4933
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4934
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4935
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4936
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4937
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4938
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4939
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4940
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4941
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4942
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4943
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4944
# forgottoputptroncleanupstack.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4945
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4946
# Checks : Neglected to put variable on cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4947
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4948
# Reason : If a variable is not put on the cleanup stack and a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4949
# leaving function or ELeave is called, a memory leak occurs. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4950
# CodeScanner occasionally gives false positives for this issue. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4951
# Individual cases should be investigated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4952
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4953
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4954
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4955
script = CScript("forgottoputptroncleanupstack")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4956
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4957
	\s+				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4958
	[b-hj-z]+		# must not be a member or parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4959
	[A-Za-z0-9]+	# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4960
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4961
	=				# assignment operator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4962
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4963
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4964
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4965
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4966
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4967
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4968
forgottoputptroncleanupstackCleanup = re.compile("""Cleanup""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4969
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4970
forgottoputptroncleanupstackDeleteOp = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4971
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4972
	delete
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4973
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4974
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4975
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4976
forgottoputptroncleanupstackReturnCmd = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4977
	(\s*|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4978
	return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4979
	(\s*|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4980
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4981
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4982
forgottoputptroncleanupstackSetFn = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4983
	Set
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4984
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4985
	[A-KM-Za-z0-9]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4986
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4987
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4988
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4989
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4990
forgottoputptroncleanupstackBreak = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4991
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4992
	break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4993
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4994
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4995
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4996
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4997
forgottoputptroncleanupstackIf = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4998
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  4999
	if
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5000
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5001
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5002
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5003
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5004
forgottoputptroncleanupstackElse = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5005
	\}*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5006
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5007
	else
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5008
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5009
	\{*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5010
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5011
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5012
forgottoputptroncleanupstackAssignToMember = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5013
	i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5014
	[A-Za-z0-9\[\]]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5015
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5016
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5017
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5018
	.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5019
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5020
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5021
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5022
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5023
forgottoputptroncleanupstackTrapMacro = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5024
	TRAP
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5025
	[D]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5026
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5027
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5028
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5029
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5030
forgottoputptroncleanupstackLeavingFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5031
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5032
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5033
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5034
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5035
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5036
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5037
forgottoputptroncleanupstackLeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5038
	User::Leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5039
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5040
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5041
forgottoputptroncleanupstackLeaveAndDelete = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5042
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5043
	[D]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5044
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5045
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5046
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5047
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5048
forgottoputptroncleanupstackNewOperator = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5049
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5050
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5051
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5052
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5053
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5054
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5055
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5056
forgottoputptroncleanupstackNewFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5057
	::NewL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5058
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5059
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5060
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5061
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5062
forgottoputptroncleanupstackCreateFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5063
	Create
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5064
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5065
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5066
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5067
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5068
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5069
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5070
forgottoputptroncleanupstackAllocFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5071
	Alloc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5072
	L*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5073
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5074
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5075
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5076
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5077
def findForgetCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5078
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5079
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5080
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5081
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5082
		foundNew = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5083
		equalPos = line.find("=")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5084
		assignedSection = line[equalPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5085
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5086
		if forgottoputptroncleanupstackNewFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5087
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5088
		if forgottoputptroncleanupstackNewOperator.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5089
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5090
		if forgottoputptroncleanupstackAllocFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5091
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5092
		if forgottoputptroncleanupstackCreateFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5093
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5094
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5095
		# if this line contains a 'new', a 'NewL(', or an 'AllocL('
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5096
		if (foundNew == 1):	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5097
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5098
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5099
		# move to next line ending if this line doesn't contain one
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5100
			while (lines[i].find(';') == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5101
				i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5102
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5103
		# go to next line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5104
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5105
			bracketdepth = GetBracketDepth(lines, i)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5106
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5107
		# get the variable name, between the '*' and the '='
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5108
			startindex = line.find("*")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5109
			if (startindex == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5110
				startindex = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5111
			endindex = line.find("=")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5112
			variable = line[startindex+1:endindex]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5113
			if (len(variable) < 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5114
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5115
			variable = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5116
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5117
			inAnIfOrSelectStatement = 1 # possibly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5118
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5119
			while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5120
				line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5121
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5122
				if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5123
					bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5124
				if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5125
					bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5126
					inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5127
					if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5128
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5129
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5130
				varIndex = line2.find(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5131
		# if a later line contains the variable...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5132
				while (varIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5133
					if (isNonAlpha(line2[varIndex-1])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5134
						if (isNonAlpha(line2[varIndex+len(variable)])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5135
		# ...and delete, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5136
							if forgottoputptroncleanupstackDeleteOp.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5137
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5138
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5139
		# ...and an xxxLD() function, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5140
							if forgottoputptroncleanupstackLeaveAndDelete.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5141
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5142
							
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5143
		# ...and the variable is assigned to a member variable, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5144
							if forgottoputptroncleanupstackAssignToMember.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5145
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5146
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5147
		# ...and it is a Set...() call, exit (e.g. SetArray, SetAppUi)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5148
							if forgottoputptroncleanupstackSetFn.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5149
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5150
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5151
		# ...and a return command, exit 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5152
							if forgottoputptroncleanupstackReturnCmd.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5153
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5154
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5155
		# search this line again incase there are similarly named variables
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5156
					line2 = line2[varIndex+1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5157
					varIndex = line2.find(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5158
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5159
				line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5160
		# if a leaving function is called...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5161
				if forgottoputptroncleanupstackLeavingFunction.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5162
		# ...if the leaving function is trapped, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5163
					if forgottoputptroncleanupstackTrapMacro.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5164
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5165
		# ...if a Cleanup function is called, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5166
					if forgottoputptroncleanupstackCleanup.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5167
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5168
		# ...otherwise this is a problem!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5169
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5170
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5171
		# if a User::Leave is called, this is a problem
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5172
				if forgottoputptroncleanupstackLeave.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5173
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5174
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5175
		# if the variable is initialised in a branch of an 'if' or 'switch' statement, ignore other branches
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5176
				if (inAnIfOrSelectStatement == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5177
					if forgottoputptroncleanupstackBreak.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5178
						atLine = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5179
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5180
						findSwitch = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5181
						line3 = lines[findSwitch]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5182
						while (line3.find("switch") == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5183
							findSwitch = findSwitch - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5184
							if (findSwitch <= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5185
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5186
							line3 = lines[findSwitch]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5187
						switchBracketDepth = GetBracketDepth(lines, findSwitch)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5188
						i = atLine
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5189
						while (bracketdepth > switchBracketDepth):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5190
							if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5191
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5192
							line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5193
							if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5194
								bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5195
							if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5196
								bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5197
							i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5198
							
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5199
					if forgottoputptroncleanupstackElse.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5200
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5201
						elseBracketDepth = bracketdepth
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5202
						if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5203
							elseBracketDepth = elseBracketDepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5204
						if (elseBracketDepth == GetBracketDepth(lines, currentline)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5205
							while (line2.find(';') == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5206
								i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5207
								if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5208
									return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5209
								line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5210
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5211
							while (bracketdepth > elseBracketDepth):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5212
								i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5213
								if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5214
									return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5215
								line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5216
								if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5217
									bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5218
								if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5219
									bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5220
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5221
					if forgottoputptroncleanupstackIf.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5222
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5223
				i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5224
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5225
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5226
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5227
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5228
script.iCompare	= findForgetCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5229
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5230
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5231
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5232
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5233
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5234
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5235
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5236
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5237
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5238
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5239
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5240
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5241
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5242
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5243
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5244
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5245
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5246
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5247
# friend.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5248
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5249
# Checks : Use of friends.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5250
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5251
# Reason : The friend directive is often misused and can indicate 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5252
# problems in the OO design.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5253
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5254
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5255
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5256
script = CScript("friend")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5257
script.iReString = "^\s*friend\s"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5258
script.iFileExts = ["cpp", "h", "hpp", "inl", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5259
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5260
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5261
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5262
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5263
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5264
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5265
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5266
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5267
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5268
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5269
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5270
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5271
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5272
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5273
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5274
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5275
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5276
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5277
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5278
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5279
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5280
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5281
# goto.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5282
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5283
# Checks : Use of goto.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5284
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5285
# Reason : Goto should not be used if it can be avoided because 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5286
# it makes the program flow more difficult to follow.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5287
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5288
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5289
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5290
script = CScript("goto")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5291
script.iReString = "(^|[^\w])goto\s+"	# a goto at the beginning of a line or after a non-alphanumeric char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5292
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5293
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5294
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5295
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5296
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5297
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5298
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5299
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5300
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5301
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5302
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5303
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5304
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5305
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5306
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5307
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5308
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5309
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5310
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5311
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5312
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5313
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5314
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5315
# ifassignments.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5316
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5317
# Checks : Assignment in an If statement.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5318
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5319
# Reason : Assignments inside an If statement often indicate that 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5320
# the assignment was not intended. Even if the assignment was 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5321
# intended, it is clearer to separate out the assignment from the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5322
# conditional. The script that detects such occurrences has a few 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5323
# false positives when the action statements are on the same line 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5324
# as the conditional check. However, this is also against the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5325
# coding standards and the action should be on a separate line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5326
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5327
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5328
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5329
script = CScript("ifassignments")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5330
script.iReString = "^\s*if\s*\(\s*.*[A-Za-z0-9_]\s*=\s*[A-Za-z0-9_].*\)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5331
script.iFileExts = ["h", "cpp", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5332
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5333
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5334
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5335
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5336
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5337
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5338
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5339
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5340
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5341
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5342
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5343
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5344
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5345
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5346
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5347
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5348
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5349
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5350
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5351
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5352
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5353
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5354
# ifpreprocessor.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5355
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5356
# Checks : Use of #if in .h files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5357
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5358
# Reason : #if in header files should only be used before the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5359
# main include guards and not around #include statements or around 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5360
# functional blocks in class definitions. The reason for the latter 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5361
# is to aid readability and to make BC breaks more difficult.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5362
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5363
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5364
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5365
script = CScript("ifpreprocessor")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5366
script.iReString = "^\s*\#if(.*)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5367
script.iFileExts = ["h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5368
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5369
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5370
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5371
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5372
def ifpreprocessorcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5373
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5374
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5375
		text = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5376
		slashindex = filename.rfind("/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5377
		if slashindex == -1 :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5378
			slashindex = filename.rfind("\\")			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5379
		if (slashindex <> -1) and (text.upper().find(filename[slashindex+1:-2].upper()) == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5380
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5381
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5382
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5383
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5384
script.iCompare = ifpreprocessorcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5385
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5386
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5387
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5388
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5389
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5390
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5391
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5392
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5393
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5394
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5395
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5396
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5397
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5398
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5399
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5400
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5401
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5402
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5403
# inheritaenceorder.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5404
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5405
# Checks : Incorrect inheritance order of M and C classes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5406
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5407
# Reason : If a C class inherits first from an M class and then a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5408
# C class, a panic can occur when trying to pop a CBase pointer 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5409
# pointing to such a class from the cleanup stack when in fact a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5410
# pointer pointing to the first predecessor, the mixin class, was 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5411
# popped instead.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5412
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5413
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5414
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5415
script = CScript("inheritanceorder")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5416
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5417
    ^\s*         # optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5418
    class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5419
    \s+          # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5420
    (\w+::)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5421
    (\w+)        # class name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5422
    \s*          # optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5423
    :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5424
    (.*)         # inheritance list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5425
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5426
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5427
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5428
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5429
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5430
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5431
def inheritancecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5432
    m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5433
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5434
        className = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5435
        if className[0] <> "C" or (len(className) == 1) or not className[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5436
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5437
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5438
        inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5439
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5440
        # check for inheritance list spanning multiple lines
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5441
        i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5442
        while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5443
            if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5444
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5445
            inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5446
            i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5447
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5448
        # construct inheritance class list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5449
        inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5450
        reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5451
        classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5452
        for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5453
            match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5454
            if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5455
                inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5456
                colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5457
                if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5458
                    inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5459
                classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5460
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5461
        # check the order of M and C classes in inheritance class list 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5462
        mclassIndex = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5463
        cclassIndex = -1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5464
        for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5465
            if (len(classname) > 2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5466
                if classname[0] == "M" and classname[1].isupper() and mclassIndex == -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5467
                    mclassIndex = classlist.index(classname)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5468
                if classname[0] == "C" and classname[1].isupper() and cclassIndex == -1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5469
                    cclassIndex = classlist.index(classname)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5470
        if mclassIndex != -1 and cclassIndex != -1 and mclassIndex < cclassIndex:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5471
            return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5472
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5473
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5474
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5475
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5476
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5477
script.iCompare = inheritancecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5478
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5479
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5480
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5481
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5482
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5483
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5484
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5485
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5486
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5487
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5488
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5489
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5490
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5491
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5492
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5493
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5494
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5495
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5496
# intleaves.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5497
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5498
# Checks : Methods that leave AND return a TInt error.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5499
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5500
# Reason : Returning an error code as well as being able to leave 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5501
# is problematical for the caller. It is preferable to adhere to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5502
# one method of returning the error. Note: CodeScanner is likely to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5503
# return false positives for this situation, because some returned 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5504
# TInt values will not be error codes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5505
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5506
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5507
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5508
script = CScript("intleaves")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5509
script.iReString = "TInt\s+\w+::\w+LC?\s*\("
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5510
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5511
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5512
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5513
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5514
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5515
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5516
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5517
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5518
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5519
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5520
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5521
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5522
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5523
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5524
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5525
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5526
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5527
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5528
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5529
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5530
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5531
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5532
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5533
# jmp.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5534
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5535
# Checks : Use of setjmp and/or longjmp.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5536
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5537
# Reason : Using setjmp and/or longjmp makes code less maintainable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5538
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5539
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5540
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5541
script = CScript("jmp")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5542
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5543
	(set|long)jmp
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5544
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5545
script.iFileExts = ["cpp", "h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5546
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5547
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5548
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5549
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5550
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5551
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5552
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5553
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5554
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5555
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5556
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5557
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5558
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5559
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5560
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5561
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5562
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5563
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5564
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5565
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5566
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5567
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5568
# leave.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5569
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5570
# Checks : Leaving functions called in non-leaving functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5571
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5572
# Reason : Non-leaving functions should not call leaving functions. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5573
# Note: Operator functions are considered to be able to leave when 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5574
# scanning the code inside them.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5575
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5576
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5577
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5578
script = CScript("leave")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5579
script.iReString = KReStringLeavingLine
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5580
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5581
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5582
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5583
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5584
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5585
reLeavingMethod = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5586
	(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5587
	\s*operator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5588
	|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5589
	\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5590
	[a-z]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5591
	\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5592
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5593
	(C(C*|[2-9])|D|P|X)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5594
	$
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5595
	)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5596
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5597
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5598
def leavecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5599
	currentMethod = scanner.iCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5600
	if (currentMethod <> "") and (currentMethod[:5] <> "Leave"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5601
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5602
		if m and not reLeavingMethod.search(currentMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5603
			line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5604
			startline = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5605
			if (lines[currentline].find("TRAP") != -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5606
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5607
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5608
			bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5609
			startBracketCount = bracketCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5610
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5611
			while (currentline > startline - 40) and (currentline >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5612
				currentline -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5613
				line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5614
				bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5615
				if (lines[currentline].find("TRAP") != -1) and (bracketCount == startBracketCount + 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5616
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5617
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5618
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5619
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5620
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5621
script.iCompare = leavecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5622
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5623
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5624
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5625
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5626
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5627
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5628
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5629
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5630
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5631
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5632
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5633
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5634
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5635
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5636
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5637
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5638
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5639
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5640
# LeaveNoError.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5641
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5642
# Checks : Leaving with KErrNone.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5643
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5644
# Reason : Leaving with KErrNone usually indicates that there is a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5645
# makeshift way around a design issue rather than a true and proper 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5646
# fix to the architecture.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5647
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5648
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5649
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5650
script = CScript("LeaveNoError")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5651
script.iReString = "User\s*::\s*Leave\(\s*KErrNone\s*\)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5652
script.iFileExts = ["cpp", "h", "c", "inl"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5653
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5654
script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5655
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5656
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5657
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5658
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5659
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5660
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5661
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5662
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5663
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5664
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5665
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5666
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5667
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5668
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5669
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5670
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5671
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5672
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5673
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5674
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5675
# leavingoperators.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5676
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5677
# Checks : Leaving functions called in operator functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5678
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5679
# Reason : It is not obvious that operator functions can leave. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5680
# Calling leaving functions in operator functions should be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5681
# considered carefully.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5682
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5683
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5684
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5685
script = CScript("leavingoperators")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5686
script.iReString = "(\w*[a-z]\w*L(C*|D|P))\s*\(|ELeave|User::Leave|tream\s+<<|tream\s+>>"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5687
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5688
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5689
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5690
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5691
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5692
reOperatorMethod = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5693
	operator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5694
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5695
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5696
def leavecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5697
	currentMethod = scanner.iCurrentMethodName
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5698
	if (currentMethod <> "") and (currentMethod[:5] <> "Leave"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5699
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5700
		if m and reOperatorMethod.search(currentMethod):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5701
			line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5702
			startline = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5703
			if (lines[currentline].find("TRAP") != -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5704
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5705
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5706
			bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5707
			startBracketCount = bracketCount
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5708
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5709
			while (currentline > startline - 20) and (currentline >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5710
				currentline -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5711
				line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5712
				bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5713
				if (lines[currentline].find("TRAP") != -1) and (bracketCount == startBracketCount + 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5714
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5715
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5716
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5717
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5718
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5719
script.iCompare = leavecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5720
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5721
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5722
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5723
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5724
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5725
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5726
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5727
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5728
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5729
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5730
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5731
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5732
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5733
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5734
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5735
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5736
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5737
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5738
# LFunctionCantLeave.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5739
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5740
# Checks : L-functions that cannot leave.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5741
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5742
# Reason : A function should not be named with an 'L' if it cannot 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5743
# leave. The only exception is in virtual functions where the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5744
# function name is defined in the base class so the L cannot be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5745
# emoved. For example, RunL().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5746
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5747
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5748
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5749
script = CScript("LFunctionCantLeave")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5750
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5751
	[A-Za-z0-9]+			# return type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5752
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5753
	[C|T|R][A-Za-z0-9]+		# class name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5754
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5755
	([A-Za-z0-9]+L(C|D)*)	# leaving function name (possible LC or LD function)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5756
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5757
	\(						# open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5758
	.*						# parameters
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5759
	\)						# close bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5760
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5761
	[^;]					# no semicolon after function definition
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5762
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5763
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5764
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5765
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5766
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5767
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5768
lfunctioncantleaveLeavingMethod = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5769
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5770
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5771
	(C|D)*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5772
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5773
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5774
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5775
lfunctioncantleaveUserLeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5776
	User::Leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5777
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5778
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5779
lfunctioncantleaveNewELeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5780
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5781
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5782
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5783
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5784
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5785
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5786
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5787
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5788
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5789
reLFunctionIgnoreStr = "RunL"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5790
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5791
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5792
	for wordNode in scriptNode.getElementsByTagName("LFunctionIgnoreRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5793
		reLFunctionIgnoreStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5794
		print "Note: ignoring the following functions when checking for L-functions that cannot leave: " + reLFunctionIgnoreStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5795
		break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5796
if len(reLFunctionIgnoreStr) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5797
	reLFunctionIgnores = re.compile(reLFunctionIgnoreStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5798
else :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5799
	reLFunctionIgnores = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5800
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5801
def lfunctioncantleavecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5802
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5803
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5804
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5805
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5806
		#ignore functions on the ignored list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5807
		functionName = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5808
		if reLFunctionIgnores:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5809
			if reLFunctionIgnores.match(functionName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5810
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5811
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5812
		i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5813
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5814
		# find opening { in function
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5815
		while (line.count("{") == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5816
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5817
			if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5818
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5819
			line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5820
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5821
		# if empty function (or one-line function?)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5822
		if (line.count("}") > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5823
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5824
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5825
		i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5826
		bracketDepth = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5827
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5828
		while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5829
			line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5830
			if lfunctioncantleaveLeavingMethod.search(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5831
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5832
			if lfunctioncantleaveUserLeave.search(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5833
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5834
			if lfunctioncantleaveNewELeave.search(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5835
				return 0 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5836
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5837
			bracketDepth += line.count("{") - line.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5838
			if (bracketDepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5839
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5840
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5841
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5842
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5843
script.iCompare = lfunctioncantleavecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5844
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5845
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5846
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5847
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5848
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5849
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5850
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5851
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5852
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5853
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5854
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5855
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5856
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5857
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5858
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5859
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5860
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5861
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5862
# longlines.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5863
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5864
# Checks : Overly long lines of code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5865
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5866
# Reason : Lines longer than about 100 characters can indicate 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5867
# messy or badly-structured code that is hard to maintain.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5868
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5869
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5870
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5871
script = CScript("longlines")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5872
# use configured line length, if available
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5873
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5874
attrInt = 100
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5875
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5876
	attr = scriptNode.getAttribute("length")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5877
	attrStr = str(attr)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5878
	attrInt = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5879
	if (attrStr.isdigit()):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5880
		attrInt = int(attrStr)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5881
	if (attrInt < 10):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5882
		attrInt = 100
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5883
		print "Warning: Invalid line length configured; using default of 100: " + attr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5884
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5885
		print "Note: 'long' line length configured as: " + str(attrInt)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5886
script.iReString = r""".{"""+str(attrInt)+r"""}"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5887
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5888
script.iFileExts = ["cpp", "h", "rss", "rls", "loc", "ra","mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5889
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5890
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5891
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5892
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5893
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5894
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5895
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5896
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5897
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5898
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5899
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5900
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5901
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5902
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5903
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5904
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5905
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5906
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5907
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5908
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5909
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5910
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5911
# magicnumbers.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5912
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5913
# Checks : Use of magic numbers.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5914
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5915
# Reason : Magic numbers - that is, numbers that are hard-coded 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5916
# into the source code and instead of being presented as constants 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5917
# - make code difficult to maintain and give no indication of why 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5918
# a calculation is the way it is. Magic numbers should be replaced 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5919
# with named constants.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5920
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5921
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5922
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5923
script = CScript("magicnumbers")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5924
script.iReString = "(.*[^a-zA-Z0-9_])([0-9]+)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5925
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5926
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5927
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5928
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5929
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5930
reEnum = re.compile("^\s*E\w+\s*=\s*");
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5931
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5932
def magiccompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5933
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5934
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5935
		pretext = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5936
		number = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5937
		if (number == "0") or (number == "1") or (number == '2'):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5938
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5939
		elif (pretext.find("const") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5940
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5941
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5942
			m2 = reEnum.search(pretext)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5943
			if m2:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5944
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5945
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5946
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5947
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5948
script.iCompare = magiccompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5949
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5950
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5951
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5952
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5953
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5954
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5955
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5956
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5957
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5958
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5959
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5960
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5961
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5962
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5963
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5964
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5965
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5966
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5967
# mclassdestructor.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5968
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5969
# Checks : M class has destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5970
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5971
# Reason : M classes should not contain a destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5972
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5973
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5974
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5975
script = CScript("mclassdestructor")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5976
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5977
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5978
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5979
	~M[A-Z]			# destructor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5980
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5981
script.iFileExts = ["cpp", "h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5982
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5983
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5984
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5985
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5986
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5987
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5988
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5989
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5990
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5991
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5992
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5993
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5994
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5995
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5996
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5997
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5998
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  5999
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6000
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6001
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6002
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6003
# memberlc.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6004
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6005
# Checks : Assigning LC methods to member variables.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6006
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6007
# Reason : Objects on the cleanup stack should not be assigned to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6008
# member variables.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6009
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6010
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6011
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6012
script = CScript("memberlc")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6013
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6014
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6015
	i[A-Z]\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6016
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6017
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6018
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6019
	[\w:]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6020
	LC
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6021
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6022
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6023
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6024
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6025
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6026
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6027
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6028
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6029
reMemberLCPop = re.compile("\s*CleanupStack::Pop\s*\(")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6030
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6031
def memberlccompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6032
	if rematch.search(lines[currentline]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6033
		if (currentline + 1) < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6034
			if reMemberLCPop.search(lines[currentline + 1]):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6035
				return 0	# next line is a Pop
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6036
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6037
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6038
		else:					
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6039
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6040
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6041
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6042
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6043
script.iCompare = memberlccompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6044
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6045
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6046
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6047
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6048
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6049
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6050
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6051
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6052
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6053
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6054
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6055
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6056
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6057
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6058
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6059
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6060
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6061
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6062
# membervariablecallld.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6063
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6064
# Checks : Calling LD function on member variable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6065
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6066
# Reason : LD functions should not be called on a member variable 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6067
# because ownership can be unclear and may lead to double deletes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6068
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6069
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6070
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6071
script = CScript("membervariablecallld")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6072
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6073
	i[A-Z]			# instance variable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6074
	\w+				# rest of the instance variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6075
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6076
	(.|->)			# operator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6077
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6078
	[A-Z]			# classname
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6079
	\w+				# rest of the instance variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6080
	LD\(			# LD function
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6081
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6082
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6083
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6084
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6085
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6086
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6087
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6088
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6089
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6090
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6091
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6092
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6093
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6094
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6095
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6096
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6097
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6098
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6099
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6100
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6101
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6102
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6103
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6104
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6105
# missingcancel.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6106
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6107
# Checks : Cancel() not called in active object's destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6108
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6109
# Reason : Cancel() should always be called in active object's 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6110
# destructor to cancel an outstanding request if there is one. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6111
# If there is no request pending then Cancel() just does nothing, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6112
# but if we do not call Cancel() when having an outstanding request 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6113
# a panic will be raised. CodeScanner occasionally gives false 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6114
# positives for this issue. Individual cases should be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6115
# investigated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6116
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6117
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6118
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6119
script = CScript("missingcancel")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6120
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6121
    ::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6122
    \s*        # optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6123
    ~C(\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6124
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6125
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6126
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6127
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6128
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6129
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6130
# possible active and timer object types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6131
activeObjectType = re.compile("\w+Active$")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6132
timerObjectType = re.compile("\w+Timer$")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6133
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6134
cancelFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6135
    Cancel
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6136
    \s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6137
    \(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6138
    """, re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6139
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6140
def isActiveDestructor(destructorType):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6141
    if (activeObjectType.match(destructorType)) or (timerObjectType.match(destructorType)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6142
        return True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6143
    return False
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6144
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6145
def cancelcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6146
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6147
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6148
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6149
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6150
        destructorType = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6151
        # skip non-active types
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6152
        if (not isActiveDestructor(destructorType)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6153
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6154
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6155
        i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6156
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6157
        # find opening { in function
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6158
        while (line.count("{") == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6159
            i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6160
            if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6161
                return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6162
            line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6163
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6164
        # if one-line or empty function
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6165
        if (line.count("}") > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6166
            if (cancelFunction.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6167
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6168
            else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6169
                return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6170
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6171
        i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6172
        bracketDepth = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6173
        while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6174
            line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6175
            if (cancelFunction.search(line)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6176
                return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6177
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6178
            bracketDepth += line.count("{") - line.count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6179
            if (bracketDepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6180
                return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6181
            i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6182
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6183
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6184
script.iCompare = cancelcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6185
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6186
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6187
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6188
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6189
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6190
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6191
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6192
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6193
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6194
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6195
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6196
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6197
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6198
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6199
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6200
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6201
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6202
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6203
# missingcclass.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6204
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6205
# Checks : C class not inheriting from another C class.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6206
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6207
# Reason : All C classes should inherit from another C class to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6208
# ensure that all data members are zeroed.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6209
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6210
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6211
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6212
script = CScript("missingcclass")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6213
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6214
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6215
	class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6216
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6217
	(\w+::)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6218
	(\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6219
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6220
	(.*)"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6221
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6222
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6223
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6224
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6225
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6226
reCClassIgnoreStr = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6227
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6228
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6229
	for wordNode in scriptNode.getElementsByTagName("cclassIgnoreRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6230
		reCClassIgnoreStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6231
		print "Note: ignoring the following classes when checking for C class not inheriting from another C class: " + reCClassIgnoreStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6232
		break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6233
if len(reCClassIgnoreStr) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6234
	reCClassIgnores = re.compile(reCClassIgnoreStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6235
else :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6236
	reCClassIgnores = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6237
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6238
def missingcclasscompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6239
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6240
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6241
		className = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6242
		if className[0] <> "C" or (len(className) == 1) or not className[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6243
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6244
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6245
		#ignore classes on the ignored list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6246
		if reCClassIgnores:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6247
			if reCClassIgnores.search(className):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6248
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6249
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6250
		inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6251
		i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6252
		while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6253
			if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6254
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6255
			inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6256
			i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6257
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6258
		inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6259
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6260
		reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6261
		classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6262
		for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6263
			match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6264
			if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6265
				inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6266
				colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6267
				if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6268
					inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6269
				classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6270
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6271
		ccount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6272
		for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6273
			if (len(classname) > 2) and classname[0] == "C" and classname[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6274
				ccount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6275
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6276
		if ccount == 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6277
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6278
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6279
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6280
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6281
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6282
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6283
script.iCompare = missingcclasscompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6284
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6285
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6286
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6287
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6288
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6289
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6290
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6291
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6292
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6293
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6294
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6295
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6296
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6297
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6298
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6299
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6300
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6301
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6302
# mmpsourcepath.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6303
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6304
# Checks : Use of absolute path names in MMP files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6305
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6306
# Reason : Use of absolute paths in MMP files makes it impossible 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6307
# to relocate the source. Relative paths should be used instead.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6308
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6309
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6310
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6311
script = CScript("mmpsourcepath")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6312
script.iReString = "^\s*[Ss][Oo][Uu][Rr][Cc][Ee][Pp][Aa][Tt][Hh]\s*\\\\"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6313
script.iFileExts = ["mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6314
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6315
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6316
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6317
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6318
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6319
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6320
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6321
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6322
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6323
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6324
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6325
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6326
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6327
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6328
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6329
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6330
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6331
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6332
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6333
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6334
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6335
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6336
# multilangrsc.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6337
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6338
# Checks : Not using BaflUtils::NearestLanguageFile() when loading 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6339
# a resource file.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6340
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6341
# Reason : If AddResourceFileL() is used without first using 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6342
# BaflUtils::NearestLanguageFile(), then not all language versions 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6343
# of resources will be picked up.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6344
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6345
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6346
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6347
script = CScript("multilangrsc")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6348
script.iReString = """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6349
	AddResourceFileL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6350
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6351
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6352
	\s*\w+.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6353
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6354
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6355
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6356
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6357
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6358
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6359
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6360
reBaflNearestLanguage = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6361
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6362
	BaflUtils::NearestLanguageFile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6363
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6364
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6365
	\s*\w+.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6366
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6367
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6368
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6369
def multilangrsccompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6370
	if (scanner.iCurrentMethodName <> ""):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6371
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6372
		if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6373
			scanLineNum = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6374
			while (scanLineNum>scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6375
				addResMatch = reBaflNearestLanguage.search(lines[scanLineNum])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6376
				if addResMatch:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6377
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6378
				scanLineNum = scanLineNum - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6379
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6380
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6381
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6382
script.iCompare = multilangrsccompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6383
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6384
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6385
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6386
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6387
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6388
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6389
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6390
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6391
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6392
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6393
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6394
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6395
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6396
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6397
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6398
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6399
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6400
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6401
# multipledeclarations.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6402
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6403
# Checks : Multiple declarations on one line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6404
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6405
# Reason : Multiple declarations on one line can be confusing. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6406
# Separate them out so that each declaration is on its own separate 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6407
# line.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6408
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6409
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6410
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6411
script = CScript("multipledeclarations")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6412
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6413
	\w+		# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6414
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6415
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6416
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6417
	\w+		# variable value
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6418
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6419
	,
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6420
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6421
	\w+		# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6422
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6423
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6424
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6425
	\w+		# variable value
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6426
	\s*		# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6427
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6428
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6429
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6430
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6431
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6432
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6433
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6434
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6435
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6436
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6437
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6438
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6439
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6440
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6441
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6442
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6443
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6444
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6445
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6446
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6447
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6448
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6449
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6450
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6451
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6452
# multipleinheritance.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6453
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6454
# Checks : Non M-class multiple inheritance.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6455
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6456
# Reason : It is bad Symbian OS practice to derive from two classes 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6457
# that have implemented functions. Complex behaviour that was not 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6458
# intended can result.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6459
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6460
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6461
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6462
script = CScript("multipleinheritance")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6463
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6464
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6465
	class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6466
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6467
	(\w+::)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6468
	(\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6469
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6470
	:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6471
	(.*)"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6472
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6473
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6474
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6475
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6476
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6477
def classcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6478
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6479
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6480
		className = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6481
		if className[0] <> "C" or (len(className) == 1) or not className[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6482
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6483
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6484
		inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6485
		i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6486
		while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6487
			if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6488
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6489
			inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6490
			i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6491
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6492
		inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6493
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6494
		reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6495
		classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6496
		for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6497
			match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6498
			if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6499
				inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6500
				colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6501
				if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6502
					inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6503
				classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6504
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6505
		ccount = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6506
		for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6507
			if (len(classname) > 2) and classname[0] == "C" and classname[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6508
				ccount += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6509
				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6510
		if ccount > 1:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6511
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6512
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6513
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6514
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6515
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6516
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6517
script.iCompare = classcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6518
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6519
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6520
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6521
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6522
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6523
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6524
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6525
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6526
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6527
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6528
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6529
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6530
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6531
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6532
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6533
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6534
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6535
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6536
# mydocs.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6537
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6538
# Checks : Hard-coded mydocs directory strings.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6539
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6540
# Reason : The mydocs directory is subject to change so should not 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6541
# be referenced directly. Note: @    This issue will only occur in 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6542
# code developed for the Nokia Series 90 platform.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6543
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6544
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6545
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6546
script = CScript("mydocs")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6547
script.iReString = """".*[Mm][Yy][Dd][Oo][Cc][Ss]"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6548
script.iFileExts = ["cpp", "h", "rss", "rls", "loc", "ra"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6549
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6550
script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6551
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6552
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6553
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6554
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6555
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6556
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6557
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6558
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6559
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6560
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6561
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6562
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6563
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6564
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6565
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6566
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6567
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6568
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6569
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6570
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6571
# namespace.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6572
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6573
# Checks : Use of namespace.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6574
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6575
# Reason : Namespaces are often used to work around a poor naming 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6576
# convention.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6577
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6578
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6579
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6580
script = CScript("namespace")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6581
script.iReString = "^\s*namespace\s*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6582
script.iFileExts = ["cpp", "h", "hpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6583
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6584
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6585
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6586
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6587
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6588
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6589
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6590
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6591
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6592
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6593
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6594
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6595
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6596
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6597
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6598
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6599
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6600
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6601
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6602
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6603
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6604
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6605
# newlreferences.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6606
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6607
# Checks : NewL() returning a reference.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6608
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6609
# Reason : NewL() and NewLC() functions should return a pointer to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6610
# an object created on the heap.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6611
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6612
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6613
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6614
script = CScript("newlreferences")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6615
script.iReString = "&\s*NewL"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6616
script.iFileExts = ["cpp", "h", "hpp", "inl", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6617
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6618
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6619
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6620
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6621
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6622
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6623
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6624
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6625
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6626
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6627
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6628
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6629
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6630
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6631
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6632
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6633
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6634
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6635
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6636
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6637
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6638
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6639
# noleavetrap.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6640
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6641
# Checks : TRAP used with no leaving functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6642
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6643
# Reason : A TRAP is unnecessary if there are no leaving functions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6644
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6645
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6646
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6647
script = CScript("noleavetrap")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6648
script.iReString = "^\s*TRAPD?"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6649
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6650
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6651
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6652
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6653
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6654
reLeave = re.compile("(L[CDP]?\s*\(|ELeave|\)\s*\(|<<|>>)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6655
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6656
def noleavetrapcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6657
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6658
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6659
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6660
    	if (line.find("(") == -1) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6661
    		currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6662
    		line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6663
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6664
        bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6665
        found = reLeave.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6666
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6667
        while (bracketCount > 0) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6668
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6669
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6670
            bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6671
            if not found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6672
                found = reLeave.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6673
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6674
        if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6675
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6676
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6677
        	return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6678
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6679
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6680
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6681
script.iCompare = noleavetrapcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6682
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6683
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6684
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6685
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6686
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6687
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6688
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6689
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6690
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6691
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6692
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6693
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6694
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6695
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6696
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6697
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6698
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6699
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6700
# nonconsthbufc.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6701
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6702
# Checks : Non-const HBufC* parameter passing.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6703
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6704
# Reason : HBufC* parameters should almost always be passed as a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6705
# const pointer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6706
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6707
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6708
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6709
script = CScript("nonconsthbufc")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6710
script.iReString = """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6711
    (\(|,)?        # open bracket or preceeding comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6712
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6713
    (\w+)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6714
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6715
    HBufC
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6716
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6717
    \*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6718
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6719
    (\w+)          # parameter name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6720
    (=|\w|\s)*     # optional parameter initialization or whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6721
    (\)|,)         # close bracket or trailing comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6722
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6723
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6724
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6725
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6726
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6727
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6728
def consthbufccompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6729
    # make sure const HBufC* parameters are skipped
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6730
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6731
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6732
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6733
        isConst = (m.group(0).find("const") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6734
        while m and isConst:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6735
            line = line[m.end():]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6736
            m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6737
            if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6738
                isConst = (m.group(0).find("const") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6739
        if isConst:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6740
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6741
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6742
            return DefaultFuncParamCompare(lines, currentline, rematch, filename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6743
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6744
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6745
script.iCompare = consthbufccompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6746
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6747
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6748
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6749
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6750
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6751
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6752
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6753
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6754
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6755
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6756
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6757
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6758
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6759
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6760
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6761
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6762
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6763
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6764
# nonconsttdesc.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6765
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6766
# Checks : Non-const TDesC& parameter passing.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6767
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6768
# Reason : TDesC& parameters should be passed as a const. If it is 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6769
# not, it may indicate that the coder does not understand 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6770
# descriptors, for example, passing descriptors by value.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6771
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6772
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6773
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6774
script = CScript("nonconsttdesc")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6775
script.iReString = """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6776
    (\(|,)?        # open bracket or preceeding comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6777
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6778
    (\w+)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6779
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6780
    (TDesC)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6781
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6782
    &
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6783
    \s*            # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6784
    (\w+)          # parameter name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6785
    (=|\w|\s)*     # optional parameter initialization or whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6786
    (\)|,)         # close bracket or trailing comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6787
    """
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6788
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6789
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6790
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6791
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6792
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6793
def consttdesccompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6794
    # make sure const TDesC& parameters are skipped
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6795
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6796
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6797
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6798
        isConst = (m.group(0).find("const") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6799
        while m and isConst:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6800
            line = line[m.end():]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6801
            m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6802
            if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6803
                isConst = (m.group(0).find("const") <> -1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6804
        if isConst:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6805
            return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6806
        else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6807
            return DefaultFuncParamCompare(lines, currentline, rematch, filename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6808
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6809
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6810
script.iCompare = consttdesccompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6811
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6812
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6813
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6814
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6815
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6816
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6817
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6818
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6819
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6820
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6821
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6822
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6823
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6824
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6825
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6826
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6827
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6828
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6829
# nonleavenew.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6830
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6831
# Checks : Use of new without (ELeave).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6832
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6833
# Reason : Using new without (ELeave) is only used in special 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6834
# circumstances. The leaving variant should typically be used in 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6835
# preference. A common exception is for application creation, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6836
# where NULL is returned for failed creation.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6837
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6838
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6839
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6840
script = CScript("nonleavenew")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6841
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6842
	(=|\(|,)		# equals, open bracket or comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6843
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6844
	new\s+			# "new" plus at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6845
	([^\(\s]		# a character other than a bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6846
	.*)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6847
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6848
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6849
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6850
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6851
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6852
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6853
currentfilename = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6854
iswindowsfile = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6855
rewindows = re.compile("^\s*#include\s+<(windows|wchar).h>", re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6856
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6857
def checkforwindowsinclude(lines, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6858
	global currentfilename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6859
	global iswindowsfile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6860
	global rewindows
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6861
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6862
	if (currentfilename <> filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6863
		currentfilename = filename
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6864
		iswindowsfile = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6865
		for line in lines:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6866
			m = rewindows.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6867
			if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6868
				iswindowsfile = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6869
				break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6870
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6871
	return iswindowsfile
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6872
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6873
def nonleavenewcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6874
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6875
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6876
		if (m.group(2).find("Application") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6877
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6878
		else:				
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6879
			return not checkforwindowsinclude(lines, filename)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6880
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6881
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6882
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6883
script.iCompare = nonleavenewcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6884
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6885
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6886
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6887
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6888
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6889
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6890
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6891
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6892
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6893
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6894
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6895
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6896
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6897
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6898
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6899
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6900
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6901
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6902
# nonunicodeskins.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6903
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6904
# Checks : Non-Unicode skins.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6905
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6906
# Reason : Skin definition files (SKN, SKE) must be Unicode. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6907
# Note: Code that causes this issue only needs attention if it is 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6908
# found in code developed for Nokia Series 90 code.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6909
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6910
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6911
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6912
script = CScript("nonunicodeskins")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6913
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6914
	^\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6915
	(//|/\*|A-Z|a-z|\#|\[)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6916
"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6917
script.iFileExts = ["skn", "ske"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6918
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6919
script.iIgnore = KIgnoreNothing
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6920
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6921
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6922
def nonunicodecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6923
	return (currentline == 0) and rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6924
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6925
script.iCompare = nonunicodecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6926
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6927
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6928
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6929
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6930
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6931
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6932
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6933
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6934
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6935
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6936
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6937
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6938
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6939
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6940
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6941
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6942
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6943
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6944
# null.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6945
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6946
# Checks : NULL equality check.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6947
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6948
# Reason : There is no need to compare pointer variables to NULL. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6949
# Use If(ptr).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6950
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6951
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6952
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6953
script = CScript("null")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6954
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6955
	[!=]=\s*NULL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6956
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6957
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6958
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6959
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6960
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6961
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6962
def nullcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6963
    # It's OK to compare against NULL in return statement
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6964
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6965
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6966
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6967
    	if (line.find("return") > -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6968
    		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6969
    	if (line.find("ASSERT") > -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6970
    		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6971
    	return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6972
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6973
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6974
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6975
script.iCompare = nullcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6976
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6977
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6978
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6979
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6980
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6981
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6982
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6983
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6984
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6985
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6986
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6987
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6988
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6989
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6990
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6991
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6992
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6993
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6994
# open.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6995
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6996
# Checks : Ignoring Open() return value.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6997
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6998
# Reason : Ignoring the return value from Open() functions 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  6999
# (due to OOM, etc.) means that when the resource is accessed next, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7000
# a panic will result.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7001
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7002
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7003
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7004
script = CScript("open")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7005
script.iReString = "^\s*(\w+)(\.|->)Open\s*\("
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7006
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7007
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7008
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7009
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7010
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7011
reOpenIgnoreStr = ""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7012
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7013
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7014
	for wordNode in scriptNode.getElementsByTagName("openIgnoreRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7015
		reOpenIgnoreStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7016
		print "Note: ignoring the following objects and classes when checking for open() return value: " + reOpenIgnoreStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7017
		break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7018
if len(reOpenIgnoreStr) > 0:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7019
	reOpenIgnores = re.compile(reOpenIgnoreStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7020
else :
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7021
	reOpenIgnores = None
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7022
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7023
reOpenAssignStr = "=\s+$"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7024
reOpenAssign = re.compile(reOpenAssignStr, re.IGNORECASE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7025
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7026
def streamcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7027
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7028
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7029
		# ignore objects with the word "tream" in object name or object type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7030
		objectName = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7031
		if (objectName.find("tream") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7032
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7033
		objectType = GetLocalVariableType(lines, currentline, objectName)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7034
		if (objectType.find("tream") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7035
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7036
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7037
		#ignore objects with either object name or object type on the ignored list
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7038
		if reOpenIgnores:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7039
			if reOpenIgnores.search(objectName):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7040
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7041
			if reOpenIgnores.search(objectType):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7042
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7043
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7044
		# look for handler of Open() return value on a different line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7045
		i = currentline - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7046
		if (i > 0) and (i >= scanner.iCurrentMethodStart):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7047
			line = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7048
			bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7049
			if (bracketCount > 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7050
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7051
			r = reOpenAssign.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7052
			if r:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7053
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7054
		return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7055
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7056
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7057
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7058
script.iCompare = streamcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7059
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7060
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7061
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7062
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7063
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7064
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7065
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7066
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7067
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7068
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7069
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7070
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7071
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7072
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7073
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7074
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7075
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7076
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7077
# pointertoarrays.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7078
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7079
# Checks : Pointer to arrays as members of a C class.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7080
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7081
# Reason : In C classes, there is no need to use pointers to arrays 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7082
# as data members. Instead, use the arrays themselves. Using 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7083
# pointers leads to obscure notation like \"(*array)[n]\" for the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7084
# more usual \"array[n]\". It also makes it necessary to explicitly 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7085
# delete the arrays in the destructor. Using the arrays themselves 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7086
# also simplifies notation, reduces indirection, and reduces heap 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7087
# fragmentation.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7088
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7089
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7090
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7091
script = CScript("pointertoarrays")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7092
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7093
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7094
	[CR]\w*Array\w*		# class name e.g. RPointerArray
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7095
    (|<\w*>)			# optional "<Xxxx>" part
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7096
	\s*\*				# "*" (with optional whitespace)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7097
	\s*i[A-Z]			# optional whitespace followed by the starting i of the member variable and then a capital letter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7098
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7099
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7100
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7101
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7102
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7103
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7104
def pointerToArraysCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7105
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7106
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7107
		if (len(scanner.iCurrentClassName) > 1)  and (scanner.iCurrentClassName[0]=="C"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7108
			return 1    # only a problem with C classes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7109
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7110
			return 0    
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7111
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7112
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7113
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7114
script.iCompare = pointerToArraysCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7115
script.iDisplayMethodName = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7116
script.iDisplayClassName = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7117
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7118
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7119
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7120
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7121
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7122
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7123
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7124
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7125
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7126
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7127
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7128
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7129
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7130
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7131
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7132
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7133
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7134
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7135
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7136
# pragmadisable.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7137
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7138
# Checks : Use of #pragma warning.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7139
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7140
# Reason : Disabling warnings can lead to problems, because the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7141
# warnings are probably there for a reason.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7142
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7143
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7144
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7145
script = CScript("pragmadisable")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7146
script.iReString = "\#pragma\s+warning"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7147
script.iFileExts = ["h","cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7148
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7149
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7150
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7151
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7152
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7153
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7154
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7155
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7156
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7157
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7158
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7159
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7160
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7161
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7162
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7163
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7164
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7165
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7166
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7167
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7168
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7169
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7170
# pragmamessage.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7171
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7172
# Checks : Use of #pragma message.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7173
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7174
# Reason : #pragma messages during the build stage can interfere 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7175
# with the build log parsing.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7176
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7177
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7178
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7179
script = CScript("pragmamessage")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7180
script.iReString = "\#pragma\s+message"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7181
script.iFileExts = ["h","cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7182
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7183
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7184
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7185
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7186
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7187
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7188
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7189
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7190
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7191
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7192
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7193
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7194
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7195
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7196
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7197
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7198
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7199
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7200
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7201
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7202
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7203
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7204
# pragmaother.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7205
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7206
# Checks : Use of #pragma other than warning and message.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7207
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7208
# Reason : #pragma directives should only be used in very edge 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7209
# cases (for example, functions consisting of inline assembler 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7210
# without explicit return statements) because, typically, their 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7211
# usage masks valid build warnings and error messages.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7212
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7213
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7214
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7215
script = CScript("pragmaother")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7216
script.iReString = "\#pragma\s+[^warning|message]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7217
script.iFileExts = ["h","cpp", "c", "inl"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7218
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7219
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7220
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7221
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7222
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7223
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7224
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7225
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7226
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7227
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7228
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7229
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7230
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7231
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7232
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7233
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7234
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7235
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7236
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7237
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7238
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7239
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7240
# privateinheritance.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7241
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7242
# Checks : Use of private inheritance.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7243
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7244
# Reason : Classes should not be inherited privately. If public or 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7245
# protected inheritance is not appropriate, consider using an 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7246
# amalgamation; that is, have an object of that type as a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7247
# member variable.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7248
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7249
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7250
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7251
script = CScript("privateinheritance")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7252
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7253
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7254
	class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7255
	\s+					# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7256
	\w+					# class name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7257
	\s*					# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7258
	:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7259
	(.*)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7260
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7261
script.iFileExts = ["cpp", "h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7262
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7263
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7264
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7265
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7266
def privatecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7267
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7268
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7269
		searchtext = m.group(1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7270
		if (searchtext.find("private") == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7271
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7272
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7273
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7274
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7275
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7276
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7277
script.iCompare = privatecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7278
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7279
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7280
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7281
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7282
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7283
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7284
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7285
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7286
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7287
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7288
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7289
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7290
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7291
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7292
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7293
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7294
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7295
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7296
# pushaddrvar.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7297
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7298
# Checks : Pushing address of a variable onto the cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7299
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7300
# Reason : If the variable is owned by the code pushing it, it 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7301
# should be stored as a pointer. If it is not, it should not be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7302
# pushed onto the cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7303
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7304
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7305
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7306
script = CScript("pushaddrvar")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7307
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7308
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7309
	PushL\s*		# "PushL" plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7310
	\(				# open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7311
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7312
	&				# taking the address?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7313
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7314
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7315
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7316
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7317
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7318
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7319
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7320
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7321
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7322
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7323
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7324
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7325
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7326
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7327
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7328
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7329
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7330
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7331
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7332
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7333
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7334
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7335
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7336
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7337
# pushmember.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7338
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7339
# Checks : Pushing data members onto the cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7340
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7341
# Reason : Pushing member variables is likely to lead to double 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7342
# deletes or leakage in certain circumstances and so should be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7343
# avoided. Even if no panic can result, it is bad practice and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7344
# makes maintenance more difficult.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7345
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7346
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7347
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7348
script = CScript("pushmember")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7349
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7350
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7351
	PushL\s*		# "PushL" plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7352
	\(				# open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7353
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7354
	i[A-Z]			# i variable
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7355
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7356
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7357
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7358
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7359
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7360
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7361
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7362
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7363
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7364
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7365
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7366
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7367
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7368
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7369
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7370
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7371
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7372
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7373
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7374
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7375
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7376
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7377
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7378
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7379
# readresource.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7380
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7381
# Checks : Using ReadResource() instead of ReadResourceL().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7382
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7383
# Reason : ReadResourceL() should always be used in preference to 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7384
# ReadResource() because in an error scenario ReadResource() 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7385
# effectively fails silently. If no check is performed on the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7386
# resulting descriptor afterwards, unexpected states can ensue. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7387
# These states are often characterized by buffer overflows.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7388
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7389
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7390
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7391
script = CScript("readresource")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7392
# matching against a line like this: iCoeEnv->ReadResource( buffer, R_RESOURCE_ID );
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7393
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7394
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7395
	\w+					# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7396
	(\.|->)				# "." or "->"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7397
	ReadResource\s*\(.*\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7398
	\s*;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7399
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7400
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7401
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7402
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7403
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7404
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7405
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7406
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7407
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7408
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7409
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7410
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7411
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7412
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7413
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7414
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7415
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7416
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7417
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7418
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7419
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7420
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7421
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7422
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7423
# resourcenotoncleanupstack.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7424
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7425
# Checks : Neglected to put resource objects on cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7426
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7427
# Reason : If a stack-based resource object is not put on the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7428
# cleanup stack with CleanupResetAndDestroyPushL() or 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7429
# CleanupClosePushL(), and a leaving function or ELeave is called, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7430
# a memory leak occurs. CodeScanner occasionally gives false 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7431
# positives for this issue. Individual cases should be investigated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7432
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7433
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7434
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7435
script = CScript("resourcenotoncleanupstack")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7436
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7437
	^\s*					# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7438
	R\w+					# resource type
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7439
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7440
	(<.*>)?					# optional class in angle brackets
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7441
	\s+						# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7442
	(\w+)					# object name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7443
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7444
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7445
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7446
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7447
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7448
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7449
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7450
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7451
cleanupFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7452
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7453
	(CleanupClosePushL|CleanupResetAndDestroyPushL)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7454
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7455
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7456
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7457
	(\w+)					# object name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7458
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7459
	\)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7460
	\s*						# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7461
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7462
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7463
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7464
def resourcecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7465
    m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7466
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7467
    	objectName = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7468
    	bracketdepth = GetBracketDepth(lines, currentline)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7469
    	i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7470
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7471
    	# search for CleanupClosePushL() or CleanupResetAndDestroyPushL() 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7472
    	# with the resource object at parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7473
    	while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7474
    		nextLine = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7475
    		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7476
    		match = cleanupFunction.search(nextLine)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7477
    		if (match):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7478
    			if objectName == match.group(2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7479
    				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7480
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7481
    		if (nextLine.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7482
    			bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7483
    		if (nextLine.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7484
    			bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7485
    			if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7486
    				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7487
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7488
    		i += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7489
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7490
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7491
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7492
script.iCompare = resourcecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7493
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7494
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7495
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7496
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7497
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7498
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7499
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7500
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7501
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7502
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7503
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7504
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7505
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7506
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7507
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7508
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7509
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7510
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7511
# resourcesonheap.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7512
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7513
# Checks : Resource objects on the heap.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7514
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7515
# Reason : There is very rarely any real need to put R classes on 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7516
# the heap (unless they are not real R classes!).  Doing so can 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7517
# lead to inefficiency and cleanup stack problems.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7518
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7519
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7520
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7521
script = CScript("resourcesonheap")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7522
script.iReString = "new\s*(|\(ELeave\))\s+R[A-Z]"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7523
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7524
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7525
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7526
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7527
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7528
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7529
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7530
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7531
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7532
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7533
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7534
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7535
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7536
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7537
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7538
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7539
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7540
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7541
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7542
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7543
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7544
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7545
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7546
# returndescriptoroutofscope.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7547
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7548
# Checks : Return descriptor out of scope.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7549
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7550
# Reason : Returning a TBuf descriptor that is declared locally 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7551
# takes it out of scope. This can cause a crash on WINSCW, although 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7552
# not on WINS.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7553
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7554
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7555
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7556
script = CScript("returndescriptoroutofscope")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7557
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7558
	TBuf
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7559
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7560
	<
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7561
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7562
	>
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7563
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7564
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7565
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7566
script.iCategory = KCategoryCanPanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7567
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7568
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7569
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7570
reReturnValue = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7571
	return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7572
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7573
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7574
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7575
reOpenCurlyBracket = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7576
	{
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7577
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7578
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7579
reCloseCurlyBracket = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7580
	}
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7581
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7582
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7583
def finddescriptor(line, descriptor):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7584
	startindex = line.find(descriptor)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7585
	if (startindex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7586
		if (line[startindex] == " "):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7587
			if (line[startindex + len(descriptor)] == ";"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7588
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7589
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7590
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7591
def returnvaluecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7592
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7593
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7594
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7595
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7596
		startindex = line.find(">");
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7597
		endindex = line.find(";");
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7598
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7599
		if (startindex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7600
			descriptor = line[startindex+1:endindex]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7601
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7602
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7603
			bracketdepth = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7604
			while (i+1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7605
				i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7606
				line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7607
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7608
				if reReturnValue.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7609
					if (finddescriptor(line2, descriptor)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7610
						return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7611
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7612
				if reOpenCurlyBracket.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7613
					bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7614
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7615
				if reCloseCurlyBracket.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7616
					bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7617
					if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7618
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7619
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7620
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7621
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7622
script.iCompare	= returnvaluecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7623
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7624
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7625
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7626
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7627
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7628
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7629
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7630
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7631
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7632
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7633
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7634
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7635
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7636
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7637
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7638
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7639
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7640
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7641
# rfs.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7642
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7643
# Checks : Use of non-pointer/reference RFs.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7644
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7645
# Reason : Connecting to an RFs is a time-consuming operation. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7646
# (It can take approximately 0.1 seconds on some devices.) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7647
# To minimise wasted time and resources, use the already-connected 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7648
# one in EikonEnv or elsewhere, if possible.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7649
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7650
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7651
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7652
script = CScript("rfs")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7653
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7654
	RFs
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7655
	\s+					# at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7656
	\w+					# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7657
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7658
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7659
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7660
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7661
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7662
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7663
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7664
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7665
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7666
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7667
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7668
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7669
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7670
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7671
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7672
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7673
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7674
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7675
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7676
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7677
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7678
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7679
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7680
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7681
# rssnames.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7682
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7683
# Checks : Duplicate RSS names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7684
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7685
# Reason : Resource files with clashing NAME fields can cause the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7686
# wrong resource file to be accessed. This can lead to incorrect 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7687
# functionality or panics.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7688
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7689
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7690
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7691
script = CScript("rssnames")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7692
script.iReString = "^\s*NAME\s+(\w+)"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7693
script.iFileExts = ["rss"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7694
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7695
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7696
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7697
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7698
rssnames = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7699
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7700
def rsscompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7701
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7702
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7703
		text = m.group(1).lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7704
		shortfilename = filename[filename.rfind("/") + 1:].lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7705
		for pair in rssnames:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7706
			if (pair[0] == text):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7707
			 	if (pair[1] == shortfilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7708
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7709
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7710
					scanner.iRendererManager.ReportAnnotation(pair[2])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7711
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7712
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7713
		rssnames.append([text, shortfilename, filename])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7714
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7715
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7716
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7717
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7718
script.iCompare = rsscompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7719
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7720
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7721
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7722
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7723
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7724
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7725
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7726
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7727
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7728
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7729
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7730
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7731
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7732
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7733
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7734
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7735
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7736
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7737
# stringliterals.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7738
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7739
# Checks : Use of _L string literals.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7740
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7741
# Reason : _L() string literals should be replaced by the _LIT() 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7742
# macro.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7743
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7744
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7745
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7746
script = CScript("stringliterals")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7747
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7748
	_L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7749
	(16|8)?			# optional "16" or "8"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7750
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7751
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7752
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7753
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7754
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7755
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7756
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7757
def stringliteralscompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7758
	if (lines[currentline].find("RDebug::Print(") != -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7759
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7760
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7761
		m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7762
		if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7763
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7764
		else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7765
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7766
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7767
script.iCompare = stringliteralscompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7768
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7769
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7770
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7771
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7772
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7773
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7774
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7775
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7776
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7777
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7778
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7779
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7780
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7781
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7782
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7783
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7784
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7785
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7786
# stringsinresourcefiles.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7787
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7788
# Checks : Strings in RSS or RA files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7789
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7790
# Reason : Strings should not be defined in RSS or RA files. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7791
# Instead, they should be put in RLS or other localisable files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7792
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7793
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7794
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7795
script = CScript("stringsinresourcefiles")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7796
script.iReString = "=\s*\"[^\"]+\""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7797
script.iFileExts = ["rss", "ra"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7798
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7799
script.iIgnore = KIgnoreComments
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7800
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7801
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7802
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7803
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7804
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7805
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7806
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7807
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7808
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7809
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7810
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7811
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7812
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7813
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7814
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7815
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7816
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7817
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7818
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7819
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7820
# struct.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7821
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7822
# Checks : Use of struct.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7823
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7824
# Reason : C-style structs should not generally be used. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7825
# The correct idiom is to use a class with public members. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7826
# A permissible use of a C-style struct is if it is used to group 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7827
# non-semantically related entities together for convenience, and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7828
# if a class-related hierarchy would be too heavy-weight.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7829
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7830
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7831
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7832
script = CScript("struct")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7833
script.iReString = "^\s*struct\s*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7834
script.iFileExts = ["cpp", "h", "hpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7835
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7836
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7837
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7838
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7839
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7840
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7841
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7842
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7843
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7844
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7845
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7846
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7847
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7848
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7849
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7850
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7851
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7852
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7853
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7854
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7855
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7856
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7857
# tcclasses.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7858
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7859
# Checks : T classes inheriting from C classes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7860
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7861
# Reason : T classes that are derived from C classes may have a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7862
# complex constructor and so need to be handled differently. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7863
# It is better to make the T class into a C class, which will make 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7864
# the code easier to maintain.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7865
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7866
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7867
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7868
script = CScript("tcclasses")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7869
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7870
	class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7871
	\s+					# at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7872
	(\w+::)?
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7873
	(\w+)				# T class
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7874
	\s*					# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7875
	:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7876
	(.*)				# save inheritance text as group 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7877
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7878
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7879
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7880
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7881
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7882
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7883
def tcclasscompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7884
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7885
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7886
		className = m.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7887
		if className[0] <> "T" or (len(className) == 1) or not className[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7888
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7889
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7890
		inheritanceString = m.group(3)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7891
		i = currentline + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7892
		while (inheritanceString.find("{") == -1) and i < len(lines):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7893
			if (inheritanceString.find(";") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7894
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7895
			inheritanceString += lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7896
			i += 1	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7897
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7898
		inheritancelist = inheritanceString.split(",")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7899
		reclass = re.compile("[\s:]*(public|protected|private)?\s*([\w:]+)")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7900
		classlist = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7901
		for inheritance in inheritancelist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7902
			match = reclass.search(inheritance)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7903
			if match:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7904
				inheritclass = match.group(2)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7905
				colonpos = inheritclass.rfind(":")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7906
				if (colonpos <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7907
					inheritclass = inheritclass[colonpos + 1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7908
				classlist.append(inheritclass)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7909
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7910
		for classname in classlist:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7911
			if (len(classname) > 2) and classname[0] == "C" and classname[1].isupper():
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7912
				return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7913
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7914
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7915
script.iCompare = tcclasscompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7916
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7917
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7918
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7919
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7920
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7921
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7922
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7923
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7924
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7925
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7926
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7927
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7928
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7929
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7930
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7931
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7932
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7933
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7934
# tclassdestructor.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7935
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7936
# Checks : T class has destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7937
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7938
# Reason : T classes should not have a destructor.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7939
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7940
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7941
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7942
script = CScript("tclassdestructor")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7943
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7944
	::
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7945
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7946
	~T[A-Z]			# destructor
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7947
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7948
script.iFileExts = ["cpp", "h"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7949
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7950
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7951
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7952
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7953
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7954
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7955
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7956
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7957
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7958
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7959
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7960
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7961
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7962
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7963
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7964
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7965
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7966
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7967
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7968
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7969
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7970
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7971
# todocomments.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7972
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7973
# Checks : "To do" comments.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7974
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7975
# Reason : "To do" comments in code suggest that it is not finished.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7976
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7977
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7978
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7979
script = CScript("todocomments")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7980
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7981
	/(/|\*)						# "//" or "/*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7982
	.*(t|T)(o|O)(d|D)(o|O)		# skip to Todo
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7983
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7984
script.iFileExts = ["h", "cpp", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7985
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7986
script.iIgnore = KIgnoreQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7987
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7988
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7989
def todocommentcodecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7990
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7991
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7992
		line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7993
		i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7994
		inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7995
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7996
		while i < len(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7997
			if not inCommentBlock:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7998
				if (line[i] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  7999
					if (line[i + 1] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8000
						return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8001
					elif (line[i + 1] == "*"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8002
						inCommentBlock = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8003
						i += 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8004
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8005
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8006
				endIndex = line[i:].find("*/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8007
				if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8008
					inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8009
					# note, that first character is ignored in comments as can be direction to the in-source documentation tool
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8010
					if (line[i+1:i + endIndex + 2].lower().find("todo") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8011
						return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8012
					i += endIndex + 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8013
					continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8014
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8015
					return 1			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8016
			i += 1		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8017
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8018
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8019
script.iCompare = todocommentcodecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8020
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8021
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8022
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8023
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8024
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8025
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8026
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8027
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8028
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8029
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8030
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8031
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8032
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8033
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8034
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8035
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8036
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8037
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8038
# trapcleanup.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8039
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8040
# Checks : Use of LC function in TRAPs.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8041
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8042
# Reason : You cannot trap something that leaves something on the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8043
# cleanup stack because it will panic.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8044
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8045
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8046
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8047
script = CScript("trapcleanup")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8048
script.iReString = "^\s*TRAPD?"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8049
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8050
script.iCategory = KCategoryDefinitePanic
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8051
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8052
script.iSeverity = KSeverityHigh
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8053
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8054
reCMethod = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8055
	\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8056
	[a-z]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8057
	\w*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8058
	LC\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8059
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8060
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8061
def trapcleanupcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8062
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8063
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8064
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8065
		bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8066
		cMethod = reCMethod.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8067
		pop = line.find("Pop")			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8068
						 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8069
		while (bracketCount > 0) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8070
			currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8071
			line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8072
			bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8073
			if not cMethod:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8074
				cMethod = reCMethod.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8075
			if (pop == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8076
				pop = line.find("Pop")			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8077
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8078
		if cMethod and (pop == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8079
			return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8080
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8081
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8082
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8083
script.iCompare = trapcleanupcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8084
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8085
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8086
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8087
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8088
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8089
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8090
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8091
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8092
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8093
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8094
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8095
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8096
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8097
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8098
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8099
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8100
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8101
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8102
# trapeleave.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8103
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8104
# Checks : Trapping new(ELeave).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8105
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8106
# Reason : The trapping of a "new(ELeave) CXxx" call is redundant 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8107
# and wasteful as the code to support TRAP is surprisingly large. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8108
# If the instantiation process really needs not to leave, use 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8109
# "new CXxx" and check for NULL.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8110
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8111
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8112
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8113
script = CScript("trapeleave")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8114
script.iReString = "^\s*TRAPD?"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8115
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8116
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8117
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8118
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8119
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8120
reELeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8121
    new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8122
    \s*        # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8123
    \(         # open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8124
    \s*        # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8125
    ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8126
    \s*        # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8127
    \)         # close bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8128
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8129
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8130
def trapeleavecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8131
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8132
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8133
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8134
        if (line.find("(") == -1) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8135
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8136
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8137
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8138
        bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8139
        found = reELeave.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8140
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8141
        while (bracketCount > 0) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8142
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8143
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8144
            bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8145
            if not found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8146
                found = reELeave.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8147
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8148
        if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8149
            return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8150
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8151
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8152
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8153
script.iCompare = trapeleavecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8154
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8155
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8156
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8157
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8158
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8159
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8160
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8161
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8162
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8163
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8164
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8165
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8166
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8167
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8168
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8169
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8170
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8171
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8172
# traprunl.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8173
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8174
# Checks : Trapping of (Do)RunL() rather than using RunError().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8175
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8176
# Reason : The RunError() function should be used rather than the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8177
# CActive derivative using its own TRAPD solution within a RunL().
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8178
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8179
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8180
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8181
script = CScript("traprunl")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8182
script.iReString = "^\s*TRAPD?"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8183
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8184
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8185
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8186
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8187
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8188
reRunL = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8189
    RunL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8190
    \s*        # whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8191
    \(         # open bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8192
""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8193
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8194
def traprunlcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8195
    line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8196
    m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8197
    if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8198
        if (line.find("(") == -1) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8199
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8200
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8201
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8202
        bracketCount = line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8203
        found = reRunL.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8204
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8205
        while (bracketCount > 0) and (currentline + 1 < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8206
            currentline += 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8207
            line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8208
            bracketCount += line.count("(") - line.count(")")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8209
            if not found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8210
                found = reRunL.search(line) 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8211
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8212
        if found:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8213
            return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8214
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8215
    return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8216
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8217
script.iCompare = traprunlcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8218
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8219
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8220
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8221
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8222
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8223
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8224
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8225
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8226
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8227
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8228
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8229
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8230
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8231
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8232
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8233
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8234
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8235
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8236
# trspassing.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8237
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8238
# Checks : Passing TRequestStatus parameters by value.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8239
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8240
# Reason : TRequestStatus parameters should be passed by reference. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8241
# If TRequestStatus is just being used as an error code, then 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8242
# convert it to a TInt.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8243
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8244
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8245
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8246
script = CScript("trspassing")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8247
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8248
    (\(|,)?				# open bracket or preceeding comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8249
    \s*					# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8250
	TRequestStatus
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8251
    \s*					# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8252
	[^&*]				# matches any character except '&' and '*'
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8253
    \s*					# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8254
	(\w+)				# parameter name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8255
    (=|\w|\s)*          # optional parameter initialization or whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8256
    (\)|,)				# close bracket or trailing comma
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8257
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8258
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8259
script.iCategory = KCategoryWrongFunctionality
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8260
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8261
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8262
script.iCompare = DefaultFuncParamCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8263
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8264
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8265
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8266
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8267
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8268
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8269
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8270
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8271
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8272
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8273
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8274
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8275
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8276
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8277
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8278
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8279
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8280
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8281
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8282
# uids.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8283
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8284
# Checks : Duplicate UIDs.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8285
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8286
# Reason : UIDs must be unique.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8287
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8288
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8289
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8290
script = CScript("uids")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8291
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8292
	^\s*			# whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8293
	[Uu][Ii][Dd]	# uid			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8294
	\s+				# at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8295
	\w+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8296
	\s+				# at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8297
	(\w+)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8298
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8299
script.iFileExts = ["mmp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8300
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8301
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8302
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8303
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8304
uids = []
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8305
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8306
def uidcompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8307
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8308
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8309
		text = m.group(1).lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8310
		shortfilename = filename[filename.rfind("/") + 1:].lower()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8311
		for pair in uids:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8312
			if (pair[0] == text):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8313
			 	if (pair[1] == shortfilename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8314
					return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8315
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8316
					scanner.iRendererManager.ReportAnnotation(pair[2])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8317
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8318
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8319
		uids.append([text, shortfilename, filename])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8320
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8321
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8322
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8323
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8324
script.iCompare = uidcompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8325
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8326
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8327
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8328
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8329
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8330
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8331
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8332
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8333
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8334
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8335
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8336
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8337
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8338
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8339
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8340
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8341
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8342
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8343
# uncompressedaif.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8344
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8345
# Checks : Uncompressed AIFs in ROM.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8346
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8347
# Reason : AIF files should be referenced as "AIF=" rather than 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8348
# "data=" or "file=" otherwise they can bloat the ROM size and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8349
# slow down application loading.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8350
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8351
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8352
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8353
script = CScript("uncompressedaif")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8354
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8355
			(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8356
			^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8357
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8358
			(data|file)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8359
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8360
			=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8361
			.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8362
			\.aif
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8363
			)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8364
			"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8365
script.iFileExts = ["iby", "hby", "oby"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8366
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8367
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8368
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8369
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8370
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8371
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8372
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8373
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8374
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8375
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8376
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8377
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8378
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8379
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8380
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8381
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8382
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8383
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8384
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8385
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8386
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8387
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8388
# uncompressedbmp.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8389
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8390
# Checks : Uncompressed bitmaps in ROM.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8391
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8392
# Reason : Using uncompressed bitmaps can significantly bloat the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8393
# size of ROM images. All occurrences of "bitmap=" in iby/hby files 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8394
# should be replaced with "auto-bitmap=". Also, including bitmaps 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8395
# using "data=" or "file=" causes bloat and load-speed reductions.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8396
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8397
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8398
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8399
script = CScript("uncompressedbmp")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8400
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8401
			(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8402
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8403
			^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8404
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8405
			bitmap
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8406
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8407
			=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8408
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8409
			|
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8410
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8411
			^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8412
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8413
			(data|file)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8414
			\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8415
			=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8416
			.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8417
			\.mbm
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8418
			)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8419
			"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8420
script.iFileExts = ["iby", "hby", "oby"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8421
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8422
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8423
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8424
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8425
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8426
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8427
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8428
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8429
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8430
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8431
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8432
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8433
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8434
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8435
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8436
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8437
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8438
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8439
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8440
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8441
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8442
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8443
# unicodesource.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8444
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8445
# Checks : Unicode source files.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8446
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8447
# Reason : Having Unicode source files (CPP, H, RLS, LOC, RSS, and 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8448
# RA) will break most build systems.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8449
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8450
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8451
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8452
script = CScript("unicodesource")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8453
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8454
	^
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8455
	\xFF\xFE	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8456
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8457
script.iFileExts = ["cpp", "h", "rls", "loc", "rss", "ra"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8458
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8459
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8460
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8461
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8462
def unicodesourcecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8463
	return (currentline == 0) and rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8464
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8465
script.iCompare = unicodesourcecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8466
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8467
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8468
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8469
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8470
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8471
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8472
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8473
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8474
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8475
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8476
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8477
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8478
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8479
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8480
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8481
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8482
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8483
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8484
# userafter.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8485
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8486
# Checks : Use of User::After.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8487
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8488
# Reason : Generally, User::After() functions are used to skirt 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8489
# around timing problems. Typically, they should be removed and the 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8490
# defects fixed properly: that is, by waiting for the correct event 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8491
# to continue execution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8492
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8493
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8494
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8495
script = CScript("userafter")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8496
script.iReString = "User::After\s*\("
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8497
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8498
script.iCategory = KCategoryPerformance
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8499
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8500
script.iSeverity = KSeverityMedium
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8501
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8502
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8503
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8504
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8505
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8506
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8507
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8508
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8509
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8510
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8511
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8512
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8513
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8514
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8515
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8516
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8517
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8518
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8519
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8520
# userfree.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8521
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8522
# Checks : Using User::Free directly.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8523
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8524
# Reason : User::Free() should never be called, because all objects 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8525
# free their memory on deletion; their destructors are not called 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8526
# and further resources cannot be freed or closed. This function 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8527
# should be removed and replaced by explicit deletes.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8528
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8529
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8530
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8531
script = CScript("userfree")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8532
script.iReString = "User::Free\s*\("
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8533
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8534
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8535
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8536
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8537
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8538
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8539
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8540
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8541
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8542
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8543
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8544
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8545
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8546
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8547
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8548
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8549
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8550
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8551
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8552
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8553
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8554
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8555
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8556
# userWaitForRequest.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8557
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8558
# Checks : Use of User::WaitForRequest.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8559
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8560
# Reason : User::WaitForRequest() should not generally be used in 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8561
# UI code because the UI will not respond to redraw events while 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8562
# its thread is stopped.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8563
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8564
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8565
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8566
script = CScript("userWaitForRequest")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8567
script.iReString = "User::WaitForRequest\s*\(\s*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8568
script.iFileExts = ["cpp","inl"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8569
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8570
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8571
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8572
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8573
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8574
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8575
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8576
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8577
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8578
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8579
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8580
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8581
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8582
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8583
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8584
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8585
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8586
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8587
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8588
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8589
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8590
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8591
# variablenames.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8592
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8593
# Checks : Local variables with member/argument names.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8594
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8595
# Reason : Local variable names should be of the form localVariable 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8596
# and not aLocalVar or iLocalVar. Badly-named variables can be 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8597
# misleading and cause maintenance and coding errors.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8598
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8599
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8600
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8601
script = CScript("variablenames")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8602
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8603
	^\s*				# start of line plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8604
	[A-Z]\w*			# class name e.g. TInt, CActive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8605
	\s*[\*&\s]\s*		# optional "*" or "&" plus at least one whitespace char
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8606
	[ai][A-Z]\w*\s*		# a or i variable name plus optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8607
	[;\(=]				# ";" or "(" or "="
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8608
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8609
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8610
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8611
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8612
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8613
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8614
def bracecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8615
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8616
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8617
		checkline = currentline - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8618
		bracecount = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8619
		while (bracecount > 0) and (checkline >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8620
			bracecount -= lines[checkline].count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8621
			bracecount += lines[checkline].count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8622
			checkline -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8623
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8624
		while (bracecount == 0) and (checkline >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8625
			if (lines[checkline].upper().find("CLASS") <> -1) or (lines[checkline].upper().find("STRUCT") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8626
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8627
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8628
			bracecount -= lines[checkline].count("{")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8629
			bracecount += lines[checkline].count("}")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8630
			checkline -= 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8631
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8632
		return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8633
	else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8634
		return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8635
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8636
script.iCompare = bracecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8637
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8638
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8639
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8640
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8641
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8642
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8643
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8644
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8645
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8646
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8647
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8648
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8649
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8650
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8651
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8652
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8653
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8654
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8655
# voidparameter.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8656
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8657
# Checks : Void parameter explicitly declared.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8658
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8659
# Reason : Declaring a void parameter is unnecessary. A function 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8660
# declared as DoSomething(void) may as well be declared as 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8661
# DoSomething(). Void casts are also unnecessary.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8662
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8663
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8664
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8665
script = CScript("voidparameter")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8666
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8667
	\(				# opening bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8668
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8669
	void			# void paramater declaration
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8670
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8671
	\)				# closing bracket
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8672
	.*;				# skip to semicolon
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8673
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8674
script.iFileExts = ["h", "cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8675
script.iCategory = KCategoryCodingStandards
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8676
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8677
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8678
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8679
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8680
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8681
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8682
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8683
# All rights reserved.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8684
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8685
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8686
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8687
# * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8688
# * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8689
# * Neither the name of Nokia Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8690
# 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8691
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8692
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8693
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8694
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8695
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8696
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8697
# worryingcomments.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8698
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8699
# Checks : Worrying comments.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8700
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8701
# Reason : Typically, exclamation and question marks in comments 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8702
# indicate that something odd is in the code or that it is 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8703
# unfinished or not understood fully.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8704
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8705
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8706
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8707
script = CScript("worryingcomments")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8708
script.iFileExts = ["h", "cpp", "c"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8709
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8710
script.iIgnore = KIgnoreQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8711
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8712
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8713
reWordsStr = r"""\!|\?|[Zz]{3}|kludge|workaround|\scrap|hack"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8714
scriptNode = script.ScriptConfig()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8715
if (scriptNode <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8716
	for wordNode in scriptNode.getElementsByTagName("worryRE"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8717
		reWordsStr = wordNode.firstChild.nodeValue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8718
		print "Note: 'worrying comments' pattern configured as: " + reWordsStr
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8719
		break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8720
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8721
	/(/|\*)						# "//" or "/*"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8722
	.*("""+reWordsStr+r""")		# skip to "!", "?", "zzz", "kludge", "workaround", " crap" or "hack"
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8723
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8724
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8725
def worryingcommentcodecompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8726
	m = rematch.search(lines[currentline])
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8727
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8728
		line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8729
		i = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8730
		inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8731
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8732
		while i < len(line):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8733
			if not inCommentBlock:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8734
				if (line[i] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8735
					if (line[i + 1] == "/"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8736
						# note i+3 to bypass the character after the start of the comment as can be an in-source documentation directive
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8737
						return (line[i+3:].find("!")<>-1) or (line[i+3:].find("?")<>-1)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8738
					elif (line[i + 1] == "*"):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8739
						inCommentBlock = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8740
						i += 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8741
						continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8742
			else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8743
				endIndex = line[i:].find("*/")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8744
				if (endIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8745
					inCommentBlock = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8746
					# note, that first character is ignored in comments as can be direction to the in-source documentation tool
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8747
					if (line[i+1:i + endIndex + 2].find("!") <> -1) or (line[i+1:i + endIndex + 2].find("?") <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8748
						return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8749
					i += endIndex + 2
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8750
					continue
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8751
				else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8752
					return 1			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8753
			i += 1		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8754
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8755
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8756
script.iCompare = worryingcommentcodecompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8757
scanner.AddScript(script)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8758
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8759
#!PARSE
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8760
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8761
if (scanner.iVerbose):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8762
	scanner.iCategoriedScripts.PrintListOfTestScripts()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8763
	scanner.iRendererManager.PrintListOfRenderers()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8764
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8765
print
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8766
print "Scanning inititated : " + scanner.iStartTime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8767
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8768
if scanner.iInputFilenames <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8769
	scanner.iComponentManager.iUseFullComponentPath = True
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8770
	#additional input files
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8771
	inputFiles = scanner.iInputFilenames.split("::")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8772
	for inputFile in inputFiles:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8773
		if inputFile <> "":
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8774
			ScanDirOrFile(inputFile)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8775
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8776
argument = args[0]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8777
ScanDirOrFile(argument)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8778
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8779
print "Scanning finished   : " + scanner.iEndTime
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8780
scanner.iLog.Close()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8781
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8782
if (scanner.iDomConfig <> None):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8783
	scanner.iDomConfig.unlink()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8784
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
  8785
sys.exit(0)