File: ReplaceContext.h

package info (click to toggle)
storm-lang 0.7.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,100 kB
  • sloc: ansic: 261,471; cpp: 140,438; 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 (56 lines) | stat: -rw-r--r-- 1,481 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
50
51
52
53
54
55
56
#pragma once
#include "Thread.h"
#include "Value.h"
#include "Core/Set.h"

namespace storm {
	STORM_PKG(core.lang);

	class Named;
	class NameSet;
	class Function;

	/**
	 * An object encapsulating various state that is required while reloading code.
	 *
	 * More specifically:
	 * - An equivalence relation between new and old types.
	 */
	class ReplaceContext : public ObjectOn<Compiler> {
		STORM_CLASS;
	public:
		// Create.
		STORM_CTOR ReplaceContext();

		// Are the two types actually the same?
		Bool STORM_FN same(Type *a, Type *b);

		// Normalize types and/or values.
		Type *STORM_FN normalize(Type *t);
		Value STORM_FN normalize(Value v);

		// Add a type that is equivalent to another.
		void STORM_FN addEquivalence(Type *oldType, Type *newType);

		// Build the type equivalence from two NameSets.
		void STORM_FN buildTypeEquivalence(NameSet *oldRoot, NameSet *newRoot);

		// Get all new types in here.
		Set<Type *> *STORM_FN allNewTypes();

	private:
		// Equivalence relation of types (new type -> old type).
		Map<Type *, Type *> *typeEq;

		// Current old root used when building a type equivalence. Used as an indicator for that situation.
		MAYBE(NameSet *) currentOldRoot;

		// Recursive helper for building 'typeEq'.
		void buildTypeEqRec(NameSet *currOld, NameSet *currNew);

		// Resolve parameters during type equivalence.
		Array<Value> *resolveParams(NameSet *root, Array<Value> *params);
		Value resolveParam(NameSet *root, Value param);
	};

}