Forráskód Böngészése

[MERGE #406] linux: builds more lib/Parser files

Merge pull request #406 from jianchun:parser2
Make 5 more lib/Parser files build.
- Added bunch of needed win error codes.
- Applied a work around StaticSymLen<N> for StaticSym (flexible array
  initialization not allowed).
- #ifdef out few resource loading code under ENABLE_GLOBALIZATION.
- Deleted unused code.
Jianchun Xu 10 éve
szülő
commit
39355eaa3f

+ 5 - 5
lib/Common/Common/NumberUtilities_strtod.cpp

@@ -57,7 +57,7 @@ struct BIGNUM
     void Round(ulong luExtra)
     {
         if (0 == (luExtra & 0x80000000) ||
-            0 == (luExtra & 0x7FFFFFFF) && 0 == (m_lu0 & 1))
+            (0 == (luExtra & 0x7FFFFFFF) && 0 == (m_lu0 & 1)))
         {
             if (luExtra)
                 m_luError++;
@@ -856,7 +856,7 @@ static double AdjustDbl(double dbl, const EncodedChar *prgch, long cch, long lwE
             goto LFail;
 
         wT = biDbl.Compare(&biDec);
-        if (wT > 0 || 0 == wT && 0 != (Js::NumberUtilities::LuLoDbl(dbl) & 1))
+        if (wT > 0 || (0 == wT && 0 != (Js::NumberUtilities::LuLoDbl(dbl) & 1)))
         {
             // Return the next lower value.
             if (!Js::NumberUtilities::AddLu(&Js::NumberUtilities::LuLoDbl(dbl), 0xFFFFFFFF))
@@ -876,7 +876,7 @@ static double AdjustDbl(double dbl, const EncodedChar *prgch, long cch, long lwE
             goto LFail;
 
         wT = biDbl.Compare(&biDec);
-        if (wT < 0 || 0 == wT && 0 != (Js::NumberUtilities::LuLoDbl(dbl) & 1))
+        if (wT < 0 || (0 == wT && 0 != (Js::NumberUtilities::LuLoDbl(dbl) & 1)))
         {
             // Return the next higher value.
             if (Js::NumberUtilities::AddLu(&Js::NumberUtilities::LuLoDbl(dbl), 1))
@@ -1492,7 +1492,7 @@ static BOOL FDblToRgbPrecise(double dbl, __out_ecount(kcbMaxRgb) byte *prgb, int
         }
 
         // if (biNum < *pbiLo || biNum == *pbiLo && even)
-        if (w1 < 0 || 0 == w1 && 0 == (Js::NumberUtilities::LuLoDbl(dbl) & 1))
+        if (w1 < 0 || (0 == w1 && 0 == (Js::NumberUtilities::LuLoDbl(dbl) & 1)))
         {
             // if (biNum + biHi > biDen)
             if (w2 > 0)
@@ -1501,7 +1501,7 @@ static BOOL FDblToRgbPrecise(double dbl, __out_ecount(kcbMaxRgb) byte *prgb, int
                 if (!biNum.FShiftLeft(1))
                     goto LFail;
                 w2 = biNum.Compare(&biDen);
-                if ((w2 > 0 || w2 == 0 && (bT & 1)) && bT++ == 9)
+                if ((w2 > 0 || (w2 == 0 && (bT & 1))) && bT++ == 9)
                     goto LRoundUp9;
             }
             Assert(ib < kcbMaxRgb);

+ 43 - 2
lib/Common/CommonPal.h

@@ -89,8 +89,49 @@ inline int get_cpuid(int cpuInfo[4], int function_id)
 #undef sprintf_s
 
 // PAL LoadLibraryExW not supported
-#define LOAD_LIBRARY_SEARCH_SYSTEM32    0
-#define FACILITY_JSCRIPT                2306
+#define LOAD_LIBRARY_SEARCH_SYSTEM32     0
+// winerror.h
+#define FACILITY_JSCRIPT                 2306
+#define JSCRIPT_E_CANTEXECUTE            _HRESULT_TYPEDEF_(0x89020001L)
+#define DISP_E_UNKNOWNINTERFACE          _HRESULT_TYPEDEF_(0x80020001L)
+#define DISP_E_MEMBERNOTFOUND            _HRESULT_TYPEDEF_(0x80020003L)
+#define DISP_E_UNKNOWNNAME               _HRESULT_TYPEDEF_(0x80020006L)
+#define DISP_E_NONAMEDARGS               _HRESULT_TYPEDEF_(0x80020007L)
+#define DISP_E_EXCEPTION                 _HRESULT_TYPEDEF_(0x80020009L)
+#define DISP_E_BADINDEX                  _HRESULT_TYPEDEF_(0x8002000BL)
+#define DISP_E_UNKNOWNLCID               _HRESULT_TYPEDEF_(0x8002000CL)
+#define DISP_E_ARRAYISLOCKED             _HRESULT_TYPEDEF_(0x8002000DL)
+#define DISP_E_BADPARAMCOUNT             _HRESULT_TYPEDEF_(0x8002000EL)
+#define DISP_E_PARAMNOTOPTIONAL          _HRESULT_TYPEDEF_(0x8002000FL)
+#define DISP_E_NOTACOLLECTION            _HRESULT_TYPEDEF_(0x80020011L)
+#define TYPE_E_DLLFUNCTIONNOTFOUND       _HRESULT_TYPEDEF_(0x8002802FL)
+#define TYPE_E_TYPEMISMATCH              _HRESULT_TYPEDEF_(0x80028CA0L)
+#define TYPE_E_OUTOFBOUNDS               _HRESULT_TYPEDEF_(0x80028CA1L)
+#define TYPE_E_IOERROR                   _HRESULT_TYPEDEF_(0x80028CA2L)
+#define TYPE_E_CANTCREATETMPFILE         _HRESULT_TYPEDEF_(0x80028CA3L)
+#define TYPE_E_CANTLOADLIBRARY           _HRESULT_TYPEDEF_(0x80029C4AL)
+#define STG_E_TOOMANYOPENFILES           _HRESULT_TYPEDEF_(0x80030004L)
+#define STG_E_ACCESSDENIED               _HRESULT_TYPEDEF_(0x80030005L)
+#define STG_E_INSUFFICIENTMEMORY         _HRESULT_TYPEDEF_(0x80030008L)
+#define STG_E_NOMOREFILES                _HRESULT_TYPEDEF_(0x80030012L)
+#define STG_E_DISKISWRITEPROTECTED       _HRESULT_TYPEDEF_(0x80030013L)
+#define STG_E_READFAULT                  _HRESULT_TYPEDEF_(0x8003001EL)
+#define STG_E_SHAREVIOLATION             _HRESULT_TYPEDEF_(0x80030020L)
+#define STG_E_LOCKVIOLATION              _HRESULT_TYPEDEF_(0x80030021L)
+#define STG_E_MEDIUMFULL                 _HRESULT_TYPEDEF_(0x80030070L)
+#define STG_E_INVALIDNAME                _HRESULT_TYPEDEF_(0x800300FCL)
+#define STG_E_INUSE                      _HRESULT_TYPEDEF_(0x80030100L)
+#define STG_E_NOTCURRENT                 _HRESULT_TYPEDEF_(0x80030101L)
+#define STG_E_CANTSAVE                   _HRESULT_TYPEDEF_(0x80030103L)
+#define REGDB_E_CLASSNOTREG              _HRESULT_TYPEDEF_(0x80040154L)
+#define MK_E_UNAVAILABLE                 _HRESULT_TYPEDEF_(0x800401E3L)
+#define MK_E_INVALIDEXTENSION            _HRESULT_TYPEDEF_(0x800401E6L)
+#define MK_E_CANTOPENFILE                _HRESULT_TYPEDEF_(0x800401EAL)
+#define CO_E_APPNOTFOUND                 _HRESULT_TYPEDEF_(0x800401F5L)
+#define CO_E_APPDIDNTREG                 _HRESULT_TYPEDEF_(0x800401FEL)
+#define GetScode(hr) ((SCODE) (hr))
+// activscp.h
+#define SCRIPT_E_RECORDED   0x86664004L
 
 // _countof
 #if defined _M_X64 || defined _M_ARM || defined _M_ARM64

+ 5 - 5
lib/Parser/CMakeLists.txt

@@ -6,7 +6,7 @@ add_library (Chakra.Parser
     # CharSet.cpp
     CharTrie.cpp
     DebugWriter.cpp
-    # Hash.cpp
+    Hash.cpp
     OctoquadIdentifier.cpp
     # Parse.cpp
     ParserPch.cpp
@@ -19,11 +19,11 @@ add_library (Chakra.Parser
     # StandardChars.cpp
     # TextbookBoyerMoore.cpp
     cmperr.cpp
-    # errstr.cpp
-    # globals.cpp
+    errstr.cpp
+    globals.cpp
     jserr.gen
-    # rterror.cpp
-    # screrror.cpp
+    rterror.cpp
+    screrror.cpp
     )
 
 target_include_directories (

+ 2 - 2
lib/Parser/Hash.cpp

@@ -22,7 +22,7 @@ const HashTbl::ReservedWordInfo HashTbl::s_reservedWordInfo[tkID] =
 {
     { nullptr, fidNil },
 #define KEYWORD(tk,f,prec2,nop2,prec1,nop1,name) \
-        { &g_ssym_##name, f },
+        { reinterpret_cast<const StaticSym*>(&g_ssym_##name), f },
 #include "keywords.h"
 };
 
@@ -237,7 +237,7 @@ IdentPtr HashTbl::PidHashNameLenWithHash(_In_reads_(cch) CharType const * prgch,
 
     IdentPtr * ppid;
     IdentPtr pid;
-    long cb;
+    LONG cb;
     long bucketCount;
 
 

+ 13 - 1
lib/Parser/Hash.h

@@ -4,7 +4,19 @@
 //-------------------------------------------------------------------------------------------------------
 #pragma once
 
-struct StaticSym;
+// StaticSym contains a string literal at the end (flexible array) and is
+// meant to be initialized statically. However, flexible array initialization
+// is not allowed in standard C++. We declare each StaticSym with length
+// instead and cast to common StaticSymLen<0>* (StaticSym*) to access.
+template <ulong N>
+struct StaticSymLen
+{
+    ulong luHash;
+    ulong cch;
+    OLECHAR sz[N];
+};
+
+typedef StaticSymLen<0> StaticSym;
 
 /***************************************************************************
 Hashing functions. Definitions in core\hashfunc.cpp.

+ 0 - 3
lib/Parser/HashFunc.cpp

@@ -16,9 +16,6 @@
  *  of the hash function so things don't go out of sync.
  */
 
-// scaffolding - define ULONG
-typedef unsigned long ULONG;
-
 ULONG CaseSensitiveComputeHashCch(LPCOLESTR prgch, long cch)
 {
     ULONG luHash = 0;

+ 2 - 1
lib/Parser/errstr.cpp

@@ -29,6 +29,7 @@ static BOOL FGetStringFromLibrary(HMODULE hlib, int istring, __out_ecount(cchMax
     istring &= 0x0F;
     BOOL fRet = FALSE;
 
+#ifdef ENABLE_GLOBALIZATION
     psz[0] = '\0';
 
     if (NULL == hlib)
@@ -106,7 +107,7 @@ LError:
     }
 
 #endif
-
+#endif // ENABLE_GLOBALIZATION
     return fRet;
 }
 

+ 7 - 5
lib/Parser/globals.cpp

@@ -6,13 +6,15 @@
 
 // strings for builtin names
 #define HASH_NAME(name, hashCS, hashCI) \
-    const StaticSym g_ssym_##name = \
+    const StaticSymLen<sizeof(#name)> g_ssym_##name = \
     { \
         hashCS, \
         sizeof(#name) - 1, \
-        OLESTR(#name) \
-    };
+        CH_WSTR(#name) \
+    }; \
+    C_ASSERT(offsetof(StaticSymLen<sizeof(#name)>, luHash) == offsetof(StaticSym, luHash)); \
+    C_ASSERT(offsetof(StaticSymLen<sizeof(#name)>, cch) == offsetof(StaticSym, cch)); \
+    C_ASSERT(offsetof(StaticSymLen<sizeof(#name)>, sz) == offsetof(StaticSym, sz)); \
+
 #include "objnames.h"
 #undef HASH_NAME
-
-

+ 2 - 8
lib/Parser/globals.h

@@ -4,15 +4,9 @@
 //-------------------------------------------------------------------------------------------------------
 #pragma once
 
-struct StaticSym
-{
-    ulong luHash;
-    ulong cch;
-    OLECHAR sz[];
-};
-
 // Builtin symbols.
-#define HASH_NAME(name, hashCS, hashCI) extern const StaticSym g_ssym_##name;
+#define HASH_NAME(name, hashCS, hashCI) \
+    extern const StaticSymLen<sizeof(#name)> g_ssym_##name;
 #include "objnames.h"
 #undef HASH_NAME
 

+ 1 - 1
lib/Parser/rterror.cpp

@@ -15,7 +15,7 @@ C_ASSERT(JSERR_CantExecute == 0x800A1393);
 // verify HR matches between public SDK and private (.h) files
 C_ASSERT(JSCRIPT_E_CANTEXECUTE == JSPUBLICERR_CantExecute);
 // verify the HR value (as MAKE_HRESULT(SEVERITY_ERROR, FACILITY_JSCRIPT, 0x0001))
-C_ASSERT(JSPUBLICERR_CantExecute == 0x89020001L);
+C_ASSERT(JSPUBLICERR_CantExecute == _HRESULT_TYPEDEF_(0x89020001L));
 
 // /PUBLIC ERROR codes
 

+ 1 - 34
lib/Parser/screrror.cpp

@@ -24,35 +24,6 @@ void CopyException (EXCEPINFO *peiDest, const EXCEPINFO *peiSource)
     }
 }
 
-/***
-*BOOL FSupportsErrorInfo
-*Purpose:
-*  Answers if the given object supports the Rich Error mechanism
-*  on the given interface.
-*
-*Entry:
-*  punk = the object
-*  riid = the IID of the interface on the object
-*
-*Exit:
-*  return value = BOOL
-*
-***********************************************************************/
-BOOL FSupportsErrorInfo(IUnknown *punk, REFIID riid)
-{
-    BOOL fSupports;
-    ISupportErrorInfo *psupport;
-
-    fSupports = FALSE;
-    if(SUCCEEDED(punk->QueryInterface(__uuidof(ISupportErrorInfo), (void **)&psupport)))
-    {
-        if(NOERROR == psupport->InterfaceSupportsErrorInfo(riid))
-            fSupports = TRUE;
-        psupport->Release();
-    }
-    return fSupports;
-}
-
 /***
 *PUBLIC HRESULT GetErrorInfo
 *Purpose:
@@ -125,12 +96,8 @@ struct MHR
 const MHR g_rgmhr[] =
 {
     // FACILITY_NULL errors
-#if _WIN32 || _WIN64
     /*0x80004001*/ MAPHR(E_NOTIMPL, VBSERR_ActionNotSupported),
     /*0x80004002*/ MAPHR(E_NOINTERFACE, VBSERR_OLENotSupported),
-#else
-#error Neither __WIN32, nor _WIN64 is defined
-#endif
 
     // FACILITY_DISPATCH - IDispatch errors.
     /*0x80020001*/ MAPHR(DISP_E_UNKNOWNINTERFACE, VBSERR_OLENoPropOrMethod),
@@ -332,7 +299,7 @@ HRESULT  CompileScriptException::ProcessError(IScanner * pScan, HRESULT hr, Pars
         BstrGetResourceString(HRESULT_CODE(ei.scode))))
     {
         OLECHAR szT[50];
-        _snwprintf_s(szT, ARRAYSIZE(szT), ARRAYSIZE(szT)-1, OLESTR("error %d"), ei.scode);
+        _snwprintf_s(szT, ARRAYSIZE(szT), ARRAYSIZE(szT)-1, CH_WSTR("error %d"), ei.scode);
         if (nullptr == (ei.bstrDescription = SysAllocString(szT)))
             ei.scode = E_OUTOFMEMORY;
     }

+ 0 - 1
lib/Parser/screrror.h

@@ -25,7 +25,6 @@ inline void FreeExcepInfo(EXCEPINFO *pei)
 
 void CopyException (EXCEPINFO *pexcepinfoDest, const EXCEPINFO *pexcepinfoSource);
 
-BOOL FSupportsErrorInfo(IUnknown *punk, REFIID riid);
 HRESULT GetErrorInfo(EXCEPINFO *pexcepinfo);
 
 HRESULT MapHr(HRESULT hr, ErrorTypeEnum * errorTypeOut = nullptr);