[Lxr-commits] CVS: lxr/lib/LXR/Lang Generic.pm,1.46,1.47
Brought to you by:
ajlittoz
From: Andre-Littoz <ajl...@us...> - 2013-11-08 18:18:57
|
Update of /cvsroot/lxr/lxr/lib/LXR/Lang In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv15801/lib/LXR/Lang Modified Files: Generic.pm Log Message: Index.pm, Lang/Generic.pm, Common.pm, genxref: make sure the human-readable type description is initialised in every database (Important for genxref, does not really matter for browsing) Parser tables are cached after first instantiation while they are written if needed into DB. Under --allurls genxref connects to new DB and, though parser initialisation is called again, the loaded cache prevents from writing the types in the new DB. A running DB counter is created. Whenever, its value is different from the cached one, writing types table is forced. (Note: something went wrong with last CVS commit, forcing to resubmit for Generic.pm) Index: Generic.pm =================================================================== RCS file: /cvsroot/lxr/lxr/lib/LXR/Lang/Generic.pm,v retrieving revision 1.46 retrieving revision 1.47 diff -u -d -r1.46 -r1.47 --- Generic.pm 8 Nov 2013 18:14:03 -0000 1.46 +++ Generic.pm 8 Nov 2013 18:18:54 -0000 1.47 @@ -114,11 +114,28 @@ Internal function (not method!) C<read_config> reads in language descriptions from configuration file. -This is only executed once, saving the overhead of processing the -config file each time. +Sets in global variable C<$config_contents> a reference to a I<hash> +equivalent to the configuration file. +The diffrences are: -The mapping between I<ctags> tags and their human readable counterpart -is stored in the database for every language. The mapping is then +=over + +=item 1 Keywords are uppercased is language is case-insensitive. + +=item 1 Keywords are stored in a I<hash> instead of an array to +speed up later retrieval (avoiding linear search and its quadratic +average time) + +=item 1 Human-readable text for type is replaced by a record-id +in the database where text is recorded. + +=back + +Loading the file and transformung if is only executed once, +saving the overhead of processing the config file each time. + +However, The mapping between I<ctags> tags and their human readable +counterpart is stored in every database for every language. The mapping is then replaced by the index of the table in the DB. =cut @@ -127,21 +144,54 @@ open(CONF, $config->{'genericconf'}) or die 'Can\'t open ' . $config->{'genericconf'} . ", $!"; - local ($/) = undef; - - my $config_contents = <CONF>; - $config_contents =~ m/(.*)/s; - $config_contents = $1; #untaint it - $generic_config = eval("\n#line 1 \"generic.conf\"\n" . $config_contents); - die($@) if $@; - close CONF; + my $todo = !defined($generic_config); + if ($todo) { + local ($/) = undef; + my $config_contents = <CONF>; + $config_contents =~ m/(.*)/s; + $config_contents = $1; #untaint it + $generic_config = eval("\n#line 1 \"generic.conf\"\n" . $config_contents); + die($@) if $@; + close CONF; + } - # Setup the ctags to declid mapping my $langmap = $generic_config->{'langmap'}; + my $langdesc; # Language description hash + my $typemap; # Language type letter/text table + my $type; # Letter for type + my $tdescr; # Human-readable type + my $langid; # Language code + foreach my $lang (keys %$langmap) { - my $typemap = $langmap->{$lang}{'typemap'}; - foreach my $type (keys %$typemap) { - $typemap->{$type} = $index->decid($langmap->{$lang}{'langid'}, $typemap->{$type}); + if ($todo) { + $langdesc = $langmap->{$lang}; # Dereference + # Transform the 'reserved' keyword list to speed up lookup + my $insensitive = 0; + if (exists($langdesc->{'flags'})) { + foreach (@{$langdesc->{'flags'}}) { + if ($_ eq 'case_insensitive') { + $insensitive = 1; + last; + } + } + } + if (exists($langdesc->{'reserved'})) { + my @kwl = @{$langdesc->{'reserved'}}; + $langdesc->{'reserved'} = {}; + foreach (@kwl) { + if ($insensitive) { + $langdesc->{'reserved'}{uc($_)} = 1; + } else { + $langdesc->{'reserved'}{$_} = 1; + } + } + } + } + # Setup the ctags to declid mapping + $typemap = $langdesc->{'typemap'}; + $langid = $langdesc->{'langid'}; + while (($type, $tdescr) = each %$typemap) { + $typemap->{$type} = $index->decid($langid, $tdescr); } } } |