1 module analysis.base; 2 3 import std.container; 4 import std.string; 5 import dparse.ast; 6 import std.array; 7 import dsymbol.scope_ : Scope; 8 9 struct Message 10 { 11 /// Name of the file where the warning was triggered 12 string fileName; 13 /// Line number where the warning was triggered 14 size_t line; 15 /// Column number where the warning was triggered (in bytes) 16 size_t column; 17 /// Name of the warning 18 string key; 19 /// Warning message 20 string message; 21 } 22 23 enum comparitor = q{ a.line < b.line || (a.line == b.line && a.column < b.column) }; 24 25 alias MessageSet = RedBlackTree!(Message, comparitor, true); 26 27 abstract class BaseAnalyzer : ASTVisitor 28 { 29 public: 30 this(string fileName, const Scope* sc) 31 { 32 this.sc = sc; 33 this.fileName = fileName; 34 _messages = new MessageSet; 35 } 36 37 Message[] messages() 38 { 39 return _messages[].array; 40 } 41 42 protected: 43 44 bool inAggregate = false; 45 46 template visitTemplate(T) 47 { 48 override void visit(const T structDec) 49 { 50 inAggregate = true; 51 structDec.accept(this); 52 inAggregate = false; 53 } 54 } 55 56 void addErrorMessage(size_t line, size_t column, string key, string message) 57 { 58 _messages.insert(Message(fileName, line, column, key, message)); 59 } 60 61 /** 62 * The file name 63 */ 64 string fileName; 65 66 const(Scope)* sc; 67 68 MessageSet _messages; 69 }