adlint-exam-c_staging 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,182 @@
1
+ NOARCH_TRAITS = <<EOF
2
+ version: "2.4.0"
3
+
4
+ exam_packages:
5
+ - "c_staging"
6
+
7
+ project_traits:
8
+ project_name: "features"
9
+ project_root: "."
10
+ include_path:
11
+ initial_header: "empty_pinit.h"
12
+ coding_style:
13
+ indent_style: "K&R"
14
+ tab_width: 8
15
+ indent_width: 4
16
+ file_encoding:
17
+
18
+ compiler_traits:
19
+ initial_header: "empty_cinit.h"
20
+ standard_type:
21
+ char_size: 8
22
+ char_alignment: 8
23
+ short_size: 16
24
+ short_alignment: 16
25
+ int_size: 32
26
+ int_alignment: 32
27
+ long_size: 32
28
+ long_alignment: 32
29
+ long_long_size: 64
30
+ long_long_alignment: 64
31
+ float_size: 32
32
+ float_alignment: 32
33
+ double_size: 64
34
+ double_alignment: 64
35
+ long_double_size: 96
36
+ long_double_alignment: 96
37
+ code_ptr_size: 32
38
+ code_ptr_alignment: 32
39
+ data_ptr_size: 32
40
+ data_ptr_alignment: 32
41
+ char_as_unsigned_char: true
42
+ include_path:
43
+ - "."
44
+ arithmetic:
45
+ logical_right_shift: true
46
+ extension_substitution:
47
+ "pascal": ""
48
+ "__pascal": ""
49
+ "fortran": ""
50
+ "__fortran": ""
51
+ "cdecl": ""
52
+ "__cdecl": ""
53
+ "near": ""
54
+ "__near": ""
55
+ "far": ""
56
+ "__far": ""
57
+ "huge": ""
58
+ "__huge": ""
59
+ "__extension__": ""
60
+ "__attribute__(__adlint__any)": ""
61
+ arbitrary_substitution:
62
+ "typeof": "__typeof__"
63
+ "__typeof": "__typeof__"
64
+ "alignof": "__alignof__"
65
+ "__alignof": "__alignof__"
66
+ identifier_max: 128
67
+
68
+ linker_traits:
69
+ identifier_max: 128
70
+ identifier_ignore_case: false
71
+
72
+ message_traits:
73
+ language: "ja_JP"
74
+ message_with_class: false
75
+ warn_files_in:
76
+ - "."
77
+ warn_files_not_in:
78
+ individual_selection: true
79
+ exclusion:
80
+ inclusion:
81
+ change_list:
82
+ EOF
83
+
84
+ DUMMY_STDIO_H = <<EOF
85
+ #if !defined(DUMMY_STDIO_H)
86
+ #define DUMMY_STDIO_H
87
+
88
+ extern int printf(const char *, ...);
89
+ extern int scanf(const char *, ...);
90
+
91
+ typedef int FILE;
92
+ extern FILE *stdin;
93
+ extern FILE *stdout;
94
+ extern FILE *stderr;
95
+
96
+ extern int fprintf(FILE *, const char *, ...);
97
+ extern int fscanf(FILE *, const char *, ...);
98
+
99
+ #endif
100
+ EOF
101
+
102
+ DUMMY_MATH_H = <<EOF
103
+ #if !defined(DUMMY_MATH_H)
104
+ #define DUMMY_MATH_H
105
+ #endif
106
+ EOF
107
+
108
+ DUMMY_ASSERT_H = <<EOF
109
+ #if !defined(DUMMY_ASSERT_H)
110
+ #define DUMMY_ASSERT_H
111
+
112
+ #define assert(expr) (0)
113
+
114
+ #endif
115
+ EOF
116
+
117
+ require "pathname"
118
+
119
+ if ENV["ADLINT_COV"] =~ /1|on|true/
120
+ require "simplecov"
121
+ require "simplecov-html"
122
+ SimpleCov.start
123
+ end
124
+
125
+ $envdir = Pathname.new(__FILE__).realpath.dirname
126
+ $prefix = Pathname.new("../..").expand_path($envdir)
127
+ $bindir = Pathname.new("bin").expand_path($prefix)
128
+ $libdir = Pathname.new("lib").expand_path($prefix)
129
+ $tmpdir = Pathname.new("cucumber-tmp").expand_path($prefix)
130
+
131
+ module Kernel
132
+ def exit(status)
133
+ # NOTE: To avoid terminating cucumber process.
134
+ end
135
+ end
136
+
137
+ def run_adlint(cmd, *args)
138
+ create_adlint_files
139
+ cd_to_tmpdir do
140
+ $all_output = exec(cmd, *args).each_line.map { |line|
141
+ if line =~ /_pinit\.h|_cinit\.h|stdio\.h|math\.h|assert\.h/
142
+ nil
143
+ else
144
+ line.chomp
145
+ end
146
+ }.compact.join("\n")
147
+ end
148
+ end
149
+
150
+ def cd_to_tmpdir(&block)
151
+ orig_wd = Dir.getwd
152
+ Dir.mkdir($tmpdir) unless Dir.exist?($tmpdir)
153
+ Dir.chdir($tmpdir)
154
+ yield
155
+ ensure
156
+ Dir.chdir(orig_wd)
157
+ end
158
+
159
+ def exec(cmd, *args)
160
+ ENV["RUBYLIB"] = "#{$libdir}:#{ENV["RUBYLIB"]}"
161
+ system "#{cmd} #{args.join(" ")} 2>&1 >all_output"
162
+ File.read("all_output")
163
+ end
164
+
165
+ def create_src_file(fpath, content)
166
+ cd_to_tmpdir { create_file(fpath, content) }
167
+ end
168
+
169
+ def create_adlint_files
170
+ cd_to_tmpdir do
171
+ create_file("noarch_traits.yml", NOARCH_TRAITS)
172
+ create_file("empty_pinit.h")
173
+ create_file("empty_cinit.h")
174
+ create_file("stdio.h", DUMMY_STDIO_H)
175
+ create_file("math.h", DUMMY_MATH_H)
176
+ create_file("assert.h", DUMMY_ASSERT_H)
177
+ end
178
+ end
179
+
180
+ def create_file(fname, content = "")
181
+ File.open(fname, "wb") { |io| io.puts content }
182
+ end
@@ -0,0 +1,78 @@
1
+ # Code checkings (cpp-phase) of adlint-exam-c_staging package.
2
+ #
3
+ # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
4
+ # Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
5
+ # License:: GPLv3+: GNU General Public License version 3 or later
6
+ #
7
+ # Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
8
+
9
+ #--
10
+ # ___ ____ __ ___ _________
11
+ # / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
12
+ # / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
13
+ # / __ |/ /_/ / /___/ / /| / / /
14
+ # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
15
+ #
16
+ # This file is part of AdLint.
17
+ #
18
+ # AdLint is free software: you can redistribute it and/or modify it under the
19
+ # terms of the GNU General Public License as published by the Free Software
20
+ # Foundation, either version 3 of the License, or (at your option) any later
21
+ # version.
22
+ #
23
+ # AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
24
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26
+ #
27
+ # You should have received a copy of the GNU General Public License along with
28
+ # AdLint. If not, see <http://www.gnu.org/licenses/>.
29
+ #
30
+ #++
31
+
32
+ module AdLint #:nodoc:
33
+ module Exam #:nodoc:
34
+ module CStaging #:nodoc:
35
+
36
+ class W2001 < PassiveCodeCheck
37
+ def_registrant_phase Cpp::Prepare2Phase
38
+
39
+ def initialize(context)
40
+ super
41
+ interp = context[:cpp_interpreter]
42
+ interp.on_user_header_included += method(:check)
43
+ interp.on_system_header_included += method(:check)
44
+ end
45
+
46
+ private
47
+ def check(include_line, *)
48
+ header_name = include_line.header_name
49
+ if Pathname.new(header_name.value.gsub(/["<>]/, "")).absolute?
50
+ W(:W2001, include_line.location, include_line.fpath)
51
+ end
52
+ end
53
+ end
54
+
55
+ class W2002 < PassiveCodeCheck
56
+ def_registrant_phase Cpp::Prepare2Phase
57
+
58
+ def initialize(context)
59
+ super
60
+ interp = context[:cpp_interpreter]
61
+ interp.on_system_header_included += method(:check)
62
+ @project_root = Traits.instance.of_project.project_root.realpath
63
+ end
64
+
65
+ private
66
+ def check(include_line, *)
67
+ include_line.fpath.realpath.descend do |path|
68
+ if path == @project_root
69
+ W(:W2002, include_line.location, include_line.fpath)
70
+ break
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,56 @@
1
+ # Examination loader of adlint-exam-c_staging package.
2
+ #
3
+ # Author:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
4
+ # Copyright:: Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
5
+ # License:: GPLv3+: GNU General Public License version 3 or later
6
+ #
7
+ # Owner:: Yutaka Yanoh <mailto:yanoh@users.sourceforge.net>
8
+
9
+ #--
10
+ # ___ ____ __ ___ _________
11
+ # / | / _ |/ / / / | / /__ __/ Source Code Static Analyzer
12
+ # / /| | / / / / / / / |/ / / / AdLint - Advanced Lint
13
+ # / __ |/ /_/ / /___/ / /| / / /
14
+ # /_/ |_|_____/_____/_/_/ |_/ /_/ Copyright (C) 2010-2012, OGIS-RI Co.,Ltd.
15
+ #
16
+ # This file is part of AdLint.
17
+ #
18
+ # AdLint is free software: you can redistribute it and/or modify it under the
19
+ # terms of the GNU General Public License as published by the Free Software
20
+ # Foundation, either version 3 of the License, or (at your option) any later
21
+ # version.
22
+ #
23
+ # AdLint is distributed in the hope that it will be useful, but WITHOUT ANY
24
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25
+ # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
26
+ #
27
+ # You should have received a copy of the GNU General Public License along with
28
+ # AdLint. If not, see <http://www.gnu.org/licenses/>.
29
+ #
30
+ #++
31
+
32
+ require "adlint"
33
+
34
+ require "adlint/exam/c_staging/cpp_check"
35
+
36
+ module AdLint #:nodoc:
37
+ module Exam #:nodoc:
38
+ module CStaging #:nodoc:
39
+
40
+ Catalog = ExaminationCatalog.new(__FILE__) do |cat|
41
+ cat.name = "c_staging"
42
+
43
+ cat.major_version = 0
44
+ cat.minor_version = 2
45
+ cat.patch_version = 0
46
+ cat.release_date = "2012-09-21"
47
+
48
+ cat.examination_classes = [
49
+ W2001,
50
+ W2002
51
+ ]
52
+ end
53
+
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adlint-exam-c_staging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yutaka Yanoh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: adlint
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.3.0
30
+ description: ! 'Experimental C language code examination package for AdLint
31
+
32
+ '
33
+ email: yanoh@users.sourceforge.net
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files:
37
+ - README
38
+ files:
39
+ - AUTHORS
40
+ - COPYING
41
+ - ChangeLog
42
+ - INSTALL
43
+ - MANIFEST
44
+ - NEWS
45
+ - README
46
+ - Rakefile
47
+ - TODO
48
+ - etc/mesg.d/c_staging/en_US/messages.yml
49
+ - etc/mesg.d/c_staging/ja_JP/messages.yml
50
+ - features/code_check/W2001.feature
51
+ - features/code_check/W2002.feature
52
+ - features/step_definitions/code_check_steps.rb
53
+ - features/support/env.rb
54
+ - lib/adlint/exam/c_staging.rb
55
+ - lib/adlint/exam/c_staging/cpp_check.rb
56
+ homepage: http://adlint.sourceforge.net/
57
+ licenses:
58
+ - ! 'GPLv3+: GNU General Public License version 3 or later'
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --main
62
+ - README
63
+ - --charset
64
+ - utf-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: 1.9.3
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.24
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Experimental C language code examination package for AdLint
85
+ test_files: []