summaryrefslogtreecommitdiff
path: root/src/source.cc
blob: d714f29c911ab83627cf991e35c363b5f492ddcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef SOURCE_CC
#define SOURCE_CC

#include "common.cc"
#include "memory.cc"

typedef u32 Source_Id;

struct Span {
  Source_Id id;
  usize start, end;

  Span(Source_Id id, usize start, usize end) : id(id), start(start), end(end) {} 
};

struct Buffer {
  String file;
  String content;
  Link link;
};

bool buffer_init(Buffer* buffer, const Allocator* allocator, const String* content_in, const String* file_in) {
  String content, file;
  bool ret = slice_copy(allocator, content_in, &content);
  if(unlikely(ret == false)) return false;
  
  ret = slice_copy(allocator, file_in, &file);
  if(unlikely(ret == false)) {
    slice_deallocate(allocator, &content);
    return false;
  }

  buffer->file = file;
  buffer->content = content;
  buffer->link = {};
  return true;
}

void buffer_deinit(Buffer* buffer, const Allocator* allocator) {
  slice_deallocate(allocator, &buffer->file);
  slice_deallocate(allocator, &buffer->content);
}

struct Buffer_Stack {
  Link* buffers;
  usize nbuffers;
};

#endif