forked from lcompilers/lpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocessor.h
More file actions
50 lines (41 loc) · 1.36 KB
/
preprocessor.h
File metadata and controls
50 lines (41 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef LFORTRAN_SRC_PARSER_PREPROCESSOR_H
#define LFORTRAN_SRC_PARSER_PREPROCESSOR_H
#include <libasr/exception.h>
#include <lpython/utils.h>
#include <lpython/parser/parser.h>
namespace LFortran
{
struct CPPMacro {
/*
Is the macro function-like.
true: #define f(a,b,c) a+b+c
false: #define f something
*/
bool function_like=false;
std::vector<std::string> args; // Only used if function_like == true
std::string expansion;
};
typedef std::map<std::string, CPPMacro> cpp_symtab;
class CPreprocessor
{
public:
CompilerOptions &compiler_options;
cpp_symtab macro_definitions;
CPreprocessor(CompilerOptions &compiler_options);
std::string token(unsigned char *tok, unsigned char* cur) const;
std::string run(const std::string &input, LocationManager &lm,
cpp_symtab ¯o_definitions) const;
std::string function_like_macro_expansion(
std::vector<std::string> &def_args,
std::string &expansion,
std::vector<std::string> &call_args) const;
// Return the current token's location
void token_loc(Location &loc, unsigned char *tok, unsigned char* cur,
unsigned char *string_start) const
{
loc.first = tok-string_start;
loc.last = cur-string_start-1;
}
};
} // namespace LFortran
#endif // LFORTRAN_SRC_PARSER_PREPROCESSOR_H