srcanamdw/codescanner/scripts/forgottoputptroncleanupstack.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
# forgottoputptroncleanupstack.py
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    18
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    19
# Checks : Neglected to put variable on cleanup stack.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    20
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    21
# Reason : If a variable is not put on the cleanup stack and a 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    22
# leaving function or ELeave is called, a memory leak occurs. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    23
# CodeScanner occasionally gives false positives for this issue. 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    24
# Individual cases should be investigated.
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    25
#
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    26
# #################################################################
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    27
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    28
script = CScript("forgottoputptroncleanupstack")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    29
script.iReString = r"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    30
	\s+				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    31
	[b-hj-z]+		# must not be a member or parameter
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    32
	[A-Za-z0-9]+	# variable name
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    33
	\s*				# optional whitespace
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    34
	=				# assignment operator
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    35
	"""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    36
script.iFileExts = ["cpp"]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    37
script.iCategory = KCategoryCodeReviewGuides
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    38
script.iIgnore = KIgnoreCommentsAndQuotes
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    39
script.iSeverity = KSeverityLow
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    40
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    41
forgottoputptroncleanupstackCleanup = re.compile("""Cleanup""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    42
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    43
forgottoputptroncleanupstackDeleteOp = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    44
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    45
	delete
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    46
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    47
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    48
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    49
forgottoputptroncleanupstackReturnCmd = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    50
	(\s*|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    51
	return
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    52
	(\s*|\()
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    53
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    54
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    55
forgottoputptroncleanupstackSetFn = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    56
	Set
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    57
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    58
	[A-KM-Za-z0-9]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    59
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    60
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    61
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    62
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    63
forgottoputptroncleanupstackBreak = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    64
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    65
	break
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    66
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    67
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    68
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    69
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    70
forgottoputptroncleanupstackIf = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    71
	\s+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    72
	if
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    73
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    74
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    75
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    76
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    77
forgottoputptroncleanupstackElse = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    78
	\}*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    79
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    80
	else
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    81
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    82
	\{*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    83
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    84
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    85
forgottoputptroncleanupstackAssignToMember = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    86
	i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    87
	[A-Za-z0-9\[\]]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    88
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    89
	=
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    90
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    91
	.*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    92
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    93
	;
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    94
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    95
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    96
forgottoputptroncleanupstackTrapMacro = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    97
	TRAP
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    98
	[D]*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
    99
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   100
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   101
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   102
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   103
forgottoputptroncleanupstackLeavingFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   104
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   105
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   106
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   107
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   108
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   109
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   110
forgottoputptroncleanupstackLeave = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   111
	User::Leave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   112
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   113
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   114
forgottoputptroncleanupstackLeaveAndDelete = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   115
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   116
	[D]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   117
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   118
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   119
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   120
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   121
forgottoputptroncleanupstackNewOperator = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   122
	new
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   123
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   124
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   125
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   126
	ELeave
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   127
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   128
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   129
forgottoputptroncleanupstackNewFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   130
	::NewL
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   131
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   132
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   133
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   134
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   135
forgottoputptroncleanupstackCreateFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   136
	Create
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   137
	[A-Za-z0-9]+
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   138
	L
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   139
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   140
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   141
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   142
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   143
forgottoputptroncleanupstackAllocFunction = re.compile("""
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   144
	Alloc
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   145
	L*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   146
	\s*
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   147
	\(
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   148
	""", re.VERBOSE)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   149
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   150
def findForgetCompare(lines, currentline, rematch, filename):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   151
	line = lines[currentline]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   152
	m = rematch.search(line)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   153
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   154
	if m:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   155
		foundNew = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   156
		equalPos = line.find("=")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   157
		assignedSection = line[equalPos:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   158
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   159
		if forgottoputptroncleanupstackNewFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   160
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   161
		if forgottoputptroncleanupstackNewOperator.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   162
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   163
		if forgottoputptroncleanupstackAllocFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   164
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   165
		if forgottoputptroncleanupstackCreateFunction.search(assignedSection):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   166
			foundNew = 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   167
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   168
		# if this line contains a 'new', a 'NewL(', or an 'AllocL('
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   169
		if (foundNew == 1):	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   170
			i = currentline
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   171
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   172
		# move to next line ending if this line doesn't contain one
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   173
			while (lines[i].find(';') == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   174
				i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   175
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   176
		# go to next line
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   177
			i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   178
			bracketdepth = GetBracketDepth(lines, i)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   179
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   180
		# get the variable name, between the '*' and the '='
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   181
			startindex = line.find("*")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   182
			if (startindex == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   183
				startindex = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   184
			endindex = line.find("=")
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   185
			variable = line[startindex+1:endindex]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   186
			if (len(variable) < 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   187
				return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   188
			variable = TrimVariableName(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   189
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   190
			inAnIfOrSelectStatement = 1 # possibly
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   191
			
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   192
			while (i < len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   193
				line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   194
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   195
				if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   196
					bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   197
				if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   198
					bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   199
					inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   200
					if (bracketdepth == 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   201
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   202
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   203
				varIndex = line2.find(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   204
		# if a later line contains the variable...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   205
				while (varIndex <> -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   206
					if (isNonAlpha(line2[varIndex-1])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   207
						if (isNonAlpha(line2[varIndex+len(variable)])):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   208
		# ...and delete, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   209
							if forgottoputptroncleanupstackDeleteOp.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   210
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   211
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   212
		# ...and an xxxLD() function, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   213
							if forgottoputptroncleanupstackLeaveAndDelete.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   214
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   215
							
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   216
		# ...and the variable is assigned to a member variable, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   217
							if forgottoputptroncleanupstackAssignToMember.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   218
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   219
		
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   220
		# ...and it is a Set...() call, exit (e.g. SetArray, SetAppUi)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   221
							if forgottoputptroncleanupstackSetFn.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   222
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   223
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   224
		# ...and a return command, exit 
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   225
							if forgottoputptroncleanupstackReturnCmd.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   226
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   227
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   228
		# search this line again incase there are similarly named variables
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   229
					line2 = line2[varIndex+1:]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   230
					varIndex = line2.find(variable)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   231
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   232
				line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   233
		# if a leaving function is called...
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   234
				if forgottoputptroncleanupstackLeavingFunction.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   235
		# ...if the leaving function is trapped, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   236
					if forgottoputptroncleanupstackTrapMacro.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   237
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   238
		# ...if a Cleanup function is called, exit
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   239
					if forgottoputptroncleanupstackCleanup.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   240
						return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   241
		# ...otherwise this is a problem!
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   242
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   243
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   244
		# if a User::Leave is called, this is a problem
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   245
				if forgottoputptroncleanupstackLeave.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   246
					return 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   247
	
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   248
		# 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
   249
				if (inAnIfOrSelectStatement == 1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   250
					if forgottoputptroncleanupstackBreak.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   251
						atLine = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   252
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   253
						findSwitch = i
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   254
						line3 = lines[findSwitch]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   255
						while (line3.find("switch") == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   256
							findSwitch = findSwitch - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   257
							if (findSwitch <= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   258
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   259
							line3 = lines[findSwitch]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   260
						switchBracketDepth = GetBracketDepth(lines, findSwitch)
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   261
						i = atLine
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   262
						while (bracketdepth > switchBracketDepth):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   263
							if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   264
								return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   265
							line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   266
							if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   267
								bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   268
							if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   269
								bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   270
							i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   271
							
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   272
					if forgottoputptroncleanupstackElse.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   273
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   274
						elseBracketDepth = bracketdepth
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   275
						if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   276
							elseBracketDepth = elseBracketDepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   277
						if (elseBracketDepth == GetBracketDepth(lines, currentline)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   278
							while (line2.find(';') == -1):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   279
								i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   280
								if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   281
									return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   282
								line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   283
						else:
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   284
							while (bracketdepth > elseBracketDepth):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   285
								i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   286
								if (i >= len(lines)):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   287
									return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   288
								line2 = lines[i]
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   289
								if (line2.find('{') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   290
									bracketdepth = bracketdepth + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   291
								if (line2.find('}') >= 0):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   292
									bracketdepth = bracketdepth - 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   293
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   294
					if forgottoputptroncleanupstackIf.search(line2):
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   295
						inAnIfOrSelectStatement = 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   296
				i = i + 1
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   297
			return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   298
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   299
	return 0
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   300
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   301
script.iCompare	= findForgetCompare
22878952f6e2 Committing the CodeScanner Core tool
noe\swadi
parents:
diff changeset
   302
scanner.AddScript(script)