/[eiffelstudio]/branches/eth/eve/Src/framework/code_analysis/ca_code_analyzer.e
ViewVC logotype

Annotation of /branches/eth/eve/Src/framework/code_analysis/ca_code_analyzer.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93426 - (hide annotations)
Tue Nov 19 08:45:14 2013 UTC (5 years, 11 months ago) by zurfluhs
File size: 7470 byte(s)
Code Analysis: GUI:

- analysis options in class indexing clauses
  - rules that ignore class
  - library / nonlibrary classes
1 zurfluhs 93168 note
2     description: "Summary description for {CA_CODE_ANALYZER}."
3     author: "Stefan Zurfluh"
4     date: "$Date$"
5     revision: "$Revision$"
6    
7     class
8     CA_CODE_ANALYZER
9    
10     inherit {NONE}
11     SHARED_EIFFEL_PROJECT
12 zurfluhs 93179 CA_SHARED_NAMES
13 zurfluhs 93168
14     create
15     make
16    
17     feature {NONE} -- Initialization
18    
19     make
20     -- Initialization for `Current'.
21     do
22     create settings
23     create rules.make
24     -- Adding example rules
25     rules.extend (create {CA_SELF_ASSIGNMENT_RULE}.make)
26     rules.extend (create {CA_UNUSED_ARGUMENT_RULE}.make)
27 zurfluhs 93216 rules.extend (create {CA_NPATH_RULE}.make)
28     rules.extend (create {CA_EMPTY_IF_RULE}.make)
29 zurfluhs 93299 rules.extend (create {CA_FEATURE_NEVER_CALLED_RULE}.make)
30 zurfluhs 93300 rules.extend (create {CA_CQ_SEPARATION_RULE}.make)
31 zurfluhs 93377
32 zurfluhs 93298 -- Issues (contract violations, exceptions) with {EPA_CFG_BUILDER} and
33     -- classes from library 'program_analysis' in general.
34     -- rules.extend (create {CA_VARIABLE_NOT_READ_RULE}.make)
35 zurfluhs 93173
36     create classes_to_analyze.make
37     create rule_violations.make (100)
38 zurfluhs 93333 create completed_actions
39 zurfluhs 93426
40     create ignoredby.make (25)
41     create library_class.make (25)
42     create nonlibrary_class.make (25)
43 zurfluhs 93168 end
44    
45 zurfluhs 93173 feature -- Analysis interface
46 zurfluhs 93168
47 zurfluhs 93333 add_completed_action (a_action: PROCEDURE [ANY, TUPLE [BOOLEAN] ])
48     do
49     completed_actions.extend (a_action)
50     end
51    
52 zurfluhs 93173 analyze
53 zurfluhs 93333 require
54     not is_running
55 zurfluhs 93168 local
56 zurfluhs 93173 l_rules_checker: CA_ALL_RULES_CHECKER
57 zurfluhs 93389 l_task: CA_RULE_CHECKING_TASK
58 zurfluhs 93168 do
59 zurfluhs 93333 is_running := True
60 zurfluhs 93377 -- TODO: caching
61     rule_violations.wipe_out
62 zurfluhs 93333
63 zurfluhs 93173 create l_rules_checker.make
64 zurfluhs 93168 across rules as l_rules loop
65 zurfluhs 93377 l_rules.item.clear_violations
66 zurfluhs 93168 if l_rules.item.is_enabled then -- important: only add enabled rules
67 zurfluhs 93174 if system_wide_check or else (not l_rules.item.is_system_wide) then
68 zurfluhs 93377 -- do not add system wide rules if we check only parts of the system
69 zurfluhs 93181 if attached {CA_STANDARD_RULE} l_rules.item as l_std_rule then
70 zurfluhs 93426
71 zurfluhs 93181 l_std_rule.prepare_checking (l_rules_checker)
72 zurfluhs 93377 -- TODO: prepare rules of other types?
73 zurfluhs 93181 end
74 zurfluhs 93174 end
75 zurfluhs 93168 end
76     end
77    
78 zurfluhs 93389 create l_task.make (l_rules_checker, rules, classes_to_analyze, agent analysis_completed)
79     rota.run_task (l_task)
80 zurfluhs 93173 end
81    
82     clear_classes_to_analyze
83     do
84     classes_to_analyze.wipe_out
85     end
86    
87     add_whole_system
88     local
89     l_groups: LIST [CONF_GROUP]
90     l_cluster: CLUSTER_I
91     do
92 zurfluhs 93168 from
93     l_groups := eiffel_universe.groups
94     l_groups.start
95     until
96     l_groups.after
97     loop
98     l_cluster ?= l_groups.item_for_iteration
99     -- Only load top-level clusters, as they are loaded recursively afterwards
100     if l_cluster /= Void and then l_cluster.parent_cluster = Void then
101 zurfluhs 93173 add_cluster (l_cluster)
102 zurfluhs 93168 end
103     l_groups.forth
104     end
105 zurfluhs 93174
106     system_wide_check := True
107 zurfluhs 93168 end
108    
109 zurfluhs 93173 add_cluster (a_cluster: CLUSTER_I)
110 zurfluhs 93168 local
111     l_conf_class: CONF_CLASS
112     l_class_i: CLASS_I
113     do
114 zurfluhs 93174 system_wide_check := False
115    
116 zurfluhs 93168 from
117     a_cluster.classes.start
118     until
119     a_cluster.classes.after
120     loop
121     l_conf_class := a_cluster.classes.item_for_iteration
122     l_class_i := eiffel_universe.class_named (l_conf_class.name, a_cluster)
123 zurfluhs 93173 add_class (l_class_i)
124 zurfluhs 93168 a_cluster.classes.forth
125     end
126     if a_cluster.sub_clusters /= Void then
127     from
128     a_cluster.sub_clusters.start
129     until
130     a_cluster.sub_clusters.after
131     loop
132 zurfluhs 93173 add_cluster (a_cluster.sub_clusters.item_for_iteration)
133 zurfluhs 93168 a_cluster.sub_clusters.forth
134     end
135     end
136     end
137    
138 zurfluhs 93333 add_group (a_group: CONF_GROUP)
139     require
140     a_group_not_void: a_group /= Void
141     local
142     l_conf_class: CONF_CLASS
143     l_class_i: CLASS_I
144     do
145     from
146     a_group.classes.start
147     until
148     a_group.classes.after
149     loop
150     l_conf_class := a_group.classes.item_for_iteration
151     l_class_i := eiffel_universe.class_named (l_conf_class.name, a_group)
152     add_class (l_class_i)
153     a_group.classes.forth
154     end
155     end
156    
157 zurfluhs 93173 add_classes (a_classes: ITERABLE[CLASS_I])
158 zurfluhs 93168 do
159 zurfluhs 93174 system_wide_check := False
160    
161 zurfluhs 93173 across a_classes as l_classes loop
162     add_class (l_classes.item)
163     end
164 zurfluhs 93168 end
165    
166 zurfluhs 93173 add_class (a_class: CLASS_I)
167     local
168     l_class_c: CLASS_C
169 zurfluhs 93168 do
170 zurfluhs 93174 system_wide_check := False
171    
172 zurfluhs 93173 if a_class.is_compiled then
173     l_class_c := a_class.compiled_class
174     check l_class_c /= Void end
175     classes_to_analyze.extend (l_class_c)
176 zurfluhs 93426
177     extract_indexes (l_class_c)
178 zurfluhs 93173 else
179     print ("Class " + a_class.name + " not compiled (skipped).%N")
180 zurfluhs 93168 end
181     end
182    
183 zurfluhs 93173 feature -- Properties
184 zurfluhs 93168
185 zurfluhs 93333 is_running: BOOLEAN
186    
187 zurfluhs 93168 analysis_successful: BOOLEAN
188    
189     rules: LINKED_LIST[CA_RULE]
190    
191 zurfluhs 93173 rule_violations: detachable HASH_TABLE[SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION], CLASS_C]
192 zurfluhs 93168
193     feature {NONE} -- Implementation
194    
195 zurfluhs 93389 analysis_completed
196     do
197     across classes_to_analyze as l_classes loop
198     rule_violations.extend (create {SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION]}.make, l_classes.item)
199     end
200    
201     across rules as l_rules loop
202     across l_rules.item.violations as l_v loop
203 zurfluhs 93426 -- check the ignore list
204     if is_violation_valid (l_v.item) then
205     rule_violations.at (l_v.item.affected_class).extend (l_v.item)
206     end
207 zurfluhs 93389 end
208     end
209    
210     clear_classes_to_analyze
211    
212     is_running := False
213     completed_actions.call ([True])
214     completed_actions.wipe_out
215     end
216    
217 zurfluhs 93426 is_violation_valid (a_viol: CA_RULE_VIOLATION): BOOLEAN
218     local
219     l_affected_class: CLASS_C
220     l_rule: CA_RULE
221     do
222     l_affected_class := a_viol.affected_class
223     l_rule := a_viol.rule
224    
225     Result := True
226    
227     if (ignoredby.has (l_affected_class))
228     and then (ignoredby.at (l_affected_class)).has (l_rule.id) then
229     Result := False
230     end
231    
232     if (not l_rule.checks_library_classes) and then library_class.at (l_affected_class) = True then
233     Result := False
234     end
235    
236     if (not l_rule.checks_nonlibrary_classes) and then nonlibrary_class.at (l_affected_class) = True then
237     Result := False
238     end
239     end
240    
241 zurfluhs 93168 settings: CA_SETTINGS
242    
243 zurfluhs 93389 classes_to_analyze: LINKED_SET [CLASS_C]
244 zurfluhs 93168
245 zurfluhs 93174 system_wide_check: BOOLEAN
246    
247 zurfluhs 93389 completed_actions: ACTION_SEQUENCE [TUPLE [BOOLEAN]]
248 zurfluhs 93298
249 zurfluhs 93389 frozen rota: detachable ROTA_S
250     -- Access to rota service
251     local
252     l_service_consumer: SERVICE_CONSUMER [ROTA_S]
253     do
254     create l_service_consumer
255     if l_service_consumer.is_service_available and then l_service_consumer.service.is_interface_usable then
256     Result := l_service_consumer.service
257     end
258     end
259    
260 zurfluhs 93426
261     feature {NONE} -- Class-wide Options (From Indexing Clauses)
262    
263     extract_indexes (a_class: CLASS_C)
264     local
265     l_ast: CLASS_AS
266     l_item: STRING
267     l_ignoredby: LINKED_LIST [STRING]
268     do
269     create l_ignoredby.make
270     l_ignoredby.compare_objects
271     library_class.force (False, a_class)
272     nonlibrary_class.force (False, a_class)
273     l_ast := a_class.ast
274    
275     across l_ast.internal_top_indexes as l_indexes loop
276    
277     if l_indexes.item.tag.name_8.is_equal ("ca_ignoredby") then
278     across l_indexes.item.index_list as l_list loop
279     l_item := l_list.item.string_value_32
280     l_item.prune_all ('%"')
281     l_ignoredby.extend (l_item)
282     end
283     elseif l_indexes.item.tag.name_8.is_equal ("ca_library") then
284     if not l_indexes.item.index_list.is_empty then
285     l_item := l_indexes.item.index_list.first.string_value_32
286     l_item.to_lower
287     l_item.prune_all ('%"')
288     if l_item.is_equal ("true") then
289     library_class.force (True, a_class)
290     elseif l_item.is_equal ("false") then
291     nonlibrary_class.force (True, a_class)
292     end
293     end
294     end
295     end
296    
297     ignoredby.force (l_ignoredby, a_class)
298     end
299    
300     ignoredby: HASH_TABLE [LINKED_LIST [STRING], CLASS_C]
301    
302     library_class, nonlibrary_class: HASH_TABLE [BOOLEAN, CLASS_C]
303    
304     invariant
305     -- law_of_non_contradiction: one class must not be both a library_class and a nonlibrary_class
306    
307 zurfluhs 93168 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23