#ifndef SCANNER_H #define SCANNER_H ///////////////////////////////////////////////////////////////// // scanner.h - scan specified file and files it includes // // ver 1.0 - process each file with an object derived // // from scanProc // // // // Language: Visual C++, ver 7.0 // // Platfrom: Dell Dimension 8100, Windows 2000, SP 2.0 // // Application: Prototype for CSE687 Pr#2, Spring 2003 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////// /* Module Operation: ================= The scanner module provides a scan function that, given a filename, attempts to open and scan the file. Scanning consists of extracting all semiExp objects from the file and processing them according to the dictates of an object derived from the scanProc interface, defined in this module. The module provides default processing in a class defaultProc, derived from scanProc to demonstrate how scanner works. The default uses grammar and display modules to discover and display function definitions in the file. A scanner object gets a reference to this processing object through a Register member function. defaultProc also calls scanner::scan recursively - since it was called by scan - to scan any files that are included by the file being processed. The defaultProc object is initialized with a reference to the scanner, enabling the recursive call. Public Interface: ================= scanner s; // create a scanner defaultProc dp(s); // create processing object with ref to s s.Register(&dp); // give s a ref to the processing object s.scan("aFile.cpp"); // scan a file s.isVerbose() = true; // set to verbose mode to see all semiExps bool b = s.isCommand(arg); // does arg start with '/' or '-' ? s.processCommand(arg); // toggle verbose mode if arg = "/v" */ // ///////////////////////////////////////////////////////////////////// // Build Process // ///////////////////////////////////////////////////////////////////// // Required Files: // // scanner.h, scanner.cpp, processing.h, processing.cpp, // // grammar.h, grammar.cpp, display.h, display.cpp, // // semi.h, semi.cpp, tok.h, tok.cpp // // // // Compiler command: // // cl /DTEST_SCANNER scanner.cpp processing.cpp\ // // grammar.cpp display.cpp semi.cpp tok.cpp // ///////////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.0 : 02/08/03 - first release */ // #include #include "semi.h" /////////////////////////////////////////////////////////////// // scanProc interface - derived classes define scanner // // processing for scanned files // /////////////////////////////////////////////////////////////// struct scanProc { bool virtual process(semiExp &se)=0; }; /////////////////////////////////////////////////////////////// // scanner class - responsible for scanning a file and all // // files it includes // /////////////////////////////////////////////////////////////// class scanner { public: scanner(); ~scanner() {} scanProc* Register(scanProc* sp); bool scan(const std::string& filename); std::string& fileName(); bool& isVerbose(); bool isCommand(const std::string &arg); void processCommand(const std::string &arg); private: scanProc* _process; std::string _filename; bool _verbose; }; //----< show details? >---------------------------------------- inline bool& scanner::isVerbose() { return _verbose; } //----< constructor sets scanProc pointer to null >------------ inline scanner::scanner() : _process(0), _verbose(false) {} //----< return name of file being processed >------------------ inline std::string& scanner::fileName() { return _filename; } //----< Registers a scanProc with scanner >-------------------- inline scanProc* scanner::Register(scanProc *sp) { scanProc* temp = _process; _process = sp; return temp; } #endif