ast/attributes.spice
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2026 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | // Std imports | ||
| 4 | import "std/data/unordered-map"; | ||
| 5 | |||
| 6 | // Constants | ||
| 7 | public const string ATTR_CORE_LINKER_FLAG = "core.linker.flag"; | ||
| 8 | public const string ATTR_CORE_LINUX_LINKER_FLAG = "core.linux.linker.flag"; | ||
| 9 | public const string ATTR_CORE_DARWIN_LINKER_FLAG = "core.darwin.linker.flag"; | ||
| 10 | public const string ATTR_CORE_WINDOWS_LINKER_FLAG = "core.windows.linker.flag"; | ||
| 11 | public const string ATTR_CORE_LINKER_ADDITIONAL_SOURCE = "core.linker.additionalSource"; | ||
| 12 | public const string ATTR_CORE_LINKER_DLL = "core.linker.dll"; | ||
| 13 | public const string ATTR_CORE_COMPILER_MANGLE = "core.compiler.mangle"; | ||
| 14 | public const string ATTR_CORE_COMPILER_MANGLED_NAME = "core.compiler.mangledName"; | ||
| 15 | public const string ATTR_CORE_COMPILER_KEEP_ON_NAME_COLLISION = "core.compiler.alwaysKeepOnNameCollision"; | ||
| 16 | public const string ATTR_CORE_COMPILER_FIXED_TYPE_ID = "core.compiler.fixedTypeId"; | ||
| 17 | public const string ATTR_CORE_COMPILER_EMIT_VTABLE = "core.compiler.alwaysEmitVTable"; | ||
| 18 | public const string ATTR_CORE_COMPILER_PACKED = "core.compiler.packed"; | ||
| 19 | public const string ATTR_CORE_COMPILER_WARNINGS_IGNORE = "core.compiler.warnings.ignore"; | ||
| 20 | public const string ATTR_CORE_COMPILER_EXPLICIT_ERROR_HANDLING = "core.compiler.explicitErrorHandling"; | ||
| 21 | public const string ATTR_CORE_COMPILER_ERROR_RETURN_TRACING = "core.compiler.errorReturnTracing"; | ||
| 22 | public const string ATTR_CORE_COMPILER_RED_ZONE = "core.compiler.redZone"; | ||
| 23 | public const string ATTR_TEST = "test"; | ||
| 24 | public const string ATTR_TEST_NAME = "test.name"; | ||
| 25 | public const string ATTR_TEST_SKIP = "test.skip"; | ||
| 26 | public const string ATTR_ASYNC = "async"; | ||
| 27 | public const string ATTR_IGNORE_UNUSED_RETURN_VALUE = "ignoreUnusedReturnValue"; | ||
| 28 | |||
| 29 | public type AttrTarget enum { | ||
| 30 | TARGET_INVALID = 0, | ||
| 31 | TARGET_MODULE = 1, | ||
| 32 | TARGET_STRUCT = 2, | ||
| 33 | TARGET_INTERFACE = 4, | ||
| 34 | TARGET_FCT_PROC = 8, | ||
| 35 | TARGET_EXT_DECL = 16, | ||
| 36 | TARGET_LAMBDA = 32, | ||
| 37 | TARGET_UNION = 64 | ||
| 38 | } | ||
| 39 | |||
| 40 | public type AttrType enum { | ||
| 41 | TYPE_INVALID, | ||
| 42 | TYPE_STRING, | ||
| 43 | TYPE_BOOL, | ||
| 44 | TYPE_INT | ||
| 45 | } | ||
| 46 | |||
| 47 | // Structs | ||
| 48 | 3579 | public type AttrConfigValue struct { | |
| 49 | public unsigned byte target | ||
| 50 | 3579 | public AttrType attrType = AttrType::TYPE_INVALID | |
| 51 | } | ||
| 52 | |||
| 53 | /** | ||
| 54 | * Look up the allowed targets and the value type of a known attribute. Spice globals must be primitives, so this is a function | ||
| 55 | * instead of a map. | ||
| 56 | * | ||
| 57 | * @param key Attribute key | ||
| 58 | * @param config Receives the configuration of the attribute if it is known | ||
| 59 | * @return True if the attribute is known | ||
| 60 | */ | ||
| 61 | 3579 | public f<bool> getAttrConfig(const String& key, AttrConfigValue& config) { | |
| 62 | 3579 | const unsigned byte targetModule = cast<unsigned byte>(AttrTarget::TARGET_MODULE); | |
| 63 | 3579 | const unsigned byte targetStruct = cast<unsigned byte>(AttrTarget::TARGET_STRUCT); | |
| 64 | 3579 | const unsigned byte targetInterface = cast<unsigned byte>(AttrTarget::TARGET_INTERFACE); | |
| 65 | 3579 | const unsigned byte targetFctProc = cast<unsigned byte>(AttrTarget::TARGET_FCT_PROC); | |
| 66 | 3579 | const unsigned byte targetExtDecl = cast<unsigned byte>(AttrTarget::TARGET_EXT_DECL); | |
| 67 | 3579 | const unsigned byte targetLambda = cast<unsigned byte>(AttrTarget::TARGET_LAMBDA); | |
| 68 | 3579 | const unsigned byte targetUnion = cast<unsigned byte>(AttrTarget::TARGET_UNION); | |
| 69 | |||
| 70 | 3579 | if key == ATTR_CORE_LINKER_FLAG || key == ATTR_CORE_LINUX_LINKER_FLAG || key == ATTR_CORE_DARWIN_LINKER_FLAG || | |
| 71 | 3579 | key == ATTR_CORE_WINDOWS_LINKER_FLAG || key == ATTR_CORE_LINKER_ADDITIONAL_SOURCE { | |
| 72 | 480 | config.target = targetModule; | |
| 73 | 480 | config.attrType = AttrType::TYPE_STRING; | |
| 74 | 3579 | } else if key == ATTR_CORE_COMPILER_KEEP_ON_NAME_COLLISION || key == ATTR_CORE_COMPILER_WARNINGS_IGNORE || | |
| 75 | 3099 | key == ATTR_CORE_COMPILER_EXPLICIT_ERROR_HANDLING || key == ATTR_CORE_COMPILER_ERROR_RETURN_TRACING { | |
| 76 | 1504 | config.target = targetModule; | |
| 77 | 1504 | config.attrType = AttrType::TYPE_BOOL; | |
| 78 | 3099 | } else if key == ATTR_CORE_COMPILER_FIXED_TYPE_ID { | |
| 79 | 254 | config.target = targetStruct | targetInterface | targetUnion; | |
| 80 | 254 | config.attrType = AttrType::TYPE_INT; | |
| 81 | 1595 | } else if key == ATTR_CORE_LINKER_DLL { | |
| 82 | 1 | config.target = targetExtDecl; | |
| 83 | 1 | config.attrType = AttrType::TYPE_BOOL; | |
| 84 | 1341 | } else if key == ATTR_CORE_COMPILER_MANGLE { | |
| 85 | 2 | config.target = targetFctProc | targetExtDecl; | |
| 86 | 2 | config.attrType = AttrType::TYPE_BOOL; | |
| 87 | 1340 | } else if key == ATTR_CORE_COMPILER_RED_ZONE { | |
| 88 | 5 | config.target = targetFctProc; | |
| 89 | 5 | config.attrType = AttrType::TYPE_BOOL; | |
| 90 | 1338 | } else if key == ATTR_CORE_COMPILER_MANGLED_NAME { | |
| 91 | 2 | config.target = targetFctProc | targetExtDecl; | |
| 92 | 2 | config.attrType = AttrType::TYPE_STRING; | |
| 93 | 1333 | } else if key == ATTR_CORE_COMPILER_EMIT_VTABLE || key == ATTR_CORE_COMPILER_PACKED { | |
| 94 | 202 | config.target = targetStruct; | |
| 95 | 202 | config.attrType = AttrType::TYPE_BOOL; | |
| 96 | 1331 | } else if key == ATTR_TEST || key == ATTR_TEST_SKIP { | |
| 97 | 44 | config.target = targetFctProc; | |
| 98 | 44 | config.attrType = AttrType::TYPE_BOOL; | |
| 99 | 1129 | } else if key == ATTR_TEST_NAME { | |
| 100 | 15 | config.target = targetFctProc; | |
| 101 | 15 | config.attrType = AttrType::TYPE_STRING; | |
| 102 | 1085 | } else if key == ATTR_ASYNC || key == ATTR_IGNORE_UNUSED_RETURN_VALUE { | |
| 103 | 1069 | config.target = targetFctProc | targetLambda; | |
| 104 | 1069 | config.attrType = AttrType::TYPE_BOOL; | |
| 105 | 1069 | } else { | |
| 106 | 1 | return false; | |
| 107 | 3098 | } | |
| 108 | 3578 | return true; | |
| 109 | } | ||
| 110 |