From e68e80ddda518f5cfdfcacf50edf80e2f20be1b7 Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Fri, 5 Oct 2007 16:59:14 +0000 Subject: [PATCH] Added a new type to the C++ header, tockSendableArrayOfBytes, ready for dealing with protocols and counted arrays properly. Also removed the tockAny type. The tests for genType on channels of ANY, protocols, and counted arrays have also been changed accordingly. --- backends/GenerateCTest.hs | 18 +++++++++++--- tock_support_cppcsp.h | 52 ++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/backends/GenerateCTest.hs b/backends/GenerateCTest.hs index 36dd108..3219318 100644 --- a/backends/GenerateCTest.hs +++ b/backends/GenerateCTest.hs @@ -228,12 +228,22 @@ testGenType = TestList ,testBoth "GenType 402" "Channel*" "csp::Chanout" (tcall genType $ A.Chan A.DirOutput (A.ChanAttributes False False) A.Int) ,testBoth "GenType 403" "Channel*" "csp::Chanout" (tcall genType $ A.Chan A.DirOutput (A.ChanAttributes True False) A.Int) - --ANY and protocols can occur outside channels in C++ (e.g. temporaries for reading from channels), so they are tested here: - ,testCPPF "GenType 500" "tockAny" (tcall genType $ A.Any) - ,testCPPF "GenType 600" "protocol_foo" (tcall genType $ A.UserProtocol (simpleName "foo")) - + --ANY and protocols cannot occur outside channels in C++ or C, they are tested here: + ,testBothFail "GenType 500" (tcall genType $ A.Any) + ,testBothFail "GenType 600" (tcall genType $ A.UserProtocol (simpleName "foo")) + ,testBothFail "GenType 650" (tcall genType $ A.Counted A.Int A.Int) + ,testBoth "GenType 700" "Channel*" "tockArrayView,1>" (tcall genType $ A.Array [A.Dimension 5] $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Int) ,testBoth "GenType 701" "Channel**" "tockArrayView,1>" (tcall genType $ A.Array [A.Dimension 5] $ A.Chan A.DirInput (A.ChanAttributes False False) A.Int) + + --Test types that can only occur inside channels: + --ANY: + ,testBoth "GenType 800" "Channel" "csp::One2OneChannel" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False False) A.Any) + --Protocol: + ,testBoth "GenType 900" "Channel" "csp::One2OneChannel" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False False) $ A.UserProtocol (simpleName "foo")) + --Counted: + ,testBoth "GenType 1000" "Channel" "csp::One2OneChannel" (tcall genType $ A.Chan A.DirUnknown (A.ChanAttributes False False) $ A.Counted A.Int A.Int) + ] testStop :: Test diff --git a/tock_support_cppcsp.h b/tock_support_cppcsp.h index 627c102..5618cb6 100644 --- a/tock_support_cppcsp.h +++ b/tock_support_cppcsp.h @@ -124,28 +124,6 @@ tie10(T1& t1, T2& t2, T3& t3, T4& t4, T5& t5, T6& t6, T7& t7, T8& t8, (t1, t2, t3, t4, t5, t6, t7, t8, t9, t10); } - -class tockAny : public boost::any -{ -public: - inline tockAny() {} - - inline tockAny(const tockAny& t) - : boost::any(*(boost::any*)&t) - { - } - - template - inline tockAny(T t) : boost::any(t) {} - - template - inline operator T () const - { - return boost::any_cast(*this); - } -}; - - //Let's assume bool is an unsigned byte: #define occam_mostneg_tockBool 0 #define occam_mostpos_tockBool 255 @@ -386,3 +364,33 @@ public: return *realArray; } }; + +class tockSendableArrayOfBytes +{ +private: + unsigned n; + ///This is not as horrific as it looks - it is never used as a way to get rid of the const tag on the same pointer, only one field is used at a time. + union + { + const void* sp; + void* dp; + }; +public: + ///For the sender: + inline explicit tockSendableArrayOfBytes(const void* p) + : n(0),sp(p) + { + } + + ///For the receiver: + inline tockSendableArrayOfBytes(unsigned _n,void* p) + : n(_n),sp(p) + { + } + + inline void operator=(const tockSendableArrayOfBytes& _src) + { + //We use the receiver's byte count: + memcpy(dp,sp,n); + } +};