src/Variables.h

Sun, 09 Feb 2014 14:56:58 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Sun, 09 Feb 2014 14:56:58 +0200
changeset 101
9ffae10ef76f
parent 88
5def6ff8b466
permissions
-rw-r--r--

- variables: merged const and mutable variables into one system, added constexpr variable support. still no locals

88
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 Copyright 2012-2014 Santeri Piippo
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. The name of the author may not be used to endorse or promote products
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 derived from this software without specific prior written permission.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 */
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #ifndef BOTC_VARIABLES_H
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 #define BOTC_VARIABLES_H
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include "Main.h"
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
101
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
34 class ExpressionValue;
88
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 class BotscriptParser;
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 struct ScriptVariable
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 {
101
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
39 enum EWritability
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
40 {
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
41 WRITE_Mutable, // normal read-many-write-many variable
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
42 WRITE_Const, // write-once const variable
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
43 WRITE_Constexpr, // const variable whose value is known to compiler
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
44 };
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
45
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
46 String name;
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
47 String statename;
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
48 EType type;
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
49 int index;
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
50 EWritability writelevel;
9ffae10ef76f - variables: merged const and mutable variables into one system, added constexpr variable support. still no locals
Teemu Piippo <crimsondusk64@gmail.com>
parents: 88
diff changeset
51 int value;
88
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 inline bool IsGlobal() const
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 return statename.IsEmpty();
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 }
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 };
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 extern List<ScriptVariable> g_GlobalVariables;
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 extern List<ScriptVariable> g_LocalVariables;
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 ScriptVariable* DeclareGlobalVariable (EType type, String name);
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 ScriptVariable* FindGlobalVariable (String name);
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
5def6ff8b466 - reformatting
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 #endif // BOTC_VARIABLES_H

mercurial