File: OffsetSource.h

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 (82 lines) | stat: -rw-r--r-- 2,132 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
72
73
74
75
76
77
78
79
80
81
82
#pragma once
#include "Core/TObject.h"
#include "Core/WeakSet.h"
#include "Size.h"

namespace code {
	STORM_PKG(core.asm);

	class OffsetReference;

	/**
	 * A RefSource that provides an offset rather than a pointer.
	 *
	 * The main reason the two are kept separate is to make sure that pointer-references are not
	 * accidentally treated as offset-references, thus causing confusion for the garbage collector
	 * (one needs to be scanned, the other does not). Furthermore, we allow for offset-references to
	 * not refer to anything (they are simply zero), while pointer-references are not.
	 *
	 * Additionally, OffsetRefSource objects do not have a Content, since they are simply an
	 * offset. These offsets may not refer other things, as is the case with pointer-references.
	 */
	class OffsetSource : public ObjectOn<Compiler> {
		STORM_ABSTRACT_CLASS;
		friend class OffsetReference;
	public:
		STORM_CTOR OffsetSource();
		STORM_CTOR OffsetSource(Offset offset);

		// Set the offset.
		void STORM_FN set(Offset offset);

		// Make it so that all references in 'from' refers to this instance instead. Keeps 'from'
		// updated until there are no more 'Ref's referring to it (Reference instances are updated
		// immediately).
		void STORM_FN steal(OffsetSource *from);

		// Get the current offset.
		Offset offset() const;

		// Get our title.
		virtual Str *STORM_FN title() const ABSTRACT;

		// Force update.
		void update();

		// Get actual source, in case content was stolen.
		OffsetSource *STORM_FN findActual();

	protected:
		// Output.
		virtual void STORM_FN toS(StrBuf *to) const;

	private:
		// Data.
		Offset data;

		// All non-Ref references referring to this source.
		WeakSet<OffsetReference> *refs;

		// References stolen by.
		OffsetSource *stolenBy;
	};

	/**
	 * String-labeled OffsetSource.
	 */
	class StrOffsetSource : public OffsetSource {
		STORM_CLASS;
	public:
		StrOffsetSource(const wchar *name);
		STORM_CTOR StrOffsetSource(Str *name);
		STORM_CTOR StrOffsetSource(Str *name, Offset offset);

		// Title.
		virtual Str *STORM_FN title() const;

	private:
		// Name.
		Str *name;
	};

}