| 1 | |||
| 2 | # | ||
| 3 | # Interface Definition Language (OMG IDL CORBA v3.0) | ||
| 4 | # | ||
| 5 | |||
| 6 | package CORBA::IDL::UidVisitor; | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | our $VERSION = '2.62'; | ||
| 12 | |||
| 13 | use Digest::SHA1 qw(sha1_hex); | ||
| 14 | |||
| 15 | sub new { | ||
| 16 | my $proto = shift; | ||
| 17 | my $class = ref($proto) || $proto; | ||
| 18 | my $self = {}; | ||
| 19 | bless($self, $class); | ||
| 20 | my ($parser) = @_; | ||
| 21 | $self->{symbtab} = $parser->YYData->{symbtab}; | ||
| 22 | return $self; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub _get_defn { | ||
| 26 | my $self = shift; | ||
| 27 | my ($defn) = @_; | ||
| 28 | if (ref $defn) { | ||
| 29 | return $defn; | ||
| 30 | } | ||
| 31 | else { | ||
| 32 | return $self->{symbtab}->Lookup($defn); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | sub _get_uid { | ||
| 37 | my $self = shift; | ||
| 38 | my ($str) = @_; | ||
| 39 | return uc(substr(sha1_hex($str),0, 16)); | ||
| 40 | } | ||
| 41 | |||
| 42 | # | ||
| 43 | # 3.5 OMG IDL Specification | ||
| 44 | # | ||
| 45 | |||
| 46 | sub visitSpecification { | ||
| 47 | my $self = shift; | ||
| 48 | my ($node) = @_; | ||
| 49 | if (exists $node->{list_import}) { | ||
| 50 | foreach (@{$node->{list_import}}) { | ||
| 51 | $self->_get_defn($_)->visit($self); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | foreach (@{$node->{list_export}}) { | ||
| 55 | $self->_get_defn($_)->visit($self); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | # | ||
| 60 | # 3.6 Import Declaration | ||
| 61 | # | ||
| 62 | |||
| 63 | sub visitImport { | ||
| 64 | my $self = shift; | ||
| 65 | my ($node) = @_; | ||
| 66 | foreach (@{$node->{list_decl}}) { | ||
| 67 | $self->_get_defn($_)->visit($self); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | # | ||
| 72 | # 3.7 Module Declaration | ||
| 73 | # | ||
| 74 | |||
| 75 | sub visitModules { | ||
| 76 | my $self = shift; | ||
| 77 | my ($node) = @_; | ||
| 78 | foreach (@{$node->{list_export}}) { | ||
| 79 | $self->_get_defn($_)->visit($self); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | # | ||
| 84 | # 3.8 Interface Declaration | ||
| 85 | # | ||
| 86 | |||
| 87 | sub visitBaseInterface { | ||
| 88 | my $self = shift; | ||
| 89 | my ($node) = @_; | ||
| 90 | return if (exists $node->{serial_uid}); | ||
| 91 | my $uid_str = $node->{idf}; | ||
| 92 | foreach ($node->getInheritance()) { | ||
| 93 | my $base = $self->_get_defn($_); | ||
| 94 | $uid_str .= $base->{idf} . $base->{serial_uid}; | ||
| 95 | } | ||
| 96 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 97 | foreach (@{$node->{list_export}}) { | ||
| 98 | $self->_get_defn($_)->visit($self); | ||
| 99 | } | ||
| 100 | if (exists $node->{list_member}) { | ||
| 101 | foreach (@{$node->{list_member}}) { | ||
| 102 | my $defn = $self->_get_defn($_); | ||
| 103 | my $type = $self->_get_defn($defn->{type}); | ||
| 104 | $type->visit($self); | ||
| 105 | $uid_str .= $defn->{idf}; | ||
| 106 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 107 | } | ||
| 108 | } | ||
| 109 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 110 | } | ||
| 111 | |||
| 112 | sub visitForwardBaseInterface { | ||
| 113 | # empty | ||
| 114 | } | ||
| 115 | |||
| 116 | # | ||
| 117 | # 3.9 Value Declaration | ||
| 118 | # | ||
| 119 | |||
| 120 | sub visitStateMember { | ||
| 121 | # empty | ||
| 122 | } | ||
| 123 | |||
| 124 | sub visitInitializer { | ||
| 125 | # empty | ||
| 126 | } | ||
| 127 | |||
| 128 | sub visitBoxedValue { | ||
| 129 | my $self = shift; | ||
| 130 | my ($node) = @_; | ||
| 131 | return if (exists $node->{serial_uid}); | ||
| 132 | |||
| 133 | my $type = $self->_get_defn($node->{type}); | ||
| 134 | $type->visit($self); | ||
| 135 | my $uid_str = $node->{idf}; | ||
| 136 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 137 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 138 | } | ||
| 139 | |||
| 140 | # | ||
| 141 | # 3.10 Constant Declaration | ||
| 142 | # | ||
| 143 | |||
| 144 | sub visitConstant { | ||
| 145 | # empty | ||
| 146 | } | ||
| 147 | |||
| 148 | # | ||
| 149 | # 3.11 Type Declaration | ||
| 150 | # | ||
| 151 | |||
| 152 | sub visitTypeDeclarator { | ||
| 153 | my $self = shift; | ||
| 154 | my ($node) = @_; | ||
| 155 | return if (exists $node->{serial_uid}); | ||
| 156 | my $type = $self->_get_defn($node->{type}); | ||
| 157 | $type->visit($self); | ||
| 158 | my $uid_str = $node->{idf}; | ||
| 159 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 160 | if (exists $node->{array_size}) { | ||
| 161 | foreach (@{$node->{array_size}}) { | ||
| 162 | $uid_str .= '[' . $_->{value} . ']'; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 166 | } | ||
| 167 | |||
| 168 | sub visitNativeType { | ||
| 169 | my $self = shift; | ||
| 170 | my ($node) = @_; | ||
| 171 | my $uid_str = $node->{idf}; | ||
| 172 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 173 | } | ||
| 174 | |||
| 175 | # | ||
| 176 | # 3.11.1 Basic Types | ||
| 177 | # | ||
| 178 | |||
| 179 | sub visitBasicType { | ||
| 180 | # empty | ||
| 181 | } | ||
| 182 | |||
| 183 | # | ||
| 184 | # 3.11.2 Constructed Types | ||
| 185 | # | ||
| 186 | # 3.11.2.1 Structures | ||
| 187 | # | ||
| 188 | |||
| 189 | sub visitStructType { | ||
| 190 | my $self = shift; | ||
| 191 | my ($node) = @_; | ||
| 192 | return if (exists $node->{serial_uid}); | ||
| 193 | my $uid_str = $node->{idf}; | ||
| 194 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 195 | foreach (@{$node->{list_member}}) { | ||
| 196 | my $defn = $self->_get_defn($_); | ||
| 197 | my $type = $self->_get_defn($defn->{type}); | ||
| 198 | $type->visit($self); | ||
| 199 | $uid_str .= $defn->{idf}; | ||
| 200 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 201 | if (exists $defn->{array_size}) { | ||
| 202 | foreach (@{$defn->{array_size}}) { | ||
| 203 | $uid_str .= '[' . $_->{value} . ']'; | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 208 | } | ||
| 209 | |||
| 210 | # 3.11.2.2 Discriminated Unions | ||
| 211 | # | ||
| 212 | |||
| 213 | sub visitUnionType { | ||
| 214 | my $self = shift; | ||
| 215 | my ($node) = @_; | ||
| 216 | return if (exists $node->{serial_uid}); | ||
| 217 | $self->_get_defn($node->{type})->visit($self); | ||
| 218 | my $uid_str = $node->{idf}; | ||
| 219 | my $type = $self->_get_defn($node->{type}); | ||
| 220 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 221 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 222 | foreach my $case (@{$node->{list_expr}}) { | ||
| 223 | my $elt = $self->_get_defn($case->{element}); | ||
| 224 | foreach my $label (@{$case->{list_label}}) { | ||
| 225 | if (ref $label eq 'CORBA::IDL::Default') { | ||
| 226 | $uid_str .= '_default_'; | ||
| 227 | } | ||
| 228 | else { | ||
| 229 | if (ref $label->{value} eq 'CORBA::IDL::Enum') { | ||
| 230 | $uid_str .= $label->{value}->{idf}; | ||
| 231 | } | ||
| 232 | else { | ||
| 233 | $uid_str .= $label->{value}; | ||
| 234 | } | ||
| 235 | } | ||
| 236 | } | ||
| 237 | my $defn = $self->_get_defn($elt->{value}); | ||
| 238 | my $type = $self->_get_defn($defn->{type}); | ||
| 239 | $uid_str .= $defn->{idf}; | ||
| 240 | $uid_str .= ($type->{serial_uid} || $type->{value} || q{}); | ||
| 241 | if (exists $defn->{array_size}) { | ||
| 242 | foreach (@{$defn->{array_size}}) { | ||
| 243 | $uid_str .= '[' . $_->{value} . ']'; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | } | ||
| 247 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 248 | } | ||
| 249 | |||
| 250 | # 3.11.2.4 Enumerations | ||
| 251 | # | ||
| 252 | |||
| 253 | sub visitEnumType { | ||
| 254 | my $self = shift; | ||
| 255 | my ($node) = @_; | ||
| 256 | my $uid_str = $node->{idf}; | ||
| 257 | foreach (@{$node->{list_expr}}) { | ||
| 258 | $uid_str .= $_->{idf}; | ||
| 259 | } | ||
| 260 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 261 | } | ||
| 262 | |||
| 263 | # | ||
| 264 | # 3.11.3 Template Types | ||
| 265 | # | ||
| 266 | |||
| 267 | sub visitSequenceType { | ||
| 268 | my $self = shift; | ||
| 269 | my ($node) = @_; | ||
| 270 | return if (exists $node->{serial_uid}); | ||
| 271 | my $type = $self->_get_defn($node->{type}); | ||
| 272 | $type->visit($self); | ||
| 273 | my $uid_str = '_seq_'; | ||
| 274 | $uid_str .= $type->{serial_uid} || $type->{value}; | ||
| 275 | if (exists $node->{max}) { | ||
| 276 | $uid_str .= '_max_' . $node->{max}->{value}; | ||
| 277 | } | ||
| 278 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 279 | } | ||
| 280 | |||
| 281 | sub visitStringType { | ||
| 282 | my $self = shift; | ||
| 283 | my ($node) = @_; | ||
| 284 | my $uid_str = $node->{value}; | ||
| 285 | if (exists $node->{max}) { | ||
| 286 | $uid_str .= '_max_' . $node->{max}->{value}; | ||
| 287 | } | ||
| 288 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 289 | } | ||
| 290 | |||
| 291 | sub visitWideStringType { | ||
| 292 | my $self = shift; | ||
| 293 | my ($node) = @_; | ||
| 294 | my $uid_str = $node->{value}; | ||
| 295 | if (exists $node->{max}) { | ||
| 296 | $uid_str .= '_max_' . $node->{max}->{value}; | ||
| 297 | } | ||
| 298 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 299 | } | ||
| 300 | |||
| 301 | sub visitFixedPtType { | ||
| 302 | my $self = shift; | ||
| 303 | my ($node) = @_; | ||
| 304 | my $uid_str .= '_d_' . $node->{d}->{value}; | ||
| 305 | $uid_str .= '_s_' . $node->{s}->{value}; | ||
| 306 | $node->{serial_uid} = $self->_get_uid($uid_str); | ||
| 307 | } | ||
| 308 | |||
| 309 | # | ||
| 310 | # 3.12 Exception Declaration | ||
| 311 | # | ||
| 312 | |||
| 313 | sub visitException { | ||
| 314 | shift->visitStructType(@_); | ||
| 315 | } | ||
| 316 | |||
| 317 | # | ||
| 318 | # 3.13 Operation Declaration | ||
| 319 | # | ||
| 320 | |||
| 321 | sub visitOperation { | ||
| 322 | # empty | ||
| 323 | } | ||
| 324 | |||
| 325 | # | ||
| 326 | # 3.14 Attribute Declaration | ||
| 327 | # | ||
| 328 | |||
| 329 | sub visitAttribute { | ||
| 330 | # empty | ||
| 331 | } | ||
| 332 | |||
| 333 | # | ||
| 334 | # 3.15 Repository Identity Related Declarations | ||
| 335 | # | ||
| 336 | |||
| 337 | sub visitTypeId { | ||
| 338 | # empty | ||
| 339 | } | ||
| 340 | |||
| 341 | sub visitTypePrefix { | ||
| 342 | # empty | ||
| 343 | } | ||
| 344 | |||
| 345 | # | ||
| 346 | # 3.16 Event Declaration | ||
| 347 | # | ||
| 348 | |||
| 349 | # | ||
| 350 | # 3.17 Component Declaration | ||
| 351 | # | ||
| 352 | |||
| 353 | sub visitProvides { | ||
| 354 | # empty | ||
| 355 | } | ||
| 356 | |||
| 357 | sub visitUses { | ||
| 358 | # empty | ||
| 359 | } | ||
| 360 | |||
| 361 | sub visitPublishes { | ||
| 362 | # empty | ||
| 363 | } | ||
| 364 | |||
| 365 | sub visitEmits { | ||
| 366 | # empty | ||
| 367 | } | ||
| 368 | |||
| 369 | sub visitConsumes { | ||
| 370 | # empty | ||
| 371 | } | ||
| 372 | |||
| 373 | # | ||
| 374 | # 3.18 Home Declaration | ||
| 375 | # | ||
| 376 | |||
| 377 | sub visitFactory { | ||
| 378 | # empty | ||
| 379 | } | ||
| 380 | |||
| 381 | sub visitFinder { | ||
| 382 | # empty | ||
| 383 | } | ||
| 384 | |||
| 385 | 1; | ||
| 386 |