-
Notifications
You must be signed in to change notification settings - Fork 0
/
LanguageModule.cpp
138 lines (116 loc) · 4.4 KB
/
LanguageModule.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#ifndef _SCRIPT_PAD_LANGUAGE_MODULE_CPP
#define _SCRIPT_PAD_LANGUAGE_MODULE_CPP
#include "LanguageModule.h"
namespace querier {
LanguageFilePaths::LanguageFilePaths(std::string mainModule, std::string sourceFile = "", std::string executableFile = "") : MainModule(mainModule) {
if (!sourceFile.empty())
SourceFile = sourceFile;
else
SourceFile = "";
if (!executableFile.empty())
ExecutableFile = executableFile;
else
ExecutableFile = "";
}
LanguageFilePaths::LanguageFilePaths(std::wstring _wMainModule, std::wstring _wSourceFile = L"", std::wstring _wExecutableFile = L"") : wMainModule(_wMainModule) {
if (!_wSourceFile.empty())
wSourceFile = _wSourceFile;
else
wSourceFile = L"";
if (!_wExecutableFile.empty())
wExecutableFile = _wExecutableFile;
else
wExecutableFile = L"";
}
LanguageModule::LanguageModule(std::wstring wMainModule, std::wstring wVersionArg, bool runAsModule = true)
: ILanguage(),
BaseModule(wMainModule, wVersionArg, runAsModule),
m_LanguageFilePaths{ wMainModule } {
m_LanguageFilePaths.wSourceFile = L"";
m_wszModuleVersion = str_to_wstr(wRun(wVersionArg));
}
LanguageModule::LanguageModule(std::string mainModule, std::string versionArg, bool runAsModule = true)
: ILanguage(),
BaseModule(mainModule, versionArg, runAsModule),
m_LanguageFilePaths{ mainModule } {
m_LanguageFilePaths.SourceFile = "";
m_szModuleVersion = Run(versionArg);
}
LanguageModule::~LanguageModule() {
}
void LanguageModule::Invoke(std::string queryName) {
if (m_bIsModuleInstalled) {
switch (m_LanguageType) {
case Interpreter:
{
if (m_isUnicode) {
StartInfo.wCommandLine = wFormatCommandLine(m_LanguageFilePaths.wMainModule,
m_LanguageFilePaths.wSourceFile);
}
else {
StartInfo.CommandLine = FormatCommandLine(m_LanguageFilePaths.MainModule,
m_LanguageFilePaths.SourceFile);
}
OnProcessExited = [this]() -> void {
EndOutputRead();
EndErrorRead();
};
BeginOutputRead(queryName);
BeginErrorRead(queryName);
Start();
break;
}
case Compiler:
//Do compiler stuff
break;
default:
break;
}
}
}
bool LanguageModule::GetFileContent(std::string* ret) {
return m_File.Read(ret);
};
bool LanguageModule::wGetFileContent(std::wstring* ret) {
/*std::string read;
if (m_File.Read(&read)) {
*ret = str_to_wstr(read);
return true;
}
return false;*/
return m_File.wRead(ret);
}
void LanguageModule::SetFileContent(std::string content) {
m_File.Write(content);
};
void LanguageModule::wSetFileContent(std::wstring content) {
m_File.wWrite(content);
}
std::string LanguageModule::GetSourceFile() {
return m_LanguageFilePaths.SourceFile;
}
std::wstring LanguageModule::wGetSourceFile() {
return m_LanguageFilePaths.wSourceFile;
}
void LanguageModule::SetSourceFile(std::string fileName) {
m_LanguageFilePaths.SourceFile = fileName;
m_File.SetFileName(fileName);
}
void LanguageModule::wSetSourceFile(std::wstring fileName) {
m_LanguageFilePaths.wSourceFile = fileName;
m_File.SetFileName(wstr_to_str(fileName));
}
std::string LanguageModule::GetModuleVersion() {
if (m_szModuleVersion.size() > 0)
return m_szModuleVersion;
else if(m_wszModuleVersion.size() > 0)
return wstr_to_str(m_wszModuleVersion);
}
std::wstring LanguageModule::wGetModuleVersion() {
if (m_wszMainModulePath.size() > 0)
return m_wszMainModulePath;
else if (m_szModuleVersion.size() > 0)
return str_to_wstr(m_szModuleVersion);
}
}
#endif