1 /** 2 Copyright: Copyright (c) 2017, Joakim Brännström. All rights reserved. 3 License: MPL-2 4 Author: Joakim Brännström (joakim.brannstrom@gmx.com) 5 6 This Source Code Form is subject to the terms of the Mozilla Public License, 7 v.2.0. If a copy of the MPL was not distributed with this file, You can obtain 8 one at http://mozilla.org/MPL/2.0/. 9 10 This file contains convenient functions for logging some meta data about a 11 cursor for debugging purpose. 12 */ 13 module cpptooling.analyzer.clang.cursor_logger; 14 15 import clang.Cursor : Cursor; 16 import clang.Visitor : Visitor; 17 18 /// Log information of a cursor. 19 void logNode(ref const(Cursor) c, in int indent = 0, string func = __FUNCTION__, uint line = __LINE__) @trusted { 20 import std.array : array; 21 import std.range : repeat; 22 import logger = std.experimental.logger; 23 import clang.Cursor : dump; 24 import clang.info : abilities; 25 26 // dfmt off 27 debug { 28 string indent_ = repeat(' ', indent).array(); 29 logger.logf!(-1, "", "", "", "") 30 (logger.LogLevel.trace, 31 "%d %s%s|%s|%s|%s:%d:%d [%s:%d]", 32 indent, 33 indent_, 34 dump(c), 35 c.displayName, 36 abilities(c), 37 c.location.file, 38 c.location.spelling.line, 39 c.location.spelling.column, 40 func, 41 line); 42 } 43 // dfmt on 44 } 45 46 /// logNode can't take a rvalue so creating a temporary and then logging. 47 /// -3 because there are 3 lines until the call to logNoe. By subtracting it is 48 /// kept semantic equivalent to the mixin line. 49 template mixinNodeLog() { 50 enum mixinNodeLog = q{debug { 51 { 52 auto c = v.cursor; 53 logNode(c, indent, __FUNCTION__, __LINE__-3); 54 } 55 } 56 }; 57 }