00001 /**** 00002 ***** Copyright 2010 Intel Corporation All Rights Reserved. 00003 ***** 00004 ***** The source code, information and material contained herein are owned by Intel Corporation or its suppliers ***** 00005 ***** or licensors, and title to such Material remains with Intel Corporation or its suppliers or licensors. ***** 00006 ***** The Material contains proprietary information of Intel or its suppliers and licensors. The Material is ***** 00007 ***** protected by worldwide copyright laws and treaty provisions. No part of the Material may be used, copied, ***** 00008 ***** reproduced, modified, published, uploaded, posted, transmitted, distributed or disclosed in any way without ***** 00009 ***** Intel's prior express written permission. 00010 ***** 00011 ***** No license under any patent, copyright or other intellectual property rights in the material is granted to ***** 00012 ***** or conferred upon you, either expressly, by implication, inducement, estoppel or otherwise. Any license ***** 00013 ***** under such intellectual property rights must be express and approved by Intel in writing. 00014 ****/ 00015 00016 /**** Copyright Ends ****/ 00017 00018 #ifndef ARBB_CPP_CONTROL_FLOW_HPP 00019 #define ARBB_CPP_CONTROL_FLOW_HPP 00020 00021 #include <arbb_vmapi.h> 00022 #include "scalar.hpp" 00023 #include "detail/error_details.hpp" 00024 #include "detail/function.hpp" 00025 00028 00030 #define _if(cond) \ 00031 {{{{ \ 00032 ARBB_CPP_NS::detail::if_stack().push(true); \ 00033 ARBB_CPP_NS::detail::if_stack().top().begin(cond); \ 00034 if (ARBB_CPP_NS::detail::capturing() || \ 00035 ARBB_CPP_NS::detail::if_stack().top().if_value()) {{ 00036 00040 #define _else_if(cond) \ 00041 }} \ 00042 ARBB_CPP_NS::detail::if_stack().top().end(); \ 00043 ARBB_CPP_NS::detail::if_stack().top().begin_else_if(cond); \ 00044 if (ARBB_CPP_NS::detail::capturing() || \ 00045 ARBB_CPP_NS::detail::if_stack().top().if_value()) {{ 00046 00050 #define _else \ 00051 }} \ 00052 ARBB_CPP_NS::detail::if_stack().top().add_else(); \ 00053 if (ARBB_CPP_NS::detail::capturing() || \ 00054 ARBB_CPP_NS::detail::if_stack().top().else_value()) {{ 00055 00057 #define _end_if \ 00058 }} \ 00059 ARBB_CPP_NS::detail::if_stack().top().end(); \ 00060 ARBB_CPP_NS::detail::if_stack().pop(); \ 00061 }}}} 00062 00065 #define _while(cond) \ 00066 {{{{ \ 00067 ARBB_CPP_NS::detail::loop_stack().push(true); \ 00068 ARBB_CPP_NS::detail::loop_stack().top().while_begin(); \ 00069 if (ARBB_CPP_NS::detail::capturing()) { \ 00070 ARBB_CPP_NS::detail::loop_stack().top().while_cond(cond); \ 00071 } \ 00072 while ((ARBB_CPP_NS::detail::loop_stack().top().first_iteration() && \ 00073 (ARBB_CPP_NS::detail::capturing() || \ 00074 ARBB_CPP_NS::value(ARBB_CPP_NS::boolean(cond)))) \ 00075 || (ARBB_CPP_NS::detail::capturing() == false && \ 00076 ARBB_CPP_NS::value(ARBB_CPP_NS::boolean(cond)))) \ 00077 {{ 00078 00080 #define _end_while \ 00081 }} \ 00082 ARBB_CPP_NS::detail::loop_stack().top().end_while(); \ 00083 ARBB_CPP_NS::detail::loop_stack().pop(); \ 00084 }}}} 00085 00088 #define _for(init, cond, step) \ 00089 {{{{ \ 00090 ARBB_CPP_NS::detail::loop_stack().push(true); \ 00091 ARBB_CPP_NS::detail::loop_stack().top().for_begin(); \ 00092 init; \ 00093 if (ARBB_CPP_NS::detail::capturing()) { \ 00094 ARBB_CPP_NS::detail::loop_stack().top().for_end_init(); \ 00095 { \ 00096 ARBB_CPP_NS::boolean c = ARBB_CPP_NS::detail::accept_empty_cond(cond); \ 00097 ARBB_CPP_NS::detail::loop_stack().top().for_end_cond(c); \ 00098 } \ 00099 step; \ 00100 ARBB_CPP_NS::detail::loop_stack().top().for_end_step(); \ 00101 } \ 00102 bool forever = true; \ 00103 while (forever) {{ \ 00104 if (!ARBB_CPP_NS::detail::capturing()) { \ 00105 if (!ARBB_CPP_NS::detail::loop_stack().top().first_iteration()) { \ 00106 step; \ 00107 } \ 00108 if (!value(ARBB_CPP_NS::detail::accept_empty_cond(cond))) { \ 00109 break; \ 00110 } \ 00111 } 00112 00114 #define _end_for \ 00115 if (ARBB_CPP_NS::detail::capturing()) { \ 00116 break; \ 00117 } \ 00118 }} \ 00119 ARBB_CPP_NS::detail::loop_stack().top().for_end(); \ 00120 ARBB_CPP_NS::detail::loop_stack().pop(); \ 00121 }}}} 00122 00124 #define _break \ 00125 { \ 00126 if (ARBB_CPP_NS::detail::capturing()) { \ 00127 arbb_break(ARBB_CPP_NS::detail::function::current(), \ 00128 ARBB_CPP_NS::detail::throw_on_error_details()); \ 00129 } else { \ 00130 break; \ 00131 } \ 00132 } 00133 00135 #define _continue \ 00136 { \ 00137 if (ARBB_CPP_NS::detail::capturing()) { \ 00138 arbb_continue(ARBB_CPP_NS::detail::function::current(), \ 00139 ARBB_CPP_NS::detail::throw_on_error_details()); \ 00140 } else { \ 00141 continue; \ 00142 } \ 00143 } 00144 00146 #define _do \ 00147 {{{{ \ 00148 _while (true) \ 00149 {{ 00150 00153 #define _until(cond) \ 00154 _if (cond) { \ 00155 _break; \ 00156 } _end_if; \ 00157 }} \ 00158 _end_while; \ 00159 }}}} 00160 00162 00163 #endif // ARBB_CPP_CONTROL_FLOW_HPP
Copyright © 2010, Intel Corporation. All rights reserved.