NaturalDocs::ClassHierarchy

A package that handles all the gory details of managing the class hierarchy.  It handles the hierarchy itself, which files define them, rebuilding the files that are affected by changes, and loading and saving them to a file.

Usage and Dependencies

Summary
NaturalDocs::ClassHierarchyA package that handles all the gory details of managing the class hierarchy.
Variables
CLASS_HIERARCHY_FILEHANDLEThe file handle used with ClassHierarchy.nd.
classesA hash of all the classes.
filesA hash of the hierarchy information referenced by file.
parentReferencesA hash of all the parent reference strings and what they resolve to.
watchedFileA NaturalDocs::ClassHierarchy::File object of the file being watched for changes.
watchedFileNameThe FileName of the watched file, if any.
dontRebuildFilesA bool to set if you don’t want changes in the hierarchy to cause files to be rebuilt.
Files
ClassHierarchy.ndStores the class hierarchy on disk.
File Functions
LoadLoads the class hierarchy from disk.
SaveSaves the class hierarchy to disk.
PurgePurges the hierarchy of files that no longer have Natural Docs content.
Interface Functions
OnInterpretationChangeCalled by NaturalDocs::SymbolTable whenever a class hierarchy reference’s intepretation changes, meaning it switched from one symbol to another.
OnTargetSymbolChangeCalled by NaturalDocs::SymbolTable whenever a class hierarchy reference’s target symbol changes, but the reference still resolves to the same symbol.
Modification Functions
AddClassAdds a class to the hierarchy.
AddParentReferenceAdds a class-parent relationship to the hierarchy.
WatchFileForChangesWatches a file for changes, which can then be applied by AnalyzeChanges().
AnalyzeChangesChecks the watched file for any changes that occured since the last time is was parsed, and updates the hierarchy as necessary.
Information Functions
ParentsOfReturns a SymbolString array of the passed class’ parents, or an empty array if none.
ChildrenOfReturns a SymbolString array of the passed class’ children, or an empty array if none.
Support Functions
DeleteFileDeletes a file and everything defined in it.
DeleteClassDeletes a class definition from a file.
DeleteParentReferenceDeletes a class’ parent reference and returns whether it resulted in the loss of a parent class.
ClassReferenceOfReturns the REFERENCE_CH_CLASS ReferenceString of the passed class SymbolString.
RebuildFilesForCalls NaturalDocs::Project->RebuildFile() for every file defining the passed class, its parents, and/or its children.

Variables

CLASS_HIERARCHY_FILEHANDLE

The file handle used with ClassHierarchy.nd.

classes

my %classes

A hash of all the classes.  The keys are the class SymbolStrings and the values are NaturalDocs::ClassHierarchy::Classes.

files

my %files

A hash of the hierarchy information referenced by file.  The keys are the FileNames, and the values are NaturalDocs::ClassHierarchy::Files.

parentReferences

my %parentReferences

A hash of all the parent reference strings and what they resolve to.  The keys are the ReferenceStrings and the values are the class SymbolStrings that they resolve to.

watchedFile

my $watchedFile

A NaturalDocs::ClassHierarchy::File object of the file being watched for changes.  This is compared to the version in files to see if anything was changed since the last parse.

watchedFileName

my $watchedFileName

The FileName of the watched file, if any.  If there is no watched file, this will be undef.

dontRebuildFiles

my $dontRebuildFiles

A bool to set if you don’t want changes in the hierarchy to cause files to be rebuilt.

Files

ClassHierarchy.nd

Stores the class hierarchy on disk.

Format

[BINARY_FORMAT]
[VersionInt: app version]

The standard BINARY_FORMAT and VersionInt header.

[SymbolString: class or undef to end]

Next we begin a class segment with its SymbolString.  These continue until the end of the file.  Only defined classes are included.

[UInt32: number of files]
[UString16: file] [UString16: file] ...

Next there is the number of files that define that class.  It’s a UInt32, which seems like overkill, but I could imagine every file in a huge C++ project being under the same namespace, and thus contributing its own definition.  It’s theoretically possible.

Following the number is that many file names.  You must remember the index of each file, as they will be important later.  Indexes start at one because zero has a special meaning.

[UInt8: number of parents]
( [ReferenceString (no type): parent]
  [UInt32: file index] [UInt32: file index] ... [UInt32: 0] ) ...

Next there is the number of parents defined for this class.  For each one, we define a parent segment, which consists of its ReferenceString, and then a zero-terminated string of indexes of the files that define that parent as part of that class.  The indexes start at one, and are into the list of files we saw previously.

Note that we do store class segments for classes without parents, but not for undefined classes.

This concludes a class segment.  These segments continue until an undef SymbolString.

See Also

File Format Conventions

Revisions

1.52

  • Changed AString16s to UString16s.

1.22

1.2

  • This file was introduced in 1.2.

File Functions

Load

sub Load

Loads the class hierarchy from disk.

Save

sub Save

Saves the class hierarchy to disk.

Purge

sub Purge

Purges the hierarchy of files that no longer have Natural Docs content.

Interface Functions

OnInterpretationChange

sub OnInterpretationChange #(reference)

Called by NaturalDocs::SymbolTable whenever a class hierarchy reference’s intepretation changes, meaning it switched from one symbol to another.

referenceThe ReferenceString whose current interpretation changed.

OnTargetSymbolChange

sub OnTargetSymbolChange #(reference)

Called by NaturalDocs::SymbolTable whenever a class hierarchy reference’s target symbol changes, but the reference still resolves to the same symbol.

Parameters

referenceThe ReferenceString that was affected by the change.

Modification Functions

AddClass

sub AddClass #(file,
class,
languageName)

Adds a class to the hierarchy.

Parameters

fileThe FileName the class was defined in.
classThe class SymbolString.
languageNameThe name of the language this applies to.

Note

The file parameter must be defined when using this function externally.  It may be undef for internal use only.

AddParentReference

sub AddParentReference #(file,
class,
symbol,
scope,
using,
resolvingFlags) or (file, class, reference)

Adds a class-parent relationship to the hierarchy.  The classes will be created if they don’t already exist.

Parameters

fileThe FileName the reference was defined in.
classThe class SymbolString.
symbolThe parent class SymbolString.
scopeThe package SymbolString that the reference appeared in.
usingAn arrayref of package SymbolStrings that the reference has access to via “using” statements.
resolvingFlagsAny Resolving Flags to be used when resolving the reference.

Alternate Parameters

fileThe FileName the reference was defined in.
classThe class SymbolString.
referenceThe parent ReferenceString.

WatchFileForChanges

sub WatchFileForChanges #(file)

Watches a file for changes, which can then be applied by AnalyzeChanges().  Definitions are not deleted via a DeleteClass() function.  Instead, a file is watched for changes, reparsed, and then a comparison is made to look for definitions that disappeared and any other relevant changes.

Parameters

fileThe FileName to watch.

AnalyzeChanges

sub AnalyzeChanges

Checks the watched file for any changes that occured since the last time is was parsed, and updates the hierarchy as necessary.  Also sends any files that are affected to NaturalDocs::Project->RebuildFile().

Information Functions

ParentsOf

sub ParentsOf #(class)

Returns a SymbolString array of the passed class’ parents, or an empty array if none.  Note that not all of them may be defined.

ChildrenOf

sub ChildrenOf #(class)

Returns a SymbolString array of the passed class’ children, or an empty array if none.  Note that not all of them may be defined.

Support Functions

DeleteFile

sub DeleteFile #(file)

Deletes a file and everything defined in it.

Parameters

fileThe FileName.

DeleteClass

sub DeleteClass #(file,
class)

Deletes a class definition from a file.  Will also delete any parent references from this class and file.  Will rebuild any file affected unless dontRebuildFiles is set.

Parameters

fileThe FileName that defines the class.
classThe class SymbolString.

DeleteParentReference

sub DeleteParentReference #(file,
class,
reference)

Deletes a class’ parent reference and returns whether it resulted in the loss of a parent class.  Will rebuild any file affected unless dontRebuildFiles is set.

Parameters

fileThe FileName that defines the reference.
classThe class SymbolString.
referenceThe parent ReferenceString.

Returns

If the class lost a parent as a result of this, it will return its SymbolString.  It will return undef otherwise.

ClassReferenceOf

sub ClassReferenceOf #(class,
languageName)

Returns the REFERENCE_CH_CLASS ReferenceString of the passed class SymbolString.

RebuildFilesFor

sub RebuildFilesFor #(class,
rebuildParents,
rebuildSelf,
rebuildChildren)

Calls NaturalDocs::Project->RebuildFile() for every file defining the passed class, its parents, and/or its children.  Returns without doing anything if dontRebuildFiles is set.

Parameters

classThe class SymbolString.
rebuildParentsWhether to rebuild the class’ parents.
rebuildSelfWhether to rebuild the class.
rebuildChildrenWhether to rebuild the class’ children.
Stores the class hierarchy on disk.
my %classes
A hash of all the classes.
my %files
A hash of the hierarchy information referenced by file.
my %parentReferences
A hash of all the parent reference strings and what they resolve to.
my $watchedFile
A NaturalDocs::ClassHierarchy::File object of the file being watched for changes.
An object that stores information about what hierarchy information is present in a file.
my $watchedFileName
The FileName of the watched file, if any.
A string representing the absolute, platform-dependent path to a file.
my $dontRebuildFiles
A bool to set if you don’t want changes in the hierarchy to cause files to be rebuilt.
sub Load
Loads the class hierarchy from disk.
sub Save
Saves the class hierarchy to disk.
sub Purge
Purges the hierarchy of files that no longer have Natural Docs content.
sub OnInterpretationChange #(reference)
Called by NaturalDocs::SymbolTable whenever a class hierarchy reference’s intepretation changes, meaning it switched from one symbol to another.
A package that handles all the gory details of managing symbols.
sub OnTargetSymbolChange #(reference)
Called by NaturalDocs::SymbolTable whenever a class hierarchy reference’s target symbol changes, but the reference still resolves to the same symbol.
sub AddClass #(file,
class,
languageName)
Adds a class to the hierarchy.
sub AddParentReference #(file,
class,
symbol,
scope,
using,
resolvingFlags) or (file, class, reference)
Adds a class-parent relationship to the hierarchy.
sub WatchFileForChanges #(file)
Watches a file for changes, which can then be applied by AnalyzeChanges().
sub AnalyzeChanges
Checks the watched file for any changes that occured since the last time is was parsed, and updates the hierarchy as necessary.
sub ParentsOf #(class)
Returns a SymbolString array of the passed class’ parents, or an empty array if none.
A scalar which encodes a normalized array of identifier strings representing a full or partially-resolved symbol.
sub ChildrenOf #(class)
Returns a SymbolString array of the passed class’ children, or an empty array if none.
sub DeleteFile #(file)
Deletes a file and everything defined in it.
sub DeleteClass #(file,
class)
Deletes a class definition from a file.
sub DeleteParentReference #(file,
class,
reference)
Deletes a class’ parent reference and returns whether it resulted in the loss of a parent class.
sub ClassReferenceOf #(class,
languageName)
Returns the REFERENCE_CH_CLASS ReferenceString of the passed class SymbolString.
A class reference handled by NaturalDocs::ClassHierarchy.
All the information about a reference that makes it unique encoded into a string.
sub RebuildFilesFor #(class,
rebuildParents,
rebuildSelf,
rebuildChildren)
Calls NaturalDocs::Project->RebuildFile() for every file defining the passed class, its parents, and/or its children.
sub RebuildFile #(file)
Adds the file to the list of files to build.
A package to handle the command line and various other program settings.
A package that manages information about the files in the source tree, as well as the list of files that have to be parsed and built.
sub ParseForInformation #(file)
Parses the input file for information.
An object that stores information about a class in the hierarchy.
An 8-bit constant that’s used as the first byte of binary data files.
A comparable integer representing a version number.
Used to influence the method of resolving references in NaturalDocs::SymbolTable.
Close