1 /* 2 * Copyright 2021 Google LLC. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SKSL_DSL_ERROR_HANDLING 9 #define SKSL_DSL_ERROR_HANDLING 10 11 namespace SkSL { 12 13 namespace dsl { 14 15 #ifndef __has_builtin 16 #define __has_builtin(x) 0 17 #endif 18 19 class PositionInfo { 20 public: 21 #if __has_builtin(__builtin_FILE) && __has_builtin(__builtin_LINE) 22 explicit PositionInfo(const char* file = __builtin_FILE(), int line = __builtin_LINE()) 23 #else 24 explicit PositionInfo(const char* file = nullptr, int line = -1) 25 #endif // __has_builtin(__builtin_FILE) && __has_builtin(__builtin_LINE) fFile(file)26 : fFile(file) 27 , fLine(line) {} 28 file_name()29 const char* file_name() { 30 return fFile; 31 } 32 line()33 int line() { 34 return fLine; 35 } 36 37 private: 38 const char* fFile; 39 int fLine; 40 }; 41 42 /** 43 * Class which is notified in the event of an error. 44 */ 45 class ErrorHandler { 46 public: ~ErrorHandler()47 virtual ~ErrorHandler() {} 48 49 /** 50 * Reports a DSL error. Position may not be available, in which case it will be null. 51 */ 52 virtual void handleError(const char* msg, PositionInfo* position) = 0; 53 }; 54 55 } // namespace dsl 56 57 } // namespace SkSL 58 59 #endif 60