| 1 |
#!@perl_exec@ |
| 2 |
|
| 3 |
# PCE2 - Perl C++ Extractor version 2 |
| 4 |
# Copyright 2000-1999, Karl Nelson <[email protected]> |
| 5 |
# Copyright 1997, Mark Peskin <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by the |
| 9 |
# Free Software Foundation; either version 2 of the License, or (at your |
| 10 |
# option) any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 14 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 |
# for more details. |
| 16 |
|
| 17 |
# |
| 18 |
# Credits: |
| 19 |
# Mark Peskin - original percep extractor |
| 20 |
# Karl Nelson - rewrite of extractor, added OO tree views. |
| 21 |
# Dave Smith - xml dump |
| 22 |
# Mark Page - added file_unique_string and file_global_string option |
| 23 |
# |
| 24 |
|
| 25 |
# TODO: |
| 26 |
# add reporting functions |
| 27 |
# enums |
| 28 |
# improve plugins |
| 29 |
# add command line interface |
| 30 |
|
| 31 |
# This file is divided into 3 sections. |
| 32 |
# |
| 33 |
# 1.0 Extraction - Lexer and parser to extract the C++ headers |
| 34 |
# 2.0 Plugin - System for adding user defined code |
| 35 |
# 3.0 Symbol Tree - Perl classes representing extracted code. |
| 36 |
# |
| 37 |
|
| 38 |
# |
| 39 |
# usage: pce2 [options] files |
| 40 |
# |
| 41 |
|
| 42 |
####################################################################### |
| 43 |
##### 0.0 Global defines |
| 44 |
####################################################################### |
| 45 |
$Enum::NONE=0; |
| 46 |
|
| 47 |
@Enum::ACCESS_NAMES=("none","public","protected","private"); |
| 48 |
$Enum::PUBLIC=1; |
| 49 |
$Enum::PROTECTED=2; |
| 50 |
$Enum::PRIVATE=3; |
| 51 |
|
| 52 |
|
| 53 |
@Enum::TYPE_NAMES=("none","namespace","class","struct","union", |
| 54 |
"function","variable","typedef","friend","macro"); |
| 55 |
@Enum::TYPE_NAMES_=("none","namespaces","classes","structs","unions", |
| 56 |
"functions","variables","typedefs","friends","macros"); |
| 57 |
|
| 58 |
$Enum::NAMESPACE=1; |
| 59 |
$Enum::CLASS=2; |
| 60 |
$Enum::STRUCT=3; |
| 61 |
$Enum::UNION=4; |
| 62 |
$Enum::FUNCTION=5; |
| 63 |
$Enum::VARIABLE=6; |
| 64 |
$Enum::TYPEDEF=7; |
| 65 |
$Enum::FRIEND=8; |
| 66 |
$Enum::MACRO=9; |
| 67 |
|
| 68 |
$Enum::SYM="[A-Za-z_][A-Za-z0-9_]*"; |
| 69 |
|
| 70 |
$Html::COMMENT="<tt><font color=maroon><i>"; |
| 71 |
$Html::COMMENT_="</i></font></tt>"; |
| 72 |
|
| 73 |
$Html::BOLD="<b>"; |
| 74 |
$Html::BOLD_="</b>"; |
| 75 |
$Html::ITAL="<i>"; |
| 76 |
$Html::ITAL_="</i>"; |
| 77 |
|
| 78 |
$Html::STRING="<tt><font color=green><i>"; |
| 79 |
$Html::STRING_="</i></font></tt>"; |
| 80 |
$Html::KEYWORD="<tt><font color=black><b>"; |
| 81 |
$Html::KEYWORD_="</b></font></tt>"; |
| 82 |
$Html::FUNCTION="<tt><font color=blue><b>"; |
| 83 |
$Html::FUNCTION_="</b></font></tt>"; |
| 84 |
$Html::TYPE="<tt><font color=navy>"; |
| 85 |
$Html::TYPE_="</font></tt>"; |
| 86 |
$Html::VARIABLE="<tt><font color=blue>"; |
| 87 |
$Html::VARIABLE_="</font></tt>"; |
| 88 |
$Html::CLASS="<tt><font color=navy><b>"; |
| 89 |
$Html::CLASS_="</b></font></tt>"; |
| 90 |
$Html::ENUM="<tt><font color=green>"; |
| 91 |
$Html::ENUM_="</font></tt>"; |
| 92 |
$Html::NAMESPACE="<tt><font color=navy><b>"; |
| 93 |
$Html::NAMESPACE_="</b></font></tt>"; |
| 94 |
$Html::INTRENSIC="<tt><font color=purple>"; |
| 95 |
$Html::INTRENSIC_="</font></tt>"; |
| 96 |
$Html::SPECIFIER="<tt>"; |
| 97 |
$Html::SPECIFIER_="</tt>"; |
| 98 |
|
| 99 |
# hash tables for syntax highlighting (use init.plg to add to these) |
| 100 |
@Html::intrensics=("void","bool","char","int","float","double"); |
| 101 |
@Html::specifiers=("inline","register","auto","virtual","const","static"); |
| 102 |
|
| 103 |
####################################################################### |
| 104 |
##### 0.1 Command line and Main |
| 105 |
####################################################################### |
| 106 |
# |
| 107 |
# GLOBALS: |
| 108 |
# &PROCESS |
| 109 |
# &PLUGIN |
| 110 |
# $global - namespace for all extracted symbols |
| 111 |
# $unknown - namespace for extrapolated symbols |
| 112 |
# |
| 113 |
package main; |
| 114 |
use strict; |
| 115 |
|
| 116 |
$::debug=0; |
| 117 |
$::verbose=1; |
| 118 |
$::ws_verbose=1; |
| 119 |
$::report_xml=0; |
| 120 |
|
| 121 |
&parseArgs(@ARGV); |
| 122 |
|
| 123 |
$::global=Namespace::new("",""); |
| 124 |
$::anonymous=Namespace::new("",""); |
| 125 |
$::unknown=Namespace::new("",""); |
| 126 |
|
| 127 |
my $output_plugin="output"; |
| 128 |
my @filelist; |
| 129 |
my @suffixes=("h","H","hh"); |
| 130 |
my $buffer; |
| 131 |
my $file_unique_string; |
| 132 |
my $file_global_string = ""; |
| 133 |
|
| 134 |
&EXEC(); |
| 135 |
exit; |
| 136 |
|
| 137 |
################################################## |
| 138 |
### EXEC |
| 139 |
sub EXEC { |
| 140 |
my $buffer; |
| 141 |
my $file; |
| 142 |
|
| 143 |
&PLUGIN("init"); |
| 144 |
|
| •145 |
foreach $file (sort @filelist) { |
| 146 |
$buffer=""; |
| 147 |
print "Reading $file\n" if ($::verbose); |
| 148 |
$::currentfile=$file; |
| 149 |
$::currentfile=~s/^.*\///g; |
| 150 |
|
| 151 |
open(INPUT,"<$file"); |
| 152 |
while(<INPUT>) { $buffer.=$_; } |
| 153 |
close(INPUT); |
| 154 |
|
| 155 |
$buffer=&PLUGIN("input",$buffer); |
| 156 |
|
| 157 |
&Extract::process($buffer); |
| 158 |
} |
| 159 |
|
| 160 |
&Extract::crossRef($::global); |
| 161 |
&Extract::crossArgs($::global); |
| 162 |
&Extract::markup($::global); |
| 163 |
|
| 164 |
&PLUGIN($output_plugin,$::global); |
| 165 |
&XML if ($::report_xml); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
################################################## |
| 170 |
### parseArgs |
| 171 |
sub parseArgs { |
| 172 |
my $arg; |
| 173 |
print "Parsing Command Line\n" if $::debug; |
| 174 |
while (@_) { |
| 175 |
$arg=shift; |
| 176 |
if ( $arg=~/^--(.*)/) { |
| 177 |
if ($1 eq "help") { |
| 178 |
USAGE(); |
| 179 |
} |
| 180 |
elsif ($1 eq "plgdir") { |
| 181 |
unshift(@Plugin::directory_,shift @_); |
| 182 |
} |
| 183 |
elsif ($1 eq "xml") { |
| 184 |
$::report_xml=1; |
| 185 |
$::verbose=0; |
| 186 |
} |
| 187 |
elsif ($1 eq "output") { |
| 188 |
$output_plugin=shift; |
| 189 |
# print STDERR "USING $output_plugin\n" if ($::debug); |
| 190 |
} |
| 191 |
else { |
| 192 |
print STDERR "Unknown argument --$1\n"; |
| 193 |
exit; |
| 194 |
} |
| 195 |
} |
| 196 |
else |
| 197 |
{ |
| 198 |
if ( -d $arg ) { |
| 199 |
my $entry; |
| 200 |
my $str; |
| 201 |
|
| 202 |
$str='\.(('; |
| 203 |
$str.=join(")|(",@suffixes); |
| 204 |
$str.='))$'; |
| 205 |
|
| 206 |
opendir(DIR,"$arg"); |
| 207 |
foreach $entry (sort readdir(DIR)) { |
| 208 |
push (@filelist,"$arg/$entry") if ( $entry =~ /$str/) ; |
| 209 |
} |
| 210 |
} |
| 211 |
else { |
| 212 |
push(@filelist,$arg); |
| 213 |
} |
| 214 |
} |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
sub XML { |
| 219 |
print "<?xml version=\"1.0\"?>\n"; |
| 220 |
print "<global>\n"; |
| 221 |
$::global->dump_xml(); |
| 222 |
print "</global>\n"; |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
####################################################################### |
| 228 |
##### 1.0 Code Extractor |
| 229 |
####################################################################### |
| 230 |
package Extract; |
| 231 |
use strict; |
| 232 |
|
| 233 |
################################################## |
| 234 |
### process |
| 235 |
sub process { |
| 236 |
my ($buffer)=@_; |
| 237 |
|
| 238 |
$file_unique_string=""; |
| 239 |
|
| 240 |
$buffer=&prep($buffer); |
| 241 |
|
| 242 |
&parse($::global,$buffer); |
| 243 |
|
| 244 |
return $::global; |
| 245 |
} |
| 246 |
|
| 247 |
################################################## |
| 248 |
### Typedef |
| 249 |
sub parse { |
| 250 |
my($env,$buffer)=@_; |
| 251 |
|
| 252 |
my $line; |
| 253 |
my(@lines)=split(/\n|([}{;])/,$buffer); # lines to be processed |
| 254 |
|
| 255 |
my $block=""; |
| 256 |
my($comments); # comments collected before a block |
| 257 |
my($macro_data)=""; # macro string collected |
| 258 |
my($process)=0; # indicates time to process block |
| 259 |
my($inblock)=0; # indicates block start found |
| 260 |
my($bcount)=0; |
| 261 |
my($isdef)=0; |
| 262 |
my($needsemi)=0; |
| 263 |
my($gcomments); |
| 264 |
|
| 265 |
# |
| 266 |
# Process File |
| 267 |
# (line by line) |
| 268 |
|
| 269 |
while (@lines) { |
| 270 |
$_=shift @lines; |
| 271 |
# print STDERR "Processing \"$_\"\n"; |
| 272 |
|
| 273 |
# |
| 274 |
# main statement blocks |
| 275 |
# |
| 276 |
|
| 277 |
# collect up comments for later |
| 278 |
if (/^\s*\/\/(.*)$/) { |
| 279 |
if ($bcount<1) { |
| 280 |
$gcomments=&unmask($1); |
| 281 |
if (/^\s*\/\/! /) { |
| 282 |
# Append the Name=Variable, removing duplicates |
| 283 |
my $current_name; |
| 284 |
my $current_value; |
| 285 |
my $this_name; |
| 286 |
my $this_value; |
| 287 |
($this_name, $this_value) = split(/=/, $gcomments); |
| 288 |
# If no equals sign is provided - assume the name is "c=" |
| 289 |
if ($this_value eq "") |
| 290 |
{ |
| 291 |
$this_value = substr($this_name, 2); |
| 292 |
$this_name = "! c"; |
| 293 |
} |
| 294 |
# Check for a global string |
| 295 |
if ($this_name eq "! Global") |
| 296 |
{ |
| 297 |
$file_global_string = "${file_global_string}! ${this_value}\n$comments"; |
| 298 |
$comments = ""; |
| 299 |
}else |
| 300 |
{ |
| 301 |
my $old_global_string = $file_unique_string; |
| 302 |
$file_unique_string = ""; |
| 303 |
# Do the unique string |
| 304 |
foreach (split("\n",$old_global_string)) { |
| 305 |
/(.*)$/; |
| 306 |
($current_name, $current_value)=split(/=/, $1); |
| 307 |
if ($current_name ne $this_name) |
| 308 |
{ |
| 309 |
$file_unique_string = "$file_unique_string$current_name=$current_value\n"; |
| 310 |
} |
| 311 |
} |
| 312 |
$file_unique_string = "$file_unique_string$this_name=$this_value\n"; |
| 313 |
} |
| 314 |
}else |
| 315 |
{ |
| 316 |
$comments.=$gcomments; |
| 317 |
$comments.="\n"; |
| 318 |
} |
| 319 |
} |
| 320 |
else { |
| 321 |
$block.="$_\n"; |
| 322 |
} |
| 323 |
next; |
| 324 |
} |
| 325 |
|
| 326 |
# push back comments not starting line |
| 327 |
if (/^(.+)\s*(\/\/.*)$/) { |
| 328 |
unshift(@lines,$2); |
| 329 |
$_=$1; |
| 330 |
} |
| 331 |
|
| 332 |
if (!$inblock) { |
| 333 |
if (/^\s*(public|protected|private):(.*)$/) { |
| 334 |
$_=$2; |
| 335 |
$env->set_public() if ($1 eq "public"); |
| 336 |
$env->set_private() if ($1 eq "private"); |
| 337 |
$env->set_protected() if ($1 eq "protected"); |
| 338 |
} |
| 339 |
|
| 340 |
# break up lines with access declarations |
| 341 |
if (/^(.*)(public:|protected:|private:)(.*)$/) { |
| 342 |
unshift(@lines,$2); |
| 343 |
unshift(@lines,$3); |
| 344 |
$_=$1; |
| 345 |
} |
| 346 |
|
| 347 |
next if ($_ eq ";" ); # dump extra ; |
| 348 |
next if (/^\s*$/); |
| 349 |
|
| 350 |
# handle macros |
| 351 |
if (/^\#/ || $macro_data) { |
| 352 |
$macro_data.=$_; |
| 353 |
if (!s/\\$//) { |
| 354 |
# why do we process the macro only if there are comments? |
| 355 |
&procMacro($macro_data) if ($comments); |
| 356 |
$comments=""; |
| 357 |
$macro_data=""; |
| 358 |
} |
| 359 |
next; |
| 360 |
} |
| 361 |
|
| 362 |
# We are entering a code block |
| 363 |
$inblock=1; |
| 364 |
$isdef=0; |
| 365 |
$inblock=1; |
| 366 |
$bcount=0; |
| 367 |
|
| 368 |
$needsemi=1 if (/^(class|struct|union|enum)/); |
| 369 |
} |
| 370 |
|
| 371 |
# we must be in a block |
| 372 |
if ( $_ eq "{" ) { |
| 373 |
$bcount++; |
| 374 |
$isdef=1; |
| 375 |
} |
| 376 |
|
| 377 |
if ( $_ eq "}" ) { |
| 378 |
$bcount--; |
| 379 |
$_="} << $needsemi $isdef " if ($bcount == 0); |
| 380 |
} |
| 381 |
|
| 382 |
$process=1 if ( $bcount<1 && /^;/ ); |
| 383 |
$process=1 if ( $bcount<1 && !$needsemi && $isdef ); |
| 384 |
|
| 385 |
if ($bcount) |
| 386 |
{ $block.="$_\n";} |
| 387 |
else |
| 388 |
{ $block.="$_ ";} |
| 389 |
|
| 390 |
# |
| 391 |
# Examine extracted statement blocks: Determine type and process appropriately |
| 392 |
# |
| 393 |
if ($process) { |
| 394 |
|
| 395 |
# print STDERR "PROCESS\n"; |
| 396 |
if ($block=~/^\s*template(\s|<)/) |
| 397 |
{&procTemplate($env,$block,$comments);} |
| 398 |
elsif ($block=~/^\s*(class|struct|union)\s/) |
| 399 |
{&procClass($env,$block,$comments);} |
| 400 |
elsif ($block=~/^\s*namespace/) |
| 401 |
{&procNamespace($env,$block,$comments);} |
| 402 |
elsif ($block=~/^\s*extern %%QUOTDC%%QUOTD/) |
| 403 |
{&procExtern($env,$block,$comments);} |
| 404 |
elsif ($block=~/^\s*using\s/) |
| 405 |
{} # we don't track using |
| 406 |
elsif ($block=~/^\s*friend\s/) |
| 407 |
{&procFriend($env,$block,$comments);} |
| 408 |
elsif ($block=~/^\s*enum/) |
| 409 |
{&procEnum($env,$block,$comments);} |
| 410 |
elsif ($block=~/^\s*typedef/) |
| 411 |
{&procDef($env,$block,$comments);} |
| 412 |
elsif ($block=~/^\s*([\w<>:\,\s\*&]*[\w<>:\*&]\s[\s\*&]*)(\S+|operator\s*\S+)\s*\(([^\{\)]*)\)\s*(const|)/) |
| 413 |
{&procFunc($env,$block,$comments);} |
| 414 |
elsif ($block=~/^\s*(\S+|operator\s*\S+)\s*\(([^\{\)]*)\)\s*(const|)/) |
| 415 |
{&procFunc($env,$block,$comments);} |
| 416 |
elsif ($block=~/^\s*([\w<>:\,\s\*&]*[\w<>:\*&]\s[\s\*&]*)(\w[\w\s:\[\]]*)\s*\=*\s*\S*\s*([,;])/) |
| 417 |
{&procVar($env,$block,$comments);} |
| 418 |
else |
| 419 |
{ print STDERR "UNKNOWN: >>$block<<\n"; } |
| 420 |
|
| 421 |
$process=0; |
| 422 |
$bcount=0; |
| 423 |
$block=""; |
| 424 |
$inblock=0; |
| 425 |
$needsemi=0; |
| 426 |
$comments=""; |
| 427 |
} |
| 428 |
} |
| 429 |
# print STDERR "LEFTOVERS\n$comments\n" if ($comments); |
| 430 |
} |
| 431 |
|
| 432 |
################################################## |
| 433 |
### prep |
| 434 |
# |
| 435 |
# Prepares buffer for parser. |
| 436 |
# - removes C comments |
| 437 |
# - masks ^#.*$ ^//.*$ (.*) ".*" '.' |
| 438 |
# |
| 439 |
sub prep { |
| 440 |
my $in=join("",@_); |
| 441 |
my $str; |
| 442 |
my $token; |
| 443 |
my $last; |
| 444 |
my @tokens; |
| 445 |
my @out; |
| 446 |
my $line; |
| 447 |
my @lines; |
| 448 |
my @look=(); |
| 449 |
my $lookfor=""; |
| 450 |
my $newline=0; |
| 451 |
my @buffer=split("\n",$in);; |
| 452 |
|
| 453 |
while (@buffer) { |
| 454 |
$newline=1; |
| 455 |
|
| 456 |
# handle continued lines |
| 457 |
$str=shift(@buffer); |
| 458 |
$str.="\n"; |
| 459 |
|
| 460 |
while ($str =~/^(.*)\\$/) { |
| 461 |
$str="$1"; |
| 462 |
$str.=shift(@buffer); |
| 463 |
} |
| 464 |
|
| 465 |
|
| 466 |
@tokens=split(/(\s+|\/\*|\*\/|\/\/|\\.|\"|\'|#|\(|\))/,$str); |
| 467 |
while(@tokens) |
| 468 |
{ |
| 469 |
$last=$token if ($token ne ""); |
| 470 |
$token=shift(@tokens); |
| 471 |
|
| 472 |
# order is very important |
| 473 |
|
| 474 |
next if ($token eq ""); # skip blank tokens |
| 475 |
|
| 476 |
# C comment beats most |
| 477 |
if ($lookfor eq "/*") { |
| 478 |
if ($token eq "*/") { |
| 479 |
$line=pop(@lines); |
| 480 |
$lookfor=pop(@look); |
| 481 |
next; |
| 482 |
} |
| 483 |
$line.=$token; |
| 484 |
next; |
| 485 |
} |
| 486 |
|
| 487 |
# quote beats () |
| 488 |
if ($lookfor eq "\"" || $lookfor eq "\'") { |
| 489 |
if ($token eq $lookfor) { |
| 490 |
$line.=$token; |
| 491 |
$str=&mask($line); |
| 492 |
$line=pop(@lines); |
| 493 |
$line.=$str; |
| 494 |
$lookfor=pop(@look); |
| 495 |
next; |
| 496 |
} |
| 497 |
$line.=$token; |
| 498 |
next; |
| 499 |
} |
| 500 |
|
| 501 |
if ($lookfor eq "(" && $token eq ")") { |
| 502 |
$str=&mask($line); |
| 503 |
$line=pop(@lines); |
| 504 |
$line.=$str; |
| 505 |
$line.=$token; |
| 506 |
$lookfor=pop(@look); |
| 507 |
next; |
| 508 |
} |
| 509 |
|
| 510 |
if ($token =~ /\s+/) { |
| 511 |
$line.=$token; |
| 512 |
next; |
| 513 |
} |
| 514 |
|
| 515 |
if (!$lookfor && $newline && $token eq "#") { |
| 516 |
$line.=$token; |
| 517 |
$str=&prep(join("",@tokens)); |
| 518 |
$line.=$str; |
| 519 |
@tokens=(); |
| 520 |
next; |
| 521 |
} |
| 522 |
$newline=0; |
| 523 |
if ($token eq "//") { |
| 524 |
$line.=$token; |
| 525 |
$str=&mask(join("",@tokens)); |
| 526 |
$str=~s/\/\//%%CPCOMM/g; |
| 527 |
$line.=$str; |
| 528 |
@tokens=(); |
| 529 |
next; |
| 530 |
} |
| 531 |
|
| 532 |
if ($token eq "\"" || $ token eq "\'" || $token eq "/*" ) { |
| 533 |
push(@look,$lookfor); |
| 534 |
push(@lines,$line); |
| 535 |
$line=""; |
| 536 |
$lookfor=$token; |
| 537 |
} |
| 538 |
elsif ($token eq "(") { |
| 539 |
$line.=$token; |
| 540 |
push(@look,$lookfor); |
| 541 |
push(@lines,$line); |
| 542 |
$line=""; |
| 543 |
$lookfor=$token; |
| 544 |
next; |
| 545 |
} |
| 546 |
|
| 547 |
$line.=$token; |
| 548 |
} |
| 549 |
|
| 550 |
if (!@lines) { |
| 551 |
push(@out,$line); |
| 552 |
$line=""; |
| 553 |
} |
| 554 |
} |
| 555 |
$str=join("",@out); |
| 556 |
$str.=join("",@lines); |
| 557 |
$str; |
| 558 |
} |
| 559 |
|
| 560 |
################################################## |
| 561 |
### mask |
| 562 |
# |
| 563 |
# hides certain symbols so they don't confuse the parser |
| 564 |
sub mask { |
| 565 |
my $line=shift; |
| 566 |
$line=~s/\{/%%BRACEO/g; |
| 567 |
$line=~s/\}/%%BRACEC/g; |
| 568 |
$line=~s/\"/%%QUOTD/g; |
| 569 |
$line=~s/\'/%%QUOTS/g; |
| 570 |
$line=~s/\(/%%BRAKO/g; |
| 571 |
$line=~s/\)/%%BRAKC/g; |
| 572 |
$line=~s/,/%%COMM/g; |
| 573 |
$line=~s/;/%%SEMI/g; |
| 574 |
$line; |
| 575 |
} |
| 576 |
|
| 577 |
################################################## |
| 578 |
### mask_API |
| 579 |
# |
| 580 |
# hides certain API symbols so they don't confuse the parser |
| 581 |
sub mask_API { |
| 582 |
my $line=shift; |
| 583 |
$line=~s/CL_API_DISPLAY//g; |
| 584 |
$line=~s/CL_API_VORBIS//g; |
| 585 |
$line=~s/CL_API_MIKMOD//g; |
| 586 |
$line=~s/CL_API_SOUND//g; |
| 587 |
$line=~s/CL_API_SIGNALS//g; |
| 588 |
$line=~s/CL_API_NETWORK//g; |
| 589 |
$line=~s/CL_API_GUISTYLESILVER//g; |
| 590 |
$line=~s/CL_API_GUISTYLE_SILVER//g; |
| 591 |
$line=~s/CL_API_GUI//g; |
| 592 |
$line=~s/CL_API_CORE//g; |
| 593 |
$line=~s/CL_API_SDL//g; |
| 594 |
$line=~s/CL_API_GL//g; |
| 595 |
$line; |
| 596 |
} |
| 597 |
|
| 598 |
################################################## |
| 599 |
### unmask |
| 600 |
# |
| 601 |
# recovers masked symbols |
| 602 |
sub unmask { |
| 603 |
my $line=shift; |
| 604 |
$line=~s/%%BRACEO/\{/g; |
| 605 |
$line=~s/%%BRACEC/\}/g; |
| 606 |
$line=~s/%%QUOTD/\"/g; |
| 607 |
$line=~s/%%QUOTS/\'/g; |
| 608 |
$line=~s/%%BRAKO/\(/g; |
| 609 |
$line=~s/%%BRAKC/\)/g; |
| 610 |
$line=~s/%%COMM/,/g; |
| 611 |
$line=~s/%%SEMI/;/g; |
| 612 |
$line; |
| 613 |
} |
| 614 |
|
| 615 |
|
| 616 |
################################################## |
| 617 |
### extract |
| 618 |
# extracts part of the buffer. |
| 619 |
sub extract { |
| 620 |
my ($block,$start,$stop,$nonest)=@_; |
| 621 |
my @in=split(/($start|$stop)/,$block); |
| 622 |
my @out; |
| 623 |
my $str; |
| 624 |
my $token; |
| 625 |
my $depth=0; |
| 626 |
while (@in) { |
| 627 |
$token=shift(@in); |
| 628 |
if ($token eq $stop) { |
| 629 |
$depth--; |
| 630 |
if ($nonest || $depth==0) { |
| 631 |
$str=join("",@out); |
| 632 |
return $str; |
| 633 |
} |
| 634 |
} |
| 635 |
push(@out,$token) if ($depth>0); |
| 636 |
$depth++ if ($token eq $start); |
| 637 |
} |
| 638 |
return ""; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
################################################## |
| 643 |
### proc* |
| 644 |
|
| 645 |
# sub routines for extracting sepecific types of blocks. |
| 646 |
|
| 647 |
sub procNamespace { |
| 648 |
my($env,$block,$com)=@_; |
| 649 |
$block=~s/^\s+//; |
| 650 |
if ($block=~/^namespace\s+(\S+)\s*{/) { |
| 651 |
$env=Namespace::new($env,"$1",$com); |
| 652 |
} |
| 653 |
elsif ($block=~/^namespace\s*{/) { |
| 654 |
$env=$::anonymous; |
| 655 |
} |
| 656 |
elsif ($block=~/^namespace\s+\S+\s*=\s*\S+\s*;/) { |
| 657 |
# ignore namespaces aliases |
| 658 |
} |
| 659 |
else { |
| 660 |
print STDERR "ERROR: namespace:\n<BLOCK>\n$block\n<\BLOCK>\n\n"; |
| 661 |
return ""; |
| 662 |
} |
| 663 |
&parse($env,&extract($block,"{","}")); |
| 664 |
return $env; |
| 665 |
} |
| 666 |
|
| 667 |
sub procClass { |
| 668 |
my($env,$block,$com)=@_; |
| 669 |
|
| •670 |
if (&mask_API($block)=~/^\s*(class|union|struct)\s+(\S+)\s*:(.*)\{/) { |
| 671 |
$env=Class::new($env,$2,$com,$1,$3); |
| 672 |
} |
| •673 |
elsif (&mask_API($block)=~/^\s*(class|union|struct)\s+(\S+)\s*\{/) { |
| 674 |
$env=Class::new($env,$2,$com,$1); |
| 675 |
} |
| 676 |
elsif ($block=~/^\s*(union|struct)\s*{/) { |
| 677 |
# anonymous union (do nothing) |
| 678 |
&parse($env,&extract($block,"{","}")); |
| 679 |
return ""; |
| 680 |
} |
| 681 |
elsif ($block=~/^\s*(class|union|struct)\s+(\S+)\s*;/) { |
| 682 |
# forward decl (ignore) |
| 683 |
return ""; |
| 684 |
} |
| 685 |
else |
| 686 |
{ print STDERR "ERROR: class:\n$block\n\n"; return ""; } |
| 687 |
&parse($env,&extract($block,"{","}")); |
| 688 |
return $env; |
| 689 |
} |
| 690 |
|
| 691 |
sub procArgs { |
| 692 |
my($env,$block,$comments)=@_; |
| 693 |
return ""; |
| 694 |
} |
| 695 |
|
| 696 |
sub procFunc { |
| 697 |
my($env,$block,$com)=@_; |
| 698 |
my($obj,$type,$args,$name,$const); |
| 699 |
($block)=split("\n",$block,2); |
| 700 |
$block=~s/\s+\*/* /g; |
| 701 |
$block=~s/\s+\&/& /g; |
| 702 |
$block=~s/\s+/ /g; |
| 703 |
$block=~s/inline//g; |
| 704 |
|
| 705 |
# normal function |
| 706 |
if ($block=~/^\s*([^)]*)\s+(\~*$Enum::SYM)\s*\(([^\)]*)\)\s*(const)*\s*(=\s*0\s*)*[:{;]/) { |
| 707 |
$type=$1; |
| 708 |
$name=$2; |
| 709 |
$args=&unmask($3); |
| 710 |
$const=$4; |
| 711 |
} |
| 712 |
|
| 713 |
# ctor |
| 714 |
elsif ($block=~/^\s*(\~*$Enum::SYM)\s*\(([^)]*)\)\s*(const)*\s*[:{;]/) { |
| 715 |
$type=""; |
| 716 |
$name=$1; |
| 717 |
$args=&unmask($2); |
| 718 |
$const=$3; |
| 719 |
} |
| 720 |
|
| 721 |
#operator |
| 722 |
elsif ($block=~/^(.*)\s*operator\s*(.*)\s*\((.*)\)\s*(const)*\s*[{;]/) { |
| 723 |
$type=$1; |
| 724 |
$name="operator $2"; |
| 725 |
$args=&unmask($3); |
| 726 |
$const=$4; |
| 727 |
} |
| 728 |
else { |
| 729 |
print STDERR "ERROR: function:\n$block\n\n"; |
| 730 |
return ""; |
| 731 |
} |
| 732 |
$obj=Function::new($env,$name,$com,$type,$args); |
| 733 |
$obj->{const}=1 if ($const eq "const"); |
| 734 |
return $obj; |
| 735 |
} |
| 736 |
|
| 737 |
sub procVar { |
| 738 |
my($env,$block,$com)=@_; |
| 739 |
($block)=split("\n",$block,2); |
| 740 |
$block=~s/\s+/ /g; |
| 741 |
if ($block=~/^\s*(.*\s+\**)($Enum::SYM)\s*(\[.*\])*\s*(=\s*\S+\s*)*;/) { |
| 742 |
return Variable::new($env,$2,$com,"$1$3"); |
| 743 |
} |
| 744 |
else { |
| 745 |
print STDERR "ERROR: variable:\n$block\n\n"; |
| 746 |
} |
| 747 |
return ""; |
| 748 |
} |
| 749 |
|
| 750 |
sub procDef { |
| 751 |
my($env,$block,$com)=@_; |
| 752 |
if ($block=~/^\s*typedef\s+(.*)\s+(\S+)\s*;/) { |
| 753 |
return Typedef::new($env,$2,$com); |
| 754 |
} |
| 755 |
else { |
| 756 |
print STDERR "ERROR: typedef:\n$block\n\n"; |
| 757 |
} |
| 758 |
return ""; |
| 759 |
} |
| 760 |
|
| 761 |
sub procEnum { |
| 762 |
my($env,$block,$com)=@_; |
| 763 |
#print STDERR "ERROR: enum:\n$block\n\n"; |
| 764 |
return ""; |
| 765 |
} |
| 766 |
|
| 767 |
sub procFriend { |
| 768 |
my($env,$block,$com)=@_; |
| 769 |
if ($block=~/^\s*friend\s+(.*)\s*;/) { |
| 770 |
return Friend::new($env,$2,$com); |
| 771 |
} |
| 772 |
else { |
| 773 |
print STDERR "ERROR: friend:\n$block\n\n"; |
| 774 |
} |
| 775 |
return ""; |
| 776 |
} |
| 777 |
|
| 778 |
sub procMacro { |
| 779 |
my($env,$block,$com)=@_; |
| 780 |
return ""; |
| 781 |
} |
| 782 |
|
| 783 |
sub procExtern { |
| 784 |
my($env,$block,$com)=@_; |
| 785 |
if ($block=~/^\s*extern\s*%%QUOTDC%%QUOTD\s*{/) { |
| 786 |
&parse($env,&extract($block,"{","}")); |
| 787 |
return ""; |
| 788 |
} |
| 789 |
elsif ($block=~/^\s*extern\s*%%QUOTDC%%QUOTD\s*/) { |
| 790 |
$block=~s/^extern\s*%%QUOTDC%%QUOTD\s*//; |
| 791 |
&parse($env,$block); |
| 792 |
return ""; |
| 793 |
} |
| 794 |
else { |
| 795 |
print STDERR "ERROR: extern:\n$block\n\n"; |
| 796 |
} |
| 797 |
return ""; |
| 798 |
} |
| 799 |
|
| 800 |
sub procTemplate { |
| 801 |
my($env,$block,$comments)=@_; |
| 802 |
# sorry, not handled yet. |
| 803 |
# print STDERR "TEMPLATE\n"; |
| 804 |
return ""; |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
sub procComments { |
| 809 |
my ($comments)=@_; |
| 810 |
my ($short,$long,$str); |
| 811 |
$short = ""; |
| 812 |
$long = ""; |
| 813 |
$comments=~s/%%CPCOMM/\/\//g; |
| 814 |
foreach (split("\n",$comments)) |
| 815 |
{ |
| 816 |
if (/^\:|\-|\!|\+|\./) |
| 817 |
{ |
| 818 |
/^.(.*)$/; |
| 819 |
$str = "$1\n"; |
| 820 |
|
| 821 |
if (/^-\s*$/) { |
| 822 |
$long.= "\n"; |
| 823 |
} |
| 824 |
elsif (/^-/) { |
| 825 |
$long.=" $str"; |
| 826 |
} |
| 827 |
elsif (/^:/) { |
| 828 |
$long=""; |
| 829 |
$short.= " $str"; |
| 830 |
} |
| 831 |
} |
| 832 |
# else |
| 833 |
# { |
| 834 |
# $short = ""; |
| 835 |
# $long = ""; |
| 836 |
# } |
| 837 |
} |
| 838 |
($short,$long); |
| 839 |
} |
| 840 |
|
| 841 |
|
| 842 |
################################################## |
| 843 |
### crossRef |
| 844 |
# |
| 845 |
# This establishes all the parent and child relationships between classes |
| 846 |
# after data is extracted. |
| 847 |
sub crossRef { |
| 848 |
my $space=shift; |
| 849 |
my $access="public"; |
| 850 |
my $class; |
| 851 |
my $parent; |
| 852 |
my $pname; |
| 853 |
my $pstr; |
| 854 |
foreach $class (classes $space) { |
| 855 |
$pstr=$class->{parent_str}; |
| 856 |
$pstr=~s/<[^>]*>//g; |
| 857 |
foreach (split(",",$pstr)) { |
| 858 |
$access="private"; |
| 859 |
$access=$1 if ( s/^\s*((public)|(private)|(protected))\s+// ); |
| 860 |
$access.=$1 if ( s/^\s*(virtual\s)// ); |
| 861 |
if ( /^\s*(\S+)\s*$/) { |
| 862 |
$pname=$1; |
| 863 |
if ($pname =~ /::/) { |
| 864 |
$parent=Object::find($pname); |
| 865 |
} |
| 866 |
else { |
| 867 |
$parent=$class->{space}->lookdown($pname); |
| 868 |
} |
| 869 |
$parent=$::unknown->lookup($pname) if (!$parent); |
| 870 |
$parent=Class::new($::unknown,$pname,"","class") if (!$parent); |
| 871 |
if ($parent) { |
| 872 |
my $parents=$class->{parents}; |
| 873 |
push(@$parents,$parent); |
| 874 |
my $children=$parent->{children}; |
| 875 |
push(@$children,$class); |
| 876 |
} |
| 877 |
} |
| 878 |
else { |
| 879 |
print "can't parse $_\n"; |
| 880 |
|
| 881 |
} |
| 882 |
} |
| 883 |
} |
| 884 |
foreach (spaces $space) { |
| 885 |
crossRef($_); |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
################################################## |
| 890 |
### crossArgs |
| 891 |
# |
| 892 |
# This establishs the html args with syntax highlighting |
| 893 |
# |
| 894 |
# This uses a dumb, dumb heristic to do the dirty work, needs fixing |
| 895 |
# |
| 896 |
sub crossArgs { |
| 897 |
my $global=shift; |
| 898 |
my $intrensic=::buildRE(@Html::intrensics); |
| 899 |
my $specifier=::buildRE(@Html::specifiers); |
| 900 |
my $item; |
| 901 |
|
| 902 |
foreach $item ($global->all) { |
| 903 |
next if (!$item->is_function()&&!$item->is_variable()); |
| 904 |
|
| 905 |
# handle return type |
| 906 |
my $ret; |
| 907 |
foreach (split(/([^A-z0-9:])/,$$item{type})) { |
| 908 |
next if ($_ eq ""); |
| 909 |
if ($_ !~ /^[A-z0-9_:]+$/) { |
| 910 |
$ret.=$_; |
| 911 |
} |
| 912 |
elsif ($_ =~ /${intrensic}/) { |
| 913 |
$ret.="${Html::INTRENSIC}$_${Html::INTRENSIC_}"; |
| 914 |
} |
| 915 |
elsif ($_ =~ /${specifier}/) { |
| 916 |
$ret.="${Html::SPECIFIER}$_${Html::SPECIFIER_}"; |
| 917 |
} |
| 918 |
else { |
| 919 |
my $i; |
| 920 |
$i=$item->lookdown($_); |
| 921 |
|
| 922 |
if ($i) { |
| 923 |
$ret.=$i->href(); |
| 924 |
} |
| 925 |
else { |
| 926 |
$ret.="${Html::TYPE}$_${Html::TYPE_}"; |
| 927 |
} |
| 928 |
} |
| 929 |
} |
| 930 |
$item->{html_type}=$ret; |
| 931 |
|
| 932 |
next if (!$item->is_function()); |
| 933 |
my $args; |
| 934 |
my $drinks=0; |
| 935 |
foreach (split(/([^A-z0-9:])/,$$item{args})) { |
| 936 |
next if ($_ eq ""); |
| 937 |
|
| 938 |
# we use a drinking game style guesser. |
| 939 |
$drinks=0 if ($_ =~ /[,)<]/); |
| 940 |
$drinks=-100 if ($_ =~ /[=]/); |
| 941 |
|
| 942 |
if ($_ !~ /^[A-z_0-9:]+$/) { |
| 943 |
$args.=$_; |
| 944 |
next; |
| 945 |
} |
| 946 |
elsif ($_ =~ /${intrensic}/) { |
| 947 |
$args.="${Html::INTRENSIC}$_${Html::INTRENSIC_}"; |
| 948 |
} |
| 949 |
elsif ($_ =~ /${specifier}/) { |
| 950 |
$args.="${Html::SPECIFIER}$_${Html::SPECIFIER_}"; |
| 951 |
next; |
| 952 |
} |
| 953 |
elsif ($drinks < 0) { |
| 954 |
$args.=$_; |
| 955 |
next; |
| 956 |
} |
| 957 |
elsif ($drinks == 0 || $_ =~ /::/ ) { |
| 958 |
my $i; |
| 959 |
$i=$item->lookdown($_); |
| 960 |
|
| 961 |
if ($i) { |
| 962 |
$args.=$i->href(); |
| 963 |
} |
| 964 |
else { |
| 965 |
$args.="${Html::TYPE}$_${Html::TYPE_}"; |
| 966 |
} |
| 967 |
} |
| 968 |
elsif ($drinks > 0) { |
| 969 |
$args.="${Html::VARIABLE}$_${Html::VARIABLE_}"; |
| 970 |
} |
| 971 |
else { |
| 972 |
$args.=$_; |
| 973 |
} |
| 974 |
|
| 975 |
# take a drink |
| 976 |
$drinks++; |
| 977 |
} |
| 978 |
$item->{html_args}=$args; |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
################################################## |
| 983 |
### markup |
| 984 |
# |
| 985 |
# Markup the comments must happen after the crossRef |
| 986 |
# |
| 987 |
sub markup { |
| 988 |
my $global=shift; |
| 989 |
my $item; |
| 990 |
|
| 991 |
foreach $item ($global->all) { |
| 992 |
$$item{short}=Plugin::exec("desc",$$item{short},$item) if ($$item{short}); |
| 993 |
$$item{long}=Plugin::exec("desc",$$item{long},$item) if ($$item{long}); |
| 994 |
} |
| 995 |
} |
| 996 |
|
| 997 |
package main; |
| 998 |
|
| 999 |
sub to_xml { |
| 1000 |
my $str=join("",@_); |
| 1001 |
$str=~s/&/&/g; |
| 1002 |
$str=~s/</</g; |
| 1003 |
$str=~s/>/>/g; |
| 1004 |
$str=~s/\'/'/g; |
| 1005 |
$str=~s/\"/"/g; |
| 1006 |
$str; |
| 1007 |
} |
| 1008 |
|
| 1009 |
####################################################################### |
| 1010 |
#### 2.0 Plugin |
| 1011 |
####################################################################### |
| 1012 |
# |
| 1013 |
# Plugins represent mini perl files that can get pulled in to enhance |
| 1014 |
# the capablities of pce2. At minumum, you will need to define one |
| 1015 |
# plugin to dump our extracted information. |
| 1016 |
# |
| 1017 |
# All plugin's must have a subroutine called plugin without a package. |
| 1018 |
# they can have their own package at their option to protect their |
| 1019 |
# varables. By default, they are loaded into the namespace Plugin. |
| 1020 |
# You should take care to avoid the following globals located in that |
| 1021 |
# namespace. |
| 1022 |
# |
| 1023 |
# GLOBALS: |
| 1024 |
# %has_ |
| 1025 |
# @directory_ |
| 1026 |
# &has |
| 1027 |
# &load |
| 1028 |
# &exec |
| 1029 |
# |
| 1030 |
|
| 1031 |
package main; |
| 1032 |
|
| 1033 |
# stub to call Plugin::exec from the main space. |
| 1034 |
sub PLUGIN { |
| 1035 |
return Plugin::exec(@_); |
| 1036 |
} |
| 1037 |
|
| 1038 |
package Plugin; |
| 1039 |
BEGIN { @Plugin::ISA=qw(main); } |
| 1040 |
|
| 1041 |
BEGIN { |
| 1042 |
%Plugin::has_; |
| 1043 |
push(@Plugin::directory_,"."); |
| 1044 |
push(@Plugin::directory_,"./plugins"); |
| 1045 |
} |
| 1046 |
|
| 1047 |
sub hash_ { |
| 1048 |
my $file=shift; |
| 1049 |
$file=~s/\.plg$//; |
| 1050 |
$file=~tr/\/./__/; |
| 1051 |
return $file; |
| 1052 |
|
| 1053 |
} |
| 1054 |
|
| 1055 |
sub has { |
| 1056 |
my $name=shift; |
| 1057 |
return ($Plugin::has_{$name}); |
| 1058 |
} |
| 1059 |
|
| 1060 |
sub load { |
| 1061 |
my $plugin=shift; |
| 1062 |
my $hash=&hash_($plugin); |
| 1063 |
my $buffer; |
| 1064 |
my $line; |
| 1065 |
if (!has($plugin)) { |
| 1066 |
$Plugin::has_{$plugin}=1; |
| 1067 |
foreach (@Plugin::directory_) { |
| 1068 |
if ( -e "$_/$plugin.plg" ) { |
| 1069 |
open(FILE,"<$_/$plugin.plg"); |
| 1070 |
while ($line=<FILE>) { |
| 1071 |
$line=~s/sub +plugin/sub plugin_$hash/; |
| 1072 |
$buffer.=$line; |
| 1073 |
} |
| 1074 |
close(FILE); |
| 1075 |
eval($buffer); |
| 1076 |
return 1; |
| 1077 |
} |
| 1078 |
} |
| 1079 |
|
| 1080 |
# if it isn't found, fake it. |
| 1081 |
print STDERR "warning: can't find plugin $plugin, using default\n" |
| 1082 |
if ($::debug); |
| 1083 |
eval("sub plugin_$hash {return shift;}"); |
| 1084 |
return 1; |
| 1085 |
} |
| 1086 |
return 0; |
| 1087 |
} |
| 1088 |
|
| 1089 |
sub exec { |
| 1090 |
|
| 1091 |
my $plugin=shift; |
| 1092 |
my $hash=hash_($plugin); |
| 1093 |
|
| 1094 |
# print STDERR "PLUGIN $plugin\n" if ($::debug); |
| 1095 |
load($plugin) if (!has($plugin)); |
| 1096 |
|
| 1097 |
eval("return &plugin_$hash(\@_);"); |
| 1098 |
} |
| 1099 |
|
| 1100 |
################################################## |
| 1101 |
### Reporting globals |
| 1102 |
sub byname { $a->{name} cmp $b->{name}; } |
| 1103 |
sub byfullname { $a->{fullname} cmp $b->{fullname}; } |
| 1104 |
|
| 1105 |
sub alter { |
| 1106 |
my $self=shift; |
| 1107 |
my $str=shift; |
| •1108 |
$str=~s/\$\{/\$\$self\{/g; |
| 1109 |
$str=~s/\\n/\n/g; |
| 1110 |
$str=~s/"/\\"/g; |
| 1111 |
eval("\$str=\"$str\";"); |
| 1112 |
$str; |
| 1113 |
} |
| 1114 |
|
| 1115 |
|
| 1116 |
####################################################################### |
| 1117 |
##### 3.0 Tree |
| 1118 |
####################################################################### |
| 1119 |
# |
| 1120 |
# These Perl objects represent the extracted information |
| 1121 |
# taken from the C++ header. |
| 1122 |
# |
| 1123 |
# In here your will find the various reporting functions, you will |
| 1124 |
# use to dump the extracted information |
| 1125 |
# |
| 1126 |
|
| 1127 |
package main; |
| 1128 |
|
| 1129 |
sub buildHash { my %hash; foreach (@_) {$hash{$_}=$_;} %hash; } |
| 1130 |
|
| 1131 |
sub buildRE { |
| 1132 |
my $str='^(('; |
| 1133 |
$str.=join(')|(',@_); |
| 1134 |
$str.='))$'; |
| 1135 |
return $str; |
| 1136 |
} |
| 1137 |
|
| 1138 |
|
| 1139 |
################################################## |
| 1140 |
### Object |
| 1141 |
package Object; |
| 1142 |
use strict; |
| 1143 |
BEGIN { @Namespace::ISA=qw(main); } |
| 1144 |
|
| 1145 |
BEGIN { $Object::refnum=1;} |
| 1146 |
# |
| 1147 |
# $name - name in the class |
| 1148 |
# $space - namespace/class/struct/union that contains this object |
| 1149 |
# $access - type of access in that space |
| 1150 |
# $ntype - numerical type number |
| 1151 |
# @items - things contained in this space |
| 1152 |
# %items_hash - things contained in this space |
| 1153 |
# $refnum - unique number used for referencing |
| 1154 |
# |
| 1155 |
# $html_name - name using syntax highlighting |
| 1156 |
# |
| 1157 |
|
| 1158 |
sub new($$$) { |
| 1159 |
my ($space_,$name_,$comments_)=@_; |
| 1160 |
my $self={}; |
| 1161 |
bless $self; |
| 1162 |
$self->{name}=$name_; |
| 1163 |
$self->{html_name}=$name_; |
| 1164 |
$self->{comments}=$comments_; |
| 1165 |
$self->{space}=$space_; |
| 1166 |
$self->{ntype}=$Enum::NONE; |
| 1167 |
$self->{access}=$Enum::PUBLIC; |
| 1168 |
$self->{items}=[]; |
| 1169 |
$self->{items_hash}={}; |
| 1170 |
$self->{file}=$::currentfile; |
| 1171 |
$self->{refnum}=$Object::refnum++; |
| 1172 |
$self->{fullname}=$self->make_fullname(); |
| 1173 |
$self->{member_access}=$Enum::PUBLIC; |
| 1174 |
my ($short,$long) = &Extract::procComments($comments_); |
| 1175 |
$self->{short}=$short; # Plugin::exec("desc",$short,$self); |
| 1176 |
$self->{long}=$long; # Plugin::exec("desc",$long,$self); |
| 1177 |
$self->{unique_string}=$file_unique_string; |
| 1178 |
$space_->Object::add($self) if ($space_); |
| 1179 |
return $self; |
| 1180 |
} |
| 1181 |
|
| 1182 |
# (internal) used to generate fullname |
| 1183 |
sub make_fullname { |
| 1184 |
my $self=shift; |
| 1185 |
my $name_; |
| 1186 |
if ($self->{space}) { |
| 1187 |
$name_=$self->{space}->get_pathname() ; |
| 1188 |
} |
| 1189 |
else { |
| 1190 |
return "global"; |
| 1191 |
} |
| 1192 |
$name_.=$self->{name}; |
| 1193 |
} |
| 1194 |
|
| 1195 |
sub get_pathname { |
| 1196 |
my $self=shift; |
| 1197 |
my $name_; |
| 1198 |
if ($self->{space}) { |
| 1199 |
$name_=$self->{space}->get_pathname() ; |
| 1200 |
} |
| 1201 |
$name_.="$self->{name}::" if ($self->{name}); |
| 1202 |
$name_; |
| 1203 |
} |
| 1204 |
|
| 1205 |
sub dump_xml { |
| 1206 |
my ($self,$sp) = @_; |
| 1207 |
my $sp1="$sp " if ($::ws_verbose); |
| 1208 |
my $nl="\n" if ($::ws_verbose); |
| 1209 |
printf "$sp<%s name='%s'>$nl", $self->type_name(), &::to_xml($self->name()); |
| 1210 |
$self->dump_xml_($sp1,$nl); |
| 1211 |
printf "$sp</%s>$nl", $self->type_name(); |
| 1212 |
} |
| 1213 |
|
| 1214 |
sub dump_xml_ { |
| 1215 |
my ($self,$sp,$nl) = @_; |
| 1216 |
|
| 1217 |
# Access level |
| 1218 |
printf "$sp<%s/>$nl", $self->access_name(); |
| 1219 |
# Comments |
| 1220 |
printf "$sp<description>%s</description>$nl", &::to_xml($self->{short}) if $self->{short}; |
| 1221 |
printf "$sp<comments>%s</comments>$nl", &::to_xml($self->{long}) if $self->{long}; |
| 1222 |
# File |
| 1223 |
printf "$sp<sourcefile>%s</sourcefile>$nl", &::to_xml($self->{file}); |
| 1224 |
|
| 1225 |
# Parent objects |
| 1226 |
my $parents = $self->{parents}; |
| 1227 |
if ($parents && @$parents) { |
| 1228 |
print "$sp<parents>$nl"; |
| 1229 |
foreach (@$parents) { |
| 1230 |
printf "$sp<parent>%s</parent>$nl", &::to_xml($_->{name}); |
| 1231 |
} |
| 1232 |
print "$sp</parents>$nl"; |
| 1233 |
} |
| 1234 |
|
| 1235 |
# Process sub-items |
| 1236 |
my $items = $self->{items}; |
| 1237 |
if ($items && @$items) { |
| 1238 |
foreach (@$items) { |
| 1239 |
$_->dump_xml($sp); |
| 1240 |
} |
| 1241 |
} |
| 1242 |
} |
| 1243 |
|
| 1244 |
|
| 1245 |
sub add { |
| 1246 |
my $self=shift; |
| 1247 |
my $child=shift; |
| 1248 |
my $items=$self->{items}; |
| 1249 |
my $items_hash=$self->{items_hash}; |
| 1250 |
push(@$items,$child); |
| 1251 |
$$items_hash{$child->{name}}=$child; |
| 1252 |
$child->{access}=$self->{member_access}; |
| 1253 |
} |
| 1254 |
|
| 1255 |
sub get_by_type { |
| 1256 |
my $self=shift; |
| 1257 |
my %hash=&::buildHash(@_); |
| 1258 |
my $wild=!(@_); |
| 1259 |
my $items=$self->{items}; |
| 1260 |
my @group; |
| 1261 |
foreach (@$items) { |
| 1262 |
push(@group,$_) if ($hash{$_->{ntype}} || $wild); |
| 1263 |
} |
| 1264 |
return @group; |
| 1265 |
} |
| 1266 |
|
| 1267 |
sub get_by_access { |
| 1268 |
my $self=shift; |
| 1269 |
my %hash=&::buildHash(@_); |
| 1270 |
my $items=$self->{items}; |
| 1271 |
my @group; |
| 1272 |
foreach (@$items) { |
| 1273 |
push(@group,$_) if ($hash{$_->{access}} || !@_); |
| 1274 |
} |
| 1275 |
return @group; |
| 1276 |
} |
| 1277 |
|
| 1278 |
sub all { |
| 1279 |
my $space=shift; |
| 1280 |
my @l; |
| 1281 |
foreach ($space->items()) { |
| 1282 |
push(@l,$_); |
| 1283 |
push(@l,all($_)) if ($_->{ntype}==$Enum::NAMESPACE); |
| 1284 |
push(@l,all($_)) if ($_->{ntype}==$Enum::CLASS); |
| 1285 |
push(@l,all($_)) if ($_->{ntype}==$Enum::STRUCT); |
| 1286 |
push(@l,all($_)) if ($_->{ntype}==$Enum::UNION); |
| 1287 |
} |
| 1288 |
return @l; |
| 1289 |
} |
| 1290 |
|
| 1291 |
#places an html reference |
| 1292 |
sub href { |
| 1293 |
my $self=shift; |
| 1294 |
my $str=shift; |
| 1295 |
my $r; |
| 1296 |
my $s; |
| 1297 |
$str=$$self{html_name} if (!$str); |
| 1298 |
return $str if (!$self->is_known()); |
| 1299 |
$r="<a href=\""; |
| 1300 |
if ($self->{ntype}==$Enum::CLASS || |
| 1301 |
$self->{ntype}==$Enum::STRUCT || |
| 1302 |
$self->{ntype}==$Enum::NAMESPACE || |
| 1303 |
$self->{ntype}==$Enum::UNION) { |
| 1304 |
$r.=$self->{fullname}; |
| 1305 |
$r.=".html"; |
| 1306 |
} |
| 1307 |
else { |
| 1308 |
$s=$self->{space}; |
| 1309 |
$r.=$s->{fullname}; |
| 1310 |
$r.=".html#"; |
| 1311 |
$r.=$self->{refnum}; |
| 1312 |
} |
| 1313 |
$r.="\">"; |
| 1314 |
$r=~s/\:/_/g; |
| 1315 |
$r.=$str; |
| 1316 |
$r.="</a>"; |
| 1317 |
} |
| 1318 |
|
| 1319 |
sub full_href { |
| 1320 |
my $self=shift; |
| 1321 |
my $out=$self->href(); |
| 1322 |
my $str; |
| 1323 |
my $space=$self->{space}; |
| 1324 |
while ($space!=$::global) { |
| 1325 |
$str=$space->href(); |
| 1326 |
$str.="::$out"; |
| 1327 |
$out=$str; |
| 1328 |
$space=$space->{space}; |
| 1329 |
} |
| 1330 |
$out="<tt>$out</tt>"; |
| 1331 |
return $out; |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
# searchs by name in the child array |
| 1336 |
sub lookup { |
| 1337 |
my $self=shift; |
| 1338 |
my $name=shift; |
| 1339 |
my $items=$self->{items_hash}; |
| 1340 |
$name=~s/^:://; |
| 1341 |
if ($name =~ /::/) { |
| 1342 |
foreach (split(/::/,$name)) { |
| 1343 |
$self=$self->lookup($_); |
| 1344 |
if (!$self) {return "";} |
| 1345 |
} |
| 1346 |
return $self; |
| 1347 |
} |
| 1348 |
return $$items{$name}; |
| 1349 |
} |
| 1350 |
|
| 1351 |
# search from this level back to root space for a name |
| 1352 |
sub lookdown { |
| 1353 |
my $self=shift; |
| 1354 |
my $name=shift; |
| 1355 |
my $parent=$self->{space}; |
| 1356 |
my $items=$self->{items_hash}; |
| 1357 |
if ($name =~/::/) |
| 1358 |
{ |
| 1359 |
$name=~s/^:://; |
| 1360 |
my @path=split(/::/,$name,2); |
| 1361 |
my $place=$self->lookdown(shift(@path)); |
| 1362 |
return "" if (!$place); |
| 1363 |
return $place->lookup(shift(@path)); |
| 1364 |
} |
| 1365 |
return $$items{$name} if ($$items{$name}); |
| 1366 |
return $parent->lookdown($name) if ($parent); |
| 1367 |
return ""; |
| 1368 |
} |
| 1369 |
|
| 1370 |
# lookup using full path name |
| 1371 |
sub find { |
| 1372 |
my $name=shift; |
| 1373 |
my $space=$::global; |
| 1374 |
return $space->lookup($_); |
| 1375 |
} |
| 1376 |
|
| 1377 |
####################### |
| 1378 |
# Utility functions for reporting |
| 1379 |
|
| 1380 |
sub type_name { my $self=shift; $Enum::TYPE_NAMES[$self->{ntype}];} |
| 1381 |
sub access_name { my $self=shift; $Enum::ACCESS_NAMES[$self->{access}];} |
| 1382 |
|
| 1383 |
sub name { my $self=shift; $self->{name}; } |
| 1384 |
sub fullname { my $self=shift; $self->{fullname}; } |
| 1385 |
|
| 1386 |
sub children { my $self=shift; my $children=$self->{children}; return @$children; } |
| 1387 |
sub parents { |
| 1388 |
my $self=shift; |
| 1389 |
my $parents=$self->{parents}; |
| 1390 |
return @$parents; |
| 1391 |
} |
| 1392 |
|
| 1393 |
sub known_parents { |
| 1394 |
my $self=shift; |
| 1395 |
my @parents; |
| 1396 |
foreach ($self->parents()) { |
| 1397 |
push (@parents,$_) if $_->is_known(); |
| 1398 |
} |
| 1399 |
return @parents; |
| 1400 |
} |
| 1401 |
|
| 1402 |
sub items { return get_by_type(shift); } |
| 1403 |
sub spaces { my $self=shift; return $self->get_by_type($Enum::NAMESPACE,$Enum::CLASS,$Enum::STRUCT,$Enum::UNION); } |
| 1404 |
|
| 1405 |
sub classes { my $self=shift; return $self->get_by_type($Enum::CLASS,$Enum::STRUCT); } |
| 1406 |
sub unions { my $self=shift; return $self->get_by_type($Enum::UNION); } |
| 1407 |
sub namespaces { my $self=shift; return $self->get_by_type($Enum::NAMESPACE); } |
| 1408 |
sub friends { my $self=shift; return $self->get_by_type($Enum::FRIEND); } |
| 1409 |
sub variables { my $self=shift; return $self->get_by_type($Enum::VARIABLE); } |
| 1410 |
sub functions { my $self=shift; return $self->get_by_type($Enum::FUNCTION); } |
| 1411 |
sub typedefs { my $self=shift; return $self->get_by_type($Enum::TYPEDEF); } |
| 1412 |
sub macros { my $self=shift; return $self->get_by_type($Enum::MACRO); } |
| 1413 |
|
| 1414 |
sub public { my $self=shift; return $self->get_by_access($Enum::PUBLIC); } |
| 1415 |
sub private { my $self=shift; return $self->get_by_access($Enum::PRIVATE); } |
| 1416 |
sub protected { my $self=shift; return $self->get_by_access($Enum::PROTECTED); } |
| 1417 |
|
| 1418 |
sub is_known { my $self=shift; return $self->{space}!=$::unknown; } |
| 1419 |
sub is_class { |
| 1420 |
my $self=shift; |
| 1421 |
return $self->{ntype}==$Enum::CLASS || $self->{ntype}==$Enum::STRUCT; |
| 1422 |
} |
| 1423 |
|
| 1424 |
sub is_namespace { my $self=shift; return $self->{ntype}==$Enum::NAMESPACE; } |
| 1425 |
sub is_union { my $self=shift; return $self->{ntype}==$Enum::UNION; } |
| 1426 |
sub is_variable { my $self=shift; return $self->{ntype}==$Enum::VARIABLE; } |
| 1427 |
sub is_function { my $self=shift; return $self->{ntype}==$Enum::FUNCTION; } |
| 1428 |
sub is_typedef { my $self=shift; return $self->{ntype}==$Enum::TYPEDEF; } |
| 1429 |
sub is_friend { my $self=shift; return $self->{ntype}==$Enum::FRIEND; } |
| 1430 |
# sub is_template {} |
| 1431 |
|
| 1432 |
################################################## |
| 1433 |
### Namespace |
| 1434 |
package Namespace; |
| 1435 |
use strict; |
| 1436 |
BEGIN { @Namespace::ISA=qw(Object); } |
| 1437 |
|
| 1438 |
sub new($$$) { |
| 1439 |
my ($space_,$name_,$comments_)=@_; |
| 1440 |
my $other; |
| 1441 |
$other=$space_->lookup($name_) if ($space_); |
| 1442 |
return $other if ($other); |
| 1443 |
my $self=Object::new($space_,$name_,$comments_); |
| 1444 |
$self->{ntype}=$Enum::NAMESPACE; |
| 1445 |
$self->{html_name}="${Html::NAMESPACE}$name_${Html::NAMESPACE_}"; |
| 1446 |
bless $self; |
| 1447 |
} |
| 1448 |
|
| 1449 |
################################################## |
| 1450 |
### Class |
| 1451 |
# |
| 1452 |
# $parent_str - raw parent data |
| 1453 |
# @parents - referenced parent list |
| 1454 |
# @children - referenced child list |
| 1455 |
# |
| 1456 |
package Class; |
| 1457 |
use strict; |
| 1458 |
BEGIN { |
| 1459 |
@Class::ISA=qw(Object); |
| 1460 |
} |
| 1461 |
|
| 1462 |
sub new { |
| 1463 |
my ($space_,$name_,$comments_,$typename,$pstr)=@_; |
| 1464 |
my $self=Object::new($space_,$name_,$comments_); |
| 1465 |
|
| 1466 |
$self->{ntype}=$Enum::CLASS if ($typename eq "class"); |
| 1467 |
$self->{ntype}=$Enum::STRUCT if ($typename eq "struct"); |
| 1468 |
$self->{ntype}=$Enum::UNION if ($typename eq "union"); |
| 1469 |
|
| 1470 |
$self->{html_name}="${Html::CLASS}$name_${Html::CLASS_}"; |
| 1471 |
|
| 1472 |
$self->{member_access}=$Enum::PUBLIC ; |
| 1473 |
$self->{member_access}=$Enum::PRIVATE if ($typename eq "class"); |
| 1474 |
|
| 1475 |
$self->{parents}=[]; |
| 1476 |
$self->{children}=[]; |
| 1477 |
|
| 1478 |
$self->{parent_str}=$pstr; |
| 1479 |
|
| 1480 |
bless $self; |
| 1481 |
} |
| 1482 |
|
| 1483 |
sub set_public { my $self=shift; $self->{member_access}=$Enum::PUBLIC ; } |
| 1484 |
sub set_private { my $self=shift; $self->{member_access}=$Enum::PRIVATE ; } |
| 1485 |
sub set_protected { my $self=shift; $self->{member_access}=$Enum::PROTECTED ; } |
| 1486 |
|
| 1487 |
|
| 1488 |
################################################## |
| 1489 |
### Function |
| 1490 |
package Function; |
| 1491 |
use strict; |
| 1492 |
BEGIN { |
| 1493 |
@Function::ISA=qw(Object); |
| 1494 |
} |
| 1495 |
|
| 1496 |
sub new { |
| 1497 |
my ($space_,$name_,$comments_,$type_,$args_)=@_; |
| 1498 |
my $self=Object::new($space_,$name_,$comments_); |
| 1499 |
|
| 1500 |
$type_=" $type_ "; |
| 1501 |
$type_=~s/\s(explicit)\s//; $self->{explicit}=1 if ($1 eq "explicit"); |
| 1502 |
$type_=~s/\s(virtual)\s//; $self->{virtual}=1 if ($1 eq "virtual"); |
| 1503 |
$type_=~s/\s(static)\s//; $self->{static}=1 if ($1 eq "static"); |
| 1504 |
$type_=~s/^\s+//; |
| 1505 |
$type_=~s/\s+$//; |
| 1506 |
|
| 1507 |
$args_=~s/\,/, /g; |
| 1508 |
$args_=~s/\s+/ /g; |
| 1509 |
$args_=~s/^\s+//; |
| 1510 |
$args_=~s/\s+$//; |
| 1511 |
|
| 1512 |
$self->{ntype}=$Enum::FUNCTION; |
| 1513 |
|
| 1514 |
$self->{type}=$type_; |
| 1515 |
$self->{html_type}=$type_; |
| 1516 |
|
| 1517 |
$self->{args}=$args_; |
| 1518 |
$self->{html_args}=$args_; |
| 1519 |
|
| 1520 |
if ($name_ =~/^operator\s(.*)$/) { |
| 1521 |
$self->{html_name}="${Html::KEYWORD}operator${Html::KEYWORD_}<tt> "; |
| 1522 |
$self->{html_name}.=::to_xml($1); |
| 1523 |
$self->{html_name}.="</tt>"; |
| 1524 |
} |
| 1525 |
else { |
| 1526 |
$self->{html_name}="${Html::FUNCTION}${name_}${Html::FUNCTION_}"; |
| 1527 |
} |
| 1528 |
|
| 1529 |
bless $self; |
| 1530 |
} |
| 1531 |
|
| 1532 |
sub decl { |
| 1533 |
my $self=shift; |
| 1534 |
my $ret; |
| 1535 |
my $args; |
| 1536 |
$ret.="explicit " if $$self{explicit}; |
| 1537 |
$ret.="virtual " if $$self{virtual}; |
| 1538 |
$ret.="static " if $$self{static}; |
| 1539 |
$ret.=$$self{type}; |
| 1540 |
$ret.=" "; |
| 1541 |
$args="("; |
| 1542 |
$args=$$self{args}; |
| 1543 |
$args=")"; |
| 1544 |
$args.=" const" if $$self{const}; |
| 1545 |
return ($ret,$$self{name},$$self{args}); |
| 1546 |
} |
| 1547 |
|
| 1548 |
sub html_decl { |
| 1549 |
my $self=shift; |
| 1550 |
my $ret; |
| 1551 |
my $name; |
| 1552 |
my $args; |
| 1553 |
$ret="<tt>"; |
| 1554 |
$ret.="${Html::SPECIFIER}explicit${Html::SPECIFIER_} " if $$self{explicit}; |
| 1555 |
$ret.="${Html::SPECIFIER}virtual${Html::SPECIFIER_} " if $$self{virtual}; |
| 1556 |
$ret.="${Html::SPECIFIER}static${Html::SPECIFIER_} " if $$self{static}; |
| 1557 |
$ret.=$$self{html_type}; |
| 1558 |
$ret.="</tt> "; |
| 1559 |
$name.=$self->href(); #&Plugin::href($self,$$self{html_name}); |
| 1560 |
$args="<tt>("; |
| 1561 |
$args.=$$self{html_args}; |
| 1562 |
$args.=")"; |
| 1563 |
$args.=" ${Html::SPECIFIER}const${Html::SPECIFIER_}" if $$self{const}; |
| 1564 |
$args.="</tt>;"; |
| 1565 |
return ($ret,$name,$args); |
| 1566 |
} |
| 1567 |
|
| 1568 |
sub dump_xml_ { |
| 1569 |
my ($self,$sp,$nl) = @_; |
| 1570 |
Object::dump_xml_($self,$sp,$nl); |
| 1571 |
print "$sp<ctor/>$nl" if $self->is_ctor(); |
| 1572 |
print "$sp<dtor/>$nl" if $self->is_dtor(); |
| 1573 |
print "$sp<const/>$nl" if $self->{const}; |
| 1574 |
print "$sp<explicit/>$nl" if $self->{explicit}; |
| 1575 |
print "$sp<virtual/>$nl" if $self->{virtual}; |
| 1576 |
print "$sp<static/>$nl" if $self->{static}; |
| 1577 |
printf "$sp<returntype>%s</returntype>$nl", &::to_xml($self->{type}); |
| 1578 |
printf "$sp<args>%s</args>$nl", &::to_xml($self->{args}); |
| 1579 |
} |
| 1580 |
|
| 1581 |
sub is_ctor { |
| 1582 |
my ($self)=@_; |
| 1583 |
return !$$self{type}; |
| 1584 |
} |
| 1585 |
|
| 1586 |
sub is_dtor { |
| 1587 |
my ($self)=@_; |
| 1588 |
return $$self{name}=~/^~/; |
| 1589 |
} |
| 1590 |
|
| 1591 |
################################################## |
| 1592 |
### Variable |
| 1593 |
package Variable; |
| 1594 |
use strict; |
| 1595 |
BEGIN { |
| 1596 |
@Variable::ISA=qw(Object); |
| 1597 |
} |
| 1598 |
|
| 1599 |
sub new { |
| 1600 |
my ($space_,$name_,$comments_,$type_)=@_; |
| 1601 |
my $self=Object::new($space_,$name_,$comments_); |
| 1602 |
|
| 1603 |
$self->{ntype}=$Enum::VARIABLE; |
| 1604 |
$self->{type}=$type_; |
| 1605 |
$self->{html_name}="${Html::VARIABLE}$name_${Html::VARIABLE_}"; |
| 1606 |
|
| 1607 |
bless $self; |
| 1608 |
} |
| 1609 |
|
| 1610 |
sub html_decl { |
| 1611 |
my $self=shift; |
| 1612 |
my $ret; |
| 1613 |
my $name; |
| 1614 |
$ret="<tt>"; |
| 1615 |
$ret.=$$self{html_type}; |
| 1616 |
$ret.="</tt> "; |
| 1617 |
$name.="<tt>"; |
| 1618 |
$name.=$self->href(); |
| 1619 |
$name.=";</tt>"; |
| 1620 |
($ret,$name); |
| 1621 |
} |
| 1622 |
|
| 1623 |
sub dump_xml_ { |
| 1624 |
my ($self,$sp,$nl) = @_; |
| 1625 |
Object::dump_xml_($self,$sp,$nl); |
| 1626 |
printf "$sp<type>%s</type>$nl", &::to_xml($self->{type}); |
| 1627 |
} |
| 1628 |
|
| 1629 |
################################################## |
| 1630 |
### Typedef |
| 1631 |
package Typedef; |
| 1632 |
use strict; |
| 1633 |
BEGIN { |
| 1634 |
@Typedef::ISA=qw(Object); |
| 1635 |
} |
| 1636 |
|
| 1637 |
sub new { |
| 1638 |
my ($space_,$name_,$comments_)=@_; |
| 1639 |
my $self=Object::new($space_,$name_,$comments_); |
| 1640 |
|
| 1641 |
$self->{ntype}=$Enum::TYPEDEF; |
| 1642 |
|
| 1643 |
bless $self; |
| 1644 |
} |
| 1645 |
|
| 1646 |
################################################## |
| 1647 |
### Friend |
| 1648 |
package Friend; |
| 1649 |
use strict; |
| 1650 |
BEGIN { |
| 1651 |
@Friend::ISA=qw(Object); |
| 1652 |
} |
| 1653 |
|
| 1654 |
sub new { |
| 1655 |
my ($space_,$name_,$comments_)=@_; |
| 1656 |
my $self=Object::new($space_,$name_,$comments_); |
| 1657 |
|
| 1658 |
$self->{ntype}=$Enum::FRIEND; |
| 1659 |
|
| 1660 |
bless $self; |
| 1661 |
} |
| 1662 |
|