CE Shared.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. namespace Edit{
  4. /******************************************************************************/
  5. #define TMPL_B u"<T" // begin template operator
  6. #define TMPL_E u"T>" // end template operator
  7. #define ELLIPSIS u"(…)" // character known as "Ellipsis" surrounded by brackets
  8. #define UNIQUE_NAME '@' // used for distinguishing files of same names, also for special headers
  9. #define DIV '`' // used instead of '/'
  10. #define SEP '\\'
  11. #define SEP_FILE '.'
  12. #define SEP_LINE "/******************************************************************************/"
  13. #define EE_PATH "Esenthel Engine"
  14. /******************************************************************************/
  15. enum VAR_TYPE : Byte // native variable type
  16. {
  17. VAR_NONE ,
  18. VAR_VOID ,
  19. VAR_BOOL ,
  20. VAR_BYTE ,
  21. VAR_SBYTE ,
  22. VAR_SHORT ,
  23. VAR_USHORT,
  24. VAR_INT ,
  25. VAR_UINT ,
  26. VAR_LONG ,
  27. VAR_ULONG ,
  28. VAR_FLT ,
  29. VAR_DBL ,
  30. VAR_CHAR8 ,
  31. VAR_CHAR16,
  32. VAR_ENUM ,
  33. VAR_NULL , // null_t
  34. VAR_FROM=VAR_BOOL , // first type on which can be performed operations
  35. VAR_TO =VAR_CHAR16, // last type on which can be performed operations
  36. };
  37. struct Keyword
  38. {
  39. Str name;
  40. Bool use_for_suggestions, follow_by_space, data_type, is_modifier, cpp;
  41. VAR_TYPE var_type;
  42. };
  43. /******************************************************************************/
  44. struct RecTest // Recurrence Tester
  45. {
  46. Bool crossed;
  47. Int recurrence;
  48. operator Bool( ) {if(recurrence>=128)crossed=true; return crossed;}
  49. void operator ++ (int) {recurrence++;}
  50. RecTest() {crossed=false; recurrence=0;}
  51. };
  52. struct IntLock // Int Increase Lock
  53. {
  54. Int &value;
  55. ~IntLock( ) {value--;}
  56. IntLock(Int &value) : value( value) {value++;}
  57. IntLock(RecTest &rt) : value(rt.recurrence) {value++;}
  58. NO_COPY_CONSTRUCTOR(IntLock);
  59. };
  60. /******************************************************************************/
  61. extern Bool CppMode;
  62. extern Int PtrSize, EnumSize, TabLength;
  63. extern CChar8 *AutoSource;
  64. extern Keyword NativeKeywords[];
  65. extern Str PreprocKeywords[];
  66. extern const Int PreprocKeywordsElms, NativeKeywordsElms;
  67. /******************************************************************************/
  68. inline Bool IntType(VAR_TYPE type) {return type==VAR_BYTE || type==VAR_SBYTE || type==VAR_SHORT || type==VAR_USHORT || type==VAR_INT || type==VAR_UINT || type==VAR_LONG || type==VAR_ULONG;}
  69. inline Bool RealType(VAR_TYPE type) {return type==VAR_FLT || type==VAR_DBL;}
  70. inline Bool SignedType(VAR_TYPE type) {return type==VAR_SBYTE || type==VAR_SHORT || type==VAR_INT || type==VAR_LONG || type==VAR_FLT || type==VAR_DBL || type==VAR_ENUM;} // if type can have negative values
  71. inline Bool UnsignedType(VAR_TYPE type) {return type==VAR_BOOL || type==VAR_BYTE || type==VAR_USHORT || type==VAR_UINT || type==VAR_ULONG || type==VAR_CHAR8 || type==VAR_CHAR16 ;} // if type can't have negative values
  72. inline Bool OffsetType(VAR_TYPE type) {return IntType(type) || type==VAR_BOOL || type==VAR_CHAR8 || type==VAR_CHAR16 || type==VAR_ENUM;}
  73. Int TypeSize (VAR_TYPE type);
  74. Str TypeName (VAR_TYPE type);
  75. Symbol* TypeSymbol(VAR_TYPE type);
  76. VAR_TYPE SameSizeType (VAR_TYPE type);
  77. VAR_TYPE SameSizeSignType (VAR_TYPE type);
  78. VAR_TYPE SameSizeSignBoolType(VAR_TYPE type);
  79. VAR_TYPE ComplementResult(VAR_TYPE type);
  80. VAR_TYPE NegativeResult(VAR_TYPE type);
  81. VAR_TYPE MulResult(VAR_TYPE a, VAR_TYPE b);
  82. VAR_TYPE DivResult(VAR_TYPE a, VAR_TYPE b);
  83. VAR_TYPE ModResult(VAR_TYPE a, VAR_TYPE b);
  84. VAR_TYPE AddResult(VAR_TYPE a, VAR_TYPE b);
  85. VAR_TYPE SubResult(VAR_TYPE a, VAR_TYPE b);
  86. VAR_TYPE ShiftLeftResult(VAR_TYPE a, VAR_TYPE b);
  87. VAR_TYPE ShiftRightResult(VAR_TYPE a, VAR_TYPE b);
  88. VAR_TYPE BitResult(VAR_TYPE a, VAR_TYPE b);
  89. Bool LostConst(UInt src_const_level, UInt dest_const_level);
  90. Int AlignAddress(Int address, Int size);
  91. inline CHAR_TYPE CodeCharType(Char c) {return (c=='$') ? CHART_CHAR : CharType(c);}
  92. inline Int AlignToTab(Int x) {return (x/TabLength)*TabLength;}
  93. inline Bool AllUpCase(C Str &s) {REPA(s)if(s[i]!=CaseUp(s[i]))return false; return true;}
  94. inline Str RandomName() {UID id; id.randomize(); return TextHex(id.i[0], 8);}
  95. inline void ReplacePath(Str &path, Str src, Str dest) {if(StartsPath(path, src))path=dest.tailSlash(true)+SkipStartPath(path, src);}
  96. Bool SourceExt(C Str &ext);
  97. Bool TextExt(C Str &ext);
  98. Bool AllowedExt(C Str &ext);
  99. Memc<Str> GetFiles(C Str &files);
  100. /******************************************************************************/
  101. } // namespace
  102. /******************************************************************************/
  103. inline Int CompareCS(C Edit::Keyword &a, C Edit::Keyword &b) {return CompareCS(a.name, b.name);}
  104. inline Int CompareCS(C Edit::Keyword &a, C BStr &b) {return CompareCS(a.name, b );}
  105. /******************************************************************************/
  106. #endif
  107. /******************************************************************************/