MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / NumReadWrite

Method NumReadWrite

source/TextIO.cpp:744–808  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742 };
743
744 ResultType NumReadWrite(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
745 {
746 const bool reading = aID & F_READ;
747 const BOOL is_signed = aID & F_SIGNED, is_float = aID & F_FLOAT;
748 const DWORD size = aID & F_SIZE_MASK;
749
750 union {
751 __int64 i8;
752 int i4;
753 short i2;
754 char i1;
755 double d;
756 float f;
757 } buf;
758
759 if (reading)
760 {
761 buf.i8 = 0;
762 if ( !mFile.Read(&buf, size) )
763 _o_return_empty; // Fail.
764
765 if (is_float)
766 {
767 _o_return((size == 4) ? buf.f : buf.d);
768 }
769 else
770 {
771 if (is_signed)
772 {
773 // sign-extend to 64-bit
774 switch (size)
775 {
776 case 4: buf.i8 = buf.i4; break;
777 case 2: buf.i8 = buf.i2; break;
778 case 1: buf.i8 = buf.i1; break;
779 //case 8: not needed.
780 }
781 }
782 //else it's unsigned. No need to zero-extend thanks to init done earlier.
783 _o_return(buf.i8);
784 }
785 }
786 else
787 {
788 ExprTokenType &token_to_write = *aParam[0];
789
790 if (is_float)
791 {
792 buf.d = TokenToDouble(token_to_write);
793 if (size == 4)
794 buf.f = (float)buf.d;
795 }
796 else
797 {
798 if (size == 8 && !is_signed && !IS_NUMERIC(token_to_write.symbol))
799 buf.i8 = (__int64)ATOU64(TokenToString(token_to_write)); // For comments, search for ATOU64 in BIF_DllCall().
800 else
801 buf.i8 = TokenToInt64(token_to_write);

Callers

nothing calls this directly

Calls 6

TokenToDoubleFunction · 0.85
ATOU64Function · 0.85
TokenToStringFunction · 0.85
TokenToInt64Function · 0.85
ReadMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected