本文整理汇总了C++中clang::SourceRange::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ SourceRange::isValid方法的具体用法?C++ SourceRange::isValid怎么用?C++ SourceRange::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clang::SourceRange
的用法示例。
在下文中一共展示了SourceRange::isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getComment
std::string CommentSaver::getComment( clang::SourceRange sr ) {
if ( sr.isValid() ) {
/* fsl_begin and fsl_end are two pointers into the header file. We want the text between the two pointers. */
clang::FullSourceLoc fsl_begin(sr.getBegin() , ci.getSourceManager()) ;
clang::FullSourceLoc fsl_end(sr.getEnd() , ci.getSourceManager()) ;
std::string comment_text( fsl_begin.getCharacterData() ,
(size_t)(fsl_end.getCharacterData() - fsl_begin.getCharacterData())) ;
return comment_text ;
}
/* return an empty string if no comment found on this line of the file. */
return std::string() ;
}
示例2: applySourceRange
void ClangToSageTranslator::applySourceRange(SgNode * node, clang::SourceRange source_range) {
SgLocatedNode * located_node = isSgLocatedNode(node);
SgInitializedName * init_name = isSgInitializedName(node);
#if DEBUG_SOURCE_LOCATION
std::cerr << "Set File_Info for " << node << " of type " << node->class_name() << std::endl;
#endif
if (located_node == NULL && init_name == NULL) {
std::cerr << "Consistency error: try to apply a source range to a Sage node which is not a SgLocatedNode or a SgInitializedName." << std::endl;
exit(-1);
}
else if (located_node != NULL) {
Sg_File_Info * fi = located_node->get_startOfConstruct();
if (fi != NULL) delete fi;
fi = located_node->get_endOfConstruct();
if (fi != NULL) delete fi;
}
else if (init_name != NULL) {
Sg_File_Info * fi = init_name->get_startOfConstruct();
if (fi != NULL) delete fi;
fi = init_name->get_endOfConstruct();
if (fi != NULL) delete fi;
}
Sg_File_Info * start_fi = NULL;
Sg_File_Info * end_fi = NULL;
if (source_range.isValid()) {
clang::SourceLocation begin = source_range.getBegin();
clang::SourceLocation end = source_range.getEnd();
if (begin.isValid() && end.isValid()) {
if (begin.isMacroID()) {
#if DEBUG_SOURCE_LOCATION
std::cerr << "\tDump SourceLocation begin as it is a MacroID: ";
begin.dump(p_compiler_instance->getSourceManager());
std::cerr << std::endl;
#endif
begin = p_compiler_instance->getSourceManager().getExpansionLoc(begin);
ROSE_ASSERT(begin.isValid());
}
if (end.isMacroID()) {
#if DEBUG_SOURCE_LOCATION
std::cerr << "\tDump SourceLocation end as it is a MacroID: ";
end.dump(p_compiler_instance->getSourceManager());
std::cerr << std::endl;
#endif
end = p_compiler_instance->getSourceManager().getExpansionLoc(end);
ROSE_ASSERT(end.isValid());
}
clang::FileID file_begin = p_compiler_instance->getSourceManager().getFileID(begin);
clang::FileID file_end = p_compiler_instance->getSourceManager().getFileID(end);
bool inv_begin_line;
bool inv_begin_col;
bool inv_end_line;
bool inv_end_col;
unsigned ls = p_compiler_instance->getSourceManager().getSpellingLineNumber(begin, &inv_begin_line);
unsigned cs = p_compiler_instance->getSourceManager().getSpellingColumnNumber(begin, &inv_begin_col);
unsigned le = p_compiler_instance->getSourceManager().getSpellingLineNumber(end, &inv_end_line);
unsigned ce = p_compiler_instance->getSourceManager().getSpellingColumnNumber(end, &inv_end_col);
if (file_begin.isInvalid() || file_end.isInvalid() || inv_begin_line || inv_begin_col || inv_end_line || inv_end_col) {
ROSE_ASSERT(!"Should not happen as everything have been check before...");
}
if (p_compiler_instance->getSourceManager().getFileEntryForID(file_begin) != NULL) {
std::string file = p_compiler_instance->getSourceManager().getFileEntryForID(file_begin)->getName();
start_fi = new Sg_File_Info(file, ls, cs);
end_fi = new Sg_File_Info(file, le, ce);
#if DEBUG_SOURCE_LOCATION
std::cerr << "\tCreate FI for node in " << file << ":" << ls << ":" << cs << std::endl;
#endif
}
#if DEBUG_SOURCE_LOCATION
else {
std::cerr << "\tDump SourceLocation for \"Invalid FileID\": " << std::endl << "\t";
begin.dump(p_compiler_instance->getSourceManager());
std::cerr << std::endl << "\t";
end.dump(p_compiler_instance->getSourceManager());
std::cerr << std::endl;
}
#endif
}
}
if (start_fi == NULL && end_fi == NULL) {
start_fi = Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode();
end_fi = Sg_File_Info::generateDefaultFileInfoForCompilerGeneratedNode();
start_fi->setCompilerGenerated();
end_fi->setCompilerGenerated();
#if DEBUG_SOURCE_LOCATION
std::cerr << "Create FI for compiler generated node" << std::endl;
#endif
//.........这里部分代码省略.........