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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 93173 - (show annotations)
Fri Oct 25 16:09:21 2013 UTC (6 years ago) by zurfluhs
File size: 3919 byte(s)
Code Analysis:

- framework redesign (to be continued)
- rule violation output now sorted by class and location
1 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
13 create
14 make
15
16 feature {NONE} -- Initialization
17
18 make
19 -- Initialization for `Current'.
20 do
21 create settings
22 create rules.make
23 -- Adding example rules
24 rules.extend (create {CA_SELF_ASSIGNMENT_RULE}.make)
25 rules.extend (create {CA_UNUSED_ARGUMENT_RULE}.make)
26
27 create classes_to_analyze.make
28 create rule_violations.make (100)
29 end
30
31 feature -- Analysis interface
32
33 analyze
34 local
35 l_rules_checker: CA_ALL_RULES_CHECKER
36 do
37 create l_rules_checker.make
38 across rules as l_rules loop
39 if l_rules.item.is_enabled then -- important: only add enabled rules
40 l_rules.item.prepare_checking (l_rules_checker)
41 end
42 end
43
44 across classes_to_analyze as l_classes loop
45 l_rules_checker.run_on_class (l_classes.item)
46
47 rule_violations.extend (create {SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION]}.make, l_classes.item)
48
49 -- TODO: perhaps replace by more elegant and performant solution
50 across rules as l_rules loop
51 across l_rules.item.violations as l_v loop
52 rule_violations.at (l_classes.item).extend (l_v.item)
53 end
54 l_rules.item.violations.wipe_out
55 end
56 end
57
58 -- analysis_successful := l_rules_checker.last_run_successful
59 -- if analysis_successful then
60 -- rule_violations := l_rules_checker.last_result
61 -- end
62
63 clear_classes_to_analyze
64 ensure
65 violation_list_exists: analysis_successful implies rule_violations /= Void
66 end
67
68 clear_classes_to_analyze
69 do
70 classes_to_analyze.wipe_out
71 end
72
73 add_whole_system
74 local
75 l_groups: LIST [CONF_GROUP]
76 l_cluster: CLUSTER_I
77 do
78 from
79 l_groups := eiffel_universe.groups
80 l_groups.start
81 until
82 l_groups.after
83 loop
84 l_cluster ?= l_groups.item_for_iteration
85 -- Only load top-level clusters, as they are loaded recursively afterwards
86 if l_cluster /= Void and then l_cluster.parent_cluster = Void then
87 add_cluster (l_cluster)
88 end
89 l_groups.forth
90 end
91 end
92
93 add_cluster (a_cluster: CLUSTER_I)
94 local
95 l_conf_class: CONF_CLASS
96 l_class_i: CLASS_I
97 do
98 from
99 a_cluster.classes.start
100 until
101 a_cluster.classes.after
102 loop
103 l_conf_class := a_cluster.classes.item_for_iteration
104 l_class_i := eiffel_universe.class_named (l_conf_class.name, a_cluster)
105 add_class (l_class_i)
106 a_cluster.classes.forth
107 end
108 if a_cluster.sub_clusters /= Void then
109 from
110 a_cluster.sub_clusters.start
111 until
112 a_cluster.sub_clusters.after
113 loop
114 add_cluster (a_cluster.sub_clusters.item_for_iteration)
115 a_cluster.sub_clusters.forth
116 end
117 end
118 end
119
120 add_classes (a_classes: ITERABLE[CLASS_I])
121 do
122 across a_classes as l_classes loop
123 add_class (l_classes.item)
124 end
125 end
126
127 add_class (a_class: CLASS_I)
128 local
129 l_class_c: CLASS_C
130 do
131 if a_class.is_compiled then
132 l_class_c := a_class.compiled_class
133 check l_class_c /= Void end
134 print ("Analyzing class " + a_class.name + "...%N")
135 classes_to_analyze.extend (l_class_c)
136 else
137 print ("Class " + a_class.name + " not compiled (skipped).%N")
138 end
139 end
140
141 feature -- Properties
142
143 analysis_successful: BOOLEAN
144
145 rules: LINKED_LIST[CA_RULE]
146
147 rule_violations: detachable HASH_TABLE[SORTED_TWO_WAY_LIST[CA_RULE_VIOLATION], CLASS_C]
148
149 feature {NONE} -- Implementation
150
151 settings: CA_SETTINGS
152
153 -- analyze_class_if_compiled (a_class: CLASS_I)
154 -- local
155 -- l_class_c: CLASS_C
156 -- do
157 -- if a_class.is_compiled then
158 -- l_class_c := a_class.compiled_class
159 -- check l_class_c /= Void end
160 -- print ("Analyzing class " + a_class.name + "...%N")
161 -- rules_checker.run_on_class (l_class_c.ast)
162 -- else
163 -- print ("Class " + a_class.name + " not compiled (skipped).%N")
164 -- end
165 -- end
166
167 classes_to_analyze: LINKED_SET[CLASS_C]
168
169 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23