MCPcopy Create free account
hub / github.com/covscript/covscript / import_csym

Method import_csym

sources/compiler/compiler.cpp:1069–1132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1067 }
1068
1069 void compiler_type::import_csym(const std::string &module_path, const std::string &csym_path)
1070 {
1071 std::ifstream ifs(csym_path);
1072 if (!ifs.is_open())
1073 return;
1074 csym_info csym;
1075 std::regex reg("^#\\$cSYM/1\\.0\\(([^\\)]*)\\):(.*)$");
1076 // Read file
1077 std::string header, buff;
1078 bool expect_n = false;
1079 for (int ch = ifs.get(); ifs; ch = ifs.get()) {
1080 if (expect_n) {
1081 expect_n = false;
1082 if (ch != '\n')
1083 buff += '\r';
1084 }
1085 switch (ch) {
1086 case '\n':
1087 if (!header.empty()) {
1088 csym.codes.emplace_back(buff);
1089 buff.clear();
1090 }
1091 else
1092 std::swap(header, buff);
1093 break;
1094 case '\r':
1095 expect_n = true;
1096 break;
1097 default:
1098 buff += ch;
1099 break;
1100 }
1101 }
1102 if (!buff.empty()) {
1103 csym.codes.emplace_back(buff);
1104 }
1105 // Parsing header
1106 std::smatch match;
1107 if (!std::regex_match(header, match, reg))
1108 return;
1109 csym.file = match.str(1);
1110 std::string map_str = match.str(2);
1111 for (auto &ch : map_str) {
1112 if (ch == ',') {
1113 if (!buff.empty()) {
1114 if (buff != "-")
1115 csym.map.push_back(std::stoull(buff) + 1);
1116 else
1117 csym.map.push_back(0);
1118 buff.clear();
1119 }
1120 }
1121 else
1122 buff += ch;
1123 }
1124 if (!buff.empty()) {
1125 if (buff != "-")
1126 csym.map.push_back(std::stoull(buff) + 1);

Callers 3

covscript_mainFunction · 0.80
covscript_mainFunction · 0.80
importMethod · 0.80

Calls 5

swapFunction · 0.50
moveFunction · 0.50
getMethod · 0.45
emptyMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected