authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-25 22:16:50-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-11-25 22:17:24-05:00
log687e3592919940bc3c77a22adbee065fb5c1bc7e
treeb56205e2196c633fffe4722f549adc4d7cfc5b62
parentdf0e875856023e38af8b88dd94ef97f347d0a5e3

translate-c: avoid global state and introduce var decl scopes

in preparation to implement switch and solve variable name collisions

1 files changed, 433 insertions(+), 334 deletions(-)

src/translate_c.cpp+433-334
......@@ -23,8 +23,6 @@
2323
2424using namespace clang;
2525
26struct TransScope;
27
2826struct MacroSymbol {
2927 Buf *name;
3028 Buf *value;
......@@ -54,7 +52,6 @@ struct Context {
5452 ASTContext *ctx;
5553
5654 HashMap<Buf *, bool, buf_hash, buf_eql_buf> ptr_params;
57 TransScope *child_scope; // TODO refactor out
5855};
5956
6057enum ResultUsed {
......@@ -71,6 +68,7 @@ enum TransScopeId {
7168 TransScopeIdSwitch,
7269 TransScopeIdVar,
7370 TransScopeIdBlock,
71 TransScopeIdRoot,
7472};
7573
7674struct TransScope {
......@@ -94,17 +92,27 @@ struct TransScopeBlock {
9492 AstNode *node;
9593};
9694
97static AstNode *const skip_add_to_block_node = (AstNode *) 0x2;
95struct TransScopeRoot {
96 TransScope base;
97};
9898
99static TransScopeRoot *trans_scope_root_create(Context *c);
99100static TransScopeBlock *trans_scope_block_create(Context *c, TransScope *parent_scope);
100101static TransScopeVar *trans_scope_var_create(Context *c, TransScope *parent_scope, Buf *wanted_name);
101102//static TransScopeSwitch *trans_scope_switch_create(Context *c, TransScope *parent_scope);
102103
104static TransScopeBlock *trans_scope_block_find(TransScope *scope);
105
103106static AstNode *resolve_record_decl(Context *c, const RecordDecl *record_decl);
104107static AstNode *resolve_enum_decl(Context *c, const EnumDecl *enum_decl);
105108static AstNode *resolve_typedef_decl(Context *c, const TypedefNameDecl *typedef_decl);
106109
107static AstNode *trans_stmt(Context *c, ResultUsed result_used, TransScope *scope, const Stmt *stmt, TransLRValue lrval);
110static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
111 ResultUsed result_used, TransLRValue lrval,
112 AstNode **out_node, TransScope **out_child_scope,
113 TransScope **out_node_scope);
114static TransScope *trans_stmt(Context *c, TransScope *scope, const Stmt *stmt, AstNode **out_node);
115static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval);
108116static AstNode *trans_qual_type(Context *c, QualType qt, const SourceLocation &source_loc);
109117
110118
......@@ -620,10 +628,6 @@ static bool qual_type_has_wrapping_overflow(Context *c, QualType qt) {
620628 }
621629}
622630
623static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr, TransLRValue lrval) {
624 return trans_stmt(c, result_used, scope, expr, lrval);
625}
626
627631static AstNode *trans_type(Context *c, const Type *ty, const SourceLocation &source_loc) {
628632 switch (ty->getTypeClass()) {
629633 case Type::Builtin:
......@@ -961,16 +965,22 @@ static AstNode *trans_qual_type(Context *c, QualType qt, const SourceLocation &s
961965 return trans_type(c, qt.getTypePtr(), source_loc);
962966}
963967
964static AstNode *trans_compound_stmt(Context *c, TransScope *parent_scope, const CompoundStmt *stmt) {
965 TransScopeBlock *child_scope_block = trans_scope_block_create(c, parent_scope);
968static AstNode *trans_compound_stmt(Context *c, TransScope *scope, const CompoundStmt *stmt,
969 TransScope **out_node_scope)
970{
971 TransScopeBlock *child_scope_block = trans_scope_block_create(c, scope);
972 scope = &child_scope_block->base;
966973 for (CompoundStmt::const_body_iterator it = stmt->body_begin(), end_it = stmt->body_end(); it != end_it; ++it) {
967 AstNode *child_node = trans_stmt(c, ResultUsedNo, &child_scope_block->base, *it, TransRValue);
968 if (child_node == nullptr)
974 AstNode *child_node;
975 scope = trans_stmt(c, scope, *it, &child_node);
976 if (scope == nullptr)
969977 return nullptr;
970 if (child_node != skip_add_to_block_node)
978 if (child_node != nullptr)
971979 child_scope_block->node->data.block.statements.append(child_node);
972980 }
973 c->child_scope = &child_scope_block->base;
981 if (out_node_scope != nullptr) {
982 *out_node_scope = &child_scope_block->base;
983 }
974984 return child_scope_block->node;
975985}
976986
......@@ -1809,7 +1819,15 @@ static AstNode *trans_unary_operator(Context *c, ResultUsed result_used, TransSc
18091819 zig_unreachable();
18101820}
18111821
1812static AstNode *trans_local_declaration(Context *c, TransScope *scope, const DeclStmt *stmt) {
1822static int trans_local_declaration(Context *c, TransScope *scope, const DeclStmt *stmt,
1823 AstNode **out_node, TransScope **out_scope)
1824{
1825 // declarations are added via the scope
1826 *out_node = nullptr;
1827
1828 TransScopeBlock *scope_block = trans_scope_block_find(scope);
1829 assert(scope_block != nullptr);
1830
18131831 for (auto iter = stmt->decl_begin(); iter != stmt->decl_end(); iter++) {
18141832 Decl *decl = *iter;
18151833 switch (decl->getKind()) {
......@@ -1820,245 +1838,246 @@ static AstNode *trans_local_declaration(Context *c, TransScope *scope, const Dec
18201838 if (var_decl->hasInit()) {
18211839 init_node = trans_expr(c, ResultUsedYes, scope, var_decl->getInit(), TransRValue);
18221840 if (init_node == nullptr)
1823 return nullptr;
1841 return ErrorUnexpected;
18241842
18251843 }
18261844 AstNode *type_node = trans_qual_type(c, qual_type, stmt->getLocStart());
18271845 if (type_node == nullptr)
1828 return nullptr;
1846 return ErrorUnexpected;
1847
1848 Buf *c_symbol_name = buf_create_from_str(decl_name(var_decl));
18291849
1830 Buf *symbol_name = buf_create_from_str(decl_name(var_decl));
1850 TransScopeVar *var_scope = trans_scope_var_create(c, scope, c_symbol_name);
1851 scope = &var_scope->base;
18311852
18321853 AstNode *node = trans_create_node_var_decl_local(c, qual_type.isConstQualified(),
1833 symbol_name, type_node, init_node);
1854 var_scope->zig_name, type_node, init_node);
18341855
1835 assert(scope->id == TransScopeIdBlock);
1836 TransScopeBlock *scope_block = (TransScopeBlock *)scope;
18371856 scope_block->node->data.block.statements.append(node);
18381857 continue;
18391858 }
18401859 case Decl::AccessSpec:
18411860 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind AccessSpec");
1842 return nullptr;
1861 return ErrorUnexpected;
18431862 case Decl::Block:
18441863 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Block");
1845 return nullptr;
1864 return ErrorUnexpected;
18461865 case Decl::Captured:
18471866 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Captured");
1848 return nullptr;
1867 return ErrorUnexpected;
18491868 case Decl::ClassScopeFunctionSpecialization:
18501869 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ClassScopeFunctionSpecialization");
1851 return nullptr;
1870 return ErrorUnexpected;
18521871 case Decl::Empty:
18531872 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Empty");
1854 return nullptr;
1873 return ErrorUnexpected;
18551874 case Decl::Export:
18561875 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Export");
1857 return nullptr;
1876 return ErrorUnexpected;
18581877 case Decl::ExternCContext:
18591878 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ExternCContext");
1860 return nullptr;
1879 return ErrorUnexpected;
18611880 case Decl::FileScopeAsm:
18621881 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind FileScopeAsm");
1863 return nullptr;
1882 return ErrorUnexpected;
18641883 case Decl::Friend:
18651884 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Friend");
1866 return nullptr;
1885 return ErrorUnexpected;
18671886 case Decl::FriendTemplate:
18681887 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind FriendTemplate");
1869 return nullptr;
1888 return ErrorUnexpected;
18701889 case Decl::Import:
18711890 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Import");
1872 return nullptr;
1891 return ErrorUnexpected;
18731892 case Decl::LinkageSpec:
18741893 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind LinkageSpec");
1875 return nullptr;
1894 return ErrorUnexpected;
18761895 case Decl::Label:
18771896 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Label");
1878 return nullptr;
1897 return ErrorUnexpected;
18791898 case Decl::Namespace:
18801899 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Namespace");
1881 return nullptr;
1900 return ErrorUnexpected;
18821901 case Decl::NamespaceAlias:
18831902 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind NamespaceAlias");
1884 return nullptr;
1903 return ErrorUnexpected;
18851904 case Decl::ObjCCompatibleAlias:
18861905 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCCompatibleAlias");
1887 return nullptr;
1906 return ErrorUnexpected;
18881907 case Decl::ObjCCategory:
18891908 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCCategory");
1890 return nullptr;
1909 return ErrorUnexpected;
18911910 case Decl::ObjCCategoryImpl:
18921911 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCCategoryImpl");
1893 return nullptr;
1912 return ErrorUnexpected;
18941913 case Decl::ObjCImplementation:
18951914 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCImplementation");
1896 return nullptr;
1915 return ErrorUnexpected;
18971916 case Decl::ObjCInterface:
18981917 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCInterface");
1899 return nullptr;
1918 return ErrorUnexpected;
19001919 case Decl::ObjCProtocol:
19011920 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCProtocol");
1902 return nullptr;
1921 return ErrorUnexpected;
19031922 case Decl::ObjCMethod:
19041923 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCMethod");
1905 return nullptr;
1924 return ErrorUnexpected;
19061925 case Decl::ObjCProperty:
19071926 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCProperty");
1908 return nullptr;
1927 return ErrorUnexpected;
19091928 case Decl::BuiltinTemplate:
19101929 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind BuiltinTemplate");
1911 return nullptr;
1930 return ErrorUnexpected;
19121931 case Decl::ClassTemplate:
19131932 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ClassTemplate");
1914 return nullptr;
1933 return ErrorUnexpected;
19151934 case Decl::FunctionTemplate:
19161935 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind FunctionTemplate");
1917 return nullptr;
1936 return ErrorUnexpected;
19181937 case Decl::TypeAliasTemplate:
19191938 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind TypeAliasTemplate");
1920 return nullptr;
1939 return ErrorUnexpected;
19211940 case Decl::VarTemplate:
19221941 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind VarTemplate");
1923 return nullptr;
1942 return ErrorUnexpected;
19241943 case Decl::TemplateTemplateParm:
19251944 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind TemplateTemplateParm");
1926 return nullptr;
1945 return ErrorUnexpected;
19271946 case Decl::Enum:
19281947 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Enum");
1929 return nullptr;
1948 return ErrorUnexpected;
19301949 case Decl::Record:
19311950 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Record");
1932 return nullptr;
1951 return ErrorUnexpected;
19331952 case Decl::CXXRecord:
19341953 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXRecord");
1935 return nullptr;
1954 return ErrorUnexpected;
19361955 case Decl::ClassTemplateSpecialization:
19371956 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ClassTemplateSpecialization");
1938 return nullptr;
1957 return ErrorUnexpected;
19391958 case Decl::ClassTemplatePartialSpecialization:
19401959 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ClassTemplatePartialSpecialization");
1941 return nullptr;
1960 return ErrorUnexpected;
19421961 case Decl::TemplateTypeParm:
19431962 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind TemplateTypeParm");
1944 return nullptr;
1963 return ErrorUnexpected;
19451964 case Decl::ObjCTypeParam:
19461965 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCTypeParam");
1947 return nullptr;
1966 return ErrorUnexpected;
19481967 case Decl::TypeAlias:
19491968 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind TypeAlias");
1950 return nullptr;
1969 return ErrorUnexpected;
19511970 case Decl::Typedef:
19521971 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Typedef");
1953 return nullptr;
1972 return ErrorUnexpected;
19541973 case Decl::UnresolvedUsingTypename:
19551974 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind UnresolvedUsingTypename");
1956 return nullptr;
1975 return ErrorUnexpected;
19571976 case Decl::Using:
19581977 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Using");
1959 return nullptr;
1978 return ErrorUnexpected;
19601979 case Decl::UsingDirective:
19611980 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind UsingDirective");
1962 return nullptr;
1981 return ErrorUnexpected;
19631982 case Decl::UsingPack:
19641983 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind UsingPack");
1965 return nullptr;
1984 return ErrorUnexpected;
19661985 case Decl::UsingShadow:
19671986 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind UsingShadow");
1968 return nullptr;
1987 return ErrorUnexpected;
19691988 case Decl::ConstructorUsingShadow:
19701989 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ConstructorUsingShadow");
1971 return nullptr;
1990 return ErrorUnexpected;
19721991 case Decl::Binding:
19731992 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Binding");
1974 return nullptr;
1993 return ErrorUnexpected;
19751994 case Decl::Field:
19761995 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Field");
1977 return nullptr;
1996 return ErrorUnexpected;
19781997 case Decl::ObjCAtDefsField:
19791998 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCAtDefsField");
1980 return nullptr;
1999 return ErrorUnexpected;
19812000 case Decl::ObjCIvar:
19822001 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCIvar");
1983 return nullptr;
2002 return ErrorUnexpected;
19842003 case Decl::Function:
19852004 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Function");
1986 return nullptr;
2005 return ErrorUnexpected;
19872006 case Decl::CXXDeductionGuide:
19882007 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXDeductionGuide");
1989 return nullptr;
2008 return ErrorUnexpected;
19902009 case Decl::CXXMethod:
19912010 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXMethod");
1992 return nullptr;
2011 return ErrorUnexpected;
19932012 case Decl::CXXConstructor:
19942013 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXConstructor");
1995 return nullptr;
2014 return ErrorUnexpected;
19962015 case Decl::CXXConversion:
19972016 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXConversion");
1998 return nullptr;
2017 return ErrorUnexpected;
19992018 case Decl::CXXDestructor:
20002019 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind CXXDestructor");
2001 return nullptr;
2020 return ErrorUnexpected;
20022021 case Decl::MSProperty:
20032022 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind MSProperty");
2004 return nullptr;
2023 return ErrorUnexpected;
20052024 case Decl::NonTypeTemplateParm:
20062025 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind NonTypeTemplateParm");
2007 return nullptr;
2026 return ErrorUnexpected;
20082027 case Decl::Decomposition:
20092028 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind Decomposition");
2010 return nullptr;
2029 return ErrorUnexpected;
20112030 case Decl::ImplicitParam:
20122031 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ImplicitParam");
2013 return nullptr;
2032 return ErrorUnexpected;
20142033 case Decl::OMPCapturedExpr:
20152034 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind OMPCapturedExpr");
2016 return nullptr;
2035 return ErrorUnexpected;
20172036 case Decl::ParmVar:
20182037 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ParmVar");
2019 return nullptr;
2038 return ErrorUnexpected;
20202039 case Decl::VarTemplateSpecialization:
20212040 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind VarTemplateSpecialization");
2022 return nullptr;
2041 return ErrorUnexpected;
20232042 case Decl::VarTemplatePartialSpecialization:
20242043 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind VarTemplatePartialSpecialization");
2025 return nullptr;
2044 return ErrorUnexpected;
20262045 case Decl::EnumConstant:
20272046 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind EnumConstant");
2028 return nullptr;
2047 return ErrorUnexpected;
20292048 case Decl::IndirectField:
20302049 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind IndirectField");
2031 return nullptr;
2050 return ErrorUnexpected;
20322051 case Decl::OMPDeclareReduction:
20332052 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind OMPDeclareReduction");
2034 return nullptr;
2053 return ErrorUnexpected;
20352054 case Decl::UnresolvedUsingValue:
20362055 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind UnresolvedUsingValue");
2037 return nullptr;
2056 return ErrorUnexpected;
20382057 case Decl::OMPThreadPrivate:
20392058 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind OMPThreadPrivate");
2040 return nullptr;
2059 return ErrorUnexpected;
20412060 case Decl::ObjCPropertyImpl:
20422061 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind ObjCPropertyImpl");
2043 return nullptr;
2062 return ErrorUnexpected;
20442063 case Decl::PragmaComment:
20452064 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind PragmaComment");
2046 return nullptr;
2065 return ErrorUnexpected;
20472066 case Decl::PragmaDetectMismatch:
20482067 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind PragmaDetectMismatch");
2049 return nullptr;
2068 return ErrorUnexpected;
20502069 case Decl::StaticAssert:
20512070 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind StaticAssert");
2052 return nullptr;
2071 return ErrorUnexpected;
20532072 case Decl::TranslationUnit:
20542073 emit_warning(c, stmt->getLocStart(), "TODO handle decl kind TranslationUnit");
2055 return nullptr;
2074 return ErrorUnexpected;
20562075 }
20572076 zig_unreachable();
20582077 }
20592078
2060 // declarations were already added
2061 return skip_add_to_block_node;
2079 *out_scope = scope;
2080 return ErrorNone;
20622081}
20632082
20642083static AstNode *trans_while_loop(Context *c, TransScope *scope, const WhileStmt *stmt) {
......@@ -2068,8 +2087,8 @@ static AstNode *trans_while_loop(Context *c, TransScope *scope, const WhileStmt
20682087 if (while_node->data.while_expr.condition == nullptr)
20692088 return nullptr;
20702089
2071 while_node->data.while_expr.body = trans_stmt(c, ResultUsedNo, scope, stmt->getBody(), TransRValue);
2072 if (while_node->data.while_expr.body == nullptr)
2090 TransScope *body_scope = trans_stmt(c, scope, stmt->getBody(), &while_node->data.while_expr.body);
2091 if (body_scope == nullptr)
20732092 return nullptr;
20742093
20752094 return while_node;
......@@ -2086,13 +2105,13 @@ static AstNode *trans_if_statement(Context *c, TransScope *scope, const IfStmt *
20862105 return nullptr;
20872106 if_node->data.if_bool_expr.condition = condition_node;
20882107
2089 if_node->data.if_bool_expr.then_block = trans_stmt(c, ResultUsedNo, scope, stmt->getThen(), TransRValue);
2090 if (if_node->data.if_bool_expr.then_block == nullptr)
2108 TransScope *then_scope = trans_stmt(c, scope, stmt->getThen(), &if_node->data.if_bool_expr.then_block);
2109 if (then_scope == nullptr)
20912110 return nullptr;
20922111
20932112 if (stmt->getElse() != nullptr) {
2094 if_node->data.if_bool_expr.else_node = trans_stmt(c, ResultUsedNo, scope, stmt->getElse(), TransRValue);
2095 if (if_node->data.if_bool_expr.else_node == nullptr)
2113 TransScope *else_scope = trans_stmt(c, scope, stmt->getElse(), &if_node->data.if_bool_expr.else_node);
2114 if (else_scope == nullptr)
20962115 return nullptr;
20972116 }
20982117
......@@ -2201,10 +2220,14 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22012220 // zig: b;
22022221 // zig: if (!cond) break;
22032222 // zig: }
2204 body_node = trans_stmt(c, ResultUsedNo, parent_scope, stmt->getBody(), TransRValue);
2205 if (body_node == nullptr) return nullptr;
2223
2224 // We call the low level function so that we can set child_scope to the scope of the generated block.
2225 if (trans_stmt_extra(c, parent_scope, stmt->getBody(), ResultUsedNo, TransRValue, &body_node,
2226 nullptr, &child_scope))
2227 {
2228 return nullptr;
2229 }
22062230 assert(body_node->type == NodeTypeBlock);
2207 child_scope = c->child_scope;
22082231 } else {
22092232 // the C statement is without a block, so we need to create a block to contain it.
22102233 // c: do
......@@ -2216,10 +2239,10 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22162239 // zig: }
22172240 TransScopeBlock *child_block_scope = trans_scope_block_create(c, parent_scope);
22182241 body_node = child_block_scope->node;
2219 child_scope = &child_block_scope->base;
2220 AstNode *child_statement = trans_stmt(c, ResultUsedNo, child_scope, stmt->getBody(), TransRValue);
2221 if (child_statement == nullptr) return nullptr;
2222 child_block_scope->node->data.block.statements.append(child_statement);
2242 AstNode *child_statement;
2243 child_scope = trans_stmt(c, &child_block_scope->base, stmt->getBody(), &child_statement);
2244 if (child_scope == nullptr) return nullptr;
2245 body_node->data.block.statements.append(child_statement);
22232246 }
22242247
22252248 // if (!cond) break;
......@@ -2229,10 +2252,7 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22292252 terminator_node->data.if_bool_expr.condition = trans_create_node_prefix_op(c, PrefixOpBoolNot, condition_node);
22302253 terminator_node->data.if_bool_expr.then_block = trans_create_node(c, NodeTypeBreak);
22312254
2232 assert(child_scope->id == TransScopeIdBlock);
2233 TransScopeBlock *child_block_scope = (TransScopeBlock *)child_scope;
2234
2235 child_block_scope->node->data.block.statements.append(terminator_node);
2255 body_node->data.block.statements.append(terminator_node);
22362256
22372257 while_node->data.while_expr.body = body_node;
22382258
......@@ -2244,10 +2264,10 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22442264// AstNode *switch_node = trans_create_node(c, NodeTypeSwitchExpr);
22452265// const DeclStmt *var_decl_stmt = stmt->getConditionVariableDeclStmt();
22462266// if (var_decl_stmt != nullptr) {
2247// AstNode *vars_node = trans_stmt(c, ResultUsedNo, switch_block_node, var_decl_stmt, TransRValue);
2267// AstNode *vars_node = trans_stmt(c, switch_block_node, var_decl_stmt);
22482268// if (vars_node == nullptr)
22492269// return nullptr;
2250// if (vars_node != skip_add_to_block_node)
2270// if (vars_node != nullptr)
22512271// switch_block_node->data.block.statements.append(vars_node);
22522272// }
22532273// switch_block_node->data.block.statements.append(switch_node);
......@@ -2260,10 +2280,10 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22602280// return nullptr;
22612281// switch_node->data.switch_expr.expr = expr_node;
22622282//
2263// AstNode *body_node = trans_stmt(c, ResultUsedNo, switch_block_node, stmt->getBody(), TransRValue);
2283// AstNode *body_node = trans_stmt(c, switch_block_node, stmt->getBody());
22642284// if (body_node == nullptr)
22652285// return nullptr;
2266// if (body_node != skip_add_to_block_node)
2286// if (body_node != nullptr)
22672287// switch_block_node->data.block.statements.append(body_node);
22682288//
22692289// return switch_block_node;
......@@ -2271,21 +2291,22 @@ static AstNode *trans_do_loop(Context *c, TransScope *parent_scope, const DoStmt
22712291
22722292static AstNode *trans_for_loop(Context *c, TransScope *parent_scope, const ForStmt *stmt) {
22732293 AstNode *loop_block_node;
2274 TransScope *condition_scope;
2294 TransScope *inner_scope;
22752295 AstNode *while_node = trans_create_node(c, NodeTypeWhileExpr);
22762296 const Stmt *init_stmt = stmt->getInit();
22772297 if (init_stmt == nullptr) {
22782298 loop_block_node = while_node;
2279 condition_scope = parent_scope;
2299 inner_scope = parent_scope;
22802300 } else {
22812301 TransScopeBlock *child_scope = trans_scope_block_create(c, parent_scope);
22822302 loop_block_node = child_scope->node;
2283 condition_scope = &child_scope->base;
2303 inner_scope = &child_scope->base;
22842304
2285 AstNode *vars_node = trans_stmt(c, ResultUsedNo, &child_scope->base, init_stmt, TransRValue);
2286 if (vars_node == nullptr)
2305 AstNode *vars_node;
2306 inner_scope = trans_stmt(c, &child_scope->base, init_stmt, &vars_node);
2307 if (inner_scope == nullptr)
22872308 return nullptr;
2288 if (vars_node != skip_add_to_block_node)
2309 if (vars_node != nullptr)
22892310 child_scope->node->data.block.statements.append(vars_node);
22902311
22912312 child_scope->node->data.block.statements.append(while_node);
......@@ -2297,21 +2318,23 @@ static AstNode *trans_for_loop(Context *c, TransScope *parent_scope, const ForSt
22972318 true_node->data.bool_literal.value = true;
22982319 while_node->data.while_expr.condition = true_node;
22992320 } else {
2300 while_node->data.while_expr.condition = trans_stmt(c, ResultUsedNo, condition_scope, cond_stmt, TransRValue);
2301 if (while_node->data.while_expr.condition == nullptr)
2321 TransScope *cond_scope = trans_stmt(c, inner_scope, cond_stmt, &while_node->data.while_expr.condition);
2322 if (cond_scope == nullptr)
23022323 return nullptr;
23032324 }
23042325
23052326 const Stmt *inc_stmt = stmt->getInc();
23062327 if (inc_stmt != nullptr) {
2307 AstNode *inc_node = trans_stmt(c, ResultUsedNo, condition_scope, inc_stmt, TransRValue);
2308 if (inc_node == nullptr)
2328 AstNode *inc_node;
2329 TransScope *inc_scope = trans_stmt(c, inner_scope, inc_stmt, &inc_node);
2330 if (inc_scope == nullptr)
23092331 return nullptr;
23102332 while_node->data.while_expr.continue_expr = inc_node;
23112333 }
23122334
2313 AstNode *child_statement = trans_stmt(c, ResultUsedNo, condition_scope, stmt->getBody(), TransRValue);
2314 if (child_statement == nullptr)
2335 AstNode *child_statement;
2336 TransScope *body_scope = trans_stmt(c, inner_scope, stmt->getBody(), &child_statement);
2337 if (body_scope == nullptr)
23152338 return nullptr;
23162339 while_node->data.while_expr.body = child_statement;
23172340
......@@ -2344,578 +2367,636 @@ static AstNode *trans_continue_stmt(Context *c, TransScope *scope, const Continu
23442367 return trans_create_node(c, NodeTypeContinue);
23452368}
23462369
2347static AstNode *trans_stmt(Context *c, ResultUsed result_used, TransScope *scope, const Stmt *stmt, TransLRValue lrvalue) {
2348 c->child_scope = scope; // TODO refactor out
2370static int wrap_stmt(AstNode **out_node, TransScope **out_scope, TransScope *in_scope, AstNode *result_node) {
2371 if (result_node == nullptr)
2372 return ErrorUnexpected;
2373 *out_node = result_node;
2374 if (out_scope != nullptr) {
2375 *out_scope = in_scope;
2376 }
2377 return ErrorNone;
2378}
2379
2380static int trans_stmt_extra(Context *c, TransScope *scope, const Stmt *stmt,
2381 ResultUsed result_used, TransLRValue lrvalue,
2382 AstNode **out_node, TransScope **out_child_scope,
2383 TransScope **out_node_scope)
2384{
23492385 Stmt::StmtClass sc = stmt->getStmtClass();
23502386 switch (sc) {
23512387 case Stmt::ReturnStmtClass:
2352 return trans_return_stmt(c, scope, (const ReturnStmt *)stmt);
2388 return wrap_stmt(out_node, out_child_scope, scope,
2389 trans_return_stmt(c, scope, (const ReturnStmt *)stmt));
23532390 case Stmt::CompoundStmtClass:
2354 return trans_compound_stmt(c, scope, (const CompoundStmt *)stmt);
2391 return wrap_stmt(out_node, out_child_scope, scope,
2392 trans_compound_stmt(c, scope, (const CompoundStmt *)stmt, out_node_scope));
23552393 case Stmt::IntegerLiteralClass:
2356 return trans_integer_literal(c, (const IntegerLiteral *)stmt);
2394 return wrap_stmt(out_node, out_child_scope, scope,
2395 trans_integer_literal(c, (const IntegerLiteral *)stmt));
23572396 case Stmt::ConditionalOperatorClass:
2358 return trans_conditional_operator(c, result_used, scope, (const ConditionalOperator *)stmt);
2397 return wrap_stmt(out_node, out_child_scope, scope,
2398 trans_conditional_operator(c, result_used, scope, (const ConditionalOperator *)stmt));
23592399 case Stmt::BinaryOperatorClass:
2360 return trans_binary_operator(c, result_used, scope, (const BinaryOperator *)stmt);
2400 return wrap_stmt(out_node, out_child_scope, scope,
2401 trans_binary_operator(c, result_used, scope, (const BinaryOperator *)stmt));
23612402 case Stmt::CompoundAssignOperatorClass:
2362 return trans_compound_assign_operator(c, result_used, scope, (const CompoundAssignOperator *)stmt);
2403 return wrap_stmt(out_node, out_child_scope, scope,
2404 trans_compound_assign_operator(c, result_used, scope, (const CompoundAssignOperator *)stmt));
23632405 case Stmt::ImplicitCastExprClass:
2364 return trans_implicit_cast_expr(c, scope, (const ImplicitCastExpr *)stmt);
2406 return wrap_stmt(out_node, out_child_scope, scope,
2407 trans_implicit_cast_expr(c, scope, (const ImplicitCastExpr *)stmt));
23652408 case Stmt::DeclRefExprClass:
2366 return trans_decl_ref_expr(c, (const DeclRefExpr *)stmt, lrvalue);
2409 return wrap_stmt(out_node, out_child_scope, scope,
2410 trans_decl_ref_expr(c, (const DeclRefExpr *)stmt, lrvalue));
23672411 case Stmt::UnaryOperatorClass:
2368 return trans_unary_operator(c, result_used, scope, (const UnaryOperator *)stmt);
2412 return wrap_stmt(out_node, out_child_scope, scope,
2413 trans_unary_operator(c, result_used, scope, (const UnaryOperator *)stmt));
23692414 case Stmt::DeclStmtClass:
2370 return trans_local_declaration(c, scope, (const DeclStmt *)stmt);
2415 return trans_local_declaration(c, scope, (const DeclStmt *)stmt, out_node, out_child_scope);
23712416 case Stmt::WhileStmtClass:
2372 return trans_while_loop(c, scope, (const WhileStmt *)stmt);
2417 return wrap_stmt(out_node, out_child_scope, scope,
2418 trans_while_loop(c, scope, (const WhileStmt *)stmt));
23732419 case Stmt::IfStmtClass:
2374 return trans_if_statement(c, scope, (const IfStmt *)stmt);
2420 return wrap_stmt(out_node, out_child_scope, scope,
2421 trans_if_statement(c, scope, (const IfStmt *)stmt));
23752422 case Stmt::CallExprClass:
2376 return trans_call_expr(c, result_used, scope, (const CallExpr *)stmt);
2423 return wrap_stmt(out_node, out_child_scope, scope,
2424 trans_call_expr(c, result_used, scope, (const CallExpr *)stmt));
23772425 case Stmt::NullStmtClass:
2378 return skip_add_to_block_node;
2426 *out_node = nullptr;
2427 *out_child_scope = scope;
2428 return ErrorNone;
23792429 case Stmt::MemberExprClass:
2380 return trans_member_expr(c, scope, (const MemberExpr *)stmt);
2430 return wrap_stmt(out_node, out_child_scope, scope,
2431 trans_member_expr(c, scope, (const MemberExpr *)stmt));
23812432 case Stmt::ArraySubscriptExprClass:
2382 return trans_array_subscript_expr(c, scope, (const ArraySubscriptExpr *)stmt);
2433 return wrap_stmt(out_node, out_child_scope, scope,
2434 trans_array_subscript_expr(c, scope, (const ArraySubscriptExpr *)stmt));
23832435 case Stmt::CStyleCastExprClass:
2384 return trans_c_style_cast_expr(c, result_used, scope, (const CStyleCastExpr *)stmt, lrvalue);
2436 return wrap_stmt(out_node, out_child_scope, scope,
2437 trans_c_style_cast_expr(c, result_used, scope, (const CStyleCastExpr *)stmt, lrvalue));
23852438 case Stmt::UnaryExprOrTypeTraitExprClass:
2386 return trans_unary_expr_or_type_trait_expr(c, scope, (const UnaryExprOrTypeTraitExpr *)stmt);
2439 return wrap_stmt(out_node, out_child_scope, scope,
2440 trans_unary_expr_or_type_trait_expr(c, scope, (const UnaryExprOrTypeTraitExpr *)stmt));
23872441 case Stmt::DoStmtClass:
2388 return trans_do_loop(c, scope, (const DoStmt *)stmt);
2442 return wrap_stmt(out_node, out_child_scope, scope,
2443 trans_do_loop(c, scope, (const DoStmt *)stmt));
23892444 case Stmt::ForStmtClass:
2390 return trans_for_loop(c, scope, (const ForStmt *)stmt);
2445 return wrap_stmt(out_node, out_child_scope, scope,
2446 trans_for_loop(c, scope, (const ForStmt *)stmt));
23912447 case Stmt::StringLiteralClass:
2392 return trans_string_literal(c, scope, (const StringLiteral *)stmt);
2448 return wrap_stmt(out_node, out_child_scope, scope,
2449 trans_string_literal(c, scope, (const StringLiteral *)stmt));
23932450 case Stmt::BreakStmtClass:
2394 return trans_break_stmt(c, scope, (const BreakStmt *)stmt);
2451 return wrap_stmt(out_node, out_child_scope, scope,
2452 trans_break_stmt(c, scope, (const BreakStmt *)stmt));
23952453 case Stmt::ContinueStmtClass:
2396 return trans_continue_stmt(c, scope, (const ContinueStmt *)stmt);
2454 return wrap_stmt(out_node, out_child_scope, scope,
2455 trans_continue_stmt(c, scope, (const ContinueStmt *)stmt));
2456 case Stmt::ParenExprClass:
2457 return wrap_stmt(out_node, out_child_scope, scope,
2458 trans_expr(c, result_used, scope, ((const ParenExpr*)stmt)->getSubExpr(), lrvalue));
23972459// case Stmt::SwitchStmtClass:
2398// return trans_switch_stmt(c, scope, (const SwitchStmt *)stmt);
2460// return wrap_stmt(out_node, out_child_scope, scope,
2461// trans_switch_stmt(c, scope, (const SwitchStmt *)stmt));
23992462 case Stmt::SwitchStmtClass:
24002463 emit_warning(c, stmt->getLocStart(), "TODO handle C SwitchStmtClass");
2401 return nullptr;
2464 return ErrorUnexpected;
24022465 case Stmt::CaseStmtClass:
24032466 emit_warning(c, stmt->getLocStart(), "TODO handle C CaseStmtClass");
2404 return nullptr;
2467 return ErrorUnexpected;
24052468 case Stmt::DefaultStmtClass:
24062469 emit_warning(c, stmt->getLocStart(), "TODO handle C DefaultStmtClass");
2407 return nullptr;
2470 return ErrorUnexpected;
24082471 case Stmt::NoStmtClass:
24092472 emit_warning(c, stmt->getLocStart(), "TODO handle C NoStmtClass");
2410 return nullptr;
2473 return ErrorUnexpected;
24112474 case Stmt::GCCAsmStmtClass:
24122475 emit_warning(c, stmt->getLocStart(), "TODO handle C GCCAsmStmtClass");
2413 return nullptr;
2476 return ErrorUnexpected;
24142477 case Stmt::MSAsmStmtClass:
24152478 emit_warning(c, stmt->getLocStart(), "TODO handle C MSAsmStmtClass");
2416 return nullptr;
2479 return ErrorUnexpected;
24172480 case Stmt::AttributedStmtClass:
24182481 emit_warning(c, stmt->getLocStart(), "TODO handle C AttributedStmtClass");
2419 return nullptr;
2482 return ErrorUnexpected;
24202483 case Stmt::CXXCatchStmtClass:
24212484 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXCatchStmtClass");
2422 return nullptr;
2485 return ErrorUnexpected;
24232486 case Stmt::CXXForRangeStmtClass:
24242487 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXForRangeStmtClass");
2425 return nullptr;
2488 return ErrorUnexpected;
24262489 case Stmt::CXXTryStmtClass:
24272490 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXTryStmtClass");
2428 return nullptr;
2491 return ErrorUnexpected;
24292492 case Stmt::CapturedStmtClass:
24302493 emit_warning(c, stmt->getLocStart(), "TODO handle C CapturedStmtClass");
2431 return nullptr;
2494 return ErrorUnexpected;
24322495 case Stmt::CoreturnStmtClass:
24332496 emit_warning(c, stmt->getLocStart(), "TODO handle C CoreturnStmtClass");
2434 return nullptr;
2497 return ErrorUnexpected;
24352498 case Stmt::CoroutineBodyStmtClass:
24362499 emit_warning(c, stmt->getLocStart(), "TODO handle C CoroutineBodyStmtClass");
2437 return nullptr;
2500 return ErrorUnexpected;
24382501 case Stmt::BinaryConditionalOperatorClass:
24392502 emit_warning(c, stmt->getLocStart(), "TODO handle C BinaryConditionalOperatorClass");
2440 return nullptr;
2503 return ErrorUnexpected;
24412504 case Stmt::AddrLabelExprClass:
24422505 emit_warning(c, stmt->getLocStart(), "TODO handle C AddrLabelExprClass");
2443 return nullptr;
2506 return ErrorUnexpected;
24442507 case Stmt::ArrayInitIndexExprClass:
24452508 emit_warning(c, stmt->getLocStart(), "TODO handle C ArrayInitIndexExprClass");
2446 return nullptr;
2509 return ErrorUnexpected;
24472510 case Stmt::ArrayInitLoopExprClass:
24482511 emit_warning(c, stmt->getLocStart(), "TODO handle C ArrayInitLoopExprClass");
2449 return nullptr;
2512 return ErrorUnexpected;
24502513 case Stmt::ArrayTypeTraitExprClass:
24512514 emit_warning(c, stmt->getLocStart(), "TODO handle C ArrayTypeTraitExprClass");
2452 return nullptr;
2515 return ErrorUnexpected;
24532516 case Stmt::AsTypeExprClass:
24542517 emit_warning(c, stmt->getLocStart(), "TODO handle C AsTypeExprClass");
2455 return nullptr;
2518 return ErrorUnexpected;
24562519 case Stmt::AtomicExprClass:
24572520 emit_warning(c, stmt->getLocStart(), "TODO handle C AtomicExprClass");
2458 return nullptr;
2521 return ErrorUnexpected;
24592522 case Stmt::BlockExprClass:
24602523 emit_warning(c, stmt->getLocStart(), "TODO handle C BlockExprClass");
2461 return nullptr;
2524 return ErrorUnexpected;
24622525 case Stmt::CXXBindTemporaryExprClass:
24632526 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXBindTemporaryExprClass");
2464 return nullptr;
2527 return ErrorUnexpected;
24652528 case Stmt::CXXBoolLiteralExprClass:
24662529 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXBoolLiteralExprClass");
2467 return nullptr;
2530 return ErrorUnexpected;
24682531 case Stmt::CXXConstructExprClass:
24692532 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXConstructExprClass");
2470 return nullptr;
2533 return ErrorUnexpected;
24712534 case Stmt::CXXTemporaryObjectExprClass:
24722535 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXTemporaryObjectExprClass");
2473 return nullptr;
2536 return ErrorUnexpected;
24742537 case Stmt::CXXDefaultArgExprClass:
24752538 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXDefaultArgExprClass");
2476 return nullptr;
2539 return ErrorUnexpected;
24772540 case Stmt::CXXDefaultInitExprClass:
24782541 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXDefaultInitExprClass");
2479 return nullptr;
2542 return ErrorUnexpected;
24802543 case Stmt::CXXDeleteExprClass:
24812544 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXDeleteExprClass");
2482 return nullptr;
2545 return ErrorUnexpected;
24832546 case Stmt::CXXDependentScopeMemberExprClass:
24842547 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXDependentScopeMemberExprClass");
2485 return nullptr;
2548 return ErrorUnexpected;
24862549 case Stmt::CXXFoldExprClass:
24872550 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXFoldExprClass");
2488 return nullptr;
2551 return ErrorUnexpected;
24892552 case Stmt::CXXInheritedCtorInitExprClass:
24902553 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXInheritedCtorInitExprClass");
2491 return nullptr;
2554 return ErrorUnexpected;
24922555 case Stmt::CXXNewExprClass:
24932556 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXNewExprClass");
2494 return nullptr;
2557 return ErrorUnexpected;
24952558 case Stmt::CXXNoexceptExprClass:
24962559 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXNoexceptExprClass");
2497 return nullptr;
2560 return ErrorUnexpected;
24982561 case Stmt::CXXNullPtrLiteralExprClass:
24992562 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXNullPtrLiteralExprClass");
2500 return nullptr;
2563 return ErrorUnexpected;
25012564 case Stmt::CXXPseudoDestructorExprClass:
25022565 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXPseudoDestructorExprClass");
2503 return nullptr;
2566 return ErrorUnexpected;
25042567 case Stmt::CXXScalarValueInitExprClass:
25052568 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXScalarValueInitExprClass");
2506 return nullptr;
2569 return ErrorUnexpected;
25072570 case Stmt::CXXStdInitializerListExprClass:
25082571 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXStdInitializerListExprClass");
2509 return nullptr;
2572 return ErrorUnexpected;
25102573 case Stmt::CXXThisExprClass:
25112574 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXThisExprClass");
2512 return nullptr;
2575 return ErrorUnexpected;
25132576 case Stmt::CXXThrowExprClass:
25142577 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXThrowExprClass");
2515 return nullptr;
2578 return ErrorUnexpected;
25162579 case Stmt::CXXTypeidExprClass:
25172580 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXTypeidExprClass");
2518 return nullptr;
2581 return ErrorUnexpected;
25192582 case Stmt::CXXUnresolvedConstructExprClass:
25202583 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXUnresolvedConstructExprClass");
2521 return nullptr;
2584 return ErrorUnexpected;
25222585 case Stmt::CXXUuidofExprClass:
25232586 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXUuidofExprClass");
2524 return nullptr;
2587 return ErrorUnexpected;
25252588 case Stmt::CUDAKernelCallExprClass:
25262589 emit_warning(c, stmt->getLocStart(), "TODO handle C CUDAKernelCallExprClass");
2527 return nullptr;
2590 return ErrorUnexpected;
25282591 case Stmt::CXXMemberCallExprClass:
2529 (void)result_used;
25302592 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXMemberCallExprClass");
2531 return nullptr;
2593 return ErrorUnexpected;
25322594 case Stmt::CXXOperatorCallExprClass:
25332595 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXOperatorCallExprClass");
2534 return nullptr;
2596 return ErrorUnexpected;
25352597 case Stmt::UserDefinedLiteralClass:
25362598 emit_warning(c, stmt->getLocStart(), "TODO handle C UserDefinedLiteralClass");
2537 return nullptr;
2599 return ErrorUnexpected;
25382600 case Stmt::CXXFunctionalCastExprClass:
25392601 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXFunctionalCastExprClass");
2540 return nullptr;
2602 return ErrorUnexpected;
25412603 case Stmt::CXXConstCastExprClass:
25422604 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXConstCastExprClass");
2543 return nullptr;
2605 return ErrorUnexpected;
25442606 case Stmt::CXXDynamicCastExprClass:
25452607 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXDynamicCastExprClass");
2546 return nullptr;
2608 return ErrorUnexpected;
25472609 case Stmt::CXXReinterpretCastExprClass:
25482610 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXReinterpretCastExprClass");
2549 return nullptr;
2611 return ErrorUnexpected;
25502612 case Stmt::CXXStaticCastExprClass:
25512613 emit_warning(c, stmt->getLocStart(), "TODO handle C CXXStaticCastExprClass");
2552 return nullptr;
2614 return ErrorUnexpected;
25532615 case Stmt::ObjCBridgedCastExprClass:
25542616 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCBridgedCastExprClass");
2555 return nullptr;
2617 return ErrorUnexpected;
25562618 case Stmt::CharacterLiteralClass:
25572619 emit_warning(c, stmt->getLocStart(), "TODO handle C CharacterLiteralClass");
2558 return nullptr;
2620 return ErrorUnexpected;
25592621 case Stmt::ChooseExprClass:
25602622 emit_warning(c, stmt->getLocStart(), "TODO handle C ChooseExprClass");
2561 return nullptr;
2623 return ErrorUnexpected;
25622624 case Stmt::CompoundLiteralExprClass:
25632625 emit_warning(c, stmt->getLocStart(), "TODO handle C CompoundLiteralExprClass");
2564 return nullptr;
2626 return ErrorUnexpected;
25652627 case Stmt::ConvertVectorExprClass:
25662628 emit_warning(c, stmt->getLocStart(), "TODO handle C ConvertVectorExprClass");
2567 return nullptr;
2629 return ErrorUnexpected;
25682630 case Stmt::CoawaitExprClass:
25692631 emit_warning(c, stmt->getLocStart(), "TODO handle C CoawaitExprClass");
2570 return nullptr;
2632 return ErrorUnexpected;
25712633 case Stmt::CoyieldExprClass:
25722634 emit_warning(c, stmt->getLocStart(), "TODO handle C CoyieldExprClass");
2573 return nullptr;
2635 return ErrorUnexpected;
25742636 case Stmt::DependentCoawaitExprClass:
25752637 emit_warning(c, stmt->getLocStart(), "TODO handle C DependentCoawaitExprClass");
2576 return nullptr;
2638 return ErrorUnexpected;
25772639 case Stmt::DependentScopeDeclRefExprClass:
25782640 emit_warning(c, stmt->getLocStart(), "TODO handle C DependentScopeDeclRefExprClass");
2579 return nullptr;
2641 return ErrorUnexpected;
25802642 case Stmt::DesignatedInitExprClass:
25812643 emit_warning(c, stmt->getLocStart(), "TODO handle C DesignatedInitExprClass");
2582 return nullptr;
2644 return ErrorUnexpected;
25832645 case Stmt::DesignatedInitUpdateExprClass:
25842646 emit_warning(c, stmt->getLocStart(), "TODO handle C DesignatedInitUpdateExprClass");
2585 return nullptr;
2647 return ErrorUnexpected;
25862648 case Stmt::ExprWithCleanupsClass:
25872649 emit_warning(c, stmt->getLocStart(), "TODO handle C ExprWithCleanupsClass");
2588 return nullptr;
2650 return ErrorUnexpected;
25892651 case Stmt::ExpressionTraitExprClass:
25902652 emit_warning(c, stmt->getLocStart(), "TODO handle C ExpressionTraitExprClass");
2591 return nullptr;
2653 return ErrorUnexpected;
25922654 case Stmt::ExtVectorElementExprClass:
25932655 emit_warning(c, stmt->getLocStart(), "TODO handle C ExtVectorElementExprClass");
2594 return nullptr;
2656 return ErrorUnexpected;
25952657 case Stmt::FloatingLiteralClass:
25962658 emit_warning(c, stmt->getLocStart(), "TODO handle C FloatingLiteralClass");
2597 return nullptr;
2659 return ErrorUnexpected;
25982660 case Stmt::FunctionParmPackExprClass:
25992661 emit_warning(c, stmt->getLocStart(), "TODO handle C FunctionParmPackExprClass");
2600 return nullptr;
2662 return ErrorUnexpected;
26012663 case Stmt::GNUNullExprClass:
26022664 emit_warning(c, stmt->getLocStart(), "TODO handle C GNUNullExprClass");
2603 return nullptr;
2665 return ErrorUnexpected;
26042666 case Stmt::GenericSelectionExprClass:
26052667 emit_warning(c, stmt->getLocStart(), "TODO handle C GenericSelectionExprClass");
2606 return nullptr;
2668 return ErrorUnexpected;
26072669 case Stmt::ImaginaryLiteralClass:
26082670 emit_warning(c, stmt->getLocStart(), "TODO handle C ImaginaryLiteralClass");
2609 return nullptr;
2671 return ErrorUnexpected;
26102672 case Stmt::ImplicitValueInitExprClass:
26112673 emit_warning(c, stmt->getLocStart(), "TODO handle C ImplicitValueInitExprClass");
2612 return nullptr;
2674 return ErrorUnexpected;
26132675 case Stmt::InitListExprClass:
26142676 emit_warning(c, stmt->getLocStart(), "TODO handle C InitListExprClass");
2615 return nullptr;
2677 return ErrorUnexpected;
26162678 case Stmt::LambdaExprClass:
26172679 emit_warning(c, stmt->getLocStart(), "TODO handle C LambdaExprClass");
2618 return nullptr;
2680 return ErrorUnexpected;
26192681 case Stmt::MSPropertyRefExprClass:
26202682 emit_warning(c, stmt->getLocStart(), "TODO handle C MSPropertyRefExprClass");
2621 return nullptr;
2683 return ErrorUnexpected;
26222684 case Stmt::MSPropertySubscriptExprClass:
26232685 emit_warning(c, stmt->getLocStart(), "TODO handle C MSPropertySubscriptExprClass");
2624 return nullptr;
2686 return ErrorUnexpected;
26252687 case Stmt::MaterializeTemporaryExprClass:
26262688 emit_warning(c, stmt->getLocStart(), "TODO handle C MaterializeTemporaryExprClass");
2627 return nullptr;
2689 return ErrorUnexpected;
26282690 case Stmt::NoInitExprClass:
26292691 emit_warning(c, stmt->getLocStart(), "TODO handle C NoInitExprClass");
2630 return nullptr;
2692 return ErrorUnexpected;
26312693 case Stmt::OMPArraySectionExprClass:
26322694 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPArraySectionExprClass");
2633 return nullptr;
2695 return ErrorUnexpected;
26342696 case Stmt::ObjCArrayLiteralClass:
26352697 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCArrayLiteralClass");
2636 return nullptr;
2698 return ErrorUnexpected;
26372699 case Stmt::ObjCAvailabilityCheckExprClass:
26382700 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAvailabilityCheckExprClass");
2639 return nullptr;
2701 return ErrorUnexpected;
26402702 case Stmt::ObjCBoolLiteralExprClass:
26412703 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCBoolLiteralExprClass");
2642 return nullptr;
2704 return ErrorUnexpected;
26432705 case Stmt::ObjCBoxedExprClass:
26442706 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCBoxedExprClass");
2645 return nullptr;
2707 return ErrorUnexpected;
26462708 case Stmt::ObjCDictionaryLiteralClass:
26472709 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCDictionaryLiteralClass");
2648 return nullptr;
2710 return ErrorUnexpected;
26492711 case Stmt::ObjCEncodeExprClass:
26502712 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCEncodeExprClass");
2651 return nullptr;
2713 return ErrorUnexpected;
26522714 case Stmt::ObjCIndirectCopyRestoreExprClass:
26532715 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCIndirectCopyRestoreExprClass");
2654 return nullptr;
2716 return ErrorUnexpected;
26552717 case Stmt::ObjCIsaExprClass:
26562718 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCIsaExprClass");
2657 return nullptr;
2719 return ErrorUnexpected;
26582720 case Stmt::ObjCIvarRefExprClass:
26592721 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCIvarRefExprClass");
2660 return nullptr;
2722 return ErrorUnexpected;
26612723 case Stmt::ObjCMessageExprClass:
26622724 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCMessageExprClass");
2663 return nullptr;
2725 return ErrorUnexpected;
26642726 case Stmt::ObjCPropertyRefExprClass:
26652727 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCPropertyRefExprClass");
2666 return nullptr;
2728 return ErrorUnexpected;
26672729 case Stmt::ObjCProtocolExprClass:
26682730 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCProtocolExprClass");
2669 return nullptr;
2731 return ErrorUnexpected;
26702732 case Stmt::ObjCSelectorExprClass:
26712733 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCSelectorExprClass");
2672 return nullptr;
2734 return ErrorUnexpected;
26732735 case Stmt::ObjCStringLiteralClass:
26742736 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCStringLiteralClass");
2675 return nullptr;
2737 return ErrorUnexpected;
26762738 case Stmt::ObjCSubscriptRefExprClass:
26772739 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCSubscriptRefExprClass");
2678 return nullptr;
2740 return ErrorUnexpected;
26792741 case Stmt::OffsetOfExprClass:
26802742 emit_warning(c, stmt->getLocStart(), "TODO handle C OffsetOfExprClass");
2681 return nullptr;
2743 return ErrorUnexpected;
26822744 case Stmt::OpaqueValueExprClass:
26832745 emit_warning(c, stmt->getLocStart(), "TODO handle C OpaqueValueExprClass");
2684 return nullptr;
2746 return ErrorUnexpected;
26852747 case Stmt::UnresolvedLookupExprClass:
26862748 emit_warning(c, stmt->getLocStart(), "TODO handle C UnresolvedLookupExprClass");
2687 return nullptr;
2749 return ErrorUnexpected;
26882750 case Stmt::UnresolvedMemberExprClass:
26892751 emit_warning(c, stmt->getLocStart(), "TODO handle C UnresolvedMemberExprClass");
2690 return nullptr;
2752 return ErrorUnexpected;
26912753 case Stmt::PackExpansionExprClass:
26922754 emit_warning(c, stmt->getLocStart(), "TODO handle C PackExpansionExprClass");
2693 return nullptr;
2694 case Stmt::ParenExprClass:
2695 return trans_expr(c, result_used, scope, ((const ParenExpr*)stmt)->getSubExpr(), lrvalue);
2755 return ErrorUnexpected;
26962756 case Stmt::ParenListExprClass:
26972757 emit_warning(c, stmt->getLocStart(), "TODO handle C ParenListExprClass");
2698 return nullptr;
2758 return ErrorUnexpected;
26992759 case Stmt::PredefinedExprClass:
27002760 emit_warning(c, stmt->getLocStart(), "TODO handle C PredefinedExprClass");
2701 return nullptr;
2761 return ErrorUnexpected;
27022762 case Stmt::PseudoObjectExprClass:
27032763 emit_warning(c, stmt->getLocStart(), "TODO handle C PseudoObjectExprClass");
2704 return nullptr;
2764 return ErrorUnexpected;
27052765 case Stmt::ShuffleVectorExprClass:
27062766 emit_warning(c, stmt->getLocStart(), "TODO handle C ShuffleVectorExprClass");
2707 return nullptr;
2767 return ErrorUnexpected;
27082768 case Stmt::SizeOfPackExprClass:
27092769 emit_warning(c, stmt->getLocStart(), "TODO handle C SizeOfPackExprClass");
2710 return nullptr;
2770 return ErrorUnexpected;
27112771 case Stmt::StmtExprClass:
27122772 emit_warning(c, stmt->getLocStart(), "TODO handle C StmtExprClass");
2713 return nullptr;
2773 return ErrorUnexpected;
27142774 case Stmt::SubstNonTypeTemplateParmExprClass:
27152775 emit_warning(c, stmt->getLocStart(), "TODO handle C SubstNonTypeTemplateParmExprClass");
2716 return nullptr;
2776 return ErrorUnexpected;
27172777 case Stmt::SubstNonTypeTemplateParmPackExprClass:
27182778 emit_warning(c, stmt->getLocStart(), "TODO handle C SubstNonTypeTemplateParmPackExprClass");
2719 return nullptr;
2779 return ErrorUnexpected;
27202780 case Stmt::TypeTraitExprClass:
27212781 emit_warning(c, stmt->getLocStart(), "TODO handle C TypeTraitExprClass");
2722 return nullptr;
2782 return ErrorUnexpected;
27232783 case Stmt::TypoExprClass:
27242784 emit_warning(c, stmt->getLocStart(), "TODO handle C TypoExprClass");
2725 return nullptr;
2785 return ErrorUnexpected;
27262786 case Stmt::VAArgExprClass:
27272787 emit_warning(c, stmt->getLocStart(), "TODO handle C VAArgExprClass");
2728 return nullptr;
2788 return ErrorUnexpected;
27292789 case Stmt::GotoStmtClass:
27302790 emit_warning(c, stmt->getLocStart(), "TODO handle C GotoStmtClass");
2731 return nullptr;
2791 return ErrorUnexpected;
27322792 case Stmt::IndirectGotoStmtClass:
27332793 emit_warning(c, stmt->getLocStart(), "TODO handle C IndirectGotoStmtClass");
2734 return nullptr;
2794 return ErrorUnexpected;
27352795 case Stmt::LabelStmtClass:
27362796 emit_warning(c, stmt->getLocStart(), "TODO handle C LabelStmtClass");
2737 return nullptr;
2797 return ErrorUnexpected;
27382798 case Stmt::MSDependentExistsStmtClass:
27392799 emit_warning(c, stmt->getLocStart(), "TODO handle C MSDependentExistsStmtClass");
2740 return nullptr;
2800 return ErrorUnexpected;
27412801 case Stmt::OMPAtomicDirectiveClass:
27422802 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPAtomicDirectiveClass");
2743 return nullptr;
2803 return ErrorUnexpected;
27442804 case Stmt::OMPBarrierDirectiveClass:
27452805 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPBarrierDirectiveClass");
2746 return nullptr;
2806 return ErrorUnexpected;
27472807 case Stmt::OMPCancelDirectiveClass:
27482808 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPCancelDirectiveClass");
2749 return nullptr;
2809 return ErrorUnexpected;
27502810 case Stmt::OMPCancellationPointDirectiveClass:
27512811 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPCancellationPointDirectiveClass");
2752 return nullptr;
2812 return ErrorUnexpected;
27532813 case Stmt::OMPCriticalDirectiveClass:
27542814 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPCriticalDirectiveClass");
2755 return nullptr;
2815 return ErrorUnexpected;
27562816 case Stmt::OMPFlushDirectiveClass:
27572817 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPFlushDirectiveClass");
2758 return nullptr;
2818 return ErrorUnexpected;
27592819 case Stmt::OMPDistributeDirectiveClass:
27602820 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPDistributeDirectiveClass");
2761 return nullptr;
2821 return ErrorUnexpected;
27622822 case Stmt::OMPDistributeParallelForDirectiveClass:
27632823 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPDistributeParallelForDirectiveClass");
2764 return nullptr;
2824 return ErrorUnexpected;
27652825 case Stmt::OMPDistributeParallelForSimdDirectiveClass:
27662826 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPDistributeParallelForSimdDirectiveClass");
2767 return nullptr;
2827 return ErrorUnexpected;
27682828 case Stmt::OMPDistributeSimdDirectiveClass:
27692829 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPDistributeSimdDirectiveClass");
2770 return nullptr;
2830 return ErrorUnexpected;
27712831 case Stmt::OMPForDirectiveClass:
27722832 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPForDirectiveClass");
2773 return nullptr;
2833 return ErrorUnexpected;
27742834 case Stmt::OMPForSimdDirectiveClass:
27752835 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPForSimdDirectiveClass");
2776 return nullptr;
2836 return ErrorUnexpected;
27772837 case Stmt::OMPParallelForDirectiveClass:
27782838 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPParallelForDirectiveClass");
2779 return nullptr;
2839 return ErrorUnexpected;
27802840 case Stmt::OMPParallelForSimdDirectiveClass:
27812841 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPParallelForSimdDirectiveClass");
2782 return nullptr;
2842 return ErrorUnexpected;
27832843 case Stmt::OMPSimdDirectiveClass:
27842844 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPSimdDirectiveClass");
2785 return nullptr;
2845 return ErrorUnexpected;
27862846 case Stmt::OMPTargetParallelForSimdDirectiveClass:
27872847 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetParallelForSimdDirectiveClass");
2788 return nullptr;
2848 return ErrorUnexpected;
27892849 case Stmt::OMPTargetSimdDirectiveClass:
27902850 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetSimdDirectiveClass");
2791 return nullptr;
2851 return ErrorUnexpected;
27922852 case Stmt::OMPTargetTeamsDistributeDirectiveClass:
27932853 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetTeamsDistributeDirectiveClass");
2794 return nullptr;
2854 return ErrorUnexpected;
27952855 case Stmt::OMPTargetTeamsDistributeParallelForDirectiveClass:
27962856 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetTeamsDistributeParallelForDirectiveClass");
2797 return nullptr;
2857 return ErrorUnexpected;
27982858 case Stmt::OMPTargetTeamsDistributeParallelForSimdDirectiveClass:
27992859 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetTeamsDistributeParallelForSimdDirectiveClass");
2800 return nullptr;
2860 return ErrorUnexpected;
28012861 case Stmt::OMPTargetTeamsDistributeSimdDirectiveClass:
28022862 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetTeamsDistributeSimdDirectiveClass");
2803 return nullptr;
2863 return ErrorUnexpected;
28042864 case Stmt::OMPTaskLoopDirectiveClass:
28052865 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskLoopDirectiveClass");
2806 return nullptr;
2866 return ErrorUnexpected;
28072867 case Stmt::OMPTaskLoopSimdDirectiveClass:
28082868 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskLoopSimdDirectiveClass");
2809 return nullptr;
2869 return ErrorUnexpected;
28102870 case Stmt::OMPTeamsDistributeDirectiveClass:
28112871 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTeamsDistributeDirectiveClass");
2812 return nullptr;
2872 return ErrorUnexpected;
28132873 case Stmt::OMPTeamsDistributeParallelForDirectiveClass:
28142874 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTeamsDistributeParallelForDirectiveClass");
2815 return nullptr;
2875 return ErrorUnexpected;
28162876 case Stmt::OMPTeamsDistributeParallelForSimdDirectiveClass:
28172877 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTeamsDistributeParallelForSimdDirectiveClass");
2818 return nullptr;
2878 return ErrorUnexpected;
28192879 case Stmt::OMPTeamsDistributeSimdDirectiveClass:
28202880 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTeamsDistributeSimdDirectiveClass");
2821 return nullptr;
2881 return ErrorUnexpected;
28222882 case Stmt::OMPMasterDirectiveClass:
28232883 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPMasterDirectiveClass");
2824 return nullptr;
2884 return ErrorUnexpected;
28252885 case Stmt::OMPOrderedDirectiveClass:
28262886 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPOrderedDirectiveClass");
2827 return nullptr;
2887 return ErrorUnexpected;
28282888 case Stmt::OMPParallelDirectiveClass:
28292889 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPParallelDirectiveClass");
2830 return nullptr;
2890 return ErrorUnexpected;
28312891 case Stmt::OMPParallelSectionsDirectiveClass:
28322892 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPParallelSectionsDirectiveClass");
2833 return nullptr;
2893 return ErrorUnexpected;
28342894 case Stmt::OMPSectionDirectiveClass:
28352895 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPSectionDirectiveClass");
2836 return nullptr;
2896 return ErrorUnexpected;
28372897 case Stmt::OMPSectionsDirectiveClass:
28382898 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPSectionsDirectiveClass");
2839 return nullptr;
2899 return ErrorUnexpected;
28402900 case Stmt::OMPSingleDirectiveClass:
28412901 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPSingleDirectiveClass");
2842 return nullptr;
2902 return ErrorUnexpected;
28432903 case Stmt::OMPTargetDataDirectiveClass:
28442904 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetDataDirectiveClass");
2845 return nullptr;
2905 return ErrorUnexpected;
28462906 case Stmt::OMPTargetDirectiveClass:
28472907 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetDirectiveClass");
2848 return nullptr;
2908 return ErrorUnexpected;
28492909 case Stmt::OMPTargetEnterDataDirectiveClass:
28502910 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetEnterDataDirectiveClass");
2851 return nullptr;
2911 return ErrorUnexpected;
28522912 case Stmt::OMPTargetExitDataDirectiveClass:
28532913 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetExitDataDirectiveClass");
2854 return nullptr;
2914 return ErrorUnexpected;
28552915 case Stmt::OMPTargetParallelDirectiveClass:
28562916 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetParallelDirectiveClass");
2857 return nullptr;
2917 return ErrorUnexpected;
28582918 case Stmt::OMPTargetParallelForDirectiveClass:
28592919 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetParallelForDirectiveClass");
2860 return nullptr;
2920 return ErrorUnexpected;
28612921 case Stmt::OMPTargetTeamsDirectiveClass:
28622922 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetTeamsDirectiveClass");
2863 return nullptr;
2923 return ErrorUnexpected;
28642924 case Stmt::OMPTargetUpdateDirectiveClass:
28652925 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTargetUpdateDirectiveClass");
2866 return nullptr;
2926 return ErrorUnexpected;
28672927 case Stmt::OMPTaskDirectiveClass:
28682928 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskDirectiveClass");
2869 return nullptr;
2929 return ErrorUnexpected;
28702930 case Stmt::OMPTaskgroupDirectiveClass:
28712931 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskgroupDirectiveClass");
2872 return nullptr;
2932 return ErrorUnexpected;
28732933 case Stmt::OMPTaskwaitDirectiveClass:
28742934 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskwaitDirectiveClass");
2875 return nullptr;
2935 return ErrorUnexpected;
28762936 case Stmt::OMPTaskyieldDirectiveClass:
28772937 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTaskyieldDirectiveClass");
2878 return nullptr;
2938 return ErrorUnexpected;
28792939 case Stmt::OMPTeamsDirectiveClass:
28802940 emit_warning(c, stmt->getLocStart(), "TODO handle C OMPTeamsDirectiveClass");
2881 return nullptr;
2941 return ErrorUnexpected;
28822942 case Stmt::ObjCAtCatchStmtClass:
28832943 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAtCatchStmtClass");
2884 return nullptr;
2944 return ErrorUnexpected;
28852945 case Stmt::ObjCAtFinallyStmtClass:
28862946 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAtFinallyStmtClass");
2887 return nullptr;
2947 return ErrorUnexpected;
28882948 case Stmt::ObjCAtSynchronizedStmtClass:
28892949 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAtSynchronizedStmtClass");
2890 return nullptr;
2950 return ErrorUnexpected;
28912951 case Stmt::ObjCAtThrowStmtClass:
28922952 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAtThrowStmtClass");
2893 return nullptr;
2953 return ErrorUnexpected;
28942954 case Stmt::ObjCAtTryStmtClass:
28952955 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAtTryStmtClass");
2896 return nullptr;
2956 return ErrorUnexpected;
28972957 case Stmt::ObjCAutoreleasePoolStmtClass:
28982958 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCAutoreleasePoolStmtClass");
2899 return nullptr;
2959 return ErrorUnexpected;
29002960 case Stmt::ObjCForCollectionStmtClass:
29012961 emit_warning(c, stmt->getLocStart(), "TODO handle C ObjCForCollectionStmtClass");
2902 return nullptr;
2962 return ErrorUnexpected;
29032963 case Stmt::SEHExceptStmtClass:
29042964 emit_warning(c, stmt->getLocStart(), "TODO handle C SEHExceptStmtClass");
2905 return nullptr;
2965 return ErrorUnexpected;
29062966 case Stmt::SEHFinallyStmtClass:
29072967 emit_warning(c, stmt->getLocStart(), "TODO handle C SEHFinallyStmtClass");
2908 return nullptr;
2968 return ErrorUnexpected;
29092969 case Stmt::SEHLeaveStmtClass:
29102970 emit_warning(c, stmt->getLocStart(), "TODO handle C SEHLeaveStmtClass");
2911 return nullptr;
2971 return ErrorUnexpected;
29122972 case Stmt::SEHTryStmtClass:
29132973 emit_warning(c, stmt->getLocStart(), "TODO handle C SEHTryStmtClass");
2914 return nullptr;
2974 return ErrorUnexpected;
29152975 }
29162976 zig_unreachable();
29172977}
29182978
2979// Returns null if there was an error
2980static AstNode *trans_expr(Context *c, ResultUsed result_used, TransScope *scope, const Expr *expr,
2981 TransLRValue lrval)
2982{
2983 AstNode *result_node;
2984 if (trans_stmt_extra(c, scope, expr, result_used, lrval, &result_node, nullptr, nullptr)) {
2985 return nullptr;
2986 }
2987 return result_node;
2988}
2989
2990// Statements have no result and no concept of L or R value.
2991// Returns child scope, or null if there was an error
2992static TransScope *trans_stmt(Context *c, TransScope *scope, const Stmt *stmt, AstNode **out_node) {
2993 TransScope *child_scope;
2994 if (trans_stmt_extra(c, scope, stmt, ResultUsedNo, TransRValue, out_node, &child_scope, nullptr)) {
2995 return nullptr;
2996 }
2997 return child_scope;
2998}
2999
29193000static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
29203001 Buf *fn_name = buf_create_from_str(decl_name(fn_decl));
29213002
......@@ -2946,7 +3027,8 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
29463027 return;
29473028 }
29483029
2949 TransScope *scope = nullptr;
3030 TransScopeRoot *root_scope = trans_scope_root_create(c);
3031 TransScope *scope = &root_scope->base;
29503032
29513033 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
29523034 AstNode *param_node = proto_node->data.fn_proto.params.at(i);
......@@ -2978,16 +3060,17 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
29783060 // actual function definition with body
29793061 c->ptr_params.clear();
29803062 Stmt *body = fn_decl->getBody();
2981 AstNode *actual_body_node = trans_stmt(c, ResultUsedNo, scope, body, TransRValue);
2982 assert(actual_body_node != skip_add_to_block_node);
2983 if (actual_body_node == nullptr) {
3063 AstNode *actual_body_node;
3064 TransScope *result_scope = trans_stmt(c, scope, body, &actual_body_node);
3065 if (result_scope == nullptr) {
29843066 emit_warning(c, fn_decl->getLocation(), "unable to translate function");
29853067 return;
29863068 }
3069 assert(actual_body_node != nullptr);
3070 assert(actual_body_node->type == NodeTypeBlock);
29873071
29883072 // it worked
29893073
2990 assert(actual_body_node->type == NodeTypeBlock);
29913074 AstNode *body_node_with_param_inits = trans_create_node(c, NodeTypeBlock);
29923075
29933076 for (size_t i = 0; i < proto_node->data.fn_proto.params.length; i += 1) {
......@@ -3447,6 +3530,12 @@ static Buf *get_unique_name(Context *c, Buf *name, TransScope *scope) {
34473530 return proposed_name;
34483531}
34493532
3533static TransScopeRoot *trans_scope_root_create(Context *c) {
3534 TransScopeRoot *result = allocate<TransScopeRoot>(1);
3535 result->base.id = TransScopeIdRoot;
3536 return result;
3537}
3538
34503539static TransScopeBlock *trans_scope_block_create(Context *c, TransScope *parent_scope) {
34513540 TransScopeBlock *result = allocate<TransScopeBlock>(1);
34523541 result->base.id = TransScopeIdBlock;
......@@ -3472,6 +3561,16 @@ static TransScopeVar *trans_scope_var_create(Context *c, TransScope *parent_scop
34723561// return result;
34733562//}
34743563
3564static TransScopeBlock *trans_scope_block_find(TransScope *scope) {
3565 while (scope != nullptr) {
3566 if (scope->id == TransScopeIdBlock) {
3567 return (TransScopeBlock *)scope;
3568 }
3569 scope = scope->parent;
3570 }
3571 return nullptr;
3572}
3573
34753574static void render_aliases(Context *c) {
34763575 for (size_t i = 0; i < c->aliases.length; i += 1) {
34773576 Alias *alias = &c->aliases.at(i);