2017-04-17 6 views

답변

2

매개 변수로 fileid를 사용하는 소스 관리자의 GetIncludedLoc 기능을 사용하는 경우는 어떻습니까?

SourceManager.GetIncludedLoc (FileID에) 답변에 대한

0

감사의 @Hemant을, 당신 말이 맞아

나는 이미 자신에 의해 (연타 3.8이 getIncludeLoc라고합니다) 발견 그러나 여기에서 쓰는 것을 잊었다 . 나는 이것을 사용하여 모든 #includes 뒤에 위치를 찾을 수 있습니다. 여기에, 나는이에 대해 쓴 (확실하지 않은 가장 좋은 방법) 함수의 누군가에게 도움이되기를 바랍니다

SourceLocation getIncludeLocation(FileID fileID, SourceManager &sm, unsigned carriages) { 
     return SourceLocation(); 
    set<unsigned> lines; 
    if (fileID.isInvalid()) 
    for (auto it = sm.fileinfo_begin(); it != sm.fileinfo_end(); it++) { 
     SourceLocation includeLoc = sm.getIncludeLoc(sm.translateFile(it->first)); 
     if (includeLoc.isValid() && sm.isInFileID(includeLoc, fileID)) { 
      lines.insert(sm.getSpellingLineNumber(includeLoc)); 
     } 
    } 
    unsigned pos(0); 
    if (!lines.empty()) { 
     bool first = true; 
     for (unsigned line :lines) { 
      if (first) 
       first = false; 
      else if ((line - pos) > carriages) 
       break; 
      pos = line; 
      //cout << "Include line:" << pos << endl; 
     } 
     //cout << console_hline('-') << endl; 
    } 
    cout << sm.getFileEntryForID(fileID)->getName() << endl; 
    return sm.translateFileLineCol(sm.getFileEntryForID(fileID), ++pos, 1); 
} 

또한 몇 가지 정보에 대한

Preprocessor::GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer) 

Lexer::ComputePreamble(StringRef Buffer, const LangOptions &LangOpts, unsigned MaxLines = 0)  
에 의해 얻을 수 있습니다 포함
+0

추가 정보는 @Yuriy. 감사합니다. – Hemant