forked from PJIDC/Jvav-Windows
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJVMplus.cpp
More file actions
97 lines (91 loc) · 3.17 KB
/
JVMplus.cpp
File metadata and controls
97 lines (91 loc) · 3.17 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
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
#include "JVMplus.h"
STATUS_VALUE JvavVirtualMachine::compile() {
ifstream srcFile;
srcFile.open(fileName, ios::in);
if (!srcFile.is_open()) {
cout << "error: can not open source file. \n" << endl;
return STATUS_NO_INPUT;
} else {
for (int i = 0; i <= 4; i++)
fileName.pop_back(); //去掉.jvav后缀名
fileName += ".cpp";
stringstream ss;
ss << srcFile.rdbuf();
std::string fileToCompile = ss.str();
srcFile.close();
ifstream resFile;
resFile.open("C:\\Jvav\\resource\\identifier.res", ios::in);
if (!resFile.is_open()) {
cout << "error: Failed to open the identifier definition file. "
"\n"
<< endl;
return STATUS_NO_IDEN;
}
stringstream sr;
sr << resFile.rdbuf();
std::string identifier = sr.str();
resFile.close();
ofstream local;
local.open(fileName, std::ios::out | std::ios::app);
if (!local.is_open())
cout << "error: can not create temp file. \n" << endl;
local << identifier << fileToCompile;
// local << "system(\"pause\");";
local.close();
std::string _comArgs = "g++ ";
if (isStrict) {
_comArgs +=
"-Wall -Werror -Wextra -pedantic -Wimplicit-fallthrough "
"-Wsequence-point -Wswitch-default -Wswitch-unreachable "
"-Wswitch-enum -Wstringop-truncation -Wbool-compare "
"-Wtautological-compare -Wfloat-equal -Wshadow=global "
"-Wpointer-arith -Wpointer-compare -Wcast-align -Wcast-qual "
"-Wwrite-strings -Wdangling-else -Wlogical-op ";
}
if (stdv != 0) {
switch (stdv) {
case 17:
_comArgs += "-std=c++17 ";
break;
case 11:
_comArgs += "-std=c++11 ";
break;
case 14:
_comArgs += "-std=c++14 ";
break;
default:
break;
}
}
_comArgs += fileName;
if (compileMode == 1) {
_comArgs += " -o ";
_comArgs += oname;
}
int result = system(_comArgs.c_str());
if (compileMode != 1) {
if (result == 0) {
system("a.exe");
system("del a.exe");
} else if (result == 1) {
_comArgs = "del " + fileName;
system(_comArgs.c_str());
cout << "deleting *.cpp\n";
return STATUS_NO_GPP;
}
_comArgs = "del " + fileName;
system(_comArgs.c_str());
cout << endl;
}else{
if (result == 0) {
std::string nametodel = "del ";
nametodel+=fileName;
system(nametodel.c_str());
std::cout << "\nYour execute file has been generated." << endl;
} else if (result == 1) {
std::cout << "\nUnknown Error." << endl;
}
}
}
return STATUS_SUCCESS;
}