package HeaderDoc::ParseTree;
use strict;
use vars qw($VERSION @ISA);
use HeaderDoc::Utilities qw(isKeyword parseTokens stringToFields casecmp emptyHDok complexAvailabilityToArray printHash validTag);
use HeaderDoc::BlockParse qw(blockParse nspaces);
use Carp qw(cluck);
$HeaderDoc::ParseTree::VERSION = '$Revision: 1333668576 $';
my $debugging = 0;
my $apioDebug = 0;
my $treeDebug = 0;
my %defaults = (
PETDONE => 0,
REFCOUNT => 0,
);
sub new {
my($param) = shift;
my($class) = ref($param) || $param;
my %selfhash = %defaults;
my $self = \%selfhash;
bless($self, $class);
$self->_initialize();
my (%attributeHash) = @_;
foreach my $key (keys(%attributeHash)) {
$self->{$key} = $attributeHash{$key};
}
return ($self);
}
sub _initialize {
my($self) = shift;
$self->{ACCESSCONTROLSTATE} = $HeaderDoc::AccessControlState;
$self->{FILENAME} = $HeaderDoc::headerObject->filename();
$self->{FULLPATH} = $HeaderDoc::headerObject->fullpath();
$self->{LINENUM} = $HeaderDoc::CurLine;
$self->{HIDDEN} = $HeaderDoc::hidetokens;
$self->{APIOWNERS} = ();
$self->{PARSEDPARAMS} = ();
$self->{RAWPARSEDPARAMETERS} = ();
return;
my($self) = shift;
$self->{APIOWNERS} = ();
$self->{ACCESSCONTROLSTATE} = $HeaderDoc::AccessControlState;
$self->{PARSEDPARAMS} = ();
$self->{FILENAME} = $HeaderDoc::headerObject->filename();
$self->{FULLPATH} = $HeaderDoc::headerObject->fullpath();
$self->{LINENUM} = $HeaderDoc::CurLine; $self->{HIDDEN} = $HeaderDoc::hidetokens;
$self->{REFCOUNT} = 0;
$self->{RAWPARSEDPARAMETERS} = ();
$self->{PARSERSTATE} = undef; }
my $colorDebug = 0;
sub clone {
my $self = shift;
my $clone = undef;
if (@_) {
$clone = shift;
} else {
$clone = HeaderDoc::ParseTree->new();
}
$clone->{TOKEN} = $self->{TOKEN};
$clone->{FIRSTCHILD} = $self->{FIRSTCHILD};
$clone->{NEXT} = $self->{NEXT};
$clone->{APIOWNERS} = $self->{APIOWNERS};
$clone->{PARSEDPARAMS} = $self->{PARSEDPARAMS};
$clone->{PETDONE} = 0;
return $clone;
}
sub addSibling
{
my $self = shift;
my $name = shift;
my $hide = shift;
my $newnode = HeaderDoc::ParseTree->new();
my $localDebug = 0;
print STDERR "addSibling $self \"$name\" HIDDEN: $hide\n" if ($treeDebug || $localDebug);
if ($treeDebug == 2) { cluck("backtrace"); }
if ($self->hidden() == 2) {
$hide = 2;
} elsif ($name =~ /^\s+$/ && $self->hidden()) {
$hide = 1;
}
print STDERR "HIDE NOW $hide\n" if ($treeDebug || $localDebug);
my $parent = $self->parent;
my $pos = $self;
bless($pos, "HeaderDoc::ParseTree");
$newnode->token($name);
if ($hide) { $newnode->hidden($hide); }
$newnode->parent($parent);
my $noderef = $newnode;
my $retval = $pos->next($noderef);
print STDERR "New sibling: ".$retval if ($treeDebug);
return $retval;
}
sub addChild
{
my $self = shift;
my $name = shift;
my $hide = shift;
print STDERR "addChild to $self \"$name\"\n" if ($treeDebug);
if ($treeDebug == 2) { cluck("backtrace"); }
if ($self->hidden() == 2 || $self->hidden() == 3) { $hide = 2; }
if (!$self->firstchild()) {
my $newnode = HeaderDoc::ParseTree->new();
if ($hide) { $newnode->hidden($hide); }
$newnode->token($name);
my $noderef = $newnode;
$newnode->parent($self);
my $retval = $self->firstchild($noderef);
print STDERR "New child: ".$retval if ($treeDebug);
return $retval; } else {
warn "addChild called when firstchild exists. Dropping.\n";
}
}
sub isAfter
{
my $self = shift;
my $node = shift;
my $ptr = $node;
while ($ptr) {
if ($ptr == $self) {
return 1;
}
$ptr = $ptr->next();
}
return 0;
}
sub addAPIOwner {
my $self = shift;
my $newapio = shift;
print STDERR "addAPIOwner: SELF WAS $self\n" if ($apioDebug);
print STDERR "addAPIOwner: APIO WAS $newapio\n" if ($apioDebug);
if (!$newapio) {
warn("apiOwner called with empty APIO!\n");
return undef;
} else {
$self->{REFCOUNT}++;
cluck("REFCOUNT $self -> ".$self->{REFCOUNT}." because of $newapio (add)\n") if ($HeaderDoc::debugAllocations);
push(@{$self->{APIOWNERS}}, $newapio);
}
return $newapio;
}
sub apiOwnerSub
{
my $self = shift;
my $old = shift;
my $new = shift;
my $quiet = shift;
my $localDebug = 0;
cluck("apiOwnerSub called with SELF=$self OLD=$old NEW=$new\n") if ($localDebug);
my @arr = ();
my $found = 0;
foreach my $possowner (@{$self->{APIOWNERS}}) {
print "IN apiOwnerSub: $possowner\n" if ($HeaderDoc::debugAllocations);
if ($possowner == $new) {
$new = undef; }
if ($possowner != $old) {
push(@arr, $possowner);
} else {
$found++;
}
}
if (!$found && !$quiet) {
warn("OLD API OWNER NOT FOUND IN apiOwnerSub(). Please file a bug.\n");
}
if ($new) {
push(@arr, $new);
} elsif ($found) {
$self->{REFCOUNT} -= $found;
print STDERR "REFCOUNT $self -> ".$self->{REFCOUNT}." because of $old going away\n" if ($HeaderDoc::debugAllocations);
if (!$self->{REFCOUNT}) {
cluck("Ref count went to zero in apiOwnerSub($self)\n") if ($HeaderDoc::debugAllocations);
}
}
$self->{APIOWNERS} = \@arr;
}
sub newCTState
{
my %statedata = ();
if (@_) {
my $withref = shift;
if ($withref) {
my %withvalues = %{$withref};
foreach my $key (keys %withvalues) {
$statedata{$key} = $withvalues{$key};
}
}
if (@_) {
my (%morevalues) = @_;
foreach my $key (keys(%morevalues)) {
$statedata{$key} = $morevalues{$key};
}
}
}
return \%statedata;
}
sub apiOwner {
my $self = shift;
my $localDebug = 0;
if (@_) {
my $newapio = shift;
if (!$newapio) {
warn("apiOwner called with empty APIO!\n");
}
print STDERR "apiOwner: SETTING TO $newapio (".$newapio->rawname().")\n" if ($apioDebug || $localDebug);
$self->{APIOWNERS} = ();
push(@{$self->{APIOWNERS}}, $newapio);
$self->{REFCOUNT} = 1;
print STDERR "REFCOUNT $self -> 1 because of $newapio (set)\n" if ($HeaderDoc::debugAllocations);
}
my $apio = undef;
foreach my $possowner (@{$self->{APIOWNERS}}) {
print STDERR "TESTING $possowner\n" if ($localDebug);
if ($possowner !~ /HeaderDoc::HeaderElement/) {
if ($possowner !~ /HeaderDoc::APIOwner/) {
if ($possowner) {
$apio = $possowner;
print STDERR "CHOSE $apio\n" if ($localDebug);
}
}
}
}
if (!$apio) {
$apio = pop(@{$self->{APIOWNERS}});
push(@{$self->{APIOWNERS}}, $apio);
print STDERR "GUESSING $apio\n" if ($localDebug);
}
return $apio;
}
sub apiOwners
{
my $self = shift;
return $self->{APIOWNERS};
}
sub lastSibling {
my $self = shift;
while ($self && $self->next()) { $self = $self->next(); }
return $self;
}
sub acs {
my $self = shift;
if (@_) {
$self->{ACCESSCONTROLSTATE} = shift;
}
return $self->{ACCESSCONTROLSTATE};
}
sub token {
my $self = shift;
if (@_) {
$self->{TOKEN} = shift;
}
return $self->{TOKEN};
}
sub hidden {
my $self = shift;
if (@_) {
my $value = shift;
$self->{HIDDEN} = $value;
my $fc = $self->firstchild();
if ($fc) { $fc->hiddenrec($value); }
}
return $self->{HIDDEN};
}
sub hiddenrec
{
my $self = shift;
my $value = shift;
$self->{HIDDEN} = $value;
my $fc = $self->firstchild();
if ($fc) { $fc->hiddenrec($value); }
my $nx = $self->next();
if ($nx) { $nx->hiddenrec($value); }
}
sub objCparsedParams()
{
my $self = shift;
my $lang = shift;
my $sublang = shift;
my @parsedParams = ();
my $objCParmDebug = 0;
my $inType = 0;
my $inName = 0;
my $position = 0;
my $curType = "";
my $curName = "";
my $cur = $self;
my @stack = ();
my $eoDec = 0;
my $lastTag = "";
my $tagName = "";
my $noParse = 1;
my $noTag = 1;
while ($cur || scalar(@stack)) {
while (!$cur && !$eoDec) {
if (!($cur = pop(@stack))) {
$eoDec = 1;
} else {
$cur = $cur->next();
}
}
if ($eoDec) { last; }
my $token = $cur->token();
if ($token eq ":") {
if (!$noTag) {
$tagName = $lastTag;
}
$noParse = 0;
} elsif ($noParse) {
} elsif ($token eq "(") {
$inType++;
$curType .= $token;
} elsif ($token eq ")") {
if (!(--$inType)) {
$inName = 1;
$noTag = 0;
}
$curType .= $token;
} elsif ($token =~ /^[\s\W]/o && !$inType) {
if ($inName && ($curName ne "")) {
$inName = 0;
my $param = HeaderDoc::MinorAPIElement->new("LANG" => $lang, "SUBLANG" => $sublang);
$param->linenuminblock($self->apiOwner()->linenuminblock());
$param->blockoffset($self->apiOwner()->blockoffset());
$param->outputformat($self->apiOwner()->outputformat());
$param->tagname($tagName);
$param->name($curName);
$param->type($curType);
$param->position($position++);
print STDERR "ADDED $curType $curName [$tagName]\n" if ($objCParmDebug);
$curName = "";
$curType = "";
push(@parsedParams, $param);
$noParse = 1;
}
} elsif ($inType) {
$curType .= $token;
} elsif ($inName) {
$curName .= $token;
}
my $fc = $cur->firstchild();
if ($fc) {
push(@stack, $cur);
$cur = $fc;
} else {
$cur = $cur->next();
}
if ($token =~ /\w/) {
$lastTag = $token;
}
}
if ($objCParmDebug) {
foreach my $parm (@parsedParams) {
print STDERR "OCCPARSEDPARM: ".$parm->type()." ".$parm->name()."\n";
}
}
return @parsedParams;
}
sub parsedParams($)
{
my $self = shift;
my $lang = shift;
my $sublang = shift;
my @array = ();
if (@_) {
if ($self->apiOwner() eq "HeaderDoc::Method") {
@{$self->{PARSEDPARAMS}} = $self->objCparsedParams($lang, $sublang);
} else {
my $pplref = shift;
@{$self->{PARSEDPARAMS}} = @{$pplref};
}
}
if (!($self->{PARSEDPARAMS})) {
my $next = $self->next();
if ($next) { return $next->parsedParams($lang, $sublang); }
else { return undef; }
}
return @{$self->{PARSEDPARAMS}};
}
sub slowprev()
{
my $self = shift;
my $parent = $self->parent;
if (!$parent) { return undef; }
my $fc = $parent->firstchild;
if ($self == $fc) { return undef; }
while ($fc && $fc->next && ($fc->next != $self)) { $fc = $fc->next; }
return $fc;
}
sub parsedParamCopy
{
my $self = shift;
my $pplref = shift;
my $lang = shift;
my $sublang = shift;
my $localDebug = 0;
my @parms = @{$pplref};
my @newparms = ();
foreach my $parm (@parms) {
push(@newparms, $parm);
}
$self->parsedParams($lang, $sublang, \@newparms);
print STDERR "PARSEDPARAMCOPY -> $self\n" if ($localDebug);
print STDERR "TOKEN WAS ".$self->token()."\n" if ($localDebug);
}
sub processEmbeddedTags
{
my $self = shift;
my $xmlmode = shift;
my $apiOwner = shift;
my $apiolist = $self->apiOwners();
my $apio = $self->apiOwner();
my $localDebug = 0;
print STDERR "PET: $apio\n" if ($localDebug);
print STDERR $apio->name()."\n" if ($localDebug);
print STDERR "APIOLIST IS $apiolist\n" if ($localDebug);;
my %newapiohash = ();
foreach my $tempapio (@{$apiolist}) {
$newapiohash{$tempapio} = $tempapio;
}
my @newapiolist = ();
foreach my $tempapio (keys %newapiohash) {
push(@newapiolist, $newapiohash{$tempapio});
}
$apiolist = \@newapiolist;
if ($self->{PETDONE}) {
print STDERR "SHORTCUT\n" if ($localDebug);
return;
}
$self->{PETDONE} = 1;
if (!$apio) { return; }
my $apioclass = ref($apio) || $apio;
my $old_enable_cpp = $HeaderDoc::enable_cpp;
if ($apioclass =~ /HeaderDoc::PDefine/ && $apio->parseOnly()) {
if ($HeaderDoc::enable_cpp) {
print STDERR "CPP Enabled. Not processing comments embedded in #define macros marked as 'parse only'.\n" if ($localDebug);
return;
}
} elsif ($apioclass =~ /HeaderDoc::PDefine/) {
if ($HeaderDoc::enable_cpp) {
print STDERR "Temporarily disabling CPP.\n" if ($localDebug);
$HeaderDoc::enable_cpp = 0;
}
}
my %parseTokens = %{parseTokens($apio->lang(), $apio->sublang())};
my $eoDeclaration = 1;
my $lastDeclaration = "";
my $curDeclaration = "";
my $sodec = $self;
my $pendingHDcomment = "";
my ($case_sensitive, $keywordhashref) = $apio->keywords();
my $lastnode = undef;
my $parserState = $self->parserState();
if ($parserState) {
print STDERR "PARSERSTATE\n" if ($localDebug);
$lastnode = $parserState->{lastTreeNode};
print STDERR "LASTNODE: $lastnode\n" if ($localDebug);
if ($lastnode && $localDebug) { print STDERR "LASTNODE TEXT: \"".$lastnode->token()."\"\n"; }
}
my $enable_javadoc_comments = $HeaderDoc::parse_javadoc || ($apio->lang() eq "java");
if ($apio->isAPIOwner()) {
print STDERR "Owner is APIOwner. Using APIOprocessEmbeddedTagsRec for parse tree $self.\n" if ($localDebug);
my $hashtreecur = undef;
my $hashtreeroot = undef;
$self->APIOprocessEmbeddedTagsRec($apiOwner, $case_sensitive, \%parseTokens, $lastnode, 0, 1, $enable_javadoc_comments, $xmlmode, $apio->lang(), $apio->sublang(), $hashtreecur, $hashtreeroot);
} else {
print STDERR "calling processEmbeddedTagsRec for $apio (".$apio->name().") for parse tree $self.\n" if ($localDebug);
$self->processEmbeddedTagsRec($xmlmode, $eoDeclaration, \%parseTokens, $case_sensitive, $keywordhashref, $lastDeclaration, $curDeclaration, $pendingHDcomment,
$apio, $apiolist, $sodec, $lastnode, $enable_javadoc_comments);
}
print STDERR "PETDONE\n" if ($localDebug);
$HeaderDoc::enable_cpp = $old_enable_cpp;
return;
}
sub getNameAndFieldTypeFromDeclaration
{
my $self = shift;
my $string = shift;
my $apio = shift;
my $typedefname = shift;
my $case_sensitive = shift;
my $keywordhashref = shift;
my $localDebug = 0;
my $inputCounter = 0;
my $fullpath = $apio->fullpath();
my $linenum = $apio->linenum();
my $lang = $apio->lang();
my $sublang = $apio->sublang();
my $blockoffset = $linenum;
my $argparse = 2;
if ($string !~ /\S/) { return ("", ""); }
$string .= "\n;\n";
print STDERR "STRING WAS $string\n" if ($localDebug);
cluck("getNameAndFieldTypeFromDeclaration backtrace\n") if ($localDebug);
my @lines = split(/\n/, $string);
foreach my $line (@lines) {
$line .= "\n";
}
my $lastlang = $HeaderDoc::lang;
my $lastsublang = $HeaderDoc::sublang;
$HeaderDoc::lang = $apio->lang;
$HeaderDoc::sublang = $apio->sublang;
my ($inputCounter, $declaration, $typelist, $namelist, $posstypes, $value, $pplStackRef, $returntype, $privateDeclaration, $treeTop, $simpleTDcontents, $availability, $fileoffset, $conformsToList) = blockParse($fullpath, $blockoffset, \@lines, $inputCounter, $argparse, \%HeaderDoc::ignorePrefixes, \%HeaderDoc::perHeaderIgnorePrefixes, \%HeaderDoc::perHeaderIgnoreFuncMacros, $keywordhashref, $case_sensitive, $apio->lang, $apio->sublang);
$HeaderDoc::lang = $lastlang;
$HeaderDoc::sublang = $lastsublang;
print STDERR "IC:$inputCounter DEC:$declaration TL:$typelist NL:$namelist PT:$posstypes VAL:$value PSR:$pplStackRef RT:$returntype PD:$privateDeclaration TT:$treeTop STC:$simpleTDcontents AV:$availability\n" if ($localDebug);
$self->parsedParamCopy($pplStackRef, $lang, $sublang);
my $name = $namelist;
$name =~ s/^\s*//so; # ditch leading spaces
$name =~ s/\s.*$//so; # ditch any additional names. (There shouldn't be any)
my $typestring = $typelist . $posstypes;
print STDERR "TS: $typestring\n" if ($localDebug);
my $type = "\@constant";
if ($typestring =~ /^(function|method|ftmplt|operator|callback)/o) {
$type = "\@$1";
if ($typestring =~ /(ftmplt|operator)/) { $type = "\@function"; }
} elsif ($typestring =~ /^(class|interface|module|category|protocol)/o) {
$typestring =~ s/^ *//;
$type = "\@$typestring";
$type =~ s/ .*$//;
} elsif ($typestring =~ /^(struct|union|record|enum|typedef)/o || (($typedefname ne "") && $typestring =~ /^$typedefname/)) {
$type = "\@field";
} elsif ($typestring =~ /(MACRO| $type = "\@field";
if ($apio eq "HeaderDoc::PDefine") {
$type = "\@define";
}
} elsif ($typestring =~ /(constant)/o) {
$type = "\@constant";
print STDERR "VALUE: \"$value\"\n" if ($localDebug);
if (($value eq "")) {
if ($apio =~ /HeaderDoc::Enum/) {
$type = "\@constant"; } else {
$type = "\@field";
}
}
} else {
warn "getNameAndFieldTypeFromDeclaration: UNKNOWN TYPE ($typestring) RETURNED BY BLOCKPARSE\n";
print STDERR "STRING WAS $string\n" if ($localDebug);
}
if (!$name || ($name eq "")) {
warn "COULD NOT GET NAME FROM DECLARATION. DECLARATION WAS:\n$string\n";
return ("", "");
}
print STDERR "TYPE $type, NAME $name\n" if ($localDebug);
return ($name, $type);
}
sub commentsNestedIn
{
my $token = shift;
my $soc = shift;
my $eoc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $lbrace = shift;
my $case_sensitive = shift;
if ($token =~ /\W/o) {
if ($token =~ /[{(}):]/o) { return 1; }
if ($token =~ /^ if (casecmp($token, $lbrace, $case_sensitive)) { return 1; }
if ($token =~ /\s/o) { return 1; }
return 0;
}
return 1;
}
sub APIOprocessEmbeddedTagsRec($$$$$$$$)
{
my $self = shift;
my $apiOwner = shift; my $case_sensitive = shift;
my $parseTokensRef = shift;
my $lastTreeNode = shift;
my $skipchildren = shift;
my $isroot = shift; my $enable_javadoc_comments = shift;
my $xmlmode = shift;
my $lang = shift;
my $sublang = shift;
my $hashtreecur = shift;
my $hashtreeroot = shift;
my %parseTokens = %{$parseTokensRef};
my $localDebug = 0;
if (1 && $localDebug) {
my $apio = $self->apiOwner();
if ($apio) {
print STDERR "DUMPING TREE.\n"; $self->dbprint();
}
}
my $continue = 1;
if ($self == $lastTreeNode) {
$continue = 0;
print STDERR "CONTINUE -> 0\n" if ($localDebug);
}
my $token = $self->token();
my $firstchild = $self->firstchild();
my $next = $self->next();
print STDERR "APIOprocessEmbeddedTagsRec: TOKEN IS \"".$self->token()."\"\n" if ($localDebug);
my $handled = 0;
print STDERR "SOC: \"$parseTokens{soc}\" ILC: \"$parseTokens{ilc}\" ILC_B: \"$parseTokens{ilc_b}\"\n" if ($localDebug);
if ((length($parseTokens{soc}) && ($token eq $parseTokens{soc})) ||
(length($parseTokens{ilc}) && ($token eq $parseTokens{ilc})) ||
(length($parseTokens{ilc_b}) && ($token eq $parseTokens{ilc_b}))) {
if ((($token eq $parseTokens{soc} && $parseTokens{soc}) || ($token eq $parseTokens{ilc} && $parseTokens{ilc})) && $firstchild) {
print STDERR "COMMENT CHECK\n" if ($localDebug);
my $ntoken = $firstchild->token();
my $nntoken = "";
if ($firstchild->next()) {
$nntoken = $firstchild->next()->token();
}
if ($ntoken eq "" && $firstchild->next()) {
$ntoken = $firstchild->next()->token();
if ($firstchild->next()->next()) {
$nntoken = $firstchild->next()->next()->token();
} else {
$nntoken = "";
}
}
if ($lang eq "ruby" || $lang eq "python") {
my $node = $firstchild;
while ($node && ($node->token() !~ /\S/)) {
$node = $node->next();
}
if ($node) { $nntoken = $node->token(); }
if ($nntoken =~ /\s*!headerdoc!/i) {
$ntoken = "!";
} else {
$ntoken = "";
}
}
print STDERR "NTOKEN: $ntoken\n" if ($localDebug);
print STDERR "NNTOKEN: $nntoken\n" if ($localDebug);
if ((($lang ne "tcl" && ($ntoken eq "!" || ($enable_javadoc_comments && $ntoken eq "*" && $nntoken !~ /^\*/))) ||
($lang eq "tcl" && ($ntoken eq "/*" && $nntoken eq "!" && $firstchild->next()->next()->next()))) &&
!$self->hidden()) {
print STDERR "NODECHECK: $self\n" if ($localDebug);
$self->dbprint() if ($localDebug);
my $string = $token.$firstchild->textTree();
if ($lang eq "ruby" || $lang eq "python") {
$string = $firstchild->next()->next()->textTree();
$string =~ s/^\s*!headerdoc!\s*//si;
$string = "/*!".$string;
$token = $parseTokens{soc};
} elsif ($lang eq "tcl") {
$string = "/*!".$firstchild->next()->next()->next()->textTree();
my $foundend = 0;
if ($string =~ /\*\//) { $foundend = 1; }
my $pos = $self->next();
while ((!$foundend) && $pos) {
print "MOVING TO NEXT. POS IS $pos TOKEN IS ".$pos->token()."\n" if ($localDebug);
my $temp = $pos->firstchild();
if ($temp) {
my $tempstr = $temp->textTree();
if ($pos->token() eq "#") {
$string .= $tempstr;
} elsif ($tempstr =~ /\S/) {
$foundend;
} else {
$string .= "\n";
}
} else {
$string .= "\n";
}
if ($string =~ /\*\//) { $foundend = 1; }
$pos = $pos->next();
}
} elsif ($lang eq "applescript") {
$string =~ s/^\s*\(\*/\/\*/s;
}
if ($ntoken eq "*") { $string =~ s/^\s*\/\*\*/\/\*\!/s; }
print STDERR "FOUND HDCOMMENT:\n$string\nEND HDCOMMENT\n" if ($localDebug);
if ($token eq $parseTokens{soc} && $parseTokens{soc}) {
my $eoc = $parseTokens{eoc};
$string =~ s/\Q$eoc\E\s*$//s;
}
print STDERR "STRING IS $string\n" if ($localDebug);
my $fieldref = stringToFields($string, $self->fullpath, $self->linenum, $xmlmode, $lang, $sublang);
print STDERR "POSSOWNER of $self: $apiOwner\n" if ($localDebug);
if ($apiOwner && $apiOwner->isAPIOwner()) {
print STDERR "ADDING[1] TO $apiOwner.\n" if ($localDebug);
my $ncurly;
($ncurly, $hashtreecur, $hashtreeroot) = $apiOwner->processComment($fieldref, 1, $self->nextTokenNoComments($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, 1, $enable_javadoc_comments), $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
print STDERR "skipochildren -> 1 [1]" if ($localDebug);
$skipchildren = 1;
$next = $next->skipcurly($parseTokens{lbrace}, $ncurly); if ($localDebug) {
print STDERR "NEXT IS $next (";
if ($next) {print STDERR $next->token(); }
print STDERR ")\n";
}
}
$handled = 1;
}
} elsif ($firstchild && $firstchild->next() && $firstchild->next()->next()) {
my $pos = $firstchild->next();
my $fcntoken = $pos->token();
while ($fcntoken =~ /\s/ && $pos) {
$pos = $pos->next;
$fcntoken = $pos->token();
}
if (($fcntoken eq $parseTokens{soc} && $parseTokens{soc}) || ($fcntoken eq $parseTokens{ilc} && $parseTokens{ilc})) {
my $fcnntoken = $firstchild->next()->next()->token();
my $fcnnntoken = "";
if ($firstchild->next()->next()->next()) {
$fcnnntoken = $firstchild->next()->next()->next()->token();
}
if ($fcnntoken eq "!" || ($enable_javadoc_comments && $fcnntoken eq "*" && $fcnnntoken !~ /^\*/)) {
my $string = $fcntoken.$firstchild->textTree();
if ($fcnntoken eq "*") { $string =~ s/^\s*\/\*\*/\/\*\!/s; }
print STDERR "FOUND HDCOMMENT:\n$string\nEND HDCOMMENT\n" if ($localDebug);
if ($fcntoken eq $parseTokens{soc} && $parseTokens{soc}) {
my $eoc = $parseTokens{eoc};
$string =~ s/\Q$eoc\E\s*$//s;
}
my $fieldref = stringToFields($string, $self->fullpath, $self->linenum, $xmlmode, $lang, $sublang);
print STDERR "POSSOWNER of $self: $apiOwner\n" if ($localDebug);
if ($apiOwner && $apiOwner->isAPIOwner()) {
print STDERR "ADDING[2] TO $apiOwner.\n" if ($localDebug);
my $ncurly;
($ncurly, $hashtreecur, $hashtreeroot) = $apiOwner->processComment($fieldref, 1, $self->nextTokenNoComments($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, 1, $enable_javadoc_comments), $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
print STDERR "skipochildren -> 1 [2]" if ($localDebug);
$skipchildren = 1;
$next = $next->skipcurly($parseTokens{lbrace}, $ncurly); if ($localDebug) {
print STDERR "NEXT IS $next (";
if ($next) {print STDERR $next->token(); }
print STDERR ")\n";
}
}
$handled = 1;
}
}
}
}
if (!$handled && $self->parserState() && !$self->parserState()->{APIODONE} && $HeaderDoc::process_everything && !$isroot) {
print STDERR "Declaration without markup\n" if ($localDebug);
print STDERR "POSSOWNER of $self: $apiOwner\n" if ($localDebug);
my @fields = ();
if ($apiOwner && $apiOwner->isAPIOwner()) {
my $ncurly;
($ncurly, $hashtreecur, $hashtreeroot) = $apiOwner->processComment(\@fields, 1, $self, $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
$handled = 1;
} else {
warn "$apiOwner is not API Owner\n";
}
}
if ($handled && $localDebug) {
print STDERR "ADDED TREE TO $apiOwner (".$apiOwner->name().")\n";
$self->dbprint();
print STDERR "DUMPING API OWNER:\n";
$apiOwner->dbprint();
print STDERR "END DUMP.\n";
}
if (length($parseTokens{lbrace}) && $token eq $parseTokens{lbrace}) {
print STDERR "skipochildren -> 0 [3]" if ($localDebug);
$skipchildren = 0;
}
if ($firstchild && !$skipchildren) {
print STDERR "APIOprocessEmbeddedTagsRec: MAYBE GOING TO CHILDREN\n" if ($localDebug);
my $nestallowed = commentsNestedIn($token, $parseTokens{soc}, $parseTokens{eoc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $parseTokens{lbrace}, $case_sensitive);
if ($nestallowed) {
print STDERR "APIOprocessEmbeddedTagsRec: YUP. CHILDREN.\n" if ($localDebug);
my $newcontinue;
($newcontinue, $hashtreecur, $hashtreeroot) = $firstchild->APIOprocessEmbeddedTagsRec($apiOwner, $case_sensitive, $parseTokensRef, $lastTreeNode, $skipchildren, 0, $enable_javadoc_comments, $xmlmode, $lang, $sublang, $hashtreecur, $hashtreeroot);
if ($continue) { $continue = $newcontinue; }
print STDERR "Back from Child\n" if ($localDebug);
print STDERR "skipochildren -> $skipchildren [RECURSEOUT]" if ($localDebug);
}
}
if ($next && $continue) {
print STDERR "APIOprocessEmbeddedTagsRec: GOING TO NEXT\n" if ($localDebug);
($continue, $hashtreecur, $hashtreeroot) = $next->APIOprocessEmbeddedTagsRec($apiOwner, $case_sensitive, $parseTokensRef, $lastTreeNode, $skipchildren, 0, $enable_javadoc_comments, $xmlmode, $lang, $sublang, $hashtreecur, $hashtreeroot);
print STDERR "Back from Next\n" if ($localDebug);
}
print STDERR "HTC: $hashtreecur, HTR: $hashtreeroot\n" if ($localDebug);
print STDERR "SN: ".$self->next()." (".($self->next() ? $self->next()->token() : "").")\n" if ($localDebug);
print STDERR "RECURSEOUT (CONTINUE is $continue)\n" if ($localDebug);
return ($continue, $hashtreecur, $hashtreeroot);
}
my $extDebug = 0;
sub processEmbeddedTagsRec
{
my $self = shift;
my $xmlmode = shift;
my $eoDeclaration = shift;
my $parseTokensRef = shift;
my $case_sensitive = shift;
my $keywordhashref = shift;
my $lastDeclaration = shift;
my $curDeclaration = shift;
my $pendingHDcomment = shift;
my $apio = shift;
my $apiolist = shift;
my $sodec = shift;
my $lastTreeNode = shift;
my $enable_javadoc_comments = shift;
my %parseTokens = %{$parseTokensRef};
my $localDebug = 0 || $extDebug;
my $fieldTypeDebug = 0;
my $oldCurDeclaration = $curDeclaration;
my $oldsodec = $sodec;
my $ntoken = $self->nextpeeknc($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b});
my $skipchildren = 0;
my $oldPHD = $pendingHDcomment;
my $do_process = 0;
my $continue = 1;
my $inBlockDefine = 0;
my $dropinvalid = 0;
my $lastsodec = $sodec;
my $nextsodec = $sodec;
my $hashtreecur = undef;
my $hashtreeroot = undef;
print STDERR "PETREC\n" if ($localDebug);
print STDERR "PENDING COMMENT: $pendingHDcomment\n" if ($localDebug);
print STDERR "LAST DECLARATION: $lastDeclaration\n" if ($localDebug);
if (!$self) { return ($eoDeclaration, $pendingHDcomment, $continue); }
my $apioclass = ref($apio) || $apio;
if ($apioclass =~ /HeaderDoc::PDefine/) {
if ($apio->inDefineBlock() || $apio->isBlock()) {
$inBlockDefine = 1;
my $x = pop(@{$apiolist});
$do_process = $x;
if ($x) {
push(@{$apiolist}, $x);
}
}
}
if ($self == $lastTreeNode) {
print STDERR "CONTINUE -> 0\n" if ($localDebug);
$continue = 0;
}
my $token = $self->token();
$curDeclaration .= $token;
print STDERR "TOKEN: $token\n" if ($localDebug);
if (($token eq $parseTokens{soc} && $parseTokens{soc}) || ($token eq $parseTokens{ilc} && $parseTokens{ilc}) || ($token eq $parseTokens{ilc_b} && $parseTokens{ilc_b})) {
my $firstchild = $self->firstchild();
print STDERR "Comment start\n" if ($localDebug);
if ($firstchild) {
print STDERR "FCT: ".$firstchild->token()."\n" if ($localDebug);
my $nextchild = $firstchild->next();
my $nntoken = "";
if ($nextchild && $nextchild->next()) { $nntoken = $nextchild->next()->token(); }
if ($nextchild && ($nextchild->token eq "!" || ($enable_javadoc_comments && $nextchild->token eq "*" && $nntoken !~ /^\*/))) {
print STDERR "Found embedded HeaderDoc markup\n" if ($localDebug);
print STDERR "NCT: ".$nextchild->token()."\n" if ($localDebug);
print STDERR "WILL SET SODEC. SEARCHING IN:\n" if ($localDebug);
$self->dbprint() if ($localDebug);
$sodec = $self->nextTokenNoComments($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, 0, $enable_javadoc_comments);
print STDERR "SODEC SET TO $sodec\n" if ($localDebug);
if ($sodec) {
$sodec->dbprint() if ($localDebug);
}
my $string = $firstchild->textTree();
my $fullpath = $apio->fullpath();
my $linenum = $apio->linenum();
if ($token eq $parseTokens{soc} && $parseTokens{soc}) {
my $eoc = $parseTokens{eoc};
$string =~ s/\Q$eoc\E\s*$//s;
}
if ($string =~ /^\s*\!/o) {
$string =~ s/^\s*\!//so;
my $tagstring = $string;
$tagstring =~ s/^\s*\@//so;
print STDERR "EOD $eoDeclaration NT $ntoken STR $string\n" if ($localDebug);;
if ((($eoDeclaration && $lastDeclaration =~ /[a-zA-Z]/) || !$ntoken ||
$ntoken =~ /[)}]/o || casecmp($ntoken, $parseTokens{rbrace}, $case_sensitive)) &&
($string !~ /^\s*\@/o || !validTag($tagstring, 0))) {
if (!$inBlockDefine) {
$string =~ s/\@abstract/ /sg;
$string =~ s/\@discussion/ /sg;
}
print STDERR "Using previous declaration because:\n" if ($localDebug);
print STDERR "EODEC: $eoDeclaration NTOKEN: \"$ntoken\"\n" if ($localDebug);
print STDERR "RBRACE: \"$parseTokens{rbrace}\" STRING: \"$string\"\n" if ($localDebug);
if (!$eoDeclaration) {
print STDERR "LASTDITCH PROCESSING\n" if ($localDebug);
} else {
print STDERR "EOD PROCESSING\n" if ($localDebug);
}
$nextsodec = $sodec;
$sodec = $lastsodec;
$string =~ s/^\s*//so;
print STDERR "COMMENTSTRING WAS: $string\n" if ($localDebug);
print STDERR "PRE1\n" if ($localDebug);
print STDERR "LAST DECLARATION: $lastDeclaration\n" if ($localDebug);
print STDERR "calling getNameAndFieldTypeFromDeclaration [1]\n" if ($localDebug || $fieldTypeDebug);
my ($name, $type) = $self->getNameAndFieldTypeFromDeclaration($lastDeclaration, $apio, $parseTokens{typedefname}, $case_sensitive, $keywordhashref);
if ($name) {
$string = "$type $name\n$string";
print STDERR "COMMENTSTRING NOW: $string\n" if ($localDebug);
}
} elsif (!$eoDeclaration && (!$ntoken ||
$ntoken =~ /[)]/o || casecmp($ntoken, $parseTokens{rbrace}, $case_sensitive)) &&
$string =~ /^\s*\@/o) {
my $nlstring = $string;
$nlstring =~ s/[\n\r]/ /sg;
my $emptyok = emptyHDok($nlstring);
if (!$emptyok) {
warn "$fullpath:$linenum: warning: Found invalid headerdoc markup: $nlstring\n";
$dropinvalid = 1;
} elsif ($emptyok == 1) {
warn "$fullpath:$linenum: warning Found headerdoc markup where none expected: $nlstring\n";
} else {
print STDERR "Found always-empty headerdoc markup at end of block: $nlstring\n" if ($localDebug);
$dropinvalid = 2;
}
}
$string =~ s/^\s*//so;
my $tagstring = $string;
$tagstring =~ s/^\s*\@//so;
if ($string =~ /^\s*\@/o && validTag($tagstring, 0)) { print STDERR "COMMENTSTRING: $string\n" if ($localDebug);
my $fieldref = stringToFields($string, $fullpath, $linenum, $xmlmode, $apio->lang(), $apio->sublang());
foreach my $owner (@{$apiolist}) {
my $copy = $fieldref;
print STDERR "OWNER[1]: $owner\n" if ($localDebug);
if ($owner) {
if (!$inBlockDefine || $do_process == $owner) {
my @copyarray = @{$copy};
if ($inBlockDefine && !length($copyarray[0])) { $copyarray[1] =~ s/^field .*?\n/discussion /s; $copy = \@copyarray; }
if ($dropinvalid != 2) {
$owner->processComment($copy, 1, $sodec, $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
}
}
}
}
$apio->{APIREFSETUPDONE} = 0;
} else {
if (!$dropinvalid) {
if (!$inBlockDefine) {
$string =~ s/\@abstract/ /sg;
$string =~ s/\@discussion/ /sg;
}
$pendingHDcomment = $string;
}
}
if (!$HeaderDoc::dumb_as_dirt) {
if ($xmlmode) {
$self->hidden(1); $skipchildren = 1;
} else {
$self->{TOKEN} = "";
$self->{FIRSTCHILD} = undef;
print STDERR "HIDING $self\n" if ($localDebug);
}
print STDERR "DROP\n" if ($localDebug);
$curDeclaration = $oldCurDeclaration;
}
}
}
}
} elsif ($token =~ /[;,}]/o) {
print STDERR "Punctuation\n" if ($localDebug);
print STDERR "SETTING LASTDEC TO $curDeclaration\n" if ($localDebug);
$lastDeclaration = "$curDeclaration\n";
if ($pendingHDcomment) {
print STDERR "PRE2\n" if ($localDebug);
print STDERR "calling getNameAndFieldTypeFromDeclaration [2]\n" if ($localDebug || $fieldTypeDebug);
my ($name, $type) = $self->getNameAndFieldTypeFromDeclaration($lastDeclaration, $apio, $parseTokens{typedefname}, $case_sensitive, $keywordhashref);
if ($name) {
my $string = "$type $name\n$pendingHDcomment";
my $fullpath = $apio->fullpath();
my $linenum = $apio->linenum();
my $fieldref = stringToFields($string, $fullpath, $linenum, $xmlmode, $apio->lang(), $apio->sublang());
print STDERR "COMMENTSTRING: $string\n" if ($localDebug);
print STDERR "OWNERSTART\n" if ($localDebug);
foreach my $owner (@{$apiolist}) {
my $copy = $fieldref;
print STDERR "OWNER[2]: $owner\n" if ($localDebug);
if ($owner) {
if (!$inBlockDefine || $do_process == $owner) {
my @copyarray = @{$copy};
if ($inBlockDefine && !length($copyarray[0])) { $copyarray[1] =~ s/^field .*?\n/discussion /s; $copy = \@copyarray; }
$owner->processComment($copy, 1, $sodec, $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
}
}
}
print STDERR "OWNEREND\n" if ($localDebug);
}
$apio->{APIREFSETUPDONE} = 0;
$pendingHDcomment = "";
} else {
$eoDeclaration = 1;
}
$curDeclaration = "";
} elsif ($token =~ /[\r\n]/o && $lastDeclaration) {
print STDERR "NLCR\n" if ($localDebug);
$lastDeclaration = "";
} elsif ($token !~ /\s/o) {
print STDERR "Whitespace\n" if ($localDebug);
$eoDeclaration = 0;
}
$sodec = $nextsodec;
my $firstchild = $self->firstchild();
my $next = $self->next();
if ($firstchild && !$skipchildren) {
my $nestallowed = commentsNestedIn($token, $parseTokens{soc}, $parseTokens{eoc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $parseTokens{lbrace}, $case_sensitive);
if ($nestallowed == 1) {
my $newcontinue;
($eoDeclaration, $pendingHDcomment, $newcontinue) = $firstchild->processEmbeddedTagsRec($xmlmode, $eoDeclaration, $parseTokensRef, $case_sensitive, $keywordhashref, "", "", "", $apio, $apiolist, $sodec, $lastTreeNode, $enable_javadoc_comments);
if ($continue) { $continue = $newcontinue; }
} else {
my $newcontinue;
($eoDeclaration, $pendingHDcomment, $newcontinue) = $firstchild->processEmbeddedTagsRec($xmlmode, $eoDeclaration, $parseTokensRef, $case_sensitive, $keywordhashref, "", "$curDeclaration", "", $apio, $apiolist, $sodec, $lastTreeNode, $enable_javadoc_comments);
if ($continue) { $continue = $newcontinue; }
}
$curDeclaration .= textTree($firstchild);
} elsif ($firstchild && !$skipchildren) {
$curDeclaration .= textTree($firstchild);
}
if ($ntoken) {
print STDERR "NTOKEN: $ntoken\n" if ($localDebug);
} else {
print STDERR "NTOKEN: (null)\n" if ($localDebug);
}
if (!$ntoken || $ntoken =~ /[)]/o || casecmp($ntoken, $parseTokens{rbrace}, $case_sensitive)) {
if ($ntoken =~ /[)}]/o || casecmp($ntoken, $parseTokens{rbrace}, $case_sensitive)) {
if ($oldCurDeclaration =~ /\S/) {
$lastDeclaration = $oldCurDeclaration.$token;
print STDERR "CLOSEBRACE LASTDITCH: SETTING LASTDEC TO $lastDeclaration\n" if ($localDebug);
}
} else {
if ($oldCurDeclaration =~ /\S/) {
print STDERR "NONCLOSEBRACE LASTDITCH: SETTING LASTDEC TO $curDeclaration\n" if ($localDebug);
$lastDeclaration = $curDeclaration;
}
}
if ($pendingHDcomment) {
print STDERR "LASTDITCH\n" if ($localDebug);
print STDERR "LAST DECLARATION:\n$lastDeclaration\nEND OF LAST DECLARATION\n" if ($localDebug);
print STDERR "PRE3\n" if ($localDebug);
if (!$lastDeclaration) { $lastDeclaration = $curDeclaration; };
print STDERR "calling getNameAndFieldTypeFromDeclaration [3]\n" if ($localDebug || $fieldTypeDebug);
my ($name, $type) = $self->getNameAndFieldTypeFromDeclaration($lastDeclaration, $apio, $parseTokens{typedefname}, $case_sensitive, $keywordhashref);
if ($name) {
my $string = "$type $name\n$pendingHDcomment";
my $fullpath = $apio->fullpath();
my $linenum = $apio->linenum();
my $fieldref = stringToFields($string, $fullpath, $linenum, $xmlmode, $apio->lang(), $apio->sublang());
print STDERR "COMMENTSTRING: $string\n" if ($localDebug);
foreach my $owner (@{$apiolist}) {
my $copy = $fieldref;
print STDERR "OWNER[3]: $owner\n" if ($localDebug);
if ($owner) {
if (!$inBlockDefine || $do_process == $owner) {
my @copyarray = @{$copy};
if ($inBlockDefine && !length($copyarray[0])) { $copyarray[1] =~ s/^field .*?\n/discussion /s; $copy = \@copyarray; }
$owner->processComment($copy, 1, $sodec, $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b}, $self, $hashtreecur, $hashtreeroot);
}
}
}
}
$apio->{APIREFSETUPDONE} = 0;
$pendingHDcomment = "";
}
}
if ($next && $continue) {
($eoDeclaration, $pendingHDcomment, $continue) = $next->processEmbeddedTagsRec($xmlmode, $eoDeclaration, $parseTokensRef, $case_sensitive, $keywordhashref, $lastDeclaration, $curDeclaration, $pendingHDcomment, $apio, $apiolist, $sodec, $lastTreeNode, $enable_javadoc_comments);
}
return ($eoDeclaration, $pendingHDcomment, $continue);
}
sub next {
my $self = shift;
if (@_) {
my $node = shift;
$self->{NEXT} = $node;
}
return $self->{NEXT};
}
sub firstchild {
my $self = shift;
if (@_) {
my $node = shift;
$self->{FIRSTCHILD} = $node;
}
return $self->{FIRSTCHILD};
}
sub parent {
my $self = shift;
if (@_) {
my $node = shift;
$self->{PARENT} = $node;
}
return $self->{PARENT};
}
sub printTree {
my $self = shift;
print STDERR "BEGINPRINTTREE\n";
print STDERR $self->textTree();
print STDERR "ENDPRINTTREE\n";
}
sub textTree {
my $self = shift;
my $nohidden = 0;
if (@_) {
$nohidden = shift;
}
my $parserState = $self->parserState();
my $lastnode = undef;
my $localDebug = 0;
if ($parserState) {
$lastnode = $parserState->{lastTreeNode};
}
print STDERR "TEXTTREE: LASTNODE: $lastnode\n" if ($localDebug);
if ($lastnode && $localDebug) { print STDERR "LASTNODE TEXT: \"".$lastnode->token()."\"\n"; }
my ($string, $continue) = $self->textTreeSub(0, $nohidden, "", "", "", $lastnode);
return $string;
}
sub textTreeNC {
my $self = shift;
my $lang = shift;
my $sublang = shift;
my $nohidden = 0;
if (@_) {
$nohidden = shift;
}
my %parseTokens = %{parseTokens($lang, $sublang)};
my ($string, $continue) = $self->textTreeSub(1, $nohidden, $parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b});
return $string;
}
sub textTreeSub
{
my $self = shift;
my $nc = shift;
my $nh = shift;
my $soc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $lastnode = shift;
my $localDebug = 0;
my $continue = 1;
print STDERR "TTSUB: LN: $lastnode SELF: $self TOK: ".$self->token()."\n" if ($localDebug);
if ($lastnode == $self) {
print STDERR "TTSUB: CONTINUE -> 0\n" if ($localDebug);
$continue = 0;
}
my $string = "";
my $skip = 0;
my $token = $self->token();
if ($nc) {
if ($localDebug) {
print STDERR "NC\n";
print STDERR "SOC: $soc\n";
print STDERR "ILC: $ilc\n";
print STDERR "ILC_B: $ilc_b\n";
print STDERR "TOK: $token\n";
}
if (($token eq "$soc") || ($token eq "$ilc") || ($token eq "$ilc_b")) {
$skip = 1;
}
}
if ($nh) {
if ($self->hidden()) {
$skip = 1;
}
}
if (!$skip) {
$string .= $token;
if ($self->{FIRSTCHILD}) {
my $node = $self->{FIRSTCHILD};
bless($node, "HeaderDoc::ParseTree");
my ($newstring, $newcontinue) = $node->textTreeSub($nc, $nh, $soc, $ilc, $ilc_b, $lastnode);
if ($continue) { $continue = $newcontinue; }
$string .= $newstring;
}
}
if (!$continue) {
return ($string, $continue);
}
if ($self->{NEXT}) {
my $node = $self->{NEXT};
bless($node, "HeaderDoc::ParseTree");
my ($newstring, $newcontinue) = $node->textTreeSub($nc, $nh, $soc, $ilc, $ilc_b, $lastnode);
$continue = $newcontinue;
$string .= $newstring;
}
return ($string, $continue);
}
sub xmlTree {
my $self = shift;
my $keep_whitespace = shift;
my $drop_pdefine_contents = shift;
if ($self->{XMLTREE}) { return $self->{XMLTREE}; }
my $apiOwner = undef;
my $lang = undef;
my $sublang = undef;
my $occmethod = 0;
my $localDebug = 0;
my $debugName = "";
if ($self->apiOwner()) {
$apiOwner = $self->apiOwner();
bless($apiOwner, "HeaderDoc::HeaderElement");
bless($apiOwner, $apiOwner->class());
$lang = $apiOwner->lang();
$sublang = $apiOwner->sublang();
if (($debugName ne "") && ($apiOwner->name() eq $debugName)) {
$colorDebug = 1;
} else {
$colorDebug = 0;
print STDERR $apiOwner->name()."\n" if ($localDebug);
}
if ($apiOwner->class() eq "HeaderDoc::Method") {
$occmethod = 1;
} else {
$occmethod = 0;
}
} else {
warn("WARNING: Could not find API Owner for parse tree $self.\nFaking data structures. Please file a bug.\n");
$lang = "C"; $sublang = "C"; $apiOwner = HeaderDoc::HeaderElement->new("LANG" => $lang, "SUBLANG" => $sublang);
$apiOwner->lang($lang);
$apiOwner->sublang($sublang);
$occmethod = 0; }
my %parseTokens = %{parseTokens($apiOwner->lang(), $apiOwner->sublang())};
$self->processEmbeddedTags(1, $apiOwner);
my $lastnode = undef;
my $parserState = $self->parserState();
if ($parserState) {
$lastnode = $parserState->{lastTreeNode};
}
my %parseTokens = %{parseTokens($lang, $sublang)};
my $ctstate = newCTState( undef, keep_whitespace => $keep_whitespace, apio => $apiOwner, type => "",
depth => 0, inComment => 0, inQuote => 0, inRubyQuote => 0, inObjCMethod => $occmethod,
lastBrace => "", parseTokensRef => \%parseTokens, prespace => "", lang => $lang, sublang => $sublang,
xmlmode => 1, newlen => 0, breakable => 0, inMacro => 0, inEnum => 0, seenEquals => 0,
lastKeyword => "", lastnstoken => "", lastTreeNode => $lastnode, lastTokenType => "",
spaceSinceLastToken => 0, inAttribute => 0, inRaises => 0, inTypeOf => 0,
drop_pdefine_contents => $drop_pdefine_contents, ASinName => 0);
my ($retvalref, $junka, $junkb, $junkc, $junkd, $junke, $lastTokenType, $spaceSinceLastToken) = $self->colorTreeSub($ctstate);
my $retval = ${$retvalref};
$self->{XMLTREE} = $retval;
return $retval;
}
sub htmlTree {
my $self = shift;
my $keep_whitespace = shift;
my $drop_pdefine_contents = shift;
my $apiOwner = undef;
my $lang = undef;
my $sublang = undef;
my $occmethod = 0;
my $localDebug = 0;
my $debugName = "";
if ($self->{HTMLTREE}) {
print STDERR "SHORTCUT\n" if ($localDebug);
return $self->{HTMLTREE};
}
if ($self->apiOwner()) {
$apiOwner = $self->apiOwner();
bless($apiOwner, "HeaderDoc::HeaderElement");
bless($apiOwner, $apiOwner->class());
$lang = $apiOwner->lang();
$sublang = $apiOwner->sublang();
if (($debugName ne "") && ($apiOwner->name() eq $debugName)) {
$colorDebug = 1;
} else {
$colorDebug = 0;
print STDERR $apiOwner->name()."\n" if ($localDebug);
}
if ($apiOwner->class() eq "HeaderDoc::Method") {
$occmethod = 1;
} else {
$occmethod = 0;
}
print STDERR "APIOWNERS was type $apiOwner\n" if ($localDebug);
} else {
warn("WARNING: Could not find API Owner for parse tree $self.\nFaking data structures. Please file a bug.\n");
$lang = "C"; $sublang = "C"; $apiOwner = HeaderDoc::HeaderElement->new("LANG" => $lang, "SUBLANG" => $sublang);
cluck("BT\n");
$apiOwner->apiOwner($HeaderDoc::headerObject);
$apiOwner->lang($lang);
$apiOwner->sublang($sublang);
$occmethod = 0; }
my $lastnode = undef;
my $parserState = $self->parserState();
if ($parserState) {
$lastnode = $parserState->{lastTreeNode};
}
my %parseTokens = %{parseTokens($lang, $sublang)};
$self->processEmbeddedTags(0, $apiOwner);
my $ctstate = newCTState( undef, keep_whitespace => $keep_whitespace, apio => $apiOwner, type => "",
depth => 0, inComment => 0, inQuote => 0, inRubyQuote => 0, inObjCMethod => $occmethod,
lastBrace => "", parseTokensRef => \%parseTokens, prespace => "", lang => $lang, sublang => $sublang,
xmlmode => 0, newlen => 0, breakable => 0, inMacro => 0, inEnum => 0, seenEquals => 0,
lastKeyword => "", lastnstoken => "", lastTreeNode => $lastnode, lastTokenType => "",
spaceSinceLastToken => 0, inAttribute => 0, inRaises => 0, inTypeOf => 0,
drop_pdefine_contents => $drop_pdefine_contents, ASinName => 0);
my ($retvalref, $junka, $junkb, $junkc, $junkd, $junke, $lastTokenType, $spaceSinceLastToken) = $self->colorTreeSub($ctstate);
my $retval = ${$retvalref};
if ($HeaderDoc::align_columns) {
my @retarr = split(/(\n)/s, $retval);
my $newret = "";
foreach my $line (@retarr) {
my $first = "";
if ($line =~ s/^<tr><td nowrap=\"nowrap\"><nowrap>//s) {
$first = "<tr><td nowrap=\"nowrap\"><nowrap>";
}
if ($line =~ s/^( +)//) {
my $spaces = $1;
my $count = ($spaces =~ tr/^ //);
while ($count--) { $line = " $line"; }
$newret .= "$first$line";
} else {
$newret .= "$first$line";
}
}
$retval = $newret;
$retval = "<table><tr><td nowrap=\"nowrap\"><nowrap>$retval</nowrap></td></tr></table>";
}
$self->{HTMLTREE} = $retval;
return $retval;
}
sub childpeeknc
{
my $self = shift;
my $soc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $cache = $self->{CPNC};
if ($cache) { return $cache; }
my $node = $self->{FIRSTCHILD};
if (!$node) { return ""; }
bless($node, "HeaderDoc::ParseTree");
if (!$node->token()) { return $node->childpeeknc($soc, $ilc, $ilc_b) || return $node->nextpeeknc($soc, $ilc, $ilc_b); }
if ($node->token() =~ /\s/o) { return $node->childpeeknc($soc, $ilc, $ilc_b) || return $node->nextpeeknc($soc, $ilc, $ilc_b); }
if ($node->token() eq $soc) { return $node->childpeeknc($soc, $ilc, $ilc_b) || return $node->nextpeeknc($soc, $ilc, $ilc_b); }
if ($node->token() eq $ilc || $node->token() eq $ilc_b) { return $node->childpeeknc($soc, $ilc, $ilc_b) || return $node->nextpeeknc($soc, $ilc, $ilc_b); }
$cache = $node->token();
$self->{CPNC} = $cache;
return $cache;
}
sub nextpeek
{
my $self = shift;
my $node = undef;
if ($self->firstchild()) {
$node = $self->firstchild();
$node = $node->next;
} else {
$node = $self->next();
}
if (!$node) {
return "";
}
my $token = $node->token();
if ($token =~ /\s/o && $token !~ /[\r\n]/o) {
my $ret = $node->nextpeek();
return $ret;
}
if ($node->hidden()) {
my $ret = $node->nextpeek();
return $ret;
}
return $node->token();
}
sub nextpeeknc
{
my $self = shift;
my $soc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $node = $self->nextTokenNoComments($soc, $ilc, $ilc_b, 0, 0);
if (!$node) { return ""; }
return $node->token();
}
sub nextnextpeeknc
{
my $self = shift;
my $soc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $node = $self->nextTokenNoComments($soc, $ilc, $ilc_b, 0, 0);
if (!$node) { return ""; }
my $nodeafter = $node->nextTokenNoComments($soc, $ilc, $ilc_b, 0, 0);
if (!$nodeafter) { return ""; }
return $nodeafter->token();
}
sub nextTokenNoComments($$$$$)
{
my $self = shift;
my $soc = shift;
my $ilc = shift;
my $ilc_b = shift;
my $failOnHDComments = shift;
my $enable_javadoc_comments = shift;
my $localDebug = 0;
my $cache = $self->{NTNC};
if ($cache) { return $cache; }
my $node = $self->{NEXT};
if (!$node) { return undef }
bless($node, "HeaderDoc::ParseTree");
if ($failOnHDComments) {
if ($node->firstchild() && $node->firstchild()->next()) {
my $testnode = $node->firstchild()->next();
if (($node->token() eq $ilc) || ($node->token() eq $ilc_b)) {
if ($node->token() eq $ilc) {
my $ntoken = "";
if ($testnode->next()) { $ntoken = $testnode->next()->token(); }
if ($testnode->token() eq "!" || ($enable_javadoc_comments && $testnode->token eq "*" && $ntoken !~ /^\*/)) {
print STDERR "Unexpected HD Comment\n" if ($localDebug);
return undef;
}
} else {
if ($testnode->token() eq $ilc) {
my $nntoken = "";
if ($testnode->next() && $testnode->next()->next()) { $nntoken = $testnode->next()->next()->token(); }
if ($testnode->next() && (($testnode->next()->token() eq "!") || ($enable_javadoc_comments && $testnode->next()->token eq "*" && $nntoken !~ /^\*/))) {
print STDERR "Unexpected HD Comment\n" if ($localDebug);
return undef;
}
}
}
} elsif ($node->token() eq $soc) {
my $ntoken = "";
if ($testnode->next()) { $ntoken = $testnode->next()->token(); }
if (($testnode->token() eq "!") || ($enable_javadoc_comments && $testnode->token eq "*" && $ntoken !~ /^\*/)) {
print STDERR "Unexpected HD Comment\n" if ($localDebug);
return undef;
}
}
}
}
if (!$node->token()) { return $self->{NTNC} = $node->nextTokenNoComments($soc, $ilc, $ilc_b, $failOnHDComments, $enable_javadoc_comments); }
if ($node->token() =~ /\s/o) { return $self->{NTNC} = $node->nextTokenNoComments($soc, $ilc, $ilc_b, $failOnHDComments, $enable_javadoc_comments); }
if ($node->token() eq $soc) { return $self->{NTNC} = $node->nextTokenNoComments($soc, $ilc, $ilc_b, $failOnHDComments, $enable_javadoc_comments); }
if ($node->token() eq $ilc || $node->token() eq $ilc_b) { return $self->{NTNC} = $node->nextTokenNoComments($soc, $ilc, $ilc_b, $failOnHDComments, $enable_javadoc_comments); }
$self->{NTNC} = $node;
return $node;
}
sub nextAtLevelOf
{
my $self = shift;
my $matchingnode = shift;
my $fullpath = shift;
my $nextnode = $self;
while ($nextnode && !$nextnode->isAfter($matchingnode)) {
$nextnode = $nextnode->parent();
}
if ($nextnode) {
$nextnode = $nextnode->next();
} else {
my $tt = $self;
while ($tt->parent()) { $tt = $tt->parent(); }
my $apio = $tt->apiOwner();
cluck("TT: $tt\n");
warn("$fullpath:0:Ran off top of stack looking for next node.\n");
$nextnode = undef;
}
return $nextnode;
}
sub isMacro
{
my $self = shift;
my $token = shift;
my $lang = shift;
my $sublang = shift;
if ($lang ne "C" && $lang ne "Csource") { return 0; }
if ($token =~ /^\
return 0;
}
sub colorTreeSub
{
my $self = shift;
my $ctstateref = shift;
my $localDebug = 0;
my $psDebug = 0;
my $treeDebug = 0;
my $dropDebug = 0;
my $tokenDebug = 0;
my $codePathDebug = 0;
my $rubyDebug = 0;
print STDERR "***** TOKEN: ".$self->{TOKEN}." *****\n" if ($codePathDebug || $localDebug);
my $continue = 1;
my %ctstate = %{$ctstateref};
if ($self == $ctstate{lastTreeNode}) {
print STDERR "Node is last node in tree. Ending after this node.\n" if ($localDebug || $codePathDebug);
$continue = 0;
}
my %parseTokens = %{$ctstate{parseTokensRef}};
my %macroList = %{$parseTokens{macronames}};
my $oldLastBrace = $ctstate{lastBrace};
my $oldDepth = $ctstate{depth};
my $oldInMacro = $ctstate{inMacro};
my $oldInQuote = $ctstate{inQuote};
my $oldLastKeyword = $ctstate{lastKeyword};
my $oldInComment = $ctstate{inComment} ;
my $oldInAttribute = $ctstate{inAttribute};
my $oldInRaises = $ctstate{inRaises};
my $oldInTypeOf = $ctstate{inTypeOf};
my $dropFP = 0;
my $keep_all_newlines = 0;
print STDERR "DPC: ".$ctstate{drop_pdefine_contents}."\n" if ($localDebug);
if ($ctstate{lang} eq "shell" || $ctstate{sublang} eq "javascript") {
$keep_all_newlines = 1;
} elsif ($ctstate{lang} eq "python") {
$keep_all_newlines = 1;
$ctstate{keep_whitespace} = 1;
}
if ($ctstate{xmlmode} && $localDebug) {
print STDERR "XMLMODE.\n";
}
print STDERR "IM: ".$ctstate{inMacro}."\n" if ($localDebug);
print STDERR "IAtt: ".$ctstate{inAttribute}."\n" if ($localDebug);
print STDERR "IRai: ".$ctstate{inRaises}."\n" if ($localDebug);
my $mustbreak = 0;
my $nextprespace = "";
my $string = "";
my $tailstring = "";
my $token = $self->{TOKEN};
my $escapetoken = "";
my ($case_sensitive, $keywordhashref) = $ctstate{apio}->keywords();
my $tokennl = 0;
if ($token =~ /^[\r\n]/o) { $tokennl = 1; }
if (($token eq "\t" || $token =~ /^ +$/) && (!$ctstate{keep_whitespace})) { $token = " "; }
if ($ctstate{inQuote} == 3) {
$keep_all_newlines = 1;
$ctstate{keep_whitespace} = 1;
}
if ($ctstate{keep_whitespace}) {
$ctstate{prespace} = "";
$nextprespace = "";
}
my $tokenIsKeyword = isKeyword($token, $keywordhashref, $case_sensitive);
print STDERR "TIK: $tokenIsKeyword\n" if ($localDebug);
print STDERR "TK $token\n" if ($colorDebug || $rubyDebug || $colorDebug);
print STDERR "IRQ is ".$ctstate{inRubyQuote}."\n" if ($rubyDebug || $colorDebug);
print STDERR "IQ is ".$ctstate{inQuote}."\n" if ($rubyDebug || $colorDebug);
my $ctoken = $self->childpeeknc($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b});
my $ntoken = $self->nextpeek();
my $ntokennc = $self->nextpeeknc($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b});
my $nntokennc = $self->nextnextpeeknc($parseTokens{soc}, $parseTokens{ilc}, $parseTokens{ilc_b});
my $tokenType = undef;
my $drop = 0;
my $firstCommentToken = 0;
my $leavingComment = 0;
my $hidden = ($self->hidden() && !$ctstate{xmlmode});
my $isTypeStar = 0;
my $begintr = "";
my $endtr = "";
my $newtd = "";
if (!$ctstate{xmlmode} && $HeaderDoc::align_columns) {
$begintr = "<tr><td nowrap=\"nowrap\"><nowrap>";
$endtr = "</nowrap></td></tr>";
$newtd = "</nowrap></td><td nowrap=\"nowrap\"><nowrap>";
}
if ($ntoken eq "::" && $ctstate{lang} eq "perl") {
$ctstate{tokenAccum} .= $token.$ntoken;
$ctstate{skipToken} = 2;
} elsif ($ctstate{tokenAccum} && (!$ctstate{skipToken})) {
$token = $ctstate{tokenAccum}.$token;
$ctstate{tokenAccum} = "";
}
if ($treeDebug || $localDebug || $codePathDebug) {
my $tokenname = $token;
if ($token eq "\n") { $tokenname = "[NEWLINE]"; }
elsif ($token eq "\r") { $tokenname = "[CARRIAGE RETURN]"; }
my $ntokenname = $ntoken;
if ($ntoken eq "\n") { $ntokenname = "[NEWLINE]"; }
elsif ($ntoken eq "\r") { $ntokenname = "[CARRIAGE RETURN]"; }
my $lastnstokenname = $ctstate{lastnstoken};
if ($ctstate{lastnstoken} eq "\n") { $lastnstokenname = "[NEWLINE]"; }
elsif ($ctstate{lastnstoken} eq "\r") { $lastnstokenname = "[CARRIAGE RETURN]"; }
print STDERR "TOKEN: $tokenname NTOKEN: $ntokenname LASTNSTOKEN: $lastnstokenname IC: ".$ctstate{inComment}."\n" if ($treeDebug || $localDebug || $codePathDebug);
}
print STDERR "OCC: ".$ctstate{inObjCMethod}."\n" if ($colorDebug || $localDebug);
print STDERR "HIDDEN: $hidden\n" if ($localDebug);
print STDERR "TK $token NT $ntoken NTNC $ntokennc NNTNC $nntokennc LB: ".$ctstate{lastBrace}." PS: ".length($ctstate{prespace})."\n" if ($colorDebug);
my $nospaceafter = 0;
my $nextbreakable = 0;
if ($ctstate{breakable} == 2) {
$ctstate{breakable} = 0;
$nextbreakable = 1;
} elsif ($ctstate{breakable} == 3) {
$mustbreak = 1;
$ctstate{breakable} = 1;
$nextbreakable = 0;
}
print STDERR "POST_CHECK MUSTBREAK: $mustbreak BREAKABLE: ".$ctstate{breakable}." NEXTBREAKABLE: $nextbreakable\n" if ($localDebug);
if (($ctstate{lang} eq "C" || $ctstate{lang} eq "Csource") && $token eq $parseTokens{enumname}) {
my $curname = $ctstate{apio}->name();
print STDERR "NAME: $curname\n" if ($localDebug);
print STDERR "NOW ENUM\n" if ($localDebug);
$ctstate{inEnum} = 1;
}
if ($parseTokens{propname} && $token eq $parseTokens{propname}) {
$ctstate{inObjCProperty} = 1;
}
if ($ctstate{inObjCMethod} && $token =~ /^[+-]/o && ($ctstate{lastBrace} eq "")) {
$ctstate{lastBrace} = $token;
}
my $MIG = 0;
if ($ctstate{lang} eq "C" && $ctstate{sublang} eq "MIG") { $MIG = 1; }
my $splitre = "";
if ($ctstate{type} =~ /^(typedef|struct|record|union)/o) {
$splitre = ";";
} elsif ($ctstate{type} =~ /^(enum|funcptr)/o) {
$splitre = ",";
} elsif ($ctstate{lastBrace} eq "(") {
$splitre = ",";
if ($MIG) { $splitre = ";"; }
} elsif ($ctstate{lastBrace} eq $parseTokens{lbrace}) {
if ($ctstate{lang} eq "tcl") {
$splitre = '\s';
} elsif ($ctstate{inEnum}) {
$splitre = ",";
} else {
$splitre = ";";
}
} elsif (($ctstate{lastBrace} eq $parseTokens{structname}) && $parseTokens{structisbrace}) {
$splitre = ";";
}
print STDERR "SPLITRE IS $splitre\n" if ($localDebug);
if ($splitre && ($token =~ $splitre)) { print STDERR "WILL SPLIT AFTER \"$token\" AND BEFORE \"$ntoken\".\n" if ($localDebug);
$nextbreakable = 3;
}
print STDERR "SOC: \"$parseTokens{soc}\"\nEOC: \"$parseTokens{eoc}\"\nILC: \"$parseTokens{ilc}\"\nILC_B: \"$parseTokens{ilc_b}\"\nLBRACE: \"$parseTokens{lbrace}\"\nRBRACE: \"$parseTokens{rbrace}\"\nSOPROC: \"$parseTokens{soprocedure}\"\nSOFUNC: \"$parseTokens{sofunction}\"\nVAR: \"$parseTokens{varname}\"\nSTRUCTNAME: \"$parseTokens{structname}\"\nTYPEDEFNAME: \"$parseTokens{typedefname}\"\n" if ($tokenDebug);
print STDERR "inQuote: ".$ctstate{inQuote}."\noldInQuote: $oldInQuote\ninComment: ".$ctstate{inComment}."\ninMacro: ".$ctstate{inMacro}."\ninEnum: ".$ctstate{inEnum}."\n" if ($localDebug);
print STDERR "oldInMacro: $oldInMacro\noldInComment: $oldInComment\n" if ($localDebug);
print STDERR "TOKEN: $token ASINNAME: ".$ctstate{ASinName}."\n" if ($localDebug);
if ($ctstate{inEnum}) {
if (casecmp($token, $parseTokens{unionname}, $case_sensitive)) { $ctstate{inEnum} = 0; };
if (casecmp($token, $parseTokens{structname}, $case_sensitive)) { $ctstate{inEnum} = 0; };
if (casecmp($token, $parseTokens{typedefname}, $case_sensitive)) { $ctstate{inEnum} = 0; };
}
my $nonword = 0; my $pascal = 0; my $ruby = 0;
if ($token =~ /\W/) {
$nonword = 1;
if ($ctstate{ASinName} && (!$ctstate{inQuote}) && (!$ctstate{inComment}) && ($token !~ /\s/)) {
$ctstate{ASinName} = -1;
print STDERR "ASinName -> -1 [1]\n" if ($localDebug);
}
}
if ($ctstate{lang} eq "pascal") { $pascal = 1; }
if ($ctstate{lang} eq "ruby") { $ruby = 1; }
if ($ctstate{lang} eq "applescript" && $token =~ /(given|of|in)/) {
print STDERR "ASinName -> 3 [0a]\n" if ($localDebug);
$ctstate{ASinName} = 3;
print STDERR "AS lastBrace -> \"(\"\n" if ($localDebug);
$ctstate{lastBrace} = "(";
} elsif ($parseTokens{labelregexp} && $token =~ $parseTokens{labelregexp}) {
print STDERR "ASinName -> 3 [0b]\n" if ($localDebug);
$ctstate{ASinName} = 3;
print STDERR "AS lastBrace -> \"(\"\n" if ($localDebug);
$ctstate{lastBrace} = "(";
}
my $untypedLanguage = 0;
if ($ctstate{sublang} eq "javascript" ||
$ctstate{lang} eq "php" || $ctstate{lang} eq "perl" || $ctstate{lang} eq "python" ||
$ctstate{lang} eq "shell" || $ctstate{lang} eq "applescript") {
$untypedLanguage = 1;
} elsif ($ruby || $ctstate{lang} eq "tcl") {
$untypedLanguage = 2;
}
if ($ctstate{skipToken}) {
$ctstate{skipToken}--;
$drop = 1;
$token = "";
}
if ($ctstate{lang} eq "C" || $ctstate{lang} eq "java" || $pascal || $ctstate{sublang} eq "javascript" ||
$ctstate{lang} eq "php" || $ctstate{lang} eq "perl" || $ruby || $ctstate{lang} eq "python" ||
$ctstate{lang} eq "Csource" || $ctstate{lang} eq "shell" || $ctstate{lang} eq "applescript" ||
$ctstate{lang} eq "tcl") {
if ($ctstate{inQuote} == 1) {
print STDERR " STRING\n" if ($localDebug || $codePathDebug);
$tokenType = "string";
} elsif ($ctstate{inQuote} == 2) {
print STDERR " CHAR\n" if ($localDebug || $codePathDebug);
$tokenType = "char";
} elsif ($ctstate{inQuote} == 3 && $ctstate{inRubyQuote} != 2 && !$tokennl) {
$tokenType = "string";
} elsif ($nonword && $token eq $parseTokens{soc} && $parseTokens{soc} ne "") {
if (!$hidden) {
$tokenType = "comment";
if ($ctstate{ASinName} == -1) {
$ctstate{ASinName} = 1;
print STDERR "ASinName -> 1 [2]\n" if ($localDebug);
}
print STDERR " COMMENT [1]\n" if ($localDebug || $codePathDebug);
if (!$ctstate{inComment}) {
$ctstate{inComment} = 1;
$firstCommentToken = 1;
if ($ctstate{xmlmode}) {
$string .= "<declaration_comment>";
} else {
$string .= "<span class=\"comment\">";
}
} else {
print STDERR " nested comment\n" if ($localDebug || $codePathDebug);
}
} else {
print STDERR " COMMENT [1a]: HIDDEN\n" if ($localDebug || $codePathDebug);
}
} elsif ($nonword && ((($token eq $parseTokens{ilc}) && ($parseTokens{ilc} ne "")) || (($token eq $parseTokens{ilc_b}) && ($parseTokens{ilc_b} ne "")))) {
if (!$hidden) {
print STDERR " ILCOMMENT [1]\n" if ($localDebug || $codePathDebug);
$tokenType = "comment";
if (!$ctstate{inComment}) {
if ($ctstate{ASinName} == -1) {
$ctstate{ASinName} = 1;
print STDERR "ASinName -> 1 [3]\n" if ($localDebug);
}
print STDERR " REALILCOMMENT\n" if ($localDebug || $codePathDebug);
$ctstate{inComment} = 2;
$firstCommentToken = 1;
if ($ctstate{xmlmode}) {
$string .= "<declaration_comment>";
} else {
$string .= "<span class=\"comment\">";
}
} else {
print STDERR " nested comment\n" if ($localDebug || $codePathDebug);
}
} else {
print STDERR " ILCOMMENT [1a]: HIDDEN\n" if ($localDebug || $codePathDebug);
}
} elsif ($nonword && $token eq $parseTokens{eoc} && $parseTokens{eoc} ne "") {
print STDERR " EOCOMMENT [1]\n" if ($localDebug || $codePathDebug);
$tokenType = "comment";
if ($ctstate{xmlmode}) {
$tailstring .= "</declaration_comment>";
} else {
$tailstring = "</span>";
}
$leavingComment = 1;
$ctstate{inComment} = 0;
} elsif ($tokennl && ($ntoken !~ /^[\r\n]/o || $ctstate{keep_whitespace} || $keep_all_newlines)) {
if ($ctstate{ASinName}) {
$ctstate{ASinName} = 0;
print STDERR "ASinName -> 0 [4]\n" if ($localDebug);
}
if ($ctstate{inComment} == 2) {
print STDERR " EOL INCOMMENT: END ILCOMMENT [1]\n" if ($localDebug || $codePathDebug);
$tokenType = "comment";
if ($ctstate{xmlmode}) {
$string .= "</declaration_comment>";
} else {
$string .= "</span>";
}
$ctstate{inComment} = 0;
$ctstate{newlen} = 0;
$mustbreak = 1;
$drop = 1;
} elsif ($ctstate{inMacro} || $keep_all_newlines) {
print STDERR " EOL INMACRO\n" if ($localDebug || $codePathDebug);
$mustbreak = 1;
$ctstate{newlen} = 0;
} elsif ($ctstate{inComment}) {
print STDERR " EOL INCOMMENT\n" if ($localDebug || $codePathDebug);
$mustbreak = 1;
$ctstate{newlen} = 0;
$drop = 1;
}
$ctstate{breakable} = 0;
$nextbreakable = 0;
$ctstate{newlen} = 0;
} elsif ($ctstate{inComment}) {
print STDERR " COMMENT [2:".$ctstate{inComment}."]\n" if ($localDebug || $codePathDebug);
$tokenType = "comment";
if ($ctstate{inComment} == 1) {
if (($token =~ /^\s/o && !$tokennl && $ntoken !~ /^\s/o) && (!$ctstate{keep_whitespace})) {
$ctstate{breakable} = 1;
}
}
} elsif ($ctstate{inMacro}) {
print STDERR " MACRO [IN]\n" if ($localDebug || $codePathDebug);
$tokenType = "preprocessor";
} elsif ($token eq "=") {
print STDERR " EQUALS\n" if ($localDebug || $codePathDebug);
$nextbreakable = 1;
if ($ctstate{type} eq "pastd") {
$ctstate{type} = "";
print STDERR " END OF VAR\n" if ($localDebug || $codePathDebug);
}
if ($pascal) { $ctstate{seenEquals} = 1; }
} elsif ($token eq "-") {
print STDERR " MINUS\n" if ($localDebug || $codePathDebug);
if ($ntoken =~ /^\d/o) {
$tokenType = "number";
print STDERR " NUMBER [1]\n" if ($localDebug || $codePathDebug);
} else {
print STDERR " TEXT [1]\n" if ($localDebug || $codePathDebug);
$tokenType = "";
}
} elsif ($token =~ /^\d+$/o || $token =~ /^0x[\dabcdef]+$/io) {
$tokenType = "number";
$ctstate{type} = "hexnumber";
print STDERR " \nNUMBER [2]: $token\n" if ($localDebug || $codePathDebug);
} elsif (!$nonword && (casecmp($token, $parseTokens{sofunction}, $case_sensitive) || casecmp($token, $parseTokens{soprocedure}, $case_sensitive) || casecmp($token, $parseTokens{soconstructor}, $case_sensitive))) {
$tokenType = "keyword";
$ctstate{lastKeyword} = $token;
print STDERR " SOFUNC/SOPROC\n" if ($localDebug || $codePathDebug);
$ctstate{type} = "funcproc";
$ctstate{lastBrace} = "(";
$oldLastBrace = "(";
if ($ctstate{lang} eq "applescript") {
$ctstate{ASinName} = 1;
print STDERR "ASinName -> 1 [5]\n" if ($localDebug);
}
} elsif (!$nonword && $ctstate{type} eq "funcproc") {
if ($token =~ /^\;/o) {
$ctstate{type} = "";
$nextbreakable = 3;
}
print STDERR " FUNC/PROC NAME\n" if ($localDebug || $codePathDebug);
$tokenType = "function";
} elsif (!$nonword && casecmp($token, $parseTokens{constname}, $case_sensitive) && $ctstate{lang} eq "pascal") {
$tokenType = "keyword";
print STDERR " VAR\n" if ($localDebug || $codePathDebug);
$ctstate{type} = "pasvar";
} elsif (!$nonword && casecmp($token, $parseTokens{varname}, $case_sensitive)) {
$tokenType = "keyword";
print STDERR " VAR\n" if ($localDebug || $codePathDebug);
$ctstate{type} = "pasvar";
} elsif ($nonword && ($ctstate{type} eq "pasvar" || $ctstate{type} eq "pastd") &&
($token =~ /^[\;\:\=]/o)) {
$ctstate{type} = "";
print STDERR " END OF VAR\n" if ($localDebug || $codePathDebug);
} elsif ($ctstate{type} eq "pasvar" || $ctstate{type} eq "pastd") {
print STDERR " VAR NAME\n" if ($localDebug || $codePathDebug);
$tokenType = "var";
} elsif (!$nonword && ($pascal) && casecmp($token, $parseTokens{typedefname}, $case_sensitive)) {
print STDERR " TYPE\n" if ($localDebug || $codePathDebug);
$tokenType = "keyword";
$ctstate{type} = "pastd";
} elsif (!$nonword && ($pascal) && casecmp($token, $parseTokens{structname}, $case_sensitive)) {
print STDERR " RECORD/STRUCT\n" if ($localDebug || $codePathDebug);
$ctstate{lastBrace} = $token;
$tokenType = "keyword";
$ctstate{type} = "pasrec";
} elsif (!$nonword && $tokenIsKeyword) {
$tokenType = "keyword";
if ($ctstate{ASinName} != 1 && $ctstate{ASinName} != 3) {
$ctstate{ASinName} = 0;
print STDERR "ASinName -> 0 [6]\n" if ($localDebug);
}
if ($tokenIsKeyword == 2) {
$ctstate{inAttribute} = 1;
} elsif ($tokenIsKeyword == 5) {
$ctstate{inRaises} = 1;
} elsif ($tokenIsKeyword == 6) {
$ctstate{inTypeOf} = 1;
}
if ($ctstate{lastBrace} eq $parseTokens{sotemplate} && $parseTokens{sotemplate} ne "") {
$tokenType = "template";
}
print STDERR " KEYWORD\n" if ($localDebug || $codePathDebug);
if ($case_sensitive) {
if ($macroList{$token}) {
print STDERR " IN MACRO\n" if ($localDebug || $codePathDebug);
$ctstate{inMacro} = 1;
}
} else {
foreach my $cmpToken (keys %macroList) {
if (casecmp($token, $cmpToken, $case_sensitive)) {
$ctstate{inMacro} = 1;
}
}
}
print STDERR " TOKEN IS $token, IM is now ".$ctstate{inMacro}."\n" if ($localDebug || $codePathDebug);
if (casecmp($token, $parseTokens{rbrace}, $case_sensitive)) {
print STDERR "PS: ".length($ctstate{prespace})." -> " if ($psDebug);
$mustbreak = 2;
print STDERR length($ctstate{prespace})."\n" if ($psDebug);
}
} elsif (!$ctstate{inQuote} && !$ctstate{inComment} && isKnownMacroToken($token, \%macroList, $case_sensitive)) {
print STDERR " IN MACRO\n" if ($localDebug || $codePathDebug);
$ctstate{inMacro} = 1;
} elsif (($token eq "*") && ($ctstate{depth} == 1) && ($ctstate{lastTokenType} eq "type" || $ctstate{lastTokenType} eq "star")) {
print STDERR " ASTERISK\n" if ($localDebug || $codePathDebug);
if (!$ctstate{spaceSinceLastToken} && (!$ctstate{keep_whitespace}) && $ctstate{lastTokenType} ne "star") {
if ($ctstate{prespace} == "") { $ctstate{prespace} = " "; }
}
$tokenType = "type";
$isTypeStar = 1;
$nospaceafter = 1;
} elsif ($ntokennc eq ":" && $ctstate{inObjCMethod}) {
print STDERR " COLON (FUNCTION [1])\n" if ($localDebug || $codePathDebug);
$tokenType = "function";
} elsif ($token eq ":" && $ctstate{inObjCMethod}) {
print STDERR " COLON (FUNCTION [2])\n" if ($localDebug || $codePathDebug);
$tokenType = "function";
} elsif ($token eq ":" && $ctoken) {
$ctstate{depth} = $ctstate{depth} - 1; } elsif ($ntokennc eq "(" && !$ctstate{seenEquals} && !$ctstate{inAttribute} && !$ctstate{inRaises} && !$ctstate{inTypeOf}) {
$tokenType = "function";
print STDERR " LPAREN (FUNCTION [3])\n" if ($localDebug || $codePathDebug);
if ($nntokennc eq "(" && !$untypedLanguage) {
$tokenType = "type";
$ctstate{type} = "funcptr";
}
if ($ctstate{inObjCMethod}) {
$tokenType = ""; }
if ($token eq "(") { $dropFP = 1; }
} elsif ((!$untypedLanguage) && $ntokennc eq $parseTokens{lbrace} && $parseTokens{lbrace} ne "") {
$tokenType = "type";
print STDERR " LBRACE (TYPE [1])\n" if ($localDebug || $codePathDebug);
} elsif (($ctstate{inAttribute} || $ctstate{inRaises} || $ctstate{inTypeOf}) && $token eq "(") {
print STDERR " LPAREN (ATTRIBUTE)\n" if ($localDebug || $codePathDebug);
$nextbreakable = 0;
} elsif ($token eq "(") {
print STDERR " LPAREN (GENERAL)\n" if ($localDebug || $codePathDebug);
$ctstate{type} = "";
if ($ctstate{inObjCProperty}) {
$nextbreakable = 0;
$oldLastBrace = "";
} elsif ($ctstate{inObjCMethod} && $ctstate{lastBrace} =~ /^[+-]/o) {
$nextbreakable = 0;
$oldLastBrace = "";
} elsif ($ctoken ne ")") {
$nextbreakable = 3;
}
$ctstate{lastBrace} = $token;
} elsif ($token eq $parseTokens{sotemplate} && $parseTokens{sotemplate} ne "") {
print STDERR " TEMPLATE\n" if ($localDebug || $codePathDebug);
$ctstate{lastBrace} = $token;
$nextbreakable = 0;
$ctstate{breakable} = 0;
} elsif (casecmp($token, $parseTokens{lbrace}, $case_sensitive)) {
print STDERR " LBRACE (GENERAL)\n" if ($localDebug || $codePathDebug);
$ctstate{type} = "";
$ctstate{lastBrace} = $token;
$nextbreakable = 3;
if (!casecmp($ctoken, $parseTokens{rbrace}, $case_sensitive)) {
$nextbreakable = 3;
}
} elsif (($ctstate{lang} eq "python") && ($token eq "\"\"\"")) {
if ($ctstate{inQuote}) { $ctstate{inQuote} = 0; }
else { $ctstate{inQuote} = 3; }
} elsif ($ruby && ($token eq "%{" || $token eq "%Q{")) {
$ctstate{inQuote} = 3; $ctstate{inRubyQuote} = 1;
} elsif ($ruby && ($token eq "%/")) {
$ctstate{inQuote} = 3; $ctstate{inRubyQuote} = 1;
} elsif ($ruby && ($token eq "<<")) {
$ctstate{inQuote} = 3;
$ctstate{inRubyQuote} = 2; print STDERR "IRQ -> 2\n" if ($rubyDebug || $colorDebug);
} elsif ($ruby && ($ctstate{inRubyQuote} == 2)) {
$ctstate{inRubyQuote} = 1;
print STDERR "IRQ 2 -> 1\n" if ($rubyDebug || $colorDebug);
} elsif ($token =~ /^\"/o && !$ctstate{inRubyQuote}) {
print STDERR " DQUOTE\n" if ($localDebug || $codePathDebug);
$ctstate{inQuote} = 1;
} elsif ($token =~ /^\'/o && !$ctstate{inRubyQuote}) {
print STDERR " SQUOTE\n" if ($localDebug || $codePathDebug);
$ctstate{inQuote} = 2;
} elsif ($ntokennc =~ /^(\)|\,|\;)/o || casecmp($ntokennc, $parseTokens{rbrace}, $case_sensitive)) {
print STDERR " LASTTOKEN\n" if ($localDebug || $codePathDebug);
if ($nextbreakable != 3) {
$nextbreakable = 2;
}
if ($ctstate{lastBrace} eq $parseTokens{sotemplate} && $parseTokens{sotemplate} ne "") {
$nextbreakable = 0;
}
if ($ctstate{lastBrace} eq "(" || ($ctstate{lastBrace} eq "{" && $parseTokens{parmswithcurlybraces})) {
if ($MIG || $pascal) {
$tokenType = "type";
print STDERR " TYPE [2]\n" if ($localDebug || $codePathDebug);
} else {
$tokenType = "param";
print STDERR " PARAM [1]\n" if ($localDebug || $codePathDebug);
}
} elsif ($ctstate{lastBrace} eq $parseTokens{sotemplate} && $parseTokens{sotemplate} ne "") {
print STDERR " TEMPLATE[1]\n" if ($localDebug || $codePathDebug);
$tokenType = "template";
} elsif ($ctstate{type} eq "funcptr") {
$tokenType = "function";
print STDERR " FUNCTION [1]\n" if ($localDebug || $codePathDebug);
$ctstate{breakable} = 0;
$nextbreakable = 0;
} else {
if ($MIG || $pascal) {
$tokenType = "type";
print STDERR " TYPE [2a]\n" if ($localDebug || $codePathDebug);
} else {
$tokenType = "var";
print STDERR " VAR [1] (LB: ".$ctstate{lastBrace}.")\n" if ($localDebug || $codePathDebug);
}
}
if (casecmp($ntokennc, $parseTokens{rbrace}, $case_sensitive) && $ctstate{type} eq "pasrec") {
$ctstate{type} = "";
}
if ($ntokennc eq ")") {
$nextbreakable = 0;
if ((!$untypedLanguage) && ($ctstate{inObjCMethod} || ($token eq "*"))) {
print STDERR " TYPE [3]\n" if ($localDebug || $codePathDebug);
$tokenType = "type";
}
}
} elsif ($ctstate{prespace} ne "" && ($token =~ /^\)/o || casecmp($token, $parseTokens{rbrace}, $case_sensitive))) {
print STDERR "PS: ".length($ctstate{prespace})." -> " if ($psDebug);
if (!$ctstate{keep_whitespace}) { $ctstate{prespace} = nspaces(4 * ($ctstate{depth}-1)); }
print STDERR length($ctstate{prespace})."\n" if ($psDebug);
$mustbreak = 2;
} elsif (casecmp($token, $parseTokens{rbrace}, $case_sensitive)) {
if (!$ctstate{keep_whitespace}) { $ctstate{prespace} = nspaces(4 * ($ctstate{depth}-1)); }
print STDERR length($ctstate{prespace})."\n" if ($psDebug);
$mustbreak = 2;
} else {
if ($ctstate{inObjCMethod}) {
if ($ctstate{lastBrace} eq "(") {
print STDERR " TYPE [4]\n" if ($localDebug || $codePathDebug);
$tokenType = "type";
} else {
print STDERR " PARAM [2]\n" if ($localDebug || $codePathDebug);
$tokenType = "param";
}
} elsif ($MIG || $pascal) {
if ($ctstate{lastBrace} eq "(") {
print STDERR " PARAM [3]\n" if ($localDebug || $codePathDebug);
$tokenType = "param";
}
} else {
if ($ctstate{lastBrace} eq $parseTokens{sotemplate} && ($parseTokens{sotemplate} ne "")) {
print STDERR " TEMPLATE [5]\n" if ($localDebug || $codePathDebug);
$tokenType = "template";
} elsif ($ctstate{inEnum}) {
print STDERR " TYPE [5]\n" if ($localDebug || $codePathDebug);
$tokenType = "var";
} elsif ($untypedLanguage && $ctstate{lastBrace}) {
print STDERR " UNTYPED: PARAM [5]\n" if ($localDebug || $codePathDebug);
$tokenType = "param";
} elsif (($untypedLanguage == 1) ||
($untypedLanguage == 2 && $ctstate{lastnstoken} !~ $parseTokens{classregexp})) {
print STDERR " UNTYPED: VAR [5]\n" if ($localDebug || $codePathDebug);
$tokenType = "var";
} else {
print STDERR " TYPE [5]\n" if ($localDebug || $codePathDebug);
$tokenType = "type";
}
}
}
} else {
my $fullpath = $ctstate{apio}->fullpath;
my $linenum = $ctstate{apio}->linenum;
warn "$fullpath:$linenum: warning: Unknown language ".$ctstate{lang}.". Not coloring. Please file a bug.\n";
}
if ($ctstate{inRaises} && $tokenType && ($tokenType ne "keyword")) {
$tokenType = "type";
}
if ($ctstate{inTypeOf} && $tokenType && ($tokenType ne "keyword")) {
$tokenType = "param";
}
if ((!$hidden) && $self->isAvailabilityMacro()) {
if ($ctstate{xmlmode}) {
$string .= "<declaration_availabilitymacro>";
$tailstring = "</declaration_availabilitymacro>".$tailstring;
} else {
$string .= "<span class=\"availabilitymacro\">";
$tailstring = "</span>".$tailstring;
}
}
if ($ctstate{ASinName} == 1) {
$ctstate{ASinName} = 2;
print STDERR "ASinName -> 2 [end]\n" if ($localDebug);
} elsif ($ctstate{ASinName} == 2) {
$tokenType = "function";
} elsif ($ctstate{ASinName} == 3) {
$ctstate{ASinName} = 4;
print STDERR "ASinName -> 4 [end]\n" if ($localDebug);
} elsif ($ctstate{ASinName} == 4) {
$tokenType = "param";
} elsif ($ctstate{ASinName} == -1) {
$ctstate{ASinName} = 0;
print STDERR "ASinName -> 0 [end]\n" if ($localDebug);
}
if ($hidden) {
$tokenType = "ignore";
if ($mustbreak) {
$nextbreakable = 3;
} else {
$nextbreakable = 0;
}
$mustbreak = 0;
$ctstate{breakable} = 0;
}
if (($ntoken =~ /[,;]/) && ($token =~ /[ \t]/) && !$ctstate{inComment} && !$ctstate{inMacro} && !$ctstate{inQuote}) {
$hidden = 1;
$tokenType = "ignore";
$nextbreakable = 0;
$mustbreak = 0;
$ctstate{breakable} = 0;
}
if ($MIG || $pascal) {
if ($ctstate{lastnstoken} =~ /:/ && $ctstate{lastTokenType} eq "var") {
$string .= $newtd;
}
} else {
if (($ctstate{lastTokenType} eq "type") && !$hidden && ($token =~ /[\w\*]/) &&
($tokenType eq "var" || $tokenType eq "param" ||
$tokenType eq "function" || $token eq "*") && ($ctstate{lastnstoken} =~ /\w/)) {
$string .= $newtd;
}
}
if (((($parseTokens{ilc} ne "") && ($ntoken eq $parseTokens{ilc})) || (($parseTokens{ilc_b} ne "") && ($ntoken eq $parseTokens{ilc_b}))) && !$ctstate{inComment}) {
$ctstate{breakable} = 0; $nextbreakable = 0;
} elsif (($parseTokens{soc} ne "") && $ntoken eq $parseTokens{soc} && !$ctstate{inComment}) {
$ctstate{breakable} = 0; $nextbreakable = 0;
}
print STDERR "NB: $nextbreakable\n" if ($localDebug);
print STDERR "TESTTYPE: $tokenType\n" if ($localDebug);
if ($ctstate{inObjCMethod}) {
$nextbreakable = 0;
$ctstate{breakable} = 0;
$mustbreak = 0;
if ($ntoken eq ":" && $tokenType eq "function") {
$ctstate{breakable} = 1;
}
}
if ($ctstate{type} eq "pasrec" && $tokenType eq "") {
print STDERR "PASREC VAR\n" if ($localDebug);
$tokenType = "var";
}
else { print STDERR "TYPE: ".$ctstate{type}." TT: ".$tokenType."\n" if ($localDebug); }
print STDERR "IM: ".$ctstate{inMacro}."\n" if ($localDebug);
if (!$ctstate{inComment} && $token =~ /^\s/o && !$tokennl && ($mustbreak || !$ctstate{newlen}) && (!$ctstate{keep_whitespace})) {
print STDERR "CASEA\n" if ($localDebug);
print STDERR "NL: ".$ctstate{newlen}." TOK: \"$token\" PS: \"".$ctstate{prespace}."\" NPS: \"$nextprespace\"\n" if ($localDebug);
print STDERR "dropping leading white space\n" if ($localDebug);
$drop = 1;
} elsif (!$ctstate{inComment} && $tokennl && (!$ctstate{keep_whitespace})) {
print STDERR "CASEB\n" if ($localDebug);
if ($ctstate{lastnstoken} ne $parseTokens{eoc}) {
print STDERR "dropping newline\n" if ($localDebug);
$drop = 1;
$string .= " ";
} else {
$mustbreak = 1;
}
} elsif ($ctstate{inComment} || $token =~ /^\s/o || ($token =~ /^\W/o && $token ne "*") || !$tokenType) {
print STDERR "CASEC\n" if ($localDebug);
my $macroTail = "";
$escapetoken = $ctstate{apio}->textToXML($token);
print STDERR "OLDPS: \"".$ctstate{prespace}."\" ET=\"$escapetoken\" DROP=$drop\n" if ($localDebug);
if ($ctstate{inComment} && $ctstate{prespace} ne "" && !$hidden) {
if ($ctstate{xmlmode}) {
$string .= "</declaration_comment>\n".$ctstate{prespace}."<declaration_comment>";
} else {
$string .= "</span>\n$endtr".$ctstate{prespace}."$begintr<span class=\"comment\">";
}
} elsif ($ctstate{inMacro} && $token =~ /^\S/) {
if (!$tokenType) {
$tokenType = "preprocessor";
}
if ($ctstate{xmlmode}) {
$string .= $ctstate{prespace}."<declaration_$tokenType>";
$macroTail = "</declaration_$tokenType>";
} else {
$string .= $ctstate{prespace}."<span class=\"$tokenType\">";
$macroTail = "</span>";
}
} elsif (!$hidden) {
$string .= $ctstate{prespace};
}
if ($drop) { $escapetoken = ""; }
if ($tokenType eq "ignore") {
if (!$HeaderDoc::dumb_as_dirt) {
print STDERR "HD: DROPPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
$escapetoken = "";
} else {
print STDERR "HD BASIC: KEEPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
}
}
$string .= "$escapetoken$macroTail";
print STDERR "comment: $token\n" if ($localDebug);
} else {
print STDERR "CASED\n" if ($localDebug);
$escapetoken = $ctstate{apio}->textToXML($token);
if (($tokenType ne "") && ($token ne "") && token !~ /^\s/o) {
my $fontToken = "";
if ($ctstate{xmlmode}) {
$fontToken = "<declaration_$tokenType>$escapetoken</declaration_$tokenType>";
} else {
if ($tokenType ne "ignore") {
$fontToken = "<span class=\"$tokenType\">$escapetoken</span>";
} elsif (!$HeaderDoc::dumb_as_dirt) {
print STDERR "HD: DROPPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
$fontToken = "";
} else {
print STDERR "HD BASIC: KEEPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
$fontToken = $escapetoken;
}
}
my $linkTokenType = $tokenType;
if ($ctstate{inTypeOf} && ($tokenType ne "keyword")) {
$linkTokenType = "";
}
if ((!$drop) && ($HeaderDoc::add_link_requests && ($tokenType =~ /^(function|var|type|preprocessor)/o || $ctstate{inTypeOf}) && !$ctstate{xmlmode})) {
my $refToken = $ctstate{apio}->genRefFromDeclaration($ctstate{lastKeyword}, $escapetoken, $fontToken, $linkTokenType);
$string .= $ctstate{prespace}."$refToken";
} else {
$string .= $ctstate{prespace}."$fontToken";
}
} else {
$escapetoken = $ctstate{apio}->textToXML($token);
if ($tokenType eq "ignore") {
if (!$HeaderDoc::dumb_as_dirt) {
print STDERR "HD: DROPPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
$escapetoken = "";
} else {
print STDERR "HD BASIC: KEEPING IGNORED TOKEN $escapetoken\n" if ($dropDebug);
}
}
$string .= $ctstate{prespace}."$escapetoken";
}
print STDERR "$tokenType: $token\n" if ($localDebug);
}
$ctstate{prespace} = $nextprespace;
if (!$drop) {
$ctstate{newlen} += length($token);
}
print STDERR "NL ".$ctstate{newlen}." MDL $HeaderDoc::maxDecLen BK ".$ctstate{breakable}." IM ".$ctstate{inMacro}."\n" if ($localDebug);
if ((!$ctstate{keep_whitespace}) && ($mustbreak ||
(($ctstate{newlen} > $HeaderDoc::maxDecLen) &&
$ctstate{breakable} && !$ctstate{inMacro} && !$hidden))) {
print STDERR "MUSTBREAK CASE\n" if ($localDebug);
if (($token =~ /^\s/o || $token eq "") && (!$ctstate{keep_whitespace})) {
$nextprespace = nspaces(4 * ($ctstate{depth}+(1-$mustbreak)));
print STDERR "PS WILL BE \"$nextprespace\"\n" if ($localDebug);
$nextbreakable = 3;
} else {
print STDERR "NEWLEN: ".$ctstate{newlen}."\n" if ($localDebug);
$ctstate{newlen} = length($token);
print STDERR "NEWLEN [2]: ".$ctstate{newlen}."\n" if ($localDebug);
print STDERR "MB: $mustbreak, DP: ".$ctstate{depth}."\n" if ($localDebug);
my $ps = nspaces(4 * ($ctstate{depth}+(1-$mustbreak)));
if (($ctstate{inComment} == 1 && !$firstCommentToken) || $leavingComment) {
if ($ctstate{xmlmode}) {
$string = "</declaration_comment>\n$ps<declaration_comment>$string";
} else {
$string = "</span>$endtr\n$begintr$ps<span class=\"comment\">$string";
}
} else {
$string = "$endtr\n$begintr$ps$string";
}
print STDERR "PS WAS \"$ps\"\n" if ($localDebug);
}
}
if ($token !~ /^\s/o) { $ctstate{lastnstoken} = $token; }
if ($token !~ /\s/) {
if ($isTypeStar) {
$ctstate{lastTokenType} = "star";
} else {
$ctstate{lastTokenType} = $tokenType;
}
$ctstate{spaceSinceLastToken} = 0;
} else {
$ctstate{spaceSinceLastToken} = 1;
}
my $newstring = "";
my $node = $self->{FIRSTCHILD};
my $newstringref = undef;
if ($node && $continue) {
if ($nospaceafter == 1) { $nospaceafter = 0; }
print STDERR "BEGIN CHILDREN\n" if ($localDebug || $colorDebug || $treeDebug);
bless($node, "HeaderDoc::ParseTree");
my $childctstate = newCTState(\%ctstate, depth => $ctstate{depth} + 1, breakable => $nextbreakable);
($newstringref, $ctstate{newlen}, $nextbreakable, $ctstate{prespace}, $ctstate{lastnstoken}, $continue, $ctstate{lastTokenType}, $ctstate{spaceSinceLastToken}) = $node->colorTreeSub($childctstate);
$newstring = ${$newstringref};
print STDERR "END CHILDREN\n" if ($localDebug || $colorDebug || $treeDebug);
}
$string .= $newstring; $newstring = "";
print STDERR "SET STRING TO $string\n" if ($localDebug);
if (($ctstate{prespace} ne "")) {
$ctstate{prespace} = nspaces(4 * $ctstate{depth});
}
print STDERR "HMLT: ".$self->{HIDEMACROLASTTOKEN}."\n" if ($localDebug);
if ($self->{HIDEMACROLASTTOKEN} && $ctstate{drop_pdefine_contents}) {
$continue = 0;
}
$string .= $tailstring;
$tailstring = "";
print STDERR "LB ".$ctstate{lastBrace}." -> $oldLastBrace\n" if ($colorDebug || $localDebug);
$ctstate{lastBrace} = $oldLastBrace;
$ctstate{depth} = $oldDepth;
print STDERR "Resetting inMacro (".$ctstate{inMacro}.") to previous value ($oldInMacro).\n" if ($localDebug);
$ctstate{inMacro} = $oldInMacro;
$ctstate{lastKeyword} = $oldLastKeyword;
$ctstate{inComment} = $oldInComment;
$ctstate{inQuote} = $oldInQuote;
$ctstate{inAttribute} = $oldInAttribute;
$ctstate{inRaises} = $oldInRaises;
$ctstate{inTypeOf} = $oldInTypeOf;
if ($dropFP) { $ctstate{type} = $ctstate{apio}->class(); }
$node = $self->{NEXT};
if ($node && $continue) {
bless($node, "HeaderDoc::ParseTree");
if ($nospaceafter) {
while ($node && ($node->token =~ /[ \t]/)) {
print STDERR "SKIPPED NODE (\"".$node->token."\").\n" if ($localDebug);
$node = $node->next;
bless($node, "HeaderDoc::ParseTree");
}
print STDERR "STOPPED SKIPPING AT NODE \"".$node->token."\".\n" if ($localDebug);
}
print STDERR "CONTINUING TO NODE \"".$node->token."\".\n" if ($localDebug);
if ($node) {
my $nextctstate = newCTState(\%ctstate, breakable => $nextbreakable);
($newstringref, $ctstate{newlen}, $nextbreakable, $ctstate{prespace}, $ctstate{lastnstoken}, $continue, $ctstate{lastTokenType}, $ctstate{spaceSinceLastToken}) = $node->colorTreeSub($nextctstate);
$newstring = ${$newstringref};
}
}
$string .= $newstring;
print STDERR "SET STRING TO $string\n" if ($localDebug);
return (\$string, $ctstate{newlen}, $nextbreakable, $ctstate{prespace}, $ctstate{lastnstoken}, $continue, $ctstate{lastTokenType}, $ctstate{spaceSinceLastToken});
}
sub test_output_dump_rec
{
my $self = shift;
my $depth = shift;
my $lastnode = shift;
my $ret = "";
my $parserState = $self->parserState();
if ($parserState && !$lastnode) {
$lastnode = $parserState->{lastTreeNode};
}
if ($self->token ne "") {
my $i = $depth-1;
while ($i > 0) {
$ret .= "| ";
$i--;
}
my $HYPHEN = "-";
my $psString = "";
if ($self->parserState()) {
$HYPHEN = "*";
$psString = " (HAS STATE)";
}
if ($depth) {
$ret .= "+-$HYPHEN-";
}
if ($self->token =~ /\n$/) {
$ret .= "[ NEWLINE ]$psString\n";
} else {
$ret .= $self->token()."$psString\n";
}
}
if ($self == $lastnode) {
$ret .= "-=-=-=-=-=-=- EODEC -=-=-=-=-=-=-\n";
}
if ($self->firstchild()) {
$ret .= $self->firstchild()->test_output_dump_rec($depth+1, $lastnode);
}
if ($self->next()) {
$ret .= $self->next()->test_output_dump_rec($depth, $lastnode);
}
return $ret;
}
sub dbprintrec
{
my $self = shift;
my $depth = shift;
my $lastnode = shift;
my $include_noise = shift;
my $localDebug = 0;
my $parserState = $self->parserState();
if ($parserState && !$lastnode) {
$lastnode = $parserState->{lastTreeNode};
}
if ($self->token ne "") {
my $i = $depth-1;
while ($i > 0) {
print STDERR "| ";
$i--;
}
my $HYPHEN = "-";
my $psString = "";
my $reStateString = "";
if ($self->{RE_STATE}) { $reStateString = " ".$self->{RE_STATE}; }
if ($self->parserState()) {
$HYPHEN = "*";
$psString = " (TOKENID: ".$self.", PSID: ".$self->parserState().$reStateString.")";
} else {
$psString = " (TOKENID: ".$self.$reStateString.")";
}
if ($depth) {
print STDERR "+-$HYPHEN-";
}
if ($self->token =~ /\n$/) {
print STDERR "[ NEWLINE ]$psString\n";
} else {
print STDERR $self->token()."$psString\n";
}
}
if ($include_noise) {
printHash(%{$self});
print STDERR "API OWNERS:\n";
foreach my $apio (@{$self->{APIOWNERS}} ) {
print " ".$apio."\n";
}
print STDERR "END OF API OWNERS\n";
}
if ($self == $lastnode) {
my $deb = "";
if ($localDebug) { $deb = $lastnode; }
print STDERR "-=-=-=-=-=-=- EODEC $deb-=-=-=-=-=-=-\n";
}
if ($self->firstchild()) {
$self->firstchild()->dbprintrec($depth+1, $lastnode, $include_noise);
}
if ($self->next()) {
$self->next()->dbprintrec($depth, $lastnode, $include_noise);
}
}
sub test_output_dump
{
my $self = shift;
return $self->test_output_dump_rec(1);
}
sub dbprint
{
my $self = shift;
my $enable_noise = shift;
$self->dbprintrec(1, undef, $enable_noise);
}
sub filename
{
my $self = shift;
if (@_) {
$self->{FILENAME} = shift;
}
return $self->{FILENAME};
}
sub fullpath
{
my $self = shift;
if (@_) {
$self->{FULLPATH} = shift;
}
return $self->{FULLPATH};
}
sub linenum
{
my $self = shift;
if (@_) {
$self->{LINENUM} = shift;
}
return $self->{LINENUM};
}
sub printObject {
my $self = shift;
print STDERR "----- ParseTree Object ------\n";
print STDERR "token: $self->{TOKEN}\n";
print STDERR "next: $self->{NEXT}\n";
print STDERR "firstchild: $self->{FIRSTCHILD}\n";
print STDERR "\n";
}
sub addRawParsedParams
{
my $self = shift;
my $pplref = shift;
my @array = @{$pplref};
foreach my $param (@array) {
push(@{$self->{RAWPARSEDPARAMETERS}}, $pplref);
}
return $self->{RAWPARSEDPARAMETERS};
}
sub rawParsedParams
{
my $self = shift;
return $self->{RAWPARSEDPARAMETERS};
}
sub parserState
{
my $self = shift;
my $localDebug = 0;
if (@_) {
my $state = shift;
print STDERR "Setting parser state for $self\n" if ($localDebug);
print STDERR "Last token (raw) is $state->{lastTreeNode}\n" if ($localDebug);
print STDERR "Last token (text) is ".$state->{lastTreeNode}->token()."\n" if ($localDebug);
$self->{PARSERSTATE} = $state;
}
return $self->{PARSERSTATE};
}
sub trygcc
{
my $self = shift;
my $rawvalue = shift;
my $success = 0;
my $value = 0;
my $timestamp = time();
my $localDebug = 0;
if (open(GCCFILE, ">/tmp/headerdoc-gcctemp-$timestamp.c")) {
print GCCFILE "#include <inttypes.h>\nmain(){printf(\"%d\\n\", $rawvalue);}\n";
close(GCCFILE);
if (open(GCCPIPE, $HeaderDoc::c_compiler." /tmp/headerdoc-gcctemp-$timestamp.c -o /tmp/headerdoc-gcctemp-$timestamp > /dev/null 2> /dev/null |")) {
my $junkstring = <GCCPIPE>;
close(GCCPIPE);
if ($?) {
$success = 0;
} else {
$success = 1;
}
if ($success) {
if (open(EXECPIPE, "/tmp/headerdoc-gcctemp-$timestamp |")) {
my $retstring = <EXECPIPE>;
$value = $retstring;
$value =~ s/\n//sg;
print STDERR "VALUE: $value\nSUCCESS: $success\n" if ($localDebug);
} else {
$success = 0;
}
}
}
unlink("/tmp/headerdoc-gcctemp-$timestamp.c");
unlink("/tmp/headerdoc-gcctemp-$timestamp");
}
print STDERR "RET $success, $value\n" if ($localDebug);
return ($success, $value);
}
sub getPTvalue
{
my $self = shift;
my $success = 0;
my $value = 0;
my $localDebug = 0;
my $pos = $self;
while ($pos && ($pos->token() ne "#define")) {
$pos = $pos->next();
}
if (!$pos) {
return($success, $value);
}
$pos = $pos->firstchild();
while ($pos && ($pos->hidden != 3) && ($pos->{HIDEMACROLASTTOKEN} != 2)) {
$pos = $pos->next();
}
if ($pos) {
my $rawvalue = $pos->textTree();
print STDERR "getPTvalue: WE HAVE A WINNER.\n" if ($localDebug);
print STDERR "RAWVALUE IS: $rawvalue\n" if ($localDebug);
($success, $value) = $self->trygcc($rawvalue);
}
return($success, $value);
}
sub dispose
{
my $self = shift;
if ($self->{REFCOUNT} > 0) {
if ($HeaderDoc::debugAllocations) {
print STDERR "Parse tree reference count is ".$self->{REFCOUNT}.". Not disposing.\n";
print STDERR "SELF: ".$self."\n";
print STDERR "FC: ".$self->{FIRSTCHILD}."\n";
print STDERR "NEXT: ".$self->{NEXT}."\n";
print STDERR "PARENT: ".$self->{PARENT}."\n";
print STDERR "APIOLIST: ".$self->{APIOWNERS}."\n";
foreach my $obj (@{$self->{APIOWNERS}}) {
print STDERR " OWNER: $obj\n";
}
print STDERR "END OF LIST\n";
}
return;
}
print STDERR "Disposing of tree\n" if ($HeaderDoc::debugAllocations);
$self->{PARENT} = undef;
if ($self->{FIRSTCHILD}) {
$self->{FIRSTCHILD}->dispose();
$self->{FIRSTCHILD} = undef;
}
if ($self->{NEXT}) {
$self->{NEXT}->dispose();
$self->{NEXT} = undef;
}
$self->{NTNC} = undef;
if ($self->{APIOWNERS}) { $self->{APIOWNERS} = (); }
if ($self->{PARSERSTATE}) { $self->{PARSERSTATE} = undef; }
$self->{PARSEDPARAMS} = ();
$self->{RAWPARSEDPARAMETERS} = ();
$self->{TOKEN} = undef;
$self->dbprint() if ($HeaderDoc::debugAllocations);
}
sub DESTROY
{
my $self = shift;
print STDERR "Destroying $self\n" if ($HeaderDoc::debugAllocations);
}
sub curlycount
{
my $self = shift;
my $lbrace = shift;
my $last = shift;
my $pos = $self;
my $count = 0;
while ($last && !$last->isAfter($self)) {
$last = $last->parent();
}
if ($last) { $last = $last->next(); }
while ($pos && $pos != $last) {
if ($pos->token eq "$lbrace") {
$count++;
}
$pos = $pos->next();
}
return $count;
}
sub skipcurly
{
my $self = shift;
my $lbrace = shift;
my $count = shift;
my $localDebug = 0;
my $pos = $self;
print STDERR "SKIPPING $count curly braces (lbrace = '$lbrace') at POS=$pos\n" if ($localDebug);
if (!$count) { return $self; }
while ($pos) {
my $tok = $pos->token();
print STDERR "TOKEN: '$tok'\n" if ($localDebug);
if ($tok eq "$lbrace") {
print STDERR "MATCH\n" if ($localDebug);
if (!--$count) {
my $next = $pos->next;
if ($localDebug) {
print STDERR "FOUND ONE. Next tree is:\n";
if ($next) {
$next->dbprint();
} else {
print STDERR "UNDEFINED!\n";
}
}
return $next;
}
}
$pos = $pos->next();
}
warn "Yikes! Ran out of open braces!\n";
return $pos;
}
sub isKnownMacroToken
{
my $token = shift;
my $macroListRef = shift;
my $case_sensitive = shift;
my %macroList = %{$macroListRef};
if ($case_sensitive) {
if ($macroList{$token}) { return 1; }
return 0;
}
foreach my $cmpToken (keys %macroList) {
if (casecmp($token, $cmpToken, $case_sensitive)) {
return 1;
}
}
return 0;
}
sub parseComplexAvailability
{
my $self = shift;
my $localDebug = 0;
print STDERR "parseComplexAvailability: dumping tree for $self.\n" if ($localDebug);
$self->dbprint() if ($localDebug);
my $token = $self->token();
my $availstring = "";
my $pos = $self->firstchild();
while ($pos && ($pos->token() ne "(")) {
$pos = $pos->next();
}
if (!$pos) { my @arr = (); return \@arr; }
$pos = $pos->next();
while ($pos && ($pos->token() ne ")")) {
$availstring .= $pos->token();
$pos = $pos->next();
}
print STDERR "TOKEN: $token\nSTRING: $availstring\n" if ($localDebug);
return complexAvailabilityToArray($token, $availstring);
}
sub isAvailabilityMacro
{
my $self = shift;
if (@_) {
$self->{ISAVAILABILITYMACRO} = shift;
}
if ($self->{ISAVAILABILITYMACRO}) {
return $self->{ISAVAILABILITYMACRO};
}
return 0;
}
sub translateTree {
my $self = shift;
my %state = ();
$self->translateTreeRec(\%state);
}
sub nextNSToken
{
my $self = shift;
my $next = $self->{NEXT};
while ($next && $next->{TOKEN} !~ /\S/s) {
$next = $next->{NEXT};
}
return $next;
}
sub translateTreeRec {
my $self = shift;
my $stateref = shift;
my %state = %{$stateref};
my $localDebug = 0;
my $enteringComment = 0;
my $enteringString = 0;
my $enteringSingle = 0;
my $leavingHDComment = 0;
print STDERR "TOK: ".$self->{TOKEN}."\n" if ($localDebug);
if ((!$state{seenCode}) && $self->{TOKEN} && $self->{TOKEN} =~ /\S/s && $self->{TOKEN} ne "if" && $self->{TOKEN} ne "#" && $self->{TOKEN} ne "{" && $self->{TOKEN} ne "}") {
print STDERR "SEENCODE -> 1\n" if ($localDebug);
$state{seenCode} = 1;
$state{insertIfBeforeNode} = $self;
}
print STDERR "CHECK: INSTRING: ".$state{inString}." INCOMMENT: ".$state{inComment}." INREGEXP: ".$state{inRegExp}." INSINGLE: ".$state{inSingle}."\n" if ($localDebug);
if (!($state{inString} || $state{inComment} || $state{inRegExp} || $state{inSingle})) {
print STDERR "FIXUP OKAY\n" if ($localDebug);
if ($self->{TOKEN} eq "\"") {
$state{inString} = 1;
$enteringString = 1;
} elsif ($self->{TOKEN} eq "'") {
$state{inSingle} = 1;
$enteringSingle = 1;
} elsif ($self->{TOKEN} eq "#") {
print STDERR "ILC\n" if ($localDebug);
$state{inComment} = 1;
$enteringComment = 1;
$state{socNode} = $self;
if ($state{inHDComment}) {
$self->{TOKEN} = " ";
} else {
$self->{TOKEN} = "//";
}
if ($self->{FIRSTCHILD}->textTree() =~ /\*\//) {
$leavingHDComment = 1;
}
} elsif ($self->{TOKEN} eq "\$") { my $next = $self->{NEXT};
if ($next) {
$self->{TOKEN} = "";
$self->{NEXT}->{TOKEN} = "\$".$self->{NEXT}->{TOKEN};
}
} elsif ($self->{TOKEN} eq ":") {
if ($self->{NEXT} && $self->{NEXT}->{TOKEN} eq ":") {
$self->{TOKEN} = "_";
$self->{NEXT}->{TOKEN} = "_";
}
} elsif ($self->{TOKEN} eq "elsif") {
$self->{TOKEN} = "else if";
} elsif ($self->{TOKEN} eq "STDERR") {
$self->{TOKEN} = "stderr";
} elsif ($self->{TOKEN} eq "STDOUT") {
$self->{TOKEN} = "stdout";
} elsif ($self->{TOKEN} eq "STDIN") {
$self->{TOKEN} = "stdin";
} elsif ($self->{TOKEN} eq "<" && $self->{FIRSTCHILD} &&
$self->{FIRSTCHILD}->{NEXT} &&
$self->{FIRSTCHILD}->{NEXT}->{TOKEN} =~ /^[a-zA-Z]+$/ &&
$self->{FIRSTCHILD}->{NEXT}->{NEXT} &&
$self->{FIRSTCHILD}->{NEXT}->{NEXT}->{TOKEN} eq ">") {
print STDERR "Read from file.\n" if ($localDebug);
$self->{TOKEN} = "stringFromFP(";
$self->{FIRSTCHILD}->{NEXT}->{NEXT}->{TOKEN} = ")";
} elsif ($self->{TOKEN} eq "print" || $self->{TOKEN} eq "warn") {
my $nextnstoken = $self->nextNSToken();
if ($self->{TOKEN} eq "print") {
my $ns = $self->nextNSToken();
if ($ns && ($ns->{TOKEN} eq "\"" || $ns->{TOKEN} eq "\$")) {
$self->{TOKEN} = "printf";
} else {
$self->{TOKEN} = "fprintf";
if ($ns->{TOKEN} eq "STDERR") {
$ns->{TOKEN} = "stderr";
} elsif ($ns->{TOKEN} eq "STDOUT") {
$ns->{TOKEN} = "stdout";
}
$ns->{TOKEN} .= ",";
}
}
if ($nextnstoken->{TOKEN} ne "(") {
$self->{TOKEN} .= "(";
$state{addParenAtSemi} = 1;
$self->{NEXT} = $nextnstoken;
}
} elsif ($self->{TOKEN} eq "split") {
$self->{TOKEN} = "regexpSplit";
$state{inSplit} = 1;
print STDERR "inSplit -> 1\n" if ($localDebug);
} elsif ($self->{TOKEN} eq "(" && $state{inSplit}) {
$state{inSplit} = 2;
print STDERR "inSplit -> 1\n" if ($localDebug);
} elsif ($self->{TOKEN} eq "->") {
print STDERR "->" if ($localDebug);
my $pos = $self->{NEXT};
while ($pos && $pos->{TOKEN} !~ /\S/s) {
$pos = $pos->{NEXT};
}
if ($pos && $pos->{TOKEN} eq "{") {
my $posb = $pos->{FIRSTCHILD};
while ($posb && $posb->{TOKEN} ne "}") {
$posb = $posb->{NEXT};
}
if ($pos && $posb) {
$pos->{TOKEN} = "";
$posb->{TOKEN} = "";
}
}
} elsif ($self->{TOKEN} eq "eq" || $self->{TOKEN} eq "ne") {
my $prev = $self->slowprev();
while ($prev && ($prev->token !~ /\S/s)) {
$prev = $prev->slowprev();
}
while ($prev && $prev->{TOKEN} !~ /\&/ && $prev->{TOKEN} !~/\|/) {
print STDERR "PREV: $prev\n" if ($localDebug);
print STDERR "TOK: ".$prev->{TOKEN}."\n" if ($localDebug);
$prev = $prev->slowprev();
}
my $addspace = "";
if (!$prev) {
$prev = $self->parent()->firstchild();
} else {
$addspace = " ";
}
my $next = $self->{NEXT};
while ($next && ($next->token !~ /\S/s)) {
$next = $next->{NEXT};
}
print STDERR "NEXT IS \"".$next->{TOKEN}."\"\n" if ($localDebug);
while ($next && $next->{NEXT} && $next->{NEXT}->{TOKEN} !~ /\&/ && $next->{NEXT}->{TOKEN} !~ /\|/ &&
$next->{NEXT}->{TOKEN} !~ /\)/) {
$next = $next->{NEXT};
print STDERR "INLOOP NEXT IS ".$next->{TOKEN}."\n" if ($localDebug);
}
if ($prev && $next) {
my $newnode = HeaderDoc::ParseTree->new();
if ($self->{TOKEN} eq "eq") {
$newnode->{TOKEN} = $addspace."!strcmp(";
} else {
$newnode->{TOKEN} = $addspace."strcmp(";
}
$newnode->{NEXT} = $prev->{NEXT};
$prev->{NEXT} = $newnode;
if ($next->{TOKEN} eq "\$") {
$next->{TOKEN} = "";
$next->{NEXT}->{TOKEN} = "\$".$next->{NEXT}->{TOKEN};
$next = $next->{NEXT};
}
$newnode = HeaderDoc::ParseTree->new();
$newnode->{TOKEN} = ")";
$newnode->{NEXT} = $next->{NEXT};
$next->{NEXT} = $newnode;
$self->{TOKEN} = ",";
$prev = $self->slowprev();
while ($prev && ($prev->{TOKEN} =~ /\s/s)) {
$prev->{TOKEN} = "";
$prev = $prev->slowprev();
}
} else {
warn("Could not fix \"eq\" because previous/next token not found (PREV: $prev NEXT: $next).\n");
}
} elsif ($state{seenCode} && ($self->{TOKEN} eq ";" || $self->{TOKEN} eq "{")) {
$state{seenCode} = 0;
if ($state{addParenAtSemi}) {
$state{addParenAtSemi} = 0;
$self->{TOKEN} = ")".$self->{TOKEN};
}
print STDERR "SEENCODE -> 0\n" if ($localDebug);
if ($state{captureIf}) {
my $lastcapture = $self->slowprev();
my $beforenode = $state{insertIfBeforeNode};
my $prev = $beforenode->slowprev();
if (!$prev) {
my $newnode = HeaderDoc::ParseTree->new();
$newnode->{TOKEN} = $beforenode->{TOKEN};
$newnode->{NEXT} = $beforenode->{NEXT};
$beforenode->{NEXT} = $newnode;
$beforenode->{TOKEN} = "";
$prev = $beforenode;
$beforenode = $newnode;
}
my $trailingspace = $self->slowprev();
if (!$trailingspace) {
$trailingspace = $self->parent();
}
while ($trailingspace &&
((!$trailingspace->{TOKEN}) ||
($trailingspace->{TOKEN} =~ /\s/s))) {
$trailingspace->{TOKEN} = "";
my $temp = $trailingspace->slowprev();
if ($temp) { $trailingspace = $temp; }
else { $trailingspace = $trailingspace->parent(); }
}
my $copiedDataNode = HeaderDoc::ParseTree->new();
$copiedDataNode->{NEXT} = $prev->{NEXT};
$prev->{NEXT} = $copiedDataNode;
$copiedDataNode->{TOKEN} = $state{capturedText}." ";
print STDERR "ACCUM: ".$state{capturedText}."\n" if ($localDebug);
$state{captureIf} = 0;
print STDERR "captureIf -> 0\n" if ($localDebug);
}
} elsif ($self->{TOKEN} eq "if" && $state{seenCode}) {
$state{capturedText} = "";
$state{captureIf} = 1;
print STDERR "captureIf -> 1\n" if ($localDebug);
}
} elsif ($state{inComment} == 1 && ($self->{TOKEN} eq "/*!" || $self->{TOKEN} eq "/**")) {
$state{socNode}->{TOKEN} = " ";
$state{inHDComment} = 1;
} elsif ($state{inComment} && $self->{TOKEN} =~ /\S/) {
$state{inComment} = 2;
}
print STDERR "RE_STATE: ".$self->{RE_STATE}."\n" if ($localDebug);
if ($self->{RE_STATE} eq "RE_PREFIX") {
print STDERR "Regexp prefix found.\n" if ($localDebug);
if ($self->{TOKEN} eq "s") {
$state{inRegExp} = 3;
$state{rePrefix} = $self->{TOKEN};
$self->{TOKEN} = "";
} elsif ($self->{TOKEN} eq "tr") {
$state{inRegExp} = 4;
$state{rePrefix} = $self->{TOKEN};
$self->{TOKEN} = "";
} elsif ($self->{TOKEN} eq "m") {
$self->{TOKEN} = "";
print STDERR "Dropping prefix because 'm' is equivalent to no prefix.\n" if ($localDebug);
} else {
print STDERR "Unsupported prefix. Ignoring this expression.\n" if ($localDebug);
$state{inRegExp} = -1; }
} elsif ($self->{RE_STATE} eq "RE_PARTSEP") {
if ($self->{NEXT}->{RE_STATE} eq "RE_PARTSEP") {
$self->{NEXT}->{TOKEN} = "";
$self->{NEXT}->{RE_STATE} = "";
}
$self->{TOKEN} = "\", \"";
} elsif ($self->{RE_STATE} eq "RE_START" && ((!$state{inRegExp}) || $state{inRegExp} == 3 || $state{inRegExp} == 4)) {
print STDERR "Regexp start found. INSPLIT: ".$state{inSplit}."\n" if ($localDebug);
$state{regexpName} = $state{prevTokenNode}->{TOKEN};
print STDERR "PTN: ".$state{prevTokenNode}." (".$state{prevTokenNode}->{TOKEN}.") REGEXPNAME: ".$state{regexpName}."\n" if ($localDebug);
if ($state{inSplit}) {
$self->{TOKEN} = "\"";
$state{inRegExp} = 2;
} elsif ($state{regexpName} =~ /^\$[0-9A-Za-z_]+$/) {
if (!$state{inRegExp}) {
$state{inRegExp} = 1;
$state{prevTokenNode}->{TOKEN} = "regexpMatch(".$state{regexpName}.", ";
} elsif ($state{inRegExp} == 3) {
$state{prevTokenNode}->{TOKEN} = "regexpReplace(".$state{regexpName}.", \@\@\@DEST\@\@\@, ";
} elsif ($state{inRegExp} == 4) {
$state{prevTokenNode}->{TOKEN} = "regexptr(".$state{regexpName}.", \@\@\@DEST\@\@\@, ";
}
my $pos = $state{prevTokenNode}->{NEXT};
print STDERR "Deleting the =~ .\n" if ($localDebug);
while ($pos && !$pos->{RE_STATE}) {
print STDERR "Deleting \"".$pos->{TOKEN}."\" ($pos)\n" if ($localDebug);
if ($pos->{TOKEN} eq "!") {
$state{prevTokenNode}->{TOKEN} = "!".$state{prevTokenNode}->{TOKEN};
}
$pos->{TOKEN} = "";
$pos = $pos->{NEXT}
}
if ($state{rePrefix} eq "s") {
$self->{TOKEN} = "\"";
} else {
$self->{TOKEN} = "\"";
}
} else {
$state{inRegExp} = -1;
}
} elsif ($self->{RE_STATE} eq "RE_END") {
print STDERR "End of regexp found.\n" if ($localDebug);
my $multiline = 0;
my $insensitive = 0;
my $global = 0;
my $complement = 0;
my $delete = 0;
my $nondestructive = 0;
my $squash = 0;
my $next = $self->{NEXT};
if ($next && $next->{TOKEN} =~ /^[siogmcdr]*$/) {
my $re_trailer = $next->{TOKEN};
if ($re_trailer =~ /s/) {
$multiline = 0; $squash = 1; } elsif ($re_trailer =~ /m/) {
$multiline = 1;
}
if ($re_trailer =~ /g/) {
$global = 1;
}
if ($re_trailer =~ /i/) {
$insensitive = 1;
}
if ($re_trailer =~ /c/) {
$complement = 1;
}
if ($re_trailer =~ /d/) {
$delete = 1;
}
if ($re_trailer =~ /r/) {
$nondestructive = 1;
}
$next->{TOKEN} = "";
}
if ($state{inRegExp} == 1) {
$self->{TOKEN} = "\", $multiline, $insensitive, NULL)";
} elsif ($state{inRegExp} == 2) {
$self->{TOKEN} = "\"";
my $next = $self->nextNSToken();
print STDERR "THISNEXT: ".$next->{TOKEN}."\n" if ($localDebug);
if (!$next) {
die("Malformed split\n");
}
$next = $next->nextNSToken();
if ($next->{TOKEN} eq "\$") {
$next->{TOKEN} = "";
$next->{NEXT}->{TOKEN} = "\$".$next->{NEXT}->{TOKEN};
$next = $next->{NEXT};
}
my $argNode = HeaderDoc::ParseTree->new();
$argNode->{NEXT} = $next->{NEXT};
$next->{NEXT} = $argNode;
$argNode->{TOKEN} = ", $multiline, $insensitive";
my $afternext = $argNode->nextNSToken();
print STDERR "AN: ".$afternext->{TOKEN}."\n" if ($localDebug);
if (!$afternext || ($afternext->{TOKEN} ne ",")) {
$argNode->{TOKEN} .= ", 0";
}
} elsif ($state{inRegExp} == 3) {
if ($state{rePrefix} eq "s") {
$self->{TOKEN} = "\", $multiline, $insensitive, $global)";
} else {
die("Unknown RE prefix \"".$state{rePrefix}."\" [1]\n");
}
} elsif ($state{inRegExp} == 4) {
if ($state{rePrefix} eq "tr") {
$self->{TOKEN} = "\", $squash, $complement, $delete)";
if ($nondestructive) {
$state{prevTokenNode}->{TOKEN} = "regexptr(".$state{regexpName}.", NULL, ";
}
} else {
die("Unknown RE prefix \"".$state{rePrefix}."\" [2]\n");
}
}
$state{inRegExp} = 0;
$state{rePrefix} = "";
} elsif ($state{inRegExp}) {
$self->{TOKEN} =~ s/\\/\\\\/g;
}
if ($state{inComment} && $self->{TOKEN} =~ /[\n\r]/) {
print STDERR "Leaving comment.\n" if ($localDebug);
$state{inComment} = 0;
}
print STDERR "Checking token.\n" if ($localDebug);
if ($self->{TOKEN} =~ /^\$[a-zA-Z0-9_]+$/) {
print STDERR "setting PTN\n" if ($localDebug);
$state{prevTokenNode} = $self;
}
if ($state{captureIf}) {
print STDERR "APPEND ".$self->{TOKEN}."\n" if ($localDebug);
$state{capturedText} .= $self->{TOKEN};
$self->{TOKEN} = "";
}
my $resetSplit = 0;
if ($state{inSplit} == 2) {
$resetSplit = 1;
$state{inSplit} = 3;
}
if ($self->{FIRSTCHILD}) {
print STDERR "Processing children.\n" if ($localDebug);
my $tempstateref = $self->{FIRSTCHILD}->translateTreeRec(\%state);
my %tempstate = %{$tempstateref};
if ($state{inComment} && $tempstate{inHDComment}) {
$state{inHDComment} = 1;
}
if ($state{captureIf}) {
$state{capturedText} = $tempstate{capturedText};
}
$state{seenCode} = $tempstate{seenCode};
$state{prevTokenNode} = $tempstate{prevtoken};
}
if ($resetSplit) { $state{inSplit} = 0; print STDERR "inSplit -> 0\n" if ($localDebug) };
if ($enteringComment) { $state{inComment} = 0; $state{seenCode} = 0; }
if ($enteringString) { $state{inString} = 0; }
if ($enteringSingle) { $state{inSingle} = 0; }
if ($leavingHDComment) { $state{inHDComment} = 0; $state{seenCode} = 0; }
if ($self->{NEXT}) {
print STDERR "Processing next.\n" if ($localDebug);
$stateref = $self->{NEXT}->translateTreeRec(\%state);
%state = %{$stateref};
}
print STDERR "Returning.\n" if ($localDebug);
return \%state;
}
1;