Skip to content

Sg_File_Info

This class represents the location of the code associated with the IR node in the

Synopsis

Declared in <src/frontend/SageIII/Cxx_Grammar.h> (not stored in Git)

class [[visibility("default")]] Sg_File_Info
    : public SgSupport

Description

original source code. This object is used to represent the starting and the ending position of the source code associated with some IR nodes (in other cases the endOfConstruct returnes the same data as the startOfConstruct). Classification of the IR nodes is included in this object and applies to:

  • SgStatements
  • SgExpression
  • SgInitializedName
  • SgFile (and maybe SgDirectory)
  • Perhaps also SgTemplateArguments, SgTemplateParameters, SgBaseClass classifications are:
  • e_transformation The IR node is part of a transformation. The transformation may be assigned to a file, in which case the file id references the file (default is the source file, that reachable from the scope where the transformation is done).
  • e_compiler_generated The IR node may be part of a compiler generated IR nodes (or subtree, in which case all IR nodes in the subtree are marked as compiler generated). Compiler generated IR nodes include:

  • implicit casts

  • instantiated templates (not explicitly specialized)

  • non-explicit return statements in main function.

  • (... complete this list)

  • e_output_in_code_generation

  • Used to explicitly makr any compiler generated IR nodes for output (forces template instaiations to be output in the generated source if transformed).

  • e_shared Marks IR nodes as shared (set by AST merge mechanism). Note that SgTypes and SgSymbols don't have a Sg_File_Info object, but are ALWAYS shared. (multiple classifications can co-exist).
  • Internal: A pointer for this object is in the SgNode, but it is only valid for SgLocatedNodes and the SgInitializedName. The get_File_Info() member function (and associated get_startOfConstruct() and get_endOfConstruct() member functions) are implemented in the SgNode, for uniformity, but return NULL for all but the SgLocatedNodes and the SgInitializedName IR nodes.
  • Todo: isOutputInCodeGeneration() is orthogonal to isCompilerGenerated and isTransformation(). Currently IR nodes that are marked as isTransformation() are output, but these need to be marked as also being isOutputInCodeGeneration() so that orthogonality of the concepts is maintained.
  • Todo: It is possible to call get_file_info() on a SgFileInfo object and this needs to be fixed because it does not make any sense. This is because get_file_info is defined as a virtual function on SgNode. Not sure this is a great design, but maybe it just needs a local implementation of a private get_file_info() member function so that it can't be called (can be hidden).
  • Todo: Should there be a simpler way to copy a SgFileInfo object than: "new Sg_File_Info(*fileInfo);" or "fileInfo->copy();"; likely not!
  • Todo: Define the subset of IR nodes which would all have:

  • Sg_File_Info

  • AstAttributeMechanism

  • SgNode (parent pointer) This will make the documentation more intuative. The argument supporting this is that we operate on those IR nodes that correspond to the visual representation of the source code (so we can exclude SgSymbols, and SgTypes). Having the same subset of IR nodes permits a simpler documentation of the API and intuition as to where it applies. A likely subset would be:

  • SgLocatedNodes

  • SgFile

  • SgDirectory (questionable)

  • SgInitializedName

  • SgBaseClass

  • SgTemplateArgument

  • SgTemplateParameter

  • Todo: Consider putting the endOfConstruct information into the single Sg_File_Info object. Currently the SgLocatedNode stores two Sg_File_Info objects, one for the beginning and the end of each construct. This would save significant space in the AST. Additional information in the Sg_File_Info could be:
  • offset from starting line number to the end of construct
  • flag for if end of construct is located in the same file as the start of construct
  • Todo: Consider using "short int" instead of "int" for the file_id, line, and col (and maybe the classificationBitField) to reduce the size of the data structure. Padding is not a significant issue since data structures are allocated in contiguious memory (except for padding to at least the nearest byte if bit field widths are used.
  • See also: Example of using a Sg_File_Info object

Data members

Sg_File_Info::p_file_id

This is a key that maps integers to file names, it prevents redundent storage of filename strings. This is part of a mechanism to reduce the memory requirements of the IR (to support whole program analysis in ROSE). The values are keys to an STL map which relates file ids to file name strings, allowing a more compressed representation of the filename data in the Sg_File_Info object. There are two maps, one for finding the filename string from a file id integer (p_fileidtoname_map), and another for the reverse map (p_nametofileid_map).

  • Internal: We will in the future limit the range of this value (expect a signed short int: 16 bits, 32K = 32768 files plus negative values for special cases).

Sg_File_Info::p_line

This is the line number of the location of the source code for this IR node. This information is useful in the heuristics of attaching comments to IR nodes (SgStatement and SgExpression IR nodes). The value of this variable is always greater than or equal to zero. In the case of isCompilerGenerated() == true or isTransformation() == true then value is INT_MAX-1. This value if define for this case so that all comments will be attached before the associated statement.

  • Internal: We will in the future limit the range of this value (expect a short int: 20 bits, 1000K = 1,048,576 lines per file).

Sg_File_Info::p_col

This is the column number of the location of the source code for this IR node. This information is useful in the heuristics of attaching comments to IR nodes (SgStatement and SgExpression IR nodes). The value of this variable is always greater than or equal to zero. If IR node is compiler generated for a transformation then value is set to INT_MAX-1.

  • Internal: We will in the future limit the range of this value (expect a short int: 16 bits, 64K = 65536 charaters per line).

Sg_File_Info::p_classificationBitField

This is mechanism for classification of the IR node. IR nodes use this mechanism to classify themselves as either part of a transformation or compiler generated (other enum values of Sg_File_Info::classifier are not used).

  • Internal: We will in the future limit the range of this value (expect an unsigned char: 8 bits, 64K = 65536 charaters per line).

Sg_File_Info::p_fileIDsToUnparse

This set contains a list of all file ids for which the accompanying IR node should be unparsed. This is part of the AST Merge mechanism. This set contains a list of file ids. During unparsing, if we encounter a node with this Sg_File_Info object, we only want to unparse this file if the file we are currently unparsing is in this list.

  • Internal: NOTE: This set should be empty unless the node is marked as shared

std::map< int, std::string > Sg_File_Info::p_fileidtoname_map

This is a static STL map of file id (integers) to file names (strings).

std::map< std::string, int > Sg_File_Info::p_nametofileid_map

This is a static STL map of file names (strings) to file id (integers).

Member functions

Sg_File_Info::Sg_File_Info()

This is the less useful default constructor. This constructor builds the Sg_File_Info base class.

  • Internal: This constructor should be deprecated since we don't want it to be used. It's presence is historical, since it was previously used a lot (inappropriately). Before it is removed we likely need a constructor that can take a Sg_File_Info::classifier enum value.
  • See also: Example:create an Sg_File_Info object

`Sg_File_Info::Sg_File_Info ( const char *filename, int line=0, int

col=0 )` This is the more useful constructor. This constructor builds the Sg_File_Info base class.

  • See also: Example:create an Sg_File_Info object

Sg_File_Info::Sg_File_Info(const Sg_File_Info & X)

This the copy constructor (deep copy made).

  • Internal: This constructor does a deep copy of all data in the Sg_File_Info object.
  • See also: Example:create an Sg_File_Info object

Sg_File_Info::set_line ( int line )

Sets the line number associated with the source file.

Sg_File_Info::get_filename () const

Returns the classified filename as a C string. Transformation positions report "transformation"; compiler-generated positions outside the frontend report "compilerGenerated".

Sg_File_Info::get_line () const

Returns the line number of the associated code for this IR node.

  • Return: Returns integer.

Sg_File_Info::get_col () const

Returns the column number of the associated code for this IR node.

  • Return: Returns integer

Sg_File_Info::get_raw_filename () const

Returns the filename mapped from the stored file ID without classification.

Sg_File_Info::get_raw_line () const

Returns the line number of the associated code for this IR node.

  • Return: Returns integer.

Sg_File_Info::get_raw_col () const

Returns the column number of the associated code for this IR node.

  • Return: Returns

Sg_File_Info::generateDefaultFileInfo()

Static function to return new Sg_File_Info object set to default values.

  • Return: Returns pointer to Sg_File_Info.

Sg_File_Info::generateDefaultFileInfoForTransformationNode()

Static function to return new Sg_File_Info object set to default values appropriate for transformations. This function calls setOutputInCodeGeneration() and sets the file_id to be TRANSFORMATION_FILE_ID.

  • Return: Returns pointer to Sg_File_Info.

Sg_File_Info::generateFileInfoForTransformationNode( int file_id )

Static function to return new Sg_File_Info object set to default values appropriate for transformations that are not in the source file. Static function which allows specification of transformation with assignement to a specific file (where it would be unparsed). This function will call setOutputInCodeGeneration() and sets the file_id to a non-negative value. This function is useful when transformation to a program happen within a header file (e.g. including a header file as part of a transformation). Setting the file_id to the current source file should have the same result (semantics) as Sg_File_Info::generateDefaultFileInfoForTransformationNode().

  • Return: Returns pointer to Sg_File_Info.

Sg_File_Info::generateFileInfoForTransformationNode( string filename )

Static function to return new Sg_File_Info object set to default values appropriate for transformations that are not in the source file. Function similar to previous function, but takes a filename to support new files that have not ben seen previously (e.g. new header file).

  • Return: Returns pointer to Sg_File_Info.

Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode()

Static function to return new Sg_File_Info object set to default values appropriate for compiler generated code.

  • Return: Returns pointer to Sg_File_Info.

Sg_File_Info::hasPositionInSource() const

Abstracts query as to if an IR node maps back to the source code (evolving set of reasons whey this can be false). There are several reasons why an IR node might NOT have a mapping back to the source code:

  • could be a part of a transformation (isTransformation() == true)
  • could be a compiler generated statement or expression (isCompilerGenerated() == true)
  • Internal: This is an evolving set of reasons, so abstracting it as a member function is helpful.
  • Return: Returns bool.

Sg_File_Info::isTransformation() const

Returns true only if part of a transformation.

  • Return: Returns bool.

Sg_File_Info::isCompilerGenerated() const

Returns true only if compiler generated (either by the front-end or by ROSE). Source provenance and output eligibility have separate typed flags; being compiler generated does not by itself require emission by the unparser.

  • Return: Returns bool.

Sg_File_Info::isOutputInCodeGeneration() const

Returns true only if required to be unparsed in generated code.

  • Internal: Templates instatiated by ROSE are marked as compiler generated, but only those instatiated templates that are used in the source file are required and so only those must be unparsed in the generated code. Note that currently all transformed IR nodes are implicitly considered to be marked as outputInCodeGeneration, but this will be made an explicit requirement in the future.
  • Return: Returns bool.

Sg_File_Info::isShared() const

Returns true only if shared internally (either by the front-end or by ROSE).

  • Internal: This is a new classification supporting the AST merge mechanism. Currently numerous types of IR nodes that are shared (SgType, SgSymbol, many non-defining declarations, etc.) are not explicitly marked as shared. This may be correct in a future release (requires more thought).
  • Return: Returns bool.

Sg_File_Info::unsetTransformation()

If the IR node is a transformation it marks it false (zeros transformation marker bit internally).

  • Return: Returns void.

Sg_File_Info::setTransformation()

Marks an IR node to be a transformation if it is not one already.

  • Return: Returns void.

Sg_File_Info::unsetCompilerGenerated()

Unmarks IR node as compiler generated.

  • Return: Returns void.

Sg_File_Info::setCompilerGenerated()

Marks IR node as compiler generated.

  • Return: Returns void.

Sg_File_Info::unsetOutputInCodeGeneration()

Unmarks IR node as compiler generated but required in the generated source (e.g. requied templates).

  • Return: Returns void.

Sg_File_Info::setOutputInCodeGeneration()

Marks IR node as compiler generated but required in the generated source (e.g. requied templates).

  • Return: Returns void.

Sg_File_Info::unsetShared()

Unmarks IR node as shared.

  • Return: Returns void.

Sg_File_Info::setShared()

Marks IR node as shared.

  • Return: Returns void.

bool Sg_File_Info::ok()

Checks internal consistancy of data. Checks file ID, line, and column, with explicit allowances for generated, transformed, or unavailable source positions. Defined to be used in tests: ROSE_ASSERT(statement->get_file_info()->ok());

  • Return: Returns bool.

Sg_File_Info::display( const string label )

This function outputs the internal data to stdout, for debugging.

  • Return: Returns void.

`bool Sg_File_Info::operator== ( const Sg_File_Info & X, const

Sg_File_Info & Y )` This relational operator tests two Sg_File_Info objects for equal position information.

  • Return: Returns bool.

`bool Sg_File_Info::operator!= ( const Sg_File_Info & X, const

Sg_File_Info & Y )` This relational operator tests two Sg_File_Info objects for unequal position information.

  • Return: Returns bool.

`Sg_File_Info::operator> ( const Sg_File_Info & X, const Sg_File_Info &

Y )` This relational operator tests two Sg_File_Info objects for X being after Y in the same file.

  • Return: Returns bool.

`Sg_File_Info::operator< ( const Sg_File_Info & X, const Sg_File_Info &

Y )` This relational operator tests two Sg_File_Info objects for X being before Y in the same file.

  • Return: Returns bool.

`Sg_File_Info::operator>= ( const Sg_File_Info & X, const Sg_File_Info &

Y )` This relational operator tests two Sg_File_Info objects for X being at the same position or after Y in the same file.

  • Return: Returns bool.

`Sg_File_Info::operator<= ( const Sg_File_Info & X, const Sg_File_Info &

Y )` This relational operator tests two Sg_File_Info objects for X being at the same position or before Y in the same file.

  • Return: Returns bool.

Base Classes

Name Description
SgSupport This class represents the base class of a numbr of IR nodes that don't otherwise fit

Type Aliases

Name
base_node_type

Enums

Name Description
Unnamed enum static variant value
classifier
p_fileflags

Member Functions

Name Description
Sg_File_Info
Sg_File_Info(); [constructor]
Constructors
~Sg_File_Info
virtual ~Sg_File_Info(); [destructor] [virtual]
Destructor
operator=
Sg_File_Info& operator=(Sg_File_Info const& X);
Copy assignment operator
accept
virtual void accept(ROSE_VisitorPattern& visitor) override; [virtual]
support for the classic visitor pattern done in GoF
addFileToUnparse
void addFileToUnparse(int file_id);
Add files to the set that should be able to unparse the node
appendDestructorOwnedNodes
virtual void appendDestructorOwnedNodes(std::vector<SgNode*>& nodes) const override; [virtual]
check_file_id
void check_file_id( char const* label, bool assertion = true) const;
class_name
virtual std::string class_name() const override; [virtual]
returns a string representing the class name
copy
virtual SgNode* copy(SgCopyHelp& help) const override; [virtual]
display
void display() const;
displayString
std::string displayString(std::string const& label = "") const;
get_childIndex
virtual size_t get_childIndex(SgNode* child) const override; [virtual]
index-based access to traversal successors by child node
get_classificationBitField
unsigned int get_classificationBitField() const;
Get whole bit field fr modifier set
get_col
int get_col() const;
get_fileIDsToUnparse
SgFileIdList const& get_fileIDsToUnparse() const;
get_fileLineNumbersToUnparse
SgFileLineNumberList const& get_fileLineNumbersToUnparse() const;
get_file_id
int get_file_id() const;
get_filename
char const* get_filename() const;
get_filenameString
std::string const& get_filenameString() const;
get_line
int get_line() const;
Where this is a shared IR node across multiple files, return the line number location of the IR node for a specific file.
get_numberOfTraversalSuccessors
virtual size_t get_numberOfTraversalSuccessors() const override; [virtual]
return number of children in the traversal successor list
get_physical_file_id
int get_physical_file_id() const;
get_physical_file_occurrence_id
unsigned int get_physical_file_occurrence_id() const;
get_physical_filename
std::string get_physical_filename() const;
get_physical_line
int get_physical_line() const;
Where this is a shared IR node across multiple files, return the line number location of the IR node for a specific file.
get_raw_col
int get_raw_col() const;
get_raw_file_id
int get_raw_file_id() const;
get_raw_filename
std::string get_raw_filename() const;
get_raw_line
int get_raw_line() const;
get_raw_physical_file_id
int get_raw_physical_file_id() const;
Return the stored physical ID without semantic classification.
get_source_sequence_number
unsigned int get_source_sequence_number() const;
get_traversalSuccessorByIndex
virtual SgNode* get_traversalSuccessorByIndex(size_t idx) const override; [virtual]
index-based access to traversal successors by index number
get_traversalSuccessorContainer
virtual std::vector<SgNode*> get_traversalSuccessorContainer() const override; [virtual]
container of pointers to AST successor nodes used in the traversal overridden in every class by generated implementation
get_traversalSuccessorIsListElement
virtual std::vector<bool> get_traversalSuccessorIsListElement() const override; [virtual]
get_traversalSuccessorNamesContainer
virtual std::vector<std::string> get_traversalSuccessorNamesContainer() const override; [virtual]
container of names of variables or container indices used used in the traversal to access AST successor nodes overridden in every class by generated implementation
hasPositionInSource
bool hasPositionInSource() const;
isCommentOrDirective
bool isCommentOrDirective() const;
isCompilerGenerated
bool isCompilerGenerated() const;
isDefaultArgument
bool isDefaultArgument() const;
isFrontendSpecific
bool isFrontendSpecific() const;
isImplicitCast
bool isImplicitCast() const;
isOutputInCodeGeneration
bool isOutputInCodeGeneration() const;
isSameFile
bool isSameFile(Sg_File_Info const& fileInfo) const;
isShared
bool isShared() const;
isSourcePositionUnavailableInFrontend
bool isSourcePositionUnavailableInFrontend() const;
isToken
bool isToken() const;
isTransformation
bool isTransformation() const;
Access function for classification bit field
ok
bool ok() const;
operator delete
void operator delete( void* pointer, size_t size);
deallocated memory for IR node (returns memory to memory pool for reuse)
operator new
void* operator new(size_t size);
returns pointer to newly allocated IR node
post_construction_initialization
virtual void post_construction_initialization() override; [virtual]
processDataMemberReferenceToPointers
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler*) override; [virtual]
Pass references to stored node pointers to a handler.
returnDataMemberPointers
virtual std::vector<std::pair<SgNode*, std::string>> returnDataMemberPointers() const override; [virtual]
Return the node pointers stored in this node's data members.
roseRTI
virtual RTIReturnType roseRTI() override; [virtual]
return C++ Runtime-Time-Information
sage_class_name
virtual char const* sage_class_name() const override; [virtual]
returns a C style string (char*) representing the class name
setCommentOrDirective
void setCommentOrDirective();
setCompilerGenerated
void setCompilerGenerated();
setDefaultArgument
void setDefaultArgument();
setFrontendSpecific
void setFrontendSpecific();
setImplicitCast
void setImplicitCast();
setOutputInCodeGeneration
void setOutputInCodeGeneration();
setShared
void setShared();
setSourcePositionUnavailableInFrontend
void setSourcePositionUnavailableInFrontend();
setToken
void setToken();
setTransformation
void setTransformation();
set_classificationBitField
void set_classificationBitField(unsigned int);
set_col
void set_col(int n);
set_file_id
void set_file_id(int file_id);
set_filenameString
void set_filenameString(std::string const& filename);
set_line
void set_line(int line);
set_physical_file_id
void set_physical_file_id(int physical_file_id);
set_physical_file_occurrence_id
void set_physical_file_occurrence_id(unsigned int n);
Exact frontend lexical occurrence of the physical file. Zero means that the producing frontend has no occurrence model.
set_physical_filename
void set_physical_filename(std::string const& filename);
set_physical_line
void set_physical_line(int line);
set_physical_source_position_to_match_logical_source_position
void set_physical_source_position_to_match_logical_source_position();
set_source_sequence_number
void set_source_sequence_number(unsigned int n);
shouldUnparse
bool shouldUnparse(int file_id);
Should this node be unparsed by this file?
unsetCommentOrDirective
void unsetCommentOrDirective();
unsetCompilerGenerated
void unsetCompilerGenerated();
unsetDefaultArgument
void unsetDefaultArgument();
unsetFrontendSpecific
void unsetFrontendSpecific();
unsetImplicitCast
void unsetImplicitCast();
unsetOutputInCodeGeneration
void unsetOutputInCodeGeneration();
Mark as to be output by the unparser (code generator)
unsetShared
void unsetShared();
Support for shared IR nodes (shared via AST merge mechanism)
unsetSourcePositionUnavailableInFrontend
void unsetSourcePositionUnavailableInFrontend();
unsetToken
void unsetToken();
unsetTransformation
void unsetTransformation();
Set/unset functions for classification bit field
updateSourcePosition
void updateSourcePosition(Sg_File_Info* update);
variantT
virtual VariantT variantT() const override; [virtual]
returns new style SageIII enum values

Static Member Functions

Name Description
addFilenameToMap
static int addFilenameToMap(std::string const& filename);
Access function to permit files referenced in Dwarf to be mapped to integers using the same scheme as for source code.
display_static_data
static void display_static_data(std::string const label);
generateDefaultFileInfo
static Sg_File_Info* generateDefaultFileInfo();
generateDefaultFileInfoForCompilerGeneratedNode
static Sg_File_Info* generateDefaultFileInfoForCompilerGeneratedNode();
generateDefaultFileInfoForTransformationNode
static Sg_File_Info* generateDefaultFileInfoForTransformationNode();
generateFileInfoForTransformationNode
static Sg_File_Info* generateFileInfoForTransformationNode(int file_id);
getFilenameFromID
static std::string const& getFilenameFromID(int id);
getIDFromFilename
static int getIDFromFilename(std::string filename);
get_fileidtoname_map
static std::map<int, std::string>& get_fileidtoname_map();
Access function for static datamember fileidtoname_map.
get_nametofileid_map
static std::map<std::string, int>& get_nametofileid_map();
Access function for static datamember nametofileid_map.
memoryUsage
static size_t memoryUsage();
Returns the size in bytes of the total memory allocated for all IR nodes of this type
numberOfNodes
static size_t numberOfNodes();
Returns the total number of IR nodes of this type
numberOfSourceFiles
static int numberOfSourceFiles();
Returns the number of entries in the filename map
set_fileidtoname_map
static void set_fileidtoname_map(std::map<int, std::string>& X);
Access function for map of file names.
set_nametofileid_map
static void set_nametofileid_map(std::map<std::string, int>& X);
Access function for map of file names.
traverseMemoryPoolNodes
static void traverseMemoryPoolNodes(ROSE_VisitTraversal& visit);
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
traverseMemoryPoolVisitorPattern
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern& visitor);
FOR INTERNAL USE Support for visitor pattern.
visitRepresentativeNode
static void visitRepresentativeNode(ROSE_VisitTraversal& visit);
FOR INTERNAL USE Support for type-based traversal.

Static Data Members

Name Description
free_slots Free slots, each numbered pool_index * pool_size + slot_index. The last entry is allocated next.
pool_live_flags
pool_size
pools

Protected Data Members

Name
p_classificationBitField
p_col
p_fileIDsToUnparse
p_fileLineNumbersToUnparse
p_file_id
p_line
p_physical_file_id
p_physical_file_occurrence_id
p_physical_line
p_source_sequence_number

Protected Static Data Members

Name
p_fileidtoname_map
p_nametofileid_map

Friends

Name Description
isSg_File_Info Casts pointer from base class to derived class (for const pointers)
isSg_File_Info Casts pointer from base class to derived class
operator<= Less-than-or-equal operator
operator>= Greater-than-or-equal operator
operator< Less-than operator
operator> Greater-than operator
operator!= Inequality operator
operator== Equality operator

Created with MrDocs