Synopsis - Cross-Reference
File: /src/tools/display-symbols.cc1// 2// Copyright (C) 2005 Stefan Seefeld 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7#include <Synopsis/Buffer.hh> 8#include <Synopsis/Lexer.hh> 9#include <Synopsis/SymbolFactory.hh> 10#include <Synopsis/Parser.hh> 11#include <Synopsis/PTree.hh> 12#include <Synopsis/SymbolLookup.hh> 13#include <Synopsis/SymbolLookup/Display.hh> 14#include <Synopsis/Trace.hh> 15#include <fstream> 16 17using namespace Synopsis; 18 19int usage(const char *command) 20{ 21 std::cerr << "Usage: " << command << " <input>" << std::endl; 22 return -1; 23} 24 25int main(int argc, char **argv) 26{ 27 bool debug = false; 28 const char *input = argv[1]; 29 if (argc == 1) return usage(argv[0]); 30 for (int i = 1; i < argc - 1; ++i) 31 { 32 if (argv[i] == std::string("-d")) debug = true; 33 else return usage(argv[0]); 34 } 35 input = argv[argc - 1]; 36 try 37 { 38 if (debug) Trace::enable(Trace::SYMBOLLOOKUP); 39 40 std::ifstream ifs(input); 41 Buffer buffer(ifs.rdbuf(), input); 42 Lexer lexer(&buffer); 43 SymbolFactory symbols; 44 Parser parser(lexer, symbols); 45 PTree::Node *node = parser.parse(); 46 const Parser::ErrorList &errors = parser.errors(); 47 for (Parser::ErrorList::const_iterator i = errors.begin(); i != errors.end(); ++i) 48 (*i)->write(std::cerr); 49 50 SymbolLookup::display(symbols.current_scope(), std::cout); 51 } 52 catch (const std::exception &e) 53 { 54 std::cerr << "Caught exception : " << e.what() << std::endl; 55 } 56}