Updated simplecpp to 95be502385518402ee61830be2ce3cd0ea02eee2
This commit is contained in:
parent
2f6350a0d0
commit
75528adea0
File diff suppressed because it is too large
Load Diff
|
@ -43,13 +43,13 @@
|
||||||
|
|
||||||
namespace simplecpp {
|
namespace simplecpp {
|
||||||
|
|
||||||
typedef std::string TokenString;
|
typedef std::string TokenString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location in source code
|
* Location in source code
|
||||||
*/
|
*/
|
||||||
class SIMPLECPP_LIB Location {
|
class SIMPLECPP_LIB Location {
|
||||||
public:
|
public:
|
||||||
explicit Location(const std::vector<std::string> &f) : files(f), fileIndex(0), line(1U), col(0U) {}
|
explicit Location(const std::vector<std::string> &f) : files(f), fileIndex(0), line(1U), col(0U) {}
|
||||||
|
|
||||||
Location &operator=(const Location &other) {
|
Location &operator=(const Location &other) {
|
||||||
|
@ -76,31 +76,30 @@ public:
|
||||||
return fileIndex == other.fileIndex && line == other.line;
|
return fileIndex == other.fileIndex && line == other.line;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string file() const {
|
const std::string& file() const {
|
||||||
return fileIndex < files.size() ? files[fileIndex] : std::string("");
|
static const std::string temp;
|
||||||
|
return fileIndex < files.size() ? files[fileIndex] : temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<std::string> &files;
|
const std::vector<std::string> &files;
|
||||||
unsigned int fileIndex;
|
unsigned int fileIndex;
|
||||||
unsigned int line;
|
unsigned int line;
|
||||||
unsigned int col;
|
unsigned int col;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token class.
|
* token class.
|
||||||
* @todo don't use std::string representation - for both memory and performance reasons
|
* @todo don't use std::string representation - for both memory and performance reasons
|
||||||
*/
|
*/
|
||||||
class SIMPLECPP_LIB Token {
|
class SIMPLECPP_LIB Token {
|
||||||
public:
|
public:
|
||||||
Token(const TokenString &s, const Location &loc) :
|
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();
|
flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
Token(const Token &tok) :
|
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();
|
flags();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,12 +145,12 @@ public:
|
||||||
|
|
||||||
void printAll() const;
|
void printAll() const;
|
||||||
void printOut() const;
|
void printOut() const;
|
||||||
private:
|
private:
|
||||||
TokenString string;
|
TokenString string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Output from preprocessor */
|
/** Output from preprocessor */
|
||||||
struct SIMPLECPP_LIB Output {
|
struct SIMPLECPP_LIB Output {
|
||||||
explicit Output(const std::vector<std::string> &files) : type(ERROR), location(files) {}
|
explicit Output(const std::vector<std::string> &files) : type(ERROR), location(files) {}
|
||||||
enum Type {
|
enum Type {
|
||||||
ERROR, /* #error */
|
ERROR, /* #error */
|
||||||
|
@ -163,13 +162,13 @@ struct SIMPLECPP_LIB Output {
|
||||||
} type;
|
} type;
|
||||||
Location location;
|
Location location;
|
||||||
std::string msg;
|
std::string msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::list<Output> OutputList;
|
typedef std::list<Output> OutputList;
|
||||||
|
|
||||||
/** List of tokens. */
|
/** List of tokens. */
|
||||||
class SIMPLECPP_LIB TokenList {
|
class SIMPLECPP_LIB TokenList {
|
||||||
public:
|
public:
|
||||||
explicit TokenList(std::vector<std::string> &filenames);
|
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(std::istream &istr, std::vector<std::string> &filenames, const std::string &filename=std::string(), OutputList *outputList = 0);
|
||||||
TokenList(const TokenList &other);
|
TokenList(const TokenList &other);
|
||||||
|
@ -238,7 +237,7 @@ public:
|
||||||
/** sizeof(T) */
|
/** sizeof(T) */
|
||||||
std::map<std::string, std::size_t> sizeOfType;
|
std::map<std::string, std::size_t> sizeOfType;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void combineOperators();
|
void combineOperators();
|
||||||
|
|
||||||
void constFoldUnaryNotPosNeg(Token *tok);
|
void constFoldUnaryNotPosNeg(Token *tok);
|
||||||
|
@ -258,26 +257,26 @@ private:
|
||||||
Token *frontToken;
|
Token *frontToken;
|
||||||
Token *backToken;
|
Token *backToken;
|
||||||
std::vector<std::string> &files;
|
std::vector<std::string> &files;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Tracking how macros are used */
|
/** Tracking how macros are used */
|
||||||
struct SIMPLECPP_LIB MacroUsage {
|
struct SIMPLECPP_LIB MacroUsage {
|
||||||
explicit MacroUsage(const std::vector<std::string> &f) : macroLocation(f), useLocation(f) {}
|
explicit MacroUsage(const std::vector<std::string> &f) : macroLocation(f), useLocation(f) {}
|
||||||
std::string macroName;
|
std::string macroName;
|
||||||
Location macroLocation;
|
Location macroLocation;
|
||||||
Location useLocation;
|
Location useLocation;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SIMPLECPP_LIB DUI {
|
struct SIMPLECPP_LIB DUI {
|
||||||
std::list<std::string> defines;
|
std::list<std::string> defines;
|
||||||
std::set<std::string> undefined;
|
std::set<std::string> undefined;
|
||||||
std::list<std::string> includePaths;
|
std::list<std::string> includePaths;
|
||||||
std::list<std::string> includes;
|
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
|
* Preprocess
|
||||||
* @todo simplify interface
|
* @todo simplify interface
|
||||||
* @param output TokenList that receives the preprocessing output
|
* @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 outputList output: list that will receive output messages
|
||||||
* @param macroUsage output: macro usage
|
* @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
|
* Deallocate data
|
||||||
*/
|
*/
|
||||||
SIMPLECPP_LIB void cleanup(std::map<std::string, TokenList*> &filedata);
|
SIMPLECPP_LIB void cleanup(std::map<std::string, TokenList*> &filedata);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue