Add indentation checks for code inside classes and fix appeared issues.

Fix asserts in test_recordset.cpp.

JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-05-26 16:07:25 +03:00
parent cefeea06f6
commit 55b43071d1
4 changed files with 358 additions and 341 deletions
+1
View File
@@ -138,6 +138,7 @@ class rcs_recordset_t
*/ */
static const uint32_t _fields_offset_begin = _type_field_pos + _type_field_width; static const uint32_t _fields_offset_begin = _type_field_pos + _type_field_width;
}; };
private: private:
friend class rcs_record_iterator_t; friend class rcs_record_iterator_t;
+10 -12
View File
@@ -13,8 +13,6 @@
* limitations under the License. * limitations under the License.
*/ */
#include <assert.h>
#include "jrt.h" #include "jrt.h"
#include "mem-allocator.h" #include "mem-allocator.h"
#include "rcs-recordset.h" #include "rcs-recordset.h"
@@ -243,23 +241,23 @@ main (int __attr_unused___ argc,
{ {
if (rand () % 2) if (rand () % 2)
{ {
assert (type_one_records_number < test_sub_iters); JERRY_ASSERT (type_one_records_number < test_sub_iters);
uint32_t elements_count = ((uint32_t) rand ()) % test_max_type_one_record_elements; uint32_t elements_count = ((uint32_t) rand ()) % test_max_type_one_record_elements;
type_one_record_element_counts[type_one_records_number] = elements_count; type_one_record_element_counts[type_one_records_number] = elements_count;
type_one_records[type_one_records_number] = storage.create_record_type_one (elements_count); type_one_records[type_one_records_number] = storage.create_record_type_one (elements_count);
assert (type_one_records[type_one_records_number] != NULL); JERRY_ASSERT (type_one_records[type_one_records_number] != NULL);
type_one_records_number++; type_one_records_number++;
} }
else else
{ {
assert (type_two_records_number < test_sub_iters); JERRY_ASSERT (type_two_records_number < test_sub_iters);
type_two_records[type_two_records_number] = storage.create_record_type_two (); type_two_records[type_two_records_number] = storage.create_record_type_two ();
assert (type_two_records[type_two_records_number] != NULL); JERRY_ASSERT (type_two_records[type_two_records_number] != NULL);
type_two_records_number++; type_two_records_number++;
} }
@@ -271,13 +269,13 @@ main (int __attr_unused___ argc,
if (type_one_records_number == 0) if (type_one_records_number == 0)
{ {
assert (type_two_records_number != 0); JERRY_ASSERT (type_two_records_number != 0);
free_type_one = false; free_type_one = false;
} }
else if (type_two_records_number == 0) else if (type_two_records_number == 0)
{ {
assert (type_one_records_number != 0); JERRY_ASSERT (type_one_records_number != 0);
free_type_one = true; free_type_one = true;
} }
@@ -288,10 +286,10 @@ main (int __attr_unused___ argc,
if (free_type_one) if (free_type_one)
{ {
assert (type_one_records_number > 0); JERRY_ASSERT (type_one_records_number > 0);
int index_to_free = (rand () % type_one_records_number); int index_to_free = (rand () % type_one_records_number);
assert (index_to_free >= 0 && index_to_free < type_one_records_number); JERRY_ASSERT (index_to_free >= 0 && index_to_free < type_one_records_number);
storage.free_record_type_one (type_one_records[index_to_free]); storage.free_record_type_one (type_one_records[index_to_free]);
@@ -306,10 +304,10 @@ main (int __attr_unused___ argc,
} }
else else
{ {
assert (type_two_records_number > 0); JERRY_ASSERT (type_two_records_number > 0);
int index_to_free = (rand () % type_two_records_number); int index_to_free = (rand () % type_two_records_number);
assert (index_to_free >= 0 && index_to_free < type_two_records_number); JERRY_ASSERT (index_to_free >= 0 && index_to_free < type_two_records_number);
storage.free_record_type_two (type_two_records[index_to_free]); storage.free_record_type_two (type_two_records[index_to_free]);
@@ -22,7 +22,9 @@ foreach fileName [getSourceFileNames] {
set is_in_comment "no" set is_in_comment "no"
set is_in_pp_define "no" set is_in_pp_define "no"
set is_in_class "no" set is_in_class "no"
set is_in_template "no"
set parentheses_level 0 set parentheses_level 0
set template_brackets_level 0
foreach token [getTokens $fileName 1 0 -1 -1 {}] { foreach token [getTokens $fileName 1 0 -1 -1 {}] {
set type [lindex $token 3] set type [lindex $token 3]
@@ -36,6 +38,8 @@ foreach fileName [getSourceFileNames] {
set is_in_pp_define "no" set is_in_pp_define "no"
} elseif {$type == "class"} { } elseif {$type == "class"} {
set is_in_class "yes" set is_in_class "yes"
} elseif {$type == "template"} {
set is_in_template "yes"
} elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} { } elseif {$is_in_class == "yes" && $type == "semicolon" && $indent == 0} {
set is_in_class "no" set is_in_class "no"
} elseif {$type == "ccomment"} { } elseif {$type == "ccomment"} {
@@ -52,17 +56,20 @@ foreach fileName [getSourceFileNames] {
incr indent -2 incr indent -2
} }
if {$is_in_pp_define == "no" && $is_in_comment == "no" && $is_in_class == "no" && $parentheses_level == 0} { if {$is_in_pp_define == "no" && $is_in_comment == "no" && $parentheses_level == 0 &&
$is_in_template == "no"} {
set line [getLine $fileName $lineNumber] set line [getLine $fileName $lineNumber]
if {$lineNumber != $lastCheckedLineNumber} { if {$lineNumber != $lastCheckedLineNumber} {
if {[string length $line] == 0} {
}
if {[regexp {^[[:blank:]]*} $line match]} { if {[regexp {^[[:blank:]]*} $line match]} {
set real_indent [string length $match] set real_indent [string length $match]
if {$indent != $real_indent} { if {$indent != $real_indent} {
if {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} { if {[regexp {^[[:blank:]]*(private:|public:|protected:)} $line]} {
if {$indent != $real_indent + 2} {
set exp_indent [expr {$indent - 2}]
report $fileName $lineNumber "Indentation: $real_indent -> $exp_indent. Line: '$line'"
}
} elseif {![regexp {^[[:alnum:]_]{1,}:$} $line] || $real_indent != 0} {
report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'" report $fileName $lineNumber "Indentation: $real_indent -> $indent. Line: '$line'"
} }
} }
@@ -84,7 +91,7 @@ foreach fileName [getSourceFileNames] {
} }
} }
if {$type == "rightbrace"} { if {$type == "rightbrace"} {
if {![regexp {^[[:blank:]]*\}((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line] if {![regexp {^[[:blank:]]*\};?((( [a-z_\(][a-z0-9_\(\)]{0,}){1,})?;| /\*.*\*/| //.*)?$} $line]
&& ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} { && ![regexp {[^\{=]=[^\{=]\{.*\}[,;]?} $line]} {
report $fileName $lineNumber "Right brace is not the only non-space character in the line and \ report $fileName $lineNumber "Right brace is not the only non-space character in the line and \
is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'" is not single right brace followed by \[a-z0-9_() \] string and single semicolon character: '$line'"
@@ -100,6 +107,17 @@ foreach fileName [getSourceFileNames] {
incr parentheses_level -1 incr parentheses_level -1
} }
if {$is_in_template == "yes"} {
if {$type == "less"} {
incr template_brackets_level
} elseif {$type == "greater"} {
incr template_brackets_level -1
if {$template_brackets_level == 0} {
set is_in_template "no"
}
}
}
set lastCheckedLineNumber $lineNumber set lastCheckedLineNumber $lineNumber
} }
} }