File: Breakable.h

package info (click to toggle)
storm-lang 0.7.4-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • 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 (93 lines) | stat: -rw-r--r-- 2,066 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
#pragma once
#include "Block.h"

namespace storm {
	namespace bs {
		STORM_PKG(lang.bs);

		/**
		 * A block we can run break- and continue- statements inside, such as loops.
		 */
		class Breakable : public Block {
			STORM_ABSTRACT_CLASS;
		public:
			STORM_CTOR Breakable(SrcPos pos, Scope scope);
			STORM_CTOR Breakable(SrcPos pos, Block *parent);

			// Call to notify this block that we will perform a 'break' at some point.
			virtual void STORM_FN willBreak() ABSTRACT;

			// Call to notify this block that we will perform a 'continue' at some point.
			virtual void STORM_FN willContinue() ABSTRACT;

			// State describing where to jump to on break- and continue statements.
			class To {
				STORM_VALUE;
			public:
				To(code::Label lbl, code::Block block);

				code::Label label;
				code::Block block;
			};

			// Get where to jump on a 'break'. Call during codegen.
			virtual To STORM_FN breakTo() ABSTRACT;

			// Get where to jump on a 'continue'. Call during codegen.
			virtual To STORM_FN continueTo() ABSTRACT;
		};


		/**
		 * Break expression.
		 */
		class Break : public Expr {
			STORM_CLASS;
		public:
			STORM_CTOR Break(SrcPos pos, Block *parent);

			// Result.
			virtual ExprResult STORM_FN result();

			// Generate code.
			virtual void STORM_FN code(CodeGen *state, CodeResult *r);

			// Don't need to isolate this statement.
			virtual Bool STORM_FN isolate();

			// To string.
			virtual void STORM_FN toS(StrBuf *to) const;

		private:
			// Block we will break out of.
			Breakable *breakFrom;
		};


		/**
		 * Continue expression.
		 */
		class Continue : public Expr {
			STORM_CLASS;
		public:
			STORM_CTOR Continue(SrcPos pos, Block *parent);

			// Result.
			virtual ExprResult STORM_FN result();

			// Generate code.
			virtual void STORM_FN code(CodeGen *state, CodeResult *r);

			// Don't need to isolate this statement.
			virtual Bool STORM_FN isolate();

			// To string.
			virtual void STORM_FN toS(StrBuf *to) const;

		private:
			// Block we will continue in.
			Breakable *continueIn;
		};

	}
}