File: VTableSlot.cpp

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,004 kB
  • sloc: ansic: 261,462; cpp: 140,405; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (71 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download | duplicates (2)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "stdafx.h"
#include "VTableSlot.h"
#include "VTableCpp.h"
#include "Core/StrBuf.h"

namespace storm {

	VTableSlot::VTableSlot() : type(tNone), offset(0) {}

	VTableSlot::VTableSlot(VType t, Nat offset) : type(t), offset(offset) {
		if (offset == vtable::invalid)
			type = tNone;
	}

	Bool VTableSlot::operator ==(VTableSlot o) const {
		if (type != o.type)
			return false;

		switch (type) {
		case tNone:
			return true;
		case tStorm:
		case tCpp:
			return offset == o.offset;
		default:
			// Something is wrong...
			return false;
		}
	}

	VTableSlot cppSlot(Nat offset) {
		return VTableSlot(VTableSlot::tCpp, offset);
	}

	VTableSlot stormSlot(Nat offset) {
		return VTableSlot(VTableSlot::tStorm, offset);
	}


	wostream &operator <<(wostream &to, const VTableSlot &pos) {
		switch (pos.type) {
		case VTableSlot::tNone:
			to << L"invalid";
			return to;
		case VTableSlot::tStorm:
			to << L"storm";
			break;
		case VTableSlot::tCpp:
			to << L"c++";
			break;
		}
		to << L":" << pos.offset;
		return to;
	}

	void VTableSlot::toS(StrBuf *to) const {
		switch (type) {
		case VTableSlot::tNone:
			*to << S("invalid");
			return;
		case VTableSlot::tStorm:
			*to << S("storm");
			break;
		case VTableSlot::tCpp:
			*to << S("c++");
			break;
		}
		*to << S(":") << offset;
	}

}