Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 104
made it possible to create a TokenList from a buffer#347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -377,6 +377,42 @@ class StdIStream : public simplecpp::TokenList::Stream { | ||
| std::istream &istr; | ||
| }; | ||
| class StdCharBufStream : public simplecpp::TokenList::Stream { | ||
| public: | ||
| // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members | ||
| StdCharBufStream(const unsigned char* str, std::size_t size) | ||
| : str(str) | ||
| , size(size) | ||
| , pos(0) | ||
| , lastStatus(0) | ||
| { | ||
| init(); | ||
| } | ||
| virtual int get() OVERRIDE { | ||
| if (pos >= size) | ||
CollaboratorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks are still a hot spot. No idea if there is a way to implement this in a more performant way. | ||
| return lastStatus = EOF; | ||
| return str[pos++]; | ||
| } | ||
| virtual int peek() OVERRIDE { | ||
| if (pos >= size) | ||
| return lastStatus = EOF; | ||
| return str[pos]; | ||
| } | ||
| virtual void unget() OVERRIDE { | ||
| --pos; | ||
danmar marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| virtual bool good() OVERRIDE { | ||
| return lastStatus != EOF; | ||
| } | ||
| private: | ||
| const unsigned char *str; | ||
danmar marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const std::size_t size; | ||
| std::size_t pos; | ||
| int lastStatus; | ||
| }; | ||
| class FileStream : public simplecpp::TokenList::Stream { | ||
| public: | ||
| // cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members | ||
| @@ -442,6 +478,20 @@ simplecpp::TokenList::TokenList(std::istream &istr, std::vector<std::string> &fi | ||
| readfile(stream,filename,outputList); | ||
| } | ||
| simplecpp::TokenList::TokenList(const unsigned char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList) | ||
| : frontToken(nullptr), backToken(nullptr), files(filenames) | ||
| { | ||
| StdCharBufStream stream(data, size); | ||
| readfile(stream,filename,outputList); | ||
| } | ||
| simplecpp::TokenList::TokenList(const char* data, std::size_t size, std::vector<std::string> &filenames, const std::string &filename, OutputList *outputList) | ||
| : frontToken(nullptr), backToken(nullptr), files(filenames) | ||
| { | ||
| StdCharBufStream stream(reinterpret_cast<const unsigned char*>(data), size); | ||
| readfile(stream,filename,outputList); | ||
| } | ||
| simplecpp::TokenList::TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList) | ||
| : frontToken(nullptr), backToken(nullptr), files(filenames) | ||
| { | ||
| @@ -1447,8 +1497,7 @@ namespace simplecpp { | ||
| Macro(const std::string &name, const std::string &value, std::vector<std::string> &f) : nameTokDef(nullptr), files(f), tokenListDefine(f), valueDefinedInCode_(false) { | ||
| const std::string def(name + ' ' + value); | ||
| std::istringstream istr(def); | ||
| StdIStream stream(istr); | ||
| StdCharBufStream stream(reinterpret_cast<const unsigned char*>(def.data()), def.size()); | ||
| tokenListDefine.readfile(stream); | ||
| if (!parseDefine(tokenListDefine.cfront())) | ||
| throw std::runtime_error("bad macro syntax. macroname=" + name + " value=" + value); | ||
Uh oh!
There was an error while loading. Please reload this page.