322c66a92f28618398795a782aab600d03dafe88
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / tools / emugen / Var.h
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef __VAR__H__
17 #define __VAR__H__
18
19 #include "VarType.h"
20 #include <string>
21 #include <stdio.h>
22
23 class Var {
24 public:
25     // pointer data direction - from the client point of view.
26     typedef enum { POINTER_OUT = 0x1, POINTER_IN = 0x2, POINTER_INOUT = 0x3 } PointerDir;
27     Var() :
28         m_name(""),
29         m_type(NULL),
30         m_lenExpression(""),
31         m_pointerDir(POINTER_IN),
32         m_nullAllowed(false),
33         m_isLarge(false),
34         m_packExpression(""),
35         m_writeExpression(""),
36         m_paramCheckExpression("")
37
38     {
39     }
40
41     Var(const std::string & name,
42         const VarType * vartype,
43         const std::string & lenExpression,
44         PointerDir dir,
45         const std::string &packExpression,
46         const std::string &writeExpression) :
47         m_name(name),
48         m_type(const_cast<VarType *>(vartype)),
49         m_lenExpression(lenExpression),
50         m_pointerDir(dir),
51         m_nullAllowed(false),
52         m_isLarge(false),
53         m_packExpression(packExpression),
54         m_writeExpression(writeExpression),
55         m_paramCheckExpression("")
56     {
57     }
58
59     void init(const std::string name, const VarType * vartype,
60               std::string lenExpression,
61               PointerDir dir,
62               std::string packExpression,
63               std::string writeExpression) {
64         m_name = name;
65         m_type = vartype;
66         m_lenExpression = lenExpression;
67         m_packExpression = packExpression;
68         m_writeExpression = writeExpression;
69         m_pointerDir = dir;
70         m_nullAllowed = false;
71         m_isLarge = false;
72
73     }
74
75     const std::string & name() const { return m_name; }
76     const VarType * type() const { return m_type; }
77     bool isPointer() const { return m_type->isPointer(); }
78     bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); }
79     const std::string & lenExpression() const { return m_lenExpression; }
80     const std::string & packExpression() const { return(m_packExpression); }
81     const std::string & writeExpression() const { return(m_writeExpression); }
82     const std::string & paramCheckExpression() const { return m_paramCheckExpression; }
83     void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; }
84     void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; }
85     void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; }
86     void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; }
87     void setPointerDir(PointerDir dir) { m_pointerDir = dir; }
88     PointerDir pointerDir() { return m_pointerDir; }
89     void setNullAllowed(bool state) { m_nullAllowed = state; }
90     void setIsLarge(bool state) { m_isLarge = state; }
91     bool nullAllowed() const { return m_nullAllowed; }
92     bool isLarge() const { return m_isLarge; }
93     void printType(FILE *fp) { fprintf(fp, "%s", m_type->name().c_str()); }
94     void printTypeName(FILE *fp) { printType(fp); fprintf(fp, " %s", m_name.c_str()); }
95
96 private:
97     std::string m_name;
98     const VarType * m_type;
99     bool m_pointer; // is this variable a pointer;
100     std::string m_lenExpression; // an expression to calcualte a pointer data size
101     PointerDir m_pointerDir;
102     bool m_nullAllowed;
103     bool m_isLarge;
104     std::string m_packExpression; // an expression to pack data into the stream
105     std::string m_writeExpression; // an expression to write data into the stream
106     std::string m_paramCheckExpression; //an expression to check parameter value
107
108 };
109
110 #endif