Updated simplecpp to 95be502385518402ee61830be2ce3cd0ea02eee2

This commit is contained in:
PKEuS 2016-12-06 14:10:57 +01:00
parent 2f6350a0d0
commit 75528adea0
2 changed files with 1225 additions and 1172 deletions

File diff suppressed because it is too large Load Diff

View File

@ -43,13 +43,13 @@
namespace simplecpp {
typedef std::string TokenString;
typedef std::string TokenString;
/**
/**
* Location in source code
*/
class SIMPLECPP_LIB Location {
public:
class SIMPLECPP_LIB Location {
public:
explicit Location(const std::vector<std::string> &f) : files(f), fileIndex(0), line(1U), col(0U) {}
Location &operator=(const Location &other) {
@ -76,31 +76,30 @@ public:
return fileIndex == other.fileIndex && line == other.line;
}
std::string file() const {
return fileIndex < files.size() ? files[fileIndex] : std::string("");
const std::string& file() const {
static const std::string temp;
return fileIndex < files.size() ? files[fileIndex] : temp;
}
const std::vector<std::string> &files;
unsigned int fileIndex;
unsigned int line;
unsigned int col;
};
};
/**
/**
* token class.
* @todo don't use std::string representation - for both memory and performance reasons
*/
class SIMPLECPP_LIB Token {
public:
class SIMPLECPP_LIB Token {
public:
Token(const TokenString &s, const Location &loc) :
str(string), location(loc), previous(NULL), next(NULL), string(s)
{
str(string), location(loc), previous(NULL), next(NULL), string(s) {
flags();
}
Token(const Token &tok) :
str(string), macro(tok.macro), location(tok.location), previous(NULL), next(NULL), string(tok.str)
{
str(string), macro(tok.macro), location(tok.location), previous(NULL), next(NULL), string(tok.str) {
flags();
}
@ -146,12 +145,12 @@ public:
void printAll() const;
void printOut() const;
private:
private:
TokenString string;
};
};
/** Output from preprocessor */
struct SIMPLECPP_LIB Output {
/** Output from preprocessor */
struct SIMPLECPP_LIB Output {
explicit Output(const std::vector<std::string> &files) : type(ERROR), location(files) {}
enum Type {
ERROR, /* #error */
@ -163,13 +162,13 @@ struct SIMPLECPP_LIB Output {
} type;
Location location;
std::string msg;
};
};
typedef std::list<Output> OutputList;
typedef std::list<Output> OutputList;
/** List of tokens. */
class SIMPLECPP_LIB TokenList {
public:
/** List of tokens. */
class SIMPLECPP_LIB TokenList {
public:
explicit TokenList(std::vector<std::string> &filenames);
TokenList(std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = 0);
TokenList(const TokenList &other);
@ -238,7 +237,7 @@ public:
/** sizeof(T) */
std::map<std::string, std::size_t> sizeOfType;
private:
private:
void combineOperators();
void constFoldUnaryNotPosNeg(Token *tok);
@ -258,26 +257,26 @@ private:
Token *frontToken;
Token *backToken;
std::vector<std::string> &files;
};
};
/** Tracking how macros are used */
struct SIMPLECPP_LIB MacroUsage {
/** Tracking how macros are used */
struct SIMPLECPP_LIB MacroUsage {
explicit MacroUsage(const std::vector<std::string> &f) : macroLocation(f), useLocation(f) {}
std::string macroName;
Location macroLocation;
Location useLocation;
};
};
struct SIMPLECPP_LIB DUI {
struct SIMPLECPP_LIB DUI {
std::list<std::string> defines;
std::set<std::string> undefined;
std::list<std::string> includePaths;
std::list<std::string> includes;
};
};
SIMPLECPP_LIB std::map<std::string, TokenList*> load(const TokenList &rawtokens, std::vector<std::string> &filenames, const DUI &dui, OutputList *outputList = 0);
SIMPLECPP_LIB std::map<std::string, TokenList*> load(const TokenList &rawtokens, std::vector<std::string> &filenames, const DUI &dui, OutputList *outputList = 0);
/**
/**
* Preprocess
* @todo simplify interface
* @param output TokenList that receives the preprocessing output
@ -288,12 +287,12 @@ SIMPLECPP_LIB std::map<std::string, TokenList*> load(const TokenList &rawtokens,
* @param outputList output: list that will receive output messages
* @param macroUsage output: macro usage
*/
SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, TokenList*> &filedata, const DUI &dui, OutputList *outputList = 0, std::list<MacroUsage> *macroUsage = 0);
SIMPLECPP_LIB void preprocess(TokenList &output, const TokenList &rawtokens, std::vector<std::string> &files, std::map<std::string, TokenList*> &filedata, const DUI &dui, OutputList *outputList = 0, std::list<MacroUsage> *macroUsage = 0);
/**
/**
* Deallocate data
*/
SIMPLECPP_LIB void cleanup(std::map<std::string, TokenList*> &filedata);
SIMPLECPP_LIB void cleanup(std::map<std::string, TokenList*> &filedata);
}
#endif