int main() { FOO(12, 20); BAR(1); XXPRINTF("my name is %s", "richard"); return 0; }
int main (int argc, const char **argv) { char *foo; #define DEF_MACROS #define ONE #include "info-macros.c" foo = FOO; #define TWO #include "info-macros.c" foo = FOO; #define THREE #include "info-macros.c" foo = FOO; #undef THREE #include "info-macros.c" foo = FOO; #undef TWO #include "info-macros.c" foo = FOO; #undef ONE #include "info-macros.c" foo = (char *)0; #define FOUR #include "info-macros.c" FOO ("the end."); return 0; }
int main() { C C; C.X = 1; // CHECK: C.Y FOO(C.X); // CHECK: C.Y int y = C.X; // CHECK: C.Y }
int test(){ #ifdef MYSQL_VERSION_ID if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass), FOO(mydb), s->port, FOO(mysock), CLIENT_MULTI_STATEMENTS)) { #else if (!mysql_real_connect(s->mysql, FOO(hostname), FOO(myuser), FOO(mypass), FOO(mydb), s->port, FOO(mysock), 0)) { #endif log_error_write(srv, __FILE__, __LINE__, "s", mysql_error(s->mysql)); return HANDLER_ERROR; } }
void RChannelReaderImpl::AddUnitList(ChannelUnitList* unitList) { ChannelProcessRequestList requestList; ChannelUnitList returnUnitList; { AutoCriticalSection acs(&m_baseDR); LogAssert(m_state == RS_Running || m_state == RS_InterruptingSupplier); DrBListEntry* listEntry = unitList->RemoveHead(); while (listEntry != NULL) { RChannelUnit* unit = unitList->CastOut(listEntry); AddUnitToQueue("RChannelReaderImpl::AddUnitList", unit, &requestList, &returnUnitList); listEntry = unitList->RemoveHead(); } FOO(&requestList); m_sendLatch.AcceptList(&requestList); m_unitLatch.AcceptList(&returnUnitList); } DispatchRequests("RChannelReaderImpl::AddUnitList", &requestList, &returnUnitList); }
// CHECK: foo int foo(int i) { // CHECK-NEXT: File 0, [[@LINE]]:16 -> {{[0-9]+}}:2 = #0 switch (i) { // CHECK-NEXT: File 0, [[@LINE]]:3 -> {{[0-9]+}}:4 = #1 default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> {{[0-9]+}}:11 = #2 if (i == 1) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:15 = #2 return 0; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = #3 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:5 -> [[@LINE+2]]:8 = (#2 - #3) (Expanded file = 1) // CHECK-NEXT: File 0, [[@LINE+1]]:8 -> {{[0-9]+}}:11 = (#2 - #3) FOO(1); case 0: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+1]]:13 = ((#2 + #4) - #3) return 2; // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:3 -> [[@LINE+2]]:6 = 0 // CHECK-NEXT: File 0, [[@LINE+1]]:6 -> {{[0-9]+}}:11 = 0 FOO(1); // CHECK-NEXT: File 0, [[@LINE+1]]:3 -> {{[0-9]+}}:11 = #5 label: ; } }
WebGLExtensionColorBufferHalfFloat::WebGLExtensionColorBufferHalfFloat(WebGLContext* webgl) : WebGLExtensionBase(webgl) { MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported."); auto& fua = webgl->mFormatUsage; auto fnUpdateUsage = [&fua](GLenum sizedFormat, webgl::EffectiveFormat effFormat) { auto usage = fua->EditUsage(effFormat); usage->isRenderable = true; fua->AllowRBFormat(sizedFormat, usage); }; #define FOO(x) fnUpdateUsage(LOCAL_GL_ ## x, webgl::EffectiveFormat::x) FOO(RGBA16F); FOO(RGB16F); #undef FOO }
int main() { if (2 > 4) FOO(2) /* 这里 FOO(2) 后面一定不能添加分号,否则会报错 */ else FOO(4) /* 这里 FOO(4) 后面可加分号,也可不加,一般是不加 */ if (2 < 4) BAR(2); /* 这里 BAR(2) 后面一定要加分号,否则会报错 */ else BAR(4) /* 同时,这里的 BAR(4) 后面也一定要加分号! */ return 0; }
WebGLExtensionCompressedTextureS3TC::WebGLExtensionCompressedTextureS3TC(WebGLContext* webgl) : WebGLExtensionBase(webgl) { RefPtr<WebGLContext> webgl_ = webgl; // Bug 1201275 const auto fnAdd = [&webgl_](GLenum sizedFormat, webgl::EffectiveFormat effFormat) { auto& fua = webgl_->mFormatUsage; auto usage = fua->EditUsage(effFormat); usage->isFilterable = true; fua->AllowSizedTexFormat(sizedFormat, usage); webgl_->mCompressedTextureFormats.AppendElement(sizedFormat); }; #define FOO(x) LOCAL_GL_ ## x, webgl::EffectiveFormat::x fnAdd(FOO(COMPRESSED_RGB_S3TC_DXT1_EXT)); fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT1_EXT)); fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT3_EXT)); fnAdd(FOO(COMPRESSED_RGBA_S3TC_DXT5_EXT)); #undef FOO }
int sc_main(int argc, char *argv[]) { // sc_clock clk1("clk1", 10, SC_NS, 0.5); // sc_clock clk2("clk2", 12, SC_NS, 0.5); sc_signal<bool> clk1( "clk1" ); sc_signal<bool> clk2( "clk2" ); foo FOO("FOO"); FOO.clk1(clk1); FOO.clk2(clk2); sc_trace_file *tf = sc_create_vcd_trace_file("test"); // sc_trace(tf, clk1.signal(), "clk1"); // sc_trace(tf, clk2.signal(), "clk2"); sc_trace(tf, clk1, "clk1"); sc_trace(tf, clk2, "clk2"); sc_start(0, SC_NS); clk1 = 0; clk2 = 0; // 0 ns sc_start(3, SC_NS); clk2 = 1; // 3 ns + sc_start(2, SC_NS); clk1 = 1; // 5 ns + sc_start(4, SC_NS); clk2 = 0; // 9 ns sc_start(1, SC_NS); clk1 = 0; // 10 ns sc_start(5, SC_NS); clk2 = 1; // 15 ns + sc_start(0, SC_NS); clk1 = 1; // 15 ns + sc_start(5, SC_NS); clk1 = 0; // 20 ns sc_start(1, SC_NS); clk2 = 0; // 21 ns sc_start(4, SC_NS); clk1 = 1; // 25 ns + sc_start(2, SC_NS); clk2 = 1; // 27 ns + sc_start(3, SC_NS); clk1 = 0; // 30 ns sc_close_vcd_trace_file(tf); return 0; }
int Main(void) { short int i; Initialize( &B ); for(i = 0 ; i < 10 ; i++ ) { Insert( &B, i ); } FOO( &B, screen ); while(!Empty(&B)) { Extract( &B, &i ); } return 0; }
WebGLExtensionColorBufferFloat::WebGLExtensionColorBufferFloat(WebGLContext* webgl) : WebGLExtensionBase(webgl) { MOZ_ASSERT(IsSupported(webgl), "Don't construct extension if unsupported."); auto& fua = webgl->mFormatUsage; auto fnUpdateUsage = [&fua](GLenum sizedFormat, webgl::EffectiveFormat effFormat) { auto usage = fua->EditUsage(effFormat); usage->SetRenderable(); fua->AllowRBFormat(sizedFormat, usage); }; #define FOO(x) fnUpdateUsage(LOCAL_GL_ ## x, webgl::EffectiveFormat::x) // The extension doesn't actually add RGB32F; only RGBA32F. FOO(RGBA32F); #undef FOO }
#define FOO(n, id) id = n enum Defs { FOO(3, ABC), FOO(7, XYZ) }; enum Color { RED, GREEN, BLUE = 3, ORANGE = 8, YELLOW }; enum Foo { abc = 1 << 2, xyz = 1 << 3 }; enum Self { A = 2, B, C = A, D = A + B }; enum Plus { P = +2, M = -1, PM = -P
Score evaluateUnUseDiff(const Position& pos) { int list0[EvalList::ListSize]; int list1[EvalList::ListSize]; const Hand handB = pos.hand(Black); const Hand handW = pos.hand(White); const Square sq_bk = pos.kingSquare(Black); const Square sq_wk = pos.kingSquare(White); int nlist = 0; #define FOO(hand, HP, list0_index, list1_index) \ for (u32 i = 1; i <= hand.numOf<HP>(); ++i) { \ list0[nlist] = list0_index + i; \ list1[nlist] = list1_index + i; \ ++nlist; \ } FOO(handB, HPawn , f_hand_pawn , e_hand_pawn ); FOO(handW, HPawn , e_hand_pawn , f_hand_pawn ); FOO(handB, HLance , f_hand_lance , e_hand_lance ); FOO(handW, HLance , e_hand_lance , f_hand_lance ); FOO(handB, HKnight, f_hand_knight, e_hand_knight); FOO(handW, HKnight, e_hand_knight, f_hand_knight); FOO(handB, HSilver, f_hand_silver, e_hand_silver); FOO(handW, HSilver, e_hand_silver, f_hand_silver); FOO(handB, HGold , f_hand_gold , e_hand_gold ); FOO(handW, HGold , e_hand_gold , f_hand_gold ); FOO(handB, HBishop, f_hand_bishop, e_hand_bishop); FOO(handW, HBishop, e_hand_bishop, f_hand_bishop); FOO(handB, HRook , f_hand_rook , e_hand_rook ); FOO(handW, HRook , e_hand_rook , f_hand_rook ); #undef FOO nlist = make_list_unUseDiff(pos, list0, list1, nlist); const auto* ppkppb = Evaluater::KPP[sq_bk ]; const auto* ppkppw = Evaluater::KPP[inverse(sq_wk)]; s32 score = Evaluater::KK[sq_bk][sq_wk]; for (int i = 0; i < nlist; ++i) { const int k0 = list0[i]; const int k1 = list1[i]; const auto* pkppb = ppkppb[k0]; const auto* pkppw = ppkppw[k1]; for (int j = 0; j < i; ++j) { const int l0 = list0[j]; const int l1 = list1[j]; score += pkppb[l0]; score -= pkppw[l1]; } score += Evaluater::KKP[sq_bk][sq_wk][k0]; } score += pos.material() * FVScale; #if defined INANIWA_SHIFT score += inaniwaScore(pos); #endif if (pos.turn() == White) { score = -score; } return static_cast<Score>(score); }
bool RChannelReaderImpl::FetchNextItemArray(UInt32 maxArraySize, RChannelItemArrayRef* pItemArray, DrTimeInterval csTimeOut) { ChannelProcessRequestList requestList; ChannelUnitList returnUnitList; DryadHandleListEntry* event = NULL; bool timedOut = false; bool mustBlock = false; bool startSupplier = false; { AutoCriticalSection acs(&m_baseDR); if (m_state != RS_Running) { LogAssert(m_state != RS_Closed); /* return an empty array */ pItemArray->Attach(new RChannelItemArray()); return true; } if (!m_unitList.IsEmpty()) { LogAssert(m_startedSupplier == true); LogAssert(m_handlerList.IsEmpty()); RChannelReaderSyncWaiter dummyHandler(NULL, INVALID_HANDLE_VALUE, NULL); dummyHandler.SetMaximumArraySize(maxArraySize); RChannelProcessRequest dummyRequest(NULL, &dummyHandler, NULL); m_handlerList.InsertAsTail(m_handlerList.CastIn(&dummyRequest)); TransferWaitingItems("FetchNextItemArray", &requestList, &returnUnitList); RChannelProcessRequest* dummyReturn = requestList.CastOut(requestList.RemoveHead()); LogAssert(dummyReturn == &dummyRequest); pItemArray->Set(dummyRequest.GetItemArray()); LogAssert((*pItemArray)->GetNumberOfItems() > 0); } else if (m_writerTerminationItem != NULL || m_readerTerminationItem != NULL) { /* we have already sent a termination item for processing so there aren't going to be any more arriving on the queue and we can return an empty list immediately */ pItemArray->Attach(new RChannelItemArray()); } else if (csTimeOut > DrTimeInterval_Zero) { if (m_startedSupplier == false) { /* when we exit the lock, we will start the supplier since this is the first read we have received. After the supplier has been started we'll set m_startedSupplierEvent to prevent a race condition in Interrupt */ startSupplier = true; BOOL bRet = ::ResetEvent(m_startedSupplierEvent); LogAssert(bRet != 0); m_startedSupplier = true; } /* we are going to block */ mustBlock = true; event = m_eventCache.GetEvent(true); } else { /* there's no item available and a zero timeout --- return an empty list immediately */ pItemArray->Attach(new RChannelItemArray()); LogAssert(csTimeOut == DrTimeInterval_Zero); timedOut = true; } m_unitLatch.AcceptList(&returnUnitList); FOO(&requestList); m_sendLatch.AcceptList(&requestList); } if (startSupplier) { // DrLogI( "Starting Supplier"); m_supplier->StartSupplier(m_prefetchCookie); // DrLogI( "Started Supplier"); BOOL bRet = ::SetEvent(m_startedSupplierEvent); LogAssert(bRet != 0); } DispatchRequests("FetchNextItemArray", &requestList, &returnUnitList); if (mustBlock == false) { LogAssert(event == NULL); } else { LogAssert(event != NULL); *pItemArray = NULL; RChannelReaderSyncWaiter* waiter = new RChannelReaderSyncWaiter(this, event->GetHandle(), pItemArray); this->SupplyHandler(waiter, waiter); DWORD timeOut = DrGetTimerMsFromInterval(csTimeOut); DWORD dRet = ::WaitForSingleObject(event->GetHandle(), timeOut); if (dRet == WAIT_TIMEOUT) { /* when cancel returns it's guaranteed the handler has been called */ this->Cancel(waiter); } else { LogAssert(dRet == WAIT_OBJECT_0); } LogAssert(*pItemArray != NULL); delete waiter; { AutoCriticalSection acs(&m_baseDR); /* save this event in case we need one again in the future */ m_eventCache.ReturnEvent(event); /* even if we actually timed out the wait, the handler may have supplied an item immediately afterwards or during the cancel. We only return a timed out value if there's no item ready but we haven't processed a termination item, so it's worth waiting for another one. */ timedOut = ((*pItemArray)->GetNumberOfItems() == 0 && m_writerTerminationItem == NULL && m_readerTerminationItem == NULL); } } return (!timedOut); }
void RChannelReaderImpl::SupplyHandler(RChannelItemArrayReaderHandler* handler, void* cancelCookie) { ChannelProcessRequestList requestList; ChannelUnitList returnUnitList; bool queuedHandler = false; bool startSupplier = false; { AutoCriticalSection acs(&m_baseDR); if (m_state == RS_Running) { if (m_writerTerminationItem == NULL && m_readerTerminationItem == NULL) { if (m_startedSupplier == false) { /* when we exit the lock, we will start the supplier since this is the first read we have received. After the supplier has been started we'll set m_startedSupplierEvent to prevent a race condition in Interrupt */ startSupplier = true; BOOL bRet = ::ResetEvent(m_startedSupplierEvent); LogAssert(bRet != 0); m_startedSupplier = true; } /* we haven't yet sent a termination item for processing, so there's going to be at least one more item coming from the parser */ RChannelProcessRequest* request = new RChannelProcessRequest(this, handler, cancelCookie); m_cookieMap.insert(std::make_pair(cancelCookie, request)); AddHandlerToQueue("RChannelReaderImpl::SupplyHandler", request, &requestList, &returnUnitList); queuedHandler = true; FOO(&requestList); m_sendLatch.AcceptList(&requestList); m_unitLatch.AcceptList(&returnUnitList); } } else { LogAssert(m_state != RS_Closed); } } if (startSupplier) { // DrLogI( "Starting Supplier"); m_supplier->StartSupplier(m_prefetchCookie); // DrLogI( "Started Supplier"); BOOL bRet = ::SetEvent(m_startedSupplierEvent); LogAssert(bRet != 0); } if (queuedHandler) { DispatchRequests("RChannelReaderImpl::SupplyHandler", &requestList, &returnUnitList); } else { LogAssert(requestList.IsEmpty()); LogAssert(returnUnitList.IsEmpty()); /* we've already sent out a termination item or started to drain so just return the handler immediately as there will never be any more items to send */ RChannelItemArrayRef emptyArray; emptyArray.Attach(new RChannelItemArray()); handler->ProcessItemArray(emptyArray); } }
int g(int x) { return FOO(x); }
int main() { FOO(42); }
int Position::evaluate(const Color us) const { int list0[NLIST], list1[NLIST]; int sq_bk, sq_wk; #ifndef TWIG int score; #else EvalSum score; #endif static int count=0; count++; int nlist=0; // 持ち駒をリスト化する #define FOO(hand, Piece, list0_index, list1_index) \ for (int i = I2Hand##Piece(hand); i >= 1; --i) { \ list0[nlist] = list0_index + i; \ list1[nlist] = list1_index + i; \ ++nlist; \ } FOO(HAND_B, Pawn , f_hand_pawn , e_hand_pawn ) FOO(HAND_W, Pawn , e_hand_pawn , f_hand_pawn ) FOO(HAND_B, Lance , f_hand_lance , e_hand_lance ) FOO(HAND_W, Lance , e_hand_lance , f_hand_lance ) FOO(HAND_B, Knight, f_hand_knight, e_hand_knight) FOO(HAND_W, Knight, e_hand_knight, f_hand_knight) FOO(HAND_B, Silver, f_hand_silver, e_hand_silver) FOO(HAND_W, Silver, e_hand_silver, f_hand_silver) FOO(HAND_B, Gold , f_hand_gold , e_hand_gold ) FOO(HAND_W, Gold , e_hand_gold , f_hand_gold ) FOO(HAND_B, Bishop, f_hand_bishop, e_hand_bishop) FOO(HAND_W, Bishop, e_hand_bishop, f_hand_bishop) FOO(HAND_B, Rook , f_hand_rook , e_hand_rook ) FOO(HAND_W, Rook , e_hand_rook , f_hand_rook ) #undef FOO nlist = make_list_apery(list0, list1, nlist); sq_bk = SQ_BKING; sq_wk = SQ_WKING; assert(0 <= sq_bk && sq_bk < nsquare); assert(0 <= sq_wk && sq_wk < nsquare); const auto* ppkppb = KPP[sq_bk ]; const auto* ppkppw = KPP[Inv(sq_wk)]; #ifndef TWIG score = fv_kk[sq_bk][sq_wk]; for (int i = 0; i < nlist; i++ ) { const int k0 = list0[i]; const int k1 = list1[i]; assert(0 <= k0 && k0 < fe_end); assert(0 <= k1 && k1 < fe_end); const auto* pkppb = ppkppb[k0]; const auto* pkppw = ppkppw[k1]; for (int j = 0; j < i; j++ ) { const int l0 = list0[j]; const int l1 = list1[j]; assert(0 <= l0 && l0 < fe_end); assert(0 <= l1 && l1 < fe_end); score += pkppb[l0]; score -= pkppw[l1]; } score += fv_kkp[sq_bk][sq_wk][k0]; } score += MATERIAL * FV_SCALE; score /= FV_SCALE; score = (us == BLACK) ? score : -score; return score; #else EvalSum sum; sum.p[2] = KK[sq_bk][sq_wk]; #if defined USE_AVX2_EVAL || defined USE_SSE_EVAL sum.m[0] = _mm_setzero_si128(); for (int i = 0; i < nlist; ++i) { const int k0 = list0[i]; const int k1 = list1[i]; const auto* pkppb = ppkppb[k0]; const auto* pkppw = ppkppw[k1]; for (int j = 0; j < i; ++j) { const int l0 = list0[j]; const int l1 = list1[j]; __m128i tmp; tmp = _mm_set_epi32(0, 0, *reinterpret_cast<const int32_t*>(&pkppw[l1][0]), *reinterpret_cast<const int32_t*>(&pkppb[l0][0])); tmp = _mm_cvtepi16_epi32(tmp); sum.m[0] = _mm_add_epi32(sum.m[0], tmp); } sum.p[2] += KKP[sq_bk][sq_wk][k0]; } sum.p[2][0] += MATERIAL * FV_SCALE; #else // loop 開始を i = 1 からにして、i = 0 の分のKKPを先に足す。 sum.p[2] += KKP[sq_bk][sq_wk][list0[0]]; sum.p[0][0] = 0; sum.p[0][1] = 0; sum.p[1][0] = 0; sum.p[1][1] = 0; for (int i = 1; i < nlist; ++i) { const int k0 = list0[i]; const int k1 = list1[i]; const auto* pkppb = ppkppb[k0]; const auto* pkppw = ppkppw[k1]; for (int j = 0; j < i; ++j) { const int l0 = list0[j]; const int l1 = list1[j]; sum.p[0] += pkppb[l0]; sum.p[1] += pkppw[l1]; } sum.p[2] += KKP[sq_bk][sq_wk][k0]; } sum.p[2][0] += MATERIAL * FV_SCALE; #endif #ifdef _DEBUG score.p[2] = KK[sq_bk][sq_wk]; score.p[0][0] = 0; score.p[0][1] = 0; score.p[1][0] = 0; score.p[1][1] = 0; for (int i = 0; i < nlist; ++i) { const int k0 = list0[i]; const int k1 = list1[i]; const auto* pkppb = ppkppb[k0]; const auto* pkppw = ppkppw[k1]; for (int j = 0; j < i; ++j) { const int l0 = list0[j]; const int l1 = list1[j]; score.p[0][0] += pkppb[l0][0]; score.p[0][1] += pkppb[l0][1]; score.p[1][0] += pkppw[l1][0]; score.p[1][1] += pkppw[l1][1]; } score.p[2][0] += KKP[sq_bk][sq_wk][k0][0]; score.p[2][1] += KKP[sq_bk][sq_wk][k0][1]; } score.p[2][0] += MATERIAL * FV_SCALE; assert(score.sum(us) == sum.sum(us)); #endif return sum.sum(us) / FV_SCALE ; #endif }