git-svn-id: svn://db.shs.com.ru/libs@105 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2016-07-24 14:03:59 +00:00
parent 1f71f140eb
commit 9fc412f646
9 changed files with 145 additions and 50 deletions

View File

@@ -18,17 +18,21 @@ enum Phase {
};
void removeComment(PIString & line, PIString * comment = 0) {
void removeComment(PIString & line, PIString * type, PIString * comment) {
int ci = line.find("//");
if (ci >= 0) {
if (comment) *comment = line.right(line.size_s() - ci - 2).trim();
line.cutRight(line.size_s() - ci).trim();
if (type && comment && !line.isEmpty()) {
*type = comment->takeLeft(1);
comment->trim();
}
}
}
void parseEnumLine(PIString & line, int * value, PIString * comment = 0) {
removeComment(line, comment);
void parseEnumLine(PIString & line, int * value, PIString * type, PIString * comment) {
removeComment(line, type, comment);
int ci = line.find("=");
if (ci >= 0) {
if (value) *value = line.right(line.size_s() - ci - 1).trim().toInt();
@@ -54,15 +58,19 @@ void parseInsert(PIString line, PIString & alias, PIStringList & out) {
}
PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & sections) {
PIVector<int> enumValues(const PIString & e, const PIMap<PIString, KSection> & sections, PIStringList & enames) {
PIVector<int> ret;
enames.clear();
if (sections.contains(e)) {
ret = sections[e].indexes();
enames = sections[e].index_names();
} else {
int v = e.toInt();
if (v < 2) return ret;
for (int i = 0; i < v; ++i)
for (int i = 0; i < v; ++i) {
ret << i;
enames << PIString::fromNumber(i);
}
}
return ret;
}
@@ -75,9 +83,13 @@ KSection KParser::parse(PIIODevice * d) {
KType ck;
PIMap<PIString, KSection> sections;
PIMap<PIString, int> enum_values, cevalues;
PIString content, line, alias, comment;
PIString content, line, alias, type, comment;
PIStringList iarr;
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) content = ((PIFile*)d)->readAll();
if (PIStringAscii(d->className()) == PIStringAscii("PIFile")) {
PIByteArray c = ((PIFile*)d)->readAll();
c << uchar(0);
content = PIString::fromUTF8((const char *)c.data());
}
if (PIStringAscii(d->className()) == PIStringAscii("PIIOString")) content = *(((PIIOString*)d)->string());
PIIOString ios(&content);
//int phase = 0;
@@ -85,14 +97,15 @@ KSection KParser::parse(PIIODevice * d) {
while ((cind = content.find("enum", cind)) >= 0) {
ios.seek(cind);
line = ios.readLine().trim();
type.clear();
comment.clear();
removeComment(line, &comment);
removeComment(line, &type, &comment);
if (line.find("{") < 0) {
cind += 4;
continue;
}
line.cutLeft(line.find("enum") + 4).trim();
line.cutRight(line.size_s() - line.find("{")).trim();
line.cutRight(line.size_s() - line.find("{")).trim();
if (line.isEmpty()) {
cind += 4;
continue;
@@ -105,7 +118,7 @@ KSection KParser::parse(PIIODevice * d) {
while (!ios.isEnd()) {
line = ios.readLine().trim();
comment.clear();
removeComment(line, &comment);
removeComment(line, &type, &comment);
if (line.find("}") >= 0) break;
if (line.isEmpty()) {
if (comment.find("=") >= 0) {
@@ -124,12 +137,15 @@ KSection KParser::parse(PIIODevice * d) {
KSection is = sections.value(iarr.take_front()), ts;
int ibpos = is.name.size_s();
piForeachRC (PIString & a, iarr) {
PIVector<int> evals = enumValues(a, sections);
PIStringList enames;
PIVector<int> evals = enumValues(a, sections, enames);
//piCout << a << evals;
piForeachC (int e, evals)
ts.section(e) = is;
for (int i = 0; i < evals.size_s(); ++i) {
ts.section(evals[i]) = is;
ts.section(evals[i]).index_name = enames[i];
}
ts.name = is.name;
ts.name.insert(ibpos, PIString("[") << evals.size_s() << "]");
ts.name.insert(ibpos, PIString("[") << a << "]");
is = ts;
ts = KSection();
}
@@ -137,9 +153,9 @@ KSection KParser::parse(PIIODevice * d) {
}
}
} else {
parseEnumLine(line, &cev, &comment);
//piCout << line << "=" << cev << "//" << comment;
ck = KType(cev, line, "", "", comment);
parseEnumLine(line, &cev, &type, &comment);
piCout << line << "=" << cev << "//" << type << comment;
ck = KType(cev, line, type, "", "", comment);
cs[cev] = ck;
cevalues[line] = cev;
++cev;