Example #1
0
static void WriteTokens(Lexer &Lex, llvm::raw_ostream &OS) {
    if(Lex.EndOfStream())
        return;

    const llvm::SourceMgr &Srcs = Lex.GetSources();
    const Token *Cur = &Lex.Current();

    unsigned OutLineNo = Srcs.FindLineNumber(Cur->GetLocation()),
             CurLineNo;

    OS << Cur->GetId();

    for(Lex.Pop(); !Lex.EndOfStream(); Lex.Pop()) {
        Cur = &Lex.Current();
        CurLineNo = Srcs.FindLineNumber(Cur->GetLocation());

        if(CurLineNo > OutLineNo) {
            OS << "\n";
            OutLineNo = CurLineNo;
        } else {
            OS << " ";
        }

        OS << Cur->GetId();
    }

    OS << "\n";
}