Skip to content

Commit

Permalink
Merge branch 'ternary_operator'
Browse files Browse the repository at this point in the history
  • Loading branch information
IngeniariusSoftware committed Sep 28, 2022
2 parents a760713 + 7698701 commit f6702ef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion project/scripts/clean_before_transpilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(path_to_files: Path, cleaning_patterns) -> None:
path_to_files = path_to_files.parent
tools.clear_dir_by_patterns(path_to_files, cleaning_patterns, recursive=True)
tools.remove_empty_dirs(path_to_files)
tools.clear_dir_by_patterns(settings.get_setting('path_to_c2eo_transpiler'), {'*.eo'})
tools.clear_dir_by_patterns(settings.get_setting('path_to_c2eo_transpiler'), {'*.eo', '*.alias'})


def create_parser() -> argparse.ArgumentParser:
Expand Down
3 changes: 2 additions & 1 deletion project/scripts/data/skips/gcc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ pr88904: Unknown statement GCCAsmStmt segfault at address 0x0 while tool run
20000917-1: Unknown statement StmtExpr segfault at address 0x0 while tool run
limits-blockid, limits-externalid, limits-externdecl: too much handling time
limits-caselabels: exceeded the number of cases allowed by the c standard
921215-1: bad C standard
921215-1: Function inside function does not comply with the С standard
20020604-1: Float semantics are not IEEEdouble
1 change: 0 additions & 1 deletion project/scripts/data/skips/testcuite.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
00149: TODO pointers on structures
00197: TODO static variables
00026: TODO arithmetics
00076, 00109, 00144, 00183: TODO ternary operator
00200: TODO shift
00010, 00051, 00129, 00199, 00207, 00213: goto
00174: using math.h
Expand Down
13 changes: 13 additions & 0 deletions project/src/transpiler/transpile_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ EOObject GetUnaryExprOrTypeTraitExprEOObject(
EOObject GetGotoStmtEOObject(const clang::GotoStmt *p_stmt);
EOObject GetLabelStmtEOObject(const clang::LabelStmt *p_stmt);
EOObject GetEOStringToCharArray(const EOObject &object, const string &strValue);
EOObject GetConditionalStmtEOObject(const clang::ConditionalOperator *p_stmt);
extern UnitTranspiler transpiler;
extern ASTContext *context;

Expand Down Expand Up @@ -490,6 +491,10 @@ EOObject GetStmtEOObject(const Stmt *stmt) {
const auto *op = dyn_cast<clang::LabelStmt>(stmt);
return GetLabelStmtEOObject(op);
}
if (stmt_class == Stmt::ConditionalOperatorClass) {
const auto *op = dyn_cast<clang::ConditionalOperator>(stmt);
return GetConditionalStmtEOObject(op);
}
llvm::errs() << "Warning: Unknown statement " << stmt->getStmtClassName()
<< "\n";
return EOObject(EOObjectType::EO_PLUG);
Expand Down Expand Up @@ -1776,6 +1781,14 @@ EOObject GetIfElseStmtEOObject(const IfStmt *p_stmt) {
return if_else_stmt;
}

EOObject GetConditionalStmtEOObject(const clang::ConditionalOperator *p_stmt) {
EOObject if_else_stmt{"if-else"};
if_else_stmt.nested.push_back(GetStmtEOObject(p_stmt->getCond()));
if_else_stmt.nested.push_back(GetStmtEOObject(p_stmt->getTrueExpr()));
if_else_stmt.nested.push_back(GetStmtEOObject(p_stmt->getFalseExpr()));
return if_else_stmt;
}

EOObject GetIfStmtEOObject(const IfStmt *p_stmt) {
EOObject if_stmt{"if"};
if (p_stmt != nullptr) {
Expand Down
12 changes: 12 additions & 0 deletions project/tests/main/operations/cond_operator/cond_operator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "stdio.h"

int main() {
int x = -5;

int res = x > 0 ? x : -x;

printf("%d\n", res);
//printf("%s\n", res % 2 ? "even" : "odd");

return 0;
}

0 comments on commit f6702ef

Please sign in to comment.