Permalink
Browse files

Use LexerLocation where possible.

  • Loading branch information...
1 parent ade7808 commit 639dbb2fb36807a4ba248e7fd214c6b63bf1cd66 @simonask committed Feb 21, 2012
@@ -7,6 +7,11 @@
#include "snow/symbol.hpp"
namespace snow {
+ struct LexerLocation {
+ uint32_t line;
+ uint32_t column;
+ };
+
struct ASTNode;
struct ASTBase {
@@ -63,8 +68,7 @@ namespace snow {
struct { ASTNode *cond, *body; } loop;
struct { ASTNode *cond, *body, *else_body; } if_else;
};
- uint32_t line;
- uint32_t column;
+ LexerLocation location;
};
}
@@ -184,8 +184,7 @@ namespace snow {
ASTNode* n = _heap.alloc();
n->type = type;
n->next = NULL;
- n->line = loc.line;
- n->column = loc.column;
+ n->location = loc;
return n;
}
@@ -13,10 +13,8 @@
struct unw_cursor_t;
namespace snow {
- struct SourceLocation {
+ struct SourceLocation : LexerLocation {
uint32_t code_offset;
- uint32_t line;
- uint32_t column;
};
struct SourceFile {
View
@@ -3,16 +3,12 @@
#define LEXER_HPP_S9CRBPS5
#include "snow/basic.h"
+#include "snow/ast.hpp"
#include "linkbuffer.hpp"
#include <string>
namespace snow {
- struct LexerLocation {
- uint32_t line;
- uint32_t column;
- };
-
struct Token {
enum Type {
#define TOKEN(X) X,
@@ -28,7 +24,7 @@ namespace snow {
Token(Type t, const char* begin, size_t len, int lineno, const char* line_begin) : type(t), length(len), line_begin(line_begin) {
location.line = lineno;
- location.column = begin - line_begin;
+ location.column = begin - line_begin + 1;
}
Token(const Token& other) : type(other.type), length(other.length), location(other.location), line_begin(other.line_begin) {}
};
View
@@ -15,7 +15,7 @@
#include <vector>
#include <utility>
-#define GET_TOKEN_SZ(SZ, TOKEN) char* SZ = (char*)alloca((TOKEN)->length+1); memcpy(SZ, (TOKEN)->line_begin + (TOKEN)->location.column, (TOKEN)->length); (SZ)[(TOKEN)->length] = '\0'
+#define GET_TOKEN_SZ(SZ, TOKEN) char* SZ = (char*)alloca((TOKEN)->length+1); memcpy(SZ, (TOKEN)->line_begin + (TOKEN)->location.column-1, (TOKEN)->length); (SZ)[(TOKEN)->length] = '\0'
#define FIRST_MATCH(BLOCK) do BLOCK while(0)
#define MATCH(RULE) { Pos p = pos; ASTNode* r = RULE(p); if (r) { result = r; pos = p; break; } }
@@ -1031,8 +1031,8 @@ namespace x86_64 {
ASSERT(offset <= UINT32_MAX);
SourceLocation location;
location.code_offset = offset;
- location.line = node->line;
- location.column = node->column;
+ location.line = node->location.line;
+ location.column = node->location.column;
// Try to not record more locations than necessary.
if (source_locations.size()) {

0 comments on commit 639dbb2

Please sign in to comment.