absyntax_utils/search_expression_type.cc
changeset 205 96d8b6e006f0
parent 202 da1a8186f86f
child 208 c72748a12ae3
child 257 90782e241346
--- a/absyntax_utils/search_expression_type.cc	Wed Sep 02 13:39:05 2009 +0200
+++ b/absyntax_utils/search_expression_type.cc	Wed Sep 02 14:05:27 2009 +0200
@@ -65,32 +65,48 @@
 /* A helper function... */
 bool search_expression_type_c::is_string_type(symbol_c *type_symbol) {
   if (type_symbol == NULL) {return true;}
-  if (typeid(*type_symbol) == typeid(string_type_name_c)) {return true;}
+  if (typeid(*type_symbol) == typeid(string_type_name_c))  {return true;}
   if (typeid(*type_symbol) == typeid(wstring_type_name_c)) {return true;}
   return false;
 }
 
 /* A helper function... */
+bool search_expression_type_c::is_literal_integer_type(symbol_c *type_symbol) {
+  if (type_symbol == NULL) {return true;}
+  if (typeid(*type_symbol) == typeid(integer_c))        {return true;}
+  if (typeid(*type_symbol) == typeid(binary_integer_c)) {return true;}
+  if (typeid(*type_symbol) == typeid(octal_integer_c))  {return true;}
+  if (typeid(*type_symbol) == typeid(hex_integer_c))    {return true;}
+  return false;
+}
+
+/* A helper function... */
 bool search_expression_type_c::is_integer_type(symbol_c *type_symbol) {
   if (type_symbol == NULL) {return true;}
-  if (typeid(*type_symbol) == typeid(sint_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(int_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(dint_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(lint_type_name_c)) {return true;}
+  if (typeid(*type_symbol) == typeid(sint_type_name_c))  {return true;}
+  if (typeid(*type_symbol) == typeid(int_type_name_c))   {return true;}
+  if (typeid(*type_symbol) == typeid(dint_type_name_c))  {return true;}
+  if (typeid(*type_symbol) == typeid(lint_type_name_c))  {return true;}
   if (typeid(*type_symbol) == typeid(usint_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(uint_type_name_c)) {return true;}
+  if (typeid(*type_symbol) == typeid(uint_type_name_c))  {return true;}
   if (typeid(*type_symbol) == typeid(udint_type_name_c)) {return true;}
   if (typeid(*type_symbol) == typeid(ulint_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(constant_int_type_name_c)) {return true;}
-  return false;
-}
-
+  return is_literal_integer_type(type_symbol);
+}
+
+/* A helper function... */
+bool search_expression_type_c::is_literal_real_type(symbol_c *type_symbol) {
+  if (type_symbol == NULL) {return true;}
+  if (typeid(*type_symbol) == typeid(real_c)) {return true;}
+  return false;
+}
+
+/* A helper function... */
 bool search_expression_type_c::is_real_type(symbol_c *type_symbol) {
   if (type_symbol == NULL) {return true;}
   if (typeid(*type_symbol) == typeid(real_type_name_c)) {return true;}
   if (typeid(*type_symbol) == typeid(lreal_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(constant_real_type_name_c)) {return true;}
-  return false;
+  return is_literal_real_type(type_symbol);
 }
 
 bool search_expression_type_c::is_num_type(symbol_c *type_symbol) {
@@ -104,8 +120,7 @@
   if (typeid(*type_symbol) == typeid(word_type_name_c)) {return true;}
   if (typeid(*type_symbol) == typeid(dword_type_name_c)) {return true;}
   if (typeid(*type_symbol) == typeid(lword_type_name_c)) {return true;}
-  if (typeid(*type_symbol) == typeid(constant_int_type_name_c)) {return true;}
-  return false;
+  return is_literal_integer_type(type_symbol);
 }
 
 bool search_expression_type_c::is_binary_type(symbol_c *type_symbol) {
@@ -117,12 +132,12 @@
 bool search_expression_type_c::is_same_type(symbol_c *first_type, symbol_c *second_type) {
   if (first_type == NULL || second_type == NULL) {return true;}
   if (typeid(*first_type) == typeid(*second_type)) {return true;}
-  if (is_integer_type(first_type) && (typeid(*second_type) == typeid(constant_int_type_name_c))) {return true;}
-  if ((typeid(*first_type) == typeid(constant_int_type_name_c) && is_integer_type(second_type))) {return true;}
-  if (is_binary_type(first_type) && (typeid(*second_type) == typeid(constant_int_type_name_c))) {return true;}
-  if ((typeid(*first_type) == typeid(constant_int_type_name_c) && is_binary_type(second_type))) {return true;}
-  if (is_real_type(first_type) && (typeid(*second_type) == typeid(constant_real_type_name_c))) {return true;}
-  if ((typeid(*first_type) == typeid(constant_real_type_name_c) && is_real_type(second_type))) {return true;}
+  if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return true;}
+  if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return true;}
+  if (is_binary_type(first_type) && is_literal_integer_type(second_type))  {return true;}
+  if (is_literal_integer_type(first_type) && is_binary_type(second_type))  {return true;}
+  if (is_real_type(first_type) && is_literal_real_type(second_type)) {return true;}
+  if (is_literal_real_type(first_type) && is_real_type(second_type)) {return true;}
   return false;
 }
 
@@ -131,18 +146,28 @@
   if (first_type == NULL) {return second_type;}
   if (second_type == NULL) {return first_type;}
   if (typeid(*first_type) == typeid(*second_type)) {return first_type;}
-  if (is_integer_type(first_type) && (typeid(*second_type) == typeid(constant_int_type_name_c))) {return first_type;}
-  if ((typeid(*first_type) == typeid(constant_int_type_name_c)) && is_integer_type(second_type)) {return second_type;}
-  if (is_binary_type(first_type) && (typeid(*second_type) == typeid(constant_int_type_name_c)))  {return first_type;}
-  if ((typeid(*first_type) == typeid(constant_int_type_name_c)) && is_binary_type(second_type)) {return second_type;}
-  if (is_real_type(first_type) && (typeid(*second_type) == typeid(constant_real_type_name_c))) {return first_type;}
-  if ((typeid(*first_type) == typeid(constant_real_type_name_c)) && is_real_type(second_type)) {return second_type;}
-  return NULL;
-}
-
+  if (is_integer_type(first_type) && is_literal_integer_type(second_type)) {return first_type;}
+  if (is_literal_integer_type(first_type) && is_integer_type(second_type)) {return second_type;}
+  if (is_binary_type(first_type) && is_literal_integer_type(second_type))  {return first_type;}
+  if (is_literal_integer_type(first_type) && is_binary_type(second_type))  {return second_type;}
+  if (is_real_type(first_type) && is_literal_real_type(second_type)) {return first_type;}
+  if (is_literal_real_type(first_type) && is_real_type(second_type)) {return second_type;}
+  return NULL;
+}
+
+
+integer_c search_expression_type_c::integer("1"); // what default value should we use here ???
 #define compute_standard_function_default search_expression_type_c::compute_standard_function_default
 #define compute_standard_function_il search_expression_type_c::compute_standard_function_il
+#define search(x) search_f(x)
+#define next() next_nf()
+//     #define search_constant_type_c::constant_int_type_name  search_expression_type_c::integer
+#define constant_int_type_name  integer
 #include "search_type_code.c"
+#undef constant_int_type_name
+//     #undef search_constant_type_c::constant_int_type_name
+#undef next
+#undef search
 #undef compute_standard_function_default
 #undef compute_standard_function_il
 
@@ -154,7 +179,7 @@
     ERROR;
   if (!is_bool_type(left_type) && !is_binary_type(left_type))
     ERROR;
-  if (typeid(*left_type) == typeid(constant_int_type_name_c)) {return (void *)right_type;}
+  if (is_literal_integer_type(left_type)) {return (void *)right_type;}
   else {return (void *)left_type;}
 }
 
@@ -164,7 +189,7 @@
     ERROR;
   if (!is_integer_type(left_type) && !is_real_type(left_type))
     ERROR;
-  if ((typeid(*left_type) == typeid(constant_int_type_name_c)) || (typeid(*left_type) == typeid(constant_real_type_name_c))) {return (void *)right_type;}
+  if (is_literal_integer_type(left_type) || is_literal_real_type(left_type)) {return (void *)right_type;}
   else {return (void *)left_type;}
   return NULL;
 }