Skip to content

Commit b68e51e

Browse files
committed
Add parse-configure-ac printer for sw.
1 parent f1137f3 commit b68e51e

4 files changed

Lines changed: 91 additions & 19 deletions

File tree

src/client/autotools.cpp

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,18 @@ struct if_expr
3434
{
3535
struct if_action
3636
{
37+
enum sign_type
38+
{
39+
S_UNK,
40+
41+
S_EQ,
42+
S_NE,
43+
S_LT,
44+
S_GT,
45+
};
46+
3747
String var;
38-
bool equ;
48+
int sign;
3949
String value;
4050
String action;
4151
int start;
@@ -68,6 +78,7 @@ struct ac_processor
6878
void try_add(command &c);
6979

7080
void output();
81+
void output2();
7182
void process();
7283
void process_AC_LANG(command &c);
7384
void process_AC_CHECK_FUNCS(command &c);
@@ -203,10 +214,21 @@ auto parse_conditions(String f)
203214

204215
if_expr::if_action a;
205216
a.var = var;
206-
a.equ = sign == "=";
207217
a.value = val;
208218
a.start = (int)(m[0].first - s.begin());
209-
if (sign != "=" && sign != "!=") // TODO: implement '-gt' sign
219+
220+
if (sign == "=")
221+
a.sign = if_expr::if_action::S_EQ;
222+
else if (sign == "!=")
223+
a.sign = if_expr::if_action::S_NE;
224+
else if (sign == "-lt")
225+
a.sign = if_expr::if_action::S_LT;
226+
else if (sign == "-gt")
227+
a.sign = if_expr::if_action::S_GT;
228+
else
229+
a.sign = if_expr::if_action::S_UNK;
230+
231+
if (a.sign == if_expr::if_action::S_UNK) // TODO: implement other signs (-le, -ge)
210232
std::cerr << "Unknown sign " << sign << "\n";
211233
else
212234
{
@@ -229,6 +251,13 @@ void process_configure_ac(const path &p)
229251
proc.output();
230252
}
231253

254+
void process_configure_ac2(const path &p)
255+
{
256+
ac_processor proc(p);
257+
proc.process();
258+
proc.output2();
259+
}
260+
232261
ac_processor::ac_processor(const path &p)
233262
{
234263
file = read_file(p);
@@ -240,12 +269,21 @@ ac_processor::ac_processor(const path &p)
240269
conditions = parse_conditions(file);
241270
}
242271

272+
void print_checks2(primitives::CppContext &ctx, const ChecksSet &checks, const String &name);
273+
243274
void ac_processor::output()
244275
{
245276
checks.save(root);
246277
std::cout << dump_yaml_config(root);
247278
}
248279

280+
void ac_processor::output2()
281+
{
282+
primitives::CppContext ctx;
283+
print_checks2(ctx, checks.checks, "x");
284+
std::cout << ctx.getText();
285+
}
286+
249287
void prepare_type(String &t)
250288
{
251289
if (t == "long_long")
@@ -341,6 +379,7 @@ void ac_processor::process()
341379
SILENCE(AC_CHECK_FILE);
342380
SILENCE(AC_CHECK_TOOL);
343381
SILENCE(AC_MSG_ERROR);
382+
SILENCE(AC_MSG_FAILURE);
344383
SILENCE(AC_TRY_COMMAND);
345384

346385
// specific checks
@@ -429,6 +468,8 @@ void ac_processor::ifdef_add(command &c)
429468
; // this is a printer
430469
else if (cmd == "AC_MSG_ERROR")
431470
; // this is a printer
471+
else if (cmd == "AC_MSG_FAILURE")
472+
; // this is a printer
432473
else if (cmd == "AC_LANG_SOURCE")
433474
{
434475
auto params = parse_arguments(c.params[0].substr(cmd.size() + 1));
@@ -457,6 +498,8 @@ void ac_processor::ifdef_add(command &c)
457498
; // this is a printer
458499
else if (cmd == "AC_MSG_ERROR")
459500
; // this is a printer
501+
else if (cmd == "AC_MSG_FAILURE")
502+
; // this is a printer
460503
else if (cmd == "AC_DEFINE")
461504
{
462505
auto params = parse_arguments(c.params[1].substr(cmd.size() + 1));
@@ -498,9 +541,9 @@ void ac_processor::ifdef_add(command &c)
498541
var = params[0];
499542

500543
if (value == act.value)
501-
invert = !act.equ;
544+
invert = act.sign == if_expr::if_action::S_NE;
502545
else
503-
invert = act.equ;
546+
invert = act.sign == if_expr::if_action::S_EQ;
504547
}
505548

506549
if (ifthen.size() > 1)
@@ -513,9 +556,9 @@ void ac_processor::ifdef_add(command &c)
513556
}
514557

515558
if (value == act.value)
516-
invert = act.equ;
559+
invert = act.sign == if_expr::if_action::S_EQ;
517560
else
518-
invert = !act.equ;
561+
invert = act.sign == if_expr::if_action::S_NE;
519562
}
520563
}
521564
}
@@ -532,6 +575,8 @@ void ac_processor::ifdef_add(command &c)
532575
; // this is a printer
533576
else if (cmd == "AC_MSG_ERROR")
534577
; // this is a printer
578+
else if (cmd == "AC_MSG_FAILURE")
579+
; // this is a printer
535580
else if (cmd == "AC_DEFINE")
536581
{
537582
auto params = parse_arguments(c.params[2].substr(cmd.size() + 1));
@@ -586,6 +631,8 @@ void ac_processor::try_add(command &c)
586631
; // this is a printer
587632
else if (cmd == "AC_MSG_ERROR")
588633
; // this is a printer
634+
else if (cmd == "AC_MSG_FAILURE")
635+
; // this is a printer
589636
else if (cmd == "AC_DEFINE")
590637
{
591638
auto params = parse_arguments(c.params[2].substr(cmd.size() + 1));
@@ -714,6 +761,8 @@ void ac_processor::process_AC_CHECK_HEADER(command &c)
714761
; // this is a printer
715762
else if (cmd == "AC_MSG_ERROR")
716763
; // this is a printer
764+
else if (cmd == "AC_MSG_FAILURE")
765+
; // this is a printer
717766
else if (cmd == "AC_DEFINE")
718767
{
719768
auto params = parse_arguments(c.params[1].substr(cmd.size() + 1));

src/client/autotools.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
#include "filesystem.h"
2020

2121
void process_configure_ac(const path &p);
22+
void process_configure_ac2(const path &p);

src/client/main.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,23 @@ int main(int argc, char *argv[])
162162
return 0;
163163
}
164164

165+
if (cmd == "parse-configure-ac2")
166+
{
167+
if (args.size() != 3)
168+
{
169+
if (fs::exists("configure.ac"))
170+
{
171+
process_configure_ac2("configure.ac");
172+
return 0;
173+
}
174+
std::cout << "invalid number of arguments\n";
175+
std::cout << "usage: cppan parse-configure-ac2 configure.ac\n";
176+
return 1;
177+
}
178+
process_configure_ac2(args[2]);
179+
return 0;
180+
}
181+
165182
if (cmd == "parse-bazel")
166183
{
167184
void process_bazel(const path &p, const std::string &libname = "cc_library", const std::string &binname = "cc_binary");

src/common/project.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ String Project::print_cpp()
15891589

15901590
if (include_directories.private_.size() > additional_include_dirs_private.size())
15911591
{
1592-
ctx.addLine(name + ".Private +=");
1592+
ctx.addLine(name + " +=");
15931593
String s;
15941594
for (auto &t : include_directories.private_)
15951595
{
@@ -1632,7 +1632,7 @@ String Project::print_cpp()
16321632
auto print_def = [&ctx, &name](auto &k, auto &v)
16331633
{
16341634
if (k == "private")
1635-
ctx.addLine(name + ".Private += \"" + v + "\"_d;");
1635+
ctx.addLine(name + " += \"" + v + "\"_d;");
16361636
else if (k == "public")
16371637
ctx.addLine(name + ".Public += \"" + v + "\"_d;");
16381638
else if (k == "interface")
@@ -1672,7 +1672,7 @@ String Project::print_cpp()
16721672
auto print_def = [&ctx, &name](auto &k, auto &v)
16731673
{
16741674
if (k == "private")
1675-
ctx.addLine(name + ".Private += sw::Shared, \"" + v + "\"_d;");
1675+
ctx.addLine(name + " += sw::Shared, \"" + v + "\"_d;");
16761676
else if (k == "public")
16771677
ctx.addLine(name + ".Public += sw::Shared, \"" + v + "\"_d;");
16781678
else if (k == "interface")
@@ -1712,7 +1712,7 @@ String Project::print_cpp()
17121712
auto print_def = [&ctx, &name](auto &k, auto &v)
17131713
{
17141714
if (k == "private")
1715-
ctx.addLine(name + ".Private += sw::Static, \"" + v + "\"_d;");
1715+
ctx.addLine(name + " += sw::Static, \"" + v + "\"_d;");
17161716
else if (k == "public")
17171717
ctx.addLine(name + ".Public += sw::Static, \"" + v + "\"_d;");
17181718
else if (k == "interface")
@@ -1809,7 +1809,7 @@ String Project::print_cpp()
18091809
return ctx.getText();
18101810
}
18111811

1812-
#include <iostream>
1812+
void print_checks2(primitives::CppContext &ctx, const ChecksSet &checks, const String &name);
18131813

18141814
String Project::print_cpp2()
18151815
{
@@ -1902,7 +1902,7 @@ String Project::print_cpp2()
19021902

19031903
if (include_directories.private_.size() > additional_include_dirs_private.size())
19041904
{
1905-
ctx.addLine(name + ".Private +=");
1905+
ctx.addLine(name + " +=");
19061906
String s;
19071907
for (auto &t : include_directories.private_)
19081908
{
@@ -1962,7 +1962,7 @@ String Project::print_cpp2()
19621962
auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v, const String &ending, const String &type = {})
19631963
{
19641964
if (k == "private")
1965-
ctx.addLine(name + ".Private += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
1965+
ctx.addLine(name + " += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
19661966
else if (k == "public")
19671967
ctx.addLine(name + ".Public += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_" + ending + ";");
19681968
else if (k == "interface")
@@ -2036,11 +2036,19 @@ String Project::print_cpp2()
20362036
ctx.endBlock();
20372037
ctx.emptyLines();
20382038

2039-
if (checks.checks.size() > 2)
2039+
print_checks2(ctx, checks.checks, name);
2040+
2041+
//ctx.splitLines();
2042+
return ctx.getText();
2043+
}
2044+
2045+
void print_checks2(primitives::CppContext &ctx, const ChecksSet &checks, const String &name)
2046+
{
2047+
if (checks.size() > 2)
20402048
{
20412049
ctx.beginBlock("void check(Checker &c)");
20422050
ctx.addLine("auto &s = c.addSet(\"" + name + "\");");
2043-
for (auto &c : checks.checks)
2051+
for (auto &c : checks)
20442052
{
20452053
switch (c->getInformation().type)
20462054
{
@@ -2084,7 +2092,4 @@ String Project::print_cpp2()
20842092
}
20852093
ctx.endBlock();
20862094
}
2087-
2088-
//ctx.splitLines();
2089-
return ctx.getText();
20902095
}

0 commit comments

Comments
 (0)