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