5 /* Includes the header in the wrapper code */
6 #include <ycp/YCPCode.h>
7 #include <ycp/YCPElement.h>
8 #include <ycp/YCPExternal.h>
9 #include <ycp/YCPValue.h>
10 #include <ycp/YCPBoolean.h>
11 #include <ycp/YCPList.h>
12 #include <ycp/YCPMap.h>
13 #include <ycp/YCPString.h>
14 #include <ycp/YCPInteger.h>
15 #include <ycp/YCPFloat.h>
17 #include <y2/Y2ComponentBroker.h>
18 #include <y2/Y2Namespace.h>
19 #include <y2/Y2Component.h>
20 #include <y2/Y2Function.h>
21 #include <y2/SymbolEntry.h>
22 #include <y2util/Ustring.h>
25 #include <ycp/Import.h>
27 #include <ycp/pathsearch.h>
29 #define y2log_component "Y2Ruby"
31 //static swig_type_info _swigt__p_YCPValue;
39 %rename("+") "operator+";
40 %rename("<<") "operator<<";
41 %rename("!=") "operator!=";
42 %rename("!") "operator!";
43 %rename("==") "operator==";
45 %typemap(in) int YCPValue {
46 // TODO conver integers, and add support for lists, ah, and boleans!
50 $result = YCPString(RSTRING ($1)->ptr);
53 $result = YCPBoolean(true);
56 $result = YCPBoolean(false);
59 $result = YCPInteger(NUM2LONG($1));
62 $result = YCPFloat(NUM2DBL($1));
71 rb_raise( rb_eRuntimeError, "Object");
74 std::cout << TYPE($1) << std::endl;
75 rb_raise( rb_eRuntimeError, "Conversion of Ruby type not supported");
79 %typemap(out) YCPValue {
81 // YT_BYTEBLOCK YT_PATH YT_SYMBOL YT_LIST YT_TERM YT_MAP YT_CODE YT_RETURN YT_BREAK YT_ENTRY YT_ERROR YT_REFERENCE YT_EXTERNA
86 else if($1->isBoolean())
88 $result = $1->asBoolean()->value() ? Qtrue : Qfalse;
90 else if($1->isString())
92 $result = rb_str_new2($1->asString()->value().c_str());
94 else if($1->isInteger())
96 $result = INT2NUM( $1->asInteger()->value() );
98 else if( $1->isMap() )
101 rbhash = rb_hash_new();
102 YCPMap map = $1->asMap();
103 printf("map size %d\n", map.size());
105 for ( YCPMapIterator it = map.begin(); it != map.end(); ++it )
107 YCPValue *key = new YCPValue(it.key());
108 YCPValue *value = new YCPValue(it.value());
109 VALUE rkey = SWIG_NewPointerObj(key, SWIGTYPE_p_YCPValue, 1);
110 VALUE rvalue = SWIG_NewPointerObj(value, SWIGTYPE_p_YCPValue, 1);
111 rb_hash_aset(rbhash, rkey, rvalue );
115 else if($1->isList())
118 rblist = rb_ary_new();
119 YCPList list = $1->asList();
120 printf("list size %d\n",list.size());
121 for (int i=0; i < list.size(); i++)
123 YCPValue *value = new YCPValue(list.value(i));
124 VALUE rvalue = SWIG_NewPointerObj(value, SWIGTYPE_p_YCPValue, 1);
125 rb_ary_push( rblist, rvalue);
129 rb_raise( rb_eRuntimeError, "Conversion of YCP type %s not supported", $1->toString().c_str() );
133 //%include "y2util/RepDef.h"
134 %include "y2/Y2ComponentBroker.h"
135 %include "y2/Y2Namespace.h"
136 %include "y2/Y2Component.h"
137 %include "y2/Y2Function.h"
139 %ignore SymbolEntryPtr::_nameHash;
140 %ignore SymbolEntry::emptyUstring;
145 //static UstringHash* _nameHash;
146 //static Ustring emptyUstring;
149 c_unspec = 0, // 0 unspecified local symbol (sets m_global = false)
150 c_global, // 1 unspecified global symbol (translates to c_unspec, sets m_global = true)
151 c_module, // 2 a module identifier
152 c_variable, // 3 a variable
153 c_reference, // 4 a reference to a variable
154 c_function, // 5 a defined function
155 c_builtin, // 6 a builtin function
156 c_typedef, // 7 a type
157 c_const, // 8 a constant (a read-only c_variable)
158 c_namespace, // 9 a namespace identifier
159 c_self, // 10 the current namespace (namespace prefix used in namespace definition)
160 c_predefined, // 11 a predefined namespace identifier
161 c_filename // 12 a filename (used in conjunction with TableEntry to store definition locations)
164 // create symbol beloging to namespace (at position)
165 SymbolEntry (const Y2Namespace* name_space, unsigned int position, const char *name, category_t cat, constTypePtr type);
167 virtual ~SymbolEntry ();
169 // symbols link to the defining namespace
170 const Y2Namespace *nameSpace () const;
171 void setNamespace (const Y2Namespace *name_space);
172 virtual bool onlyDeclared () const { return false; }
174 unsigned int position () const;
175 void setPosition (unsigned int position);
177 bool isGlobal () const;
178 void setGlobal (bool global);
180 bool isModule () const { return m_category == c_module; }
181 bool isVariable () const { return m_category == c_variable; }
182 bool isReference () const { return m_category == c_reference; }
183 bool isFunction () const { return m_category == c_function; }
184 bool isBuiltin () const { return m_category == c_builtin; }
185 bool isNamespace () const { return m_category == c_namespace; }
186 bool isSelf () const { return m_category == c_self; }
187 bool isFilename () const { return m_category == c_filename; }
188 bool isPredefined () const { return m_category == c_predefined; }
190 bool likeNamespace () const { return isModule() || isNamespace() || isSelf(); }
192 const char *name () const;
193 category_t category () const;
194 void setCategory (category_t cat);
195 constTypePtr type () const;
196 string catString () const;
197 void setType (constTypePtr type);
198 YCPValue setValue (YCPValue value);
199 YCPValue value () const;
204 virtual string toString (bool with_type = true) const;
207 template < typename T >
212 %template (SymbolEntryPtr) Ptr<SymbolEntry>;
214 %include "ycp/SymbolTable.h"
216 %include "ycp/Import.h"
217 %include "ycp/Type.h"
218 %include "ycp/TypePtr.h"