Fix catch trace bug and inline cost bug
[hiphop-php.git] / hphp / parser / location.h
blob84ae2bf167fdd1e952d61bde3c0cefa4a574cc7e
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_PARSER_LOCATION_H_
18 #define incl_HPHP_PARSER_LOCATION_H_
20 #include "hphp/util/base.h"
22 namespace HPHP {
23 ///////////////////////////////////////////////////////////////////////////////
25 DECLARE_BOOST_TYPES(Location);
26 class Location {
27 public:
28 Location() : file(""), line0(1), char0(1), line1(1), char1(1), cursor(0) {}
30 const char *file;
31 int line0;
32 int char0;
33 int line1;
34 int char1;
35 int cursor;
37 void first(int line, char pos) {
38 line0 = line; char0 = pos;
40 void first(Location &loc) {
41 line0 = loc.line0; char0 = loc.char0;
43 void last(int line, char pos) {
44 line1 = line; char1 = pos;
46 void last(Location &loc) {
47 line1 = loc.line1; char1 = loc.char1;
50 /**
51 * This only guarantees consistent result between two locations, whether or
52 * not it makes sense, because we're comparing those integers first for
53 * quicker sorting.
55 int compare(Location *loc) {
56 if (line0 < loc->line0) return -1; if (line0 > loc->line0) return 1;
57 if (char0 < loc->char0) return -1; if (char0 > loc->char0) return 1;
58 if (line1 < loc->line1) return -1; if (line1 > loc->line1) return 1;
59 if (char1 < loc->char1) return -1; if (char1 > loc->char1) return 1;
60 return strcmp(file, loc->file);
64 ///////////////////////////////////////////////////////////////////////////////
67 #endif // incl_HPHP_PARSER_LOCATION_H_