File: RefHandle.cpp

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (156 lines) | stat: -rw-r--r-- 4,718 bytes parent folder | download | duplicates (3)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "stdafx.h"
#include "RefHandle.h"
#include "Function.h"
#include "Engine.h"
#include "Utils/Memory.h"
#include "Code/Listing.h"

namespace storm {

	RefHandle::RefHandle(code::Content *content) : content(content) {}

	void RefHandle::setCopyCtor(code::Ref ref) {
		if (copyRef)
			copyRef->disable();
		copyRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, copyFn), ref, content);
	}

	void RefHandle::setCopyCtor(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		copyFn = (Handle::CopyFn)thunk->address();
	}

	void RefHandle::setDestroy(code::Ref ref) {
		if (destroyRef)
			destroyRef->disable();
		destroyRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, destroyFn), ref, content);
	}

	void RefHandle::setDestroy(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		destroyFn = (Handle::DestroyFn)thunk->address();
	}

	void RefHandle::setDeepCopy(code::Ref ref) {
		if (deepCopyRef)
			deepCopyRef->disable();
		deepCopyRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, deepCopyFn), ref, content);
	}

	void RefHandle::setDeepCopy(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		deepCopyFn = (Handle::DeepCopyFn)thunk->address();
	}

	void RefHandle::setToS(code::Ref ref) {
		if (toSRef)
			toSRef->disable();
		toSRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, toSFn), ref, content);
	}

	void RefHandle::setToS(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		toSFn = (Handle::ToSFn)thunk->address();
	}

	void RefHandle::setHash(code::Ref ref) {
		if (hashRef)
			hashRef->disable();
		hashRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, hashFn), ref, content);
	}

	void RefHandle::setHash(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		hashFn = (Handle::HashFn)thunk->address();
	}

	void RefHandle::setEqual(code::Ref ref) {
		if (equalRef)
			equalRef->disable();
		equalRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, equalFn), ref, content);
	}

	void RefHandle::setEqual(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		equalFn = (Handle::EqualFn)thunk->address();
	}

	void RefHandle::setLess(code::Ref ref) {
		if (lessRef)
			lessRef->disable();
		lessRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, lessFn), ref, content);
	}

	void RefHandle::setLess(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		lessFn = (Handle::LessFn)thunk->address();
	}

	void RefHandle::setSerializedType(code::Ref ref) {
		if (serializedTypeRef)
			serializedTypeRef->disable();
		serializedTypeRef = new (this) code::MemberRef(this, OFFSET_OF(RefHandle, serializedTypeFn), ref, content);
	}

	void RefHandle::setSerializedType(code::Binary *thunk) {
		if (copyRef)
			copyRef->disable();
		// No need to use references for this to work. The code and metadata is kept alive by just
		// storing a pointer in the appropriate variable:
		serializedTypeFn = (Handle::SerializedTypeFn)thunk->address();
	}

	template <class T>
	static Nat wrapHash(const void *obj) {
		const T *&o = *(const T **)obj;
		return o->hash();
	}

	template <class T>
	static Bool wrapEquals(const void *a, const void *b) {
		const T *&oa = *(const T **)a;
		const T *&ob = *(const T **)b;
		return *oa == *ob;
	}

	template <class T>
	static Bool wrapLess(const void *a, const void *b) {
		const T *&oa = *(const T **)a;
		const T *&ob = *(const T **)b;
		return *oa < *ob;
	}


	static void populateStr(Handle *h) {
		h->hashFn = &wrapHash<Str>;
		h->equalFn = &wrapEquals<Str>;
		h->lessFn = &wrapLess<Str>;
	}

	void populateHandle(Type *type, Handle *h) {
		Engine &e = type->engine;
		if (type == Str::stormType(e))
			populateStr(h);
	}
}