1 /// Author: Aziz Köksal 2 /// License: GPL3 3 /// $(Maturity average) 4 module dil.Compilation; 5 6 import dil.semantic.Types; 7 import dil.String : hashOf; 8 import dil.Tables, 9 dil.Diagnostics; 10 import common; 11 12 /// A group of settings relevant to the compilation process. 13 class CompilationContext 14 { 15 alias CC = typeof(this); 16 CC parent; 17 cstring[] importPaths; /// Import paths. 18 cstring[] includePaths; /// String include paths. 19 uint debugLevel; /// The debug level. 20 uint versionLevel; /// The version level. 21 cstring[hash_t] debugIds; /// Set of debug identifiers. 22 cstring[hash_t] versionIds; /// Set of version identifiers. 23 bool releaseBuild; /// Build release version? 24 bool unittestBuild; /// Include unittests? 25 bool acceptDeprecated; /// Allow deprecated symbols/features? 26 uint structAlign = 4; 27 28 Tables tables; /// Tables used by the Lexer and the semantic phase. 29 30 Diagnostics diag; /// Diagnostics object. 31 32 /// Constructs a CompilationContext object. 33 /// Params: 34 /// parent = Optional parent object. Members are copied or inherited. 35 this(CC parent = null) 36 { 37 this.parent = parent; 38 if (isRoot()) 39 (tables = new Tables()), 40 (diag = new Diagnostics()); 41 else 42 { 43 this.importPaths = parent.importPaths.dup; 44 this.includePaths = parent.includePaths.dup; 45 this.debugLevel = parent.debugLevel; 46 this.versionLevel = parent.versionLevel; 47 this.releaseBuild = parent.releaseBuild; 48 this.structAlign = parent.structAlign; 49 this.tables = parent.tables; 50 this.diag = parent.diag; 51 } 52 } 53 54 /// Makes accessing the tables thread-safe. 55 void threadsafeTables(bool safe) 56 { 57 tables.idents.setThreadsafe(safe); 58 } 59 60 void addDebugId(cstring id) 61 { 62 debugIds[hashOf(id)] = id; 63 } 64 65 void addVersionId(cstring id) 66 { 67 versionIds[hashOf(id)] = id; 68 } 69 70 bool findDebugId(cstring id) 71 { 72 if (auto pId = hashOf(id) in debugIds) 73 return true; 74 if (!isRoot()) 75 return parent.findDebugId(id); 76 return false; 77 } 78 79 bool findVersionId(cstring id) 80 { 81 if (auto pId = hashOf(id) in versionIds) 82 return true; 83 if (!isRoot()) 84 return parent.findVersionId(id); 85 return false; 86 } 87 88 bool isRoot() 89 { 90 return parent is null; 91 } 92 }