1 /* 2 * Copyright (C) 2020, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <iostream> 20 #include <string> 21 22 class AidlLocation { 23 public: 24 struct Point { 25 int line; 26 int column; 27 }; 28 29 enum class Source { 30 // From internal aidl source code 31 INTERNAL = 0, 32 // From a parsed file 33 EXTERNAL = 1 34 }; 35 36 AidlLocation(const std::string& file, Point begin, Point end, Source source); AidlLocation(const std::string & file,Source source)37 AidlLocation(const std::string& file, Source source) 38 : AidlLocation(file, {0, 0}, {0, 0}, source) {} 39 IsInternal()40 bool IsInternal() const { return source_ == Source::INTERNAL; } 41 42 // The first line of a file is line 1. LocationKnown()43 bool LocationKnown() const { return begin_.line != 0; } 44 GetFile()45 std::string GetFile() const { return file_; } 46 47 friend std::ostream& operator<<(std::ostream& os, const AidlLocation& l); 48 friend class AidlNode; 49 50 private: 51 // INTENTIONALLY HIDDEN: only operator<< should access details here. 52 // Otherwise, locations should only ever be copied around to construct new 53 // objects. 54 const std::string file_; 55 Point begin_; 56 Point end_; 57 Source source_; 58 }; 59 60 #define AIDL_LOCATION_HERE \ 61 (AidlLocation{__FILE__, {__LINE__, 0}, {__LINE__, 0}, AidlLocation::Source::INTERNAL}) 62 63 std::ostream& operator<<(std::ostream& os, const AidlLocation& l);