File: NamedThread.cpp

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; 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 (49 lines) | stat: -rw-r--r-- 1,216 bytes parent folder | download
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
#include "stdafx.h"
#include "NamedThread.h"
#include "NamedSource.h"
#include "Core/Thread.h"
#include "Core/StrBuf.h"

namespace storm {

	NamedThread::NamedThread(SrcPos pos, Str *name) : Named(pos, name) {
		myThread = new (this) Thread();
	}

	NamedThread::NamedThread(syntax::SStr *name) : Named(name->pos, name->v) {
		myThread = new (this) Thread();
	}

	NamedThread::NamedThread(Str *name, Thread *thread) : Named(name), myThread(thread) {}

	code::Ref NamedThread::ref() {
		if (!reference) {
			reference = new (this) NamedSource(this);
			reference->setPtr(myThread);
		}
		return code::Ref(reference);
	}

	void NamedThread::toS(StrBuf *to) const {
		*to << L"thread " << identifier();
	}

	MAYBE(Str *) NamedThread::canReplace(Named *old, ReplaceContext *) {
		if (!as<NamedThread>(old))
			return new (this) Str(S("Cannot replace anything other than a thread with a thread."));
		else
			return null;
	}

	void NamedThread::doReplace(Named *old, ReplaceTasks *tasks, ReplaceContext *) {
		NamedThread *t = (NamedThread *)old;

		// Steal the references.
		myThread = t->myThread;
		reference = t->reference;

		// Make sure the new thread object is used everywhere.
		tasks->replace(old, this);
	}

}