示例#1
0
CXSourceLocation lfort_getLocation(CXProgram tu,
                                   CXFile file,
                                   unsigned line,
                                   unsigned column) {
  if (!tu || !file)
    return lfort_getNullLocation();
  
  bool Logging = ::getenv("LIBLFORT_LOGGING");
  ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->PgmData);
  ASTUnit::ConcurrencyCheck Check(*CXXUnit);
  const FileEntry *File = static_cast<const FileEntry *>(file);
  SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
  if (SLoc.isInvalid()) {
    if (Logging)
      llvm::errs() << "lfort_getLocation(\"" << File->getName() 
      << "\", " << line << ", " << column << ") = invalid\n";
    return lfort_getNullLocation();
  }
  
  if (Logging)
    llvm::errs() << "lfort_getLocation(\"" << File->getName() 
    << "\", " << line << ", " << column << ") = " 
    << SLoc.getRawEncoding() << "\n";
  
  return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
}
示例#2
0
CXSourceLocation clang_getLocation(CXTranslationUnit TU,
                                   CXFile file,
                                   unsigned line,
                                   unsigned column) {
  if (cxtu::isNotUsableTU(TU)) {
    LOG_BAD_TU(TU);
    return clang_getNullLocation();
  }
  if (!file)
    return clang_getNullLocation();
  if (line == 0 || column == 0)
    return clang_getNullLocation();
  
  LogRef Log = Logger::make(__func__);
  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
  ASTUnit::ConcurrencyCheck Check(*CXXUnit);
  const FileEntry *File = static_cast<const FileEntry *>(file);
  SourceLocation SLoc = CXXUnit->getLocation(File, line, column);
  if (SLoc.isInvalid()) {
    if (Log)
      *Log << llvm::format("(\"%s\", %d, %d) = invalid",
                           File->getName().str().c_str(), line, column);
    return clang_getNullLocation();
  }
  
  CXSourceLocation CXLoc =
      cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
  if (Log)
    *Log << llvm::format("(\"%s\", %d, %d) = ", File->getName().str().c_str(),
                         line, column)
         << CXLoc;

  return CXLoc;
}
示例#3
0
CXSourceLocation lfort_getLocationForOffset(CXProgram tu,
                                            CXFile file,
                                            unsigned offset) {
  if (!tu || !file)
    return lfort_getNullLocation();
  
  ASTUnit *CXXUnit = static_cast<ASTUnit *>(tu->PgmData);

  SourceLocation SLoc 
    = CXXUnit->getLocation(static_cast<const FileEntry *>(file), offset);

  if (SLoc.isInvalid())
    return lfort_getNullLocation();
  
  return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
}
示例#4
0
CXSourceLocation clang_getLocationForOffset(CXTranslationUnit TU,
                                            CXFile file,
                                            unsigned offset) {
  if (cxtu::isNotUsableTU(TU)) {
    LOG_BAD_TU(TU);
    return clang_getNullLocation();
  }
  if (!file)
    return clang_getNullLocation();

  ASTUnit *CXXUnit = cxtu::getASTUnit(TU);

  SourceLocation SLoc 
    = CXXUnit->getLocation(static_cast<const FileEntry *>(file), offset);

  if (SLoc.isInvalid())
    return clang_getNullLocation();
  
  return cxloc::translateSourceLocation(CXXUnit->getASTContext(), SLoc);
}