# | Line 44 | Line 44 | |
---|---|---|
44 | #include <iostream> | |
45 | #include <set> | |
46 | #include <fstream> | |
47 | + | #include <sstream> |
48 | #include "utils/StringTokenizer.hpp" | |
49 | #include "utils/Trim.hpp" | |
50 | + | #include "utils/OOPSEException.hpp" |
51 | + | #include "utils/simError.h" |
52 | + | |
53 | + | |
54 | /** | |
55 | * @class SimplePreprocessor | |
56 | * @brief A simple preprocessor. | |
57 | < | * @note only support #include #ifdef, #ifndef, #endif, #define and #undef, c-like multiple line |
58 | < | * comment is not support, macro substitude is not support. |
57 | > | * @note only supports #include #ifdef, #ifndef, #endif, #define and #undef, c-like multiple line |
58 | > | * comment is not supported, macro substitute is not supported. |
59 | */ | |
60 | namespace oopse { | |
61 | class SimplePreprocessor { | |
# | Line 66 | Line 71 | class SimplePreprocessor { | |
71 | private: | |
72 | bool doPreprocess(const std::string& filename, ostream& os, std::set<std::string>& defineSet, std::stack<bool>& ifStates) { | |
73 | std::ifstream input(filename.c_str()); | |
74 | < | |
74 | > | if (!input.is_open()) { |
75 | > | std::stringstream ss; |
76 | > | ss << "Can not open " << filename << " for preprocessing\n"; |
77 | > | |
78 | > | sprintf(painCave.errMsg, |
79 | > | "Can not open (%s) for processing. \n" |
80 | > | "\tPlease check md file name syntax.\n", filename.c_str()); |
81 | > | |
82 | > | painCave.isFatal = 1; |
83 | > | simError(); |
84 | > | |
85 | > | throw OOPSEException(ss.str()); |
86 | > | } |
87 | int lineNo =1; | |
88 | os << "#line " << lineNo << " \"" << filename << "\"\n"; | |
89 | while(input.getline(buffer, bufferSize)) { | |
# | Line 118 | Line 135 | class SimplePreprocessor { | |
135 | } | |
136 | os << std::endl; | |
137 | } else { | |
138 | < | std::cout << tokens[0] << " is not support" << std::endl; |
138 | > | std::cout << tokens[0] << " is not supported (yet)." << std::endl; |
139 | return false; | |
140 | } | |
141 | }else { |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |