1 #include "CppBase.h"
2 #include "Internal.h"
3 
4 namespace Upp {
5 
HasCPPFileKeyword(const String & path,const String & id)6 bool HasCPPFileKeyword(const String& path, const String& id)
7 {
8 	const PPFile& f = GetPPFile(NormalizeSourcePath(path));
9 	return FindIndex(f.keywords, id) >= 0;
10 }
11 
GetDependeciesMD5(const String & path,Index<String> & visited)12 String GetDependeciesMD5(const String& path, Index<String>& visited)
13 {
14 	Cpp pp;
15 	FileIn in(path);
16 	String npath = NormalizeSourcePath(path);
17 	pp.Preprocess(npath, in, GetMasterFile(npath), true);
18 	String md5 = pp.GetDependeciesMd5(GetPPFile(path).keywords);
19 	visited = pick(pp.visited);
20 	return md5;
21 }
22 
GetPPMD5(const String & fn)23 String GetPPMD5(const String& fn)
24 {
25 	return GetPPFile(fn).md5sum;
26 }
27 
Parse(CppBase & base,const String & src,int file,int filetype,const String & path,Event<int,const String &> error,const Vector<String> & namespace_stack,const Index<String> & namespace_using)28 void Parse(CppBase& base,
29            const String& src, int file, int filetype, const String& path,
30            Event<int, const String&> error, const Vector<String>& namespace_stack,
31 	       const Index<String>& namespace_using)
32 {
33 	StringStream pin(src);
34 	Parser p;
35 	p.Do(pin, base, file, filetype, GetFileName(path), error, Vector<String>(),
36 	     namespace_stack, namespace_using);
37 }
38 
PreprocessParse(CppBase & base,Stream & in,int file,const String & path,Event<int,const String &> error)39 void PreprocessParse(CppBase& base, Stream& in, int file, const String& path,
40                      Event<int, const String&> error)
41 {
42 	Cpp cpp;
43 	cpp.Preprocess(path, in, GetMasterFile(path));
44 	int filetype = decode(ToLower(GetFileExt(path)), ".h", FILE_H, ".hpp", FILE_HPP,
45 	                       ".cpp", FILE_CPP, ".icpp", FILE_CPP, ".c", FILE_C, FILE_OTHER);
46 	Parse(base, cpp.output, file, filetype, path, error, cpp.namespace_stack, cpp.namespace_using);
47 }
48 
PreprocessCpp(const String & src,const String & path)49 String PreprocessCpp(const String& src, const String& path)
50 {
51 	Cpp cpp;
52 	StringStream in(src);
53 	String p = NormalizeSourcePath(path);
54 	cpp.Preprocess(p, in, GetMasterFile(p));
55 	return cpp.output;
56 }
57 
AssistParse(const String & src,const String & path_,Event<int,const String &> error,Function<String (String,String,String)> qualify)58 ParserContext AssistParse(const String& src, const String& path_, Event<int, const String&> error,
59                           Function<String(String, String, String)> qualify)
60 {
61 	String path = NormalizeSourcePath(path_);
62 	Cpp cpp;
63 	StringStream ss(src);
64 	cpp.Preprocess(path, ss, GetMasterFile(path));
65 	Parser parser;
66 	parser.dobody = true; // will do bodies and not write anything to base
67 	parser.qualify = qualify;
68 	StringStream pin(cpp.output);
69 	CppBase dummy;
70 	parser.Do(pin, dummy, Null, Null, GetFileTitle(path), error,
71 	          Vector<String>(), cpp.namespace_stack, cpp.namespace_using); // needs CodeBase to identify type names
72 	return pick(parser);
73 }
74 
SimpleParse(CppBase & cpp,const String & txt,const String & cls)75 void SimpleParse(CppBase& cpp, const String& txt, const String& cls)
76 {
77 	Parser parser; // we do not need/want preprocessing here
78 	StringStream ss(txt);
79 	parser.Do(ss, cpp, Null, Null, Null, CNULL, Split(cls, ':'),
80 	          Vector<String>(), Index<String>());
81 }
82 
83 };