Пример #1
0
void
openGL_function_info::
SetNames(const string &functionName,
         const string &returnType,
         string &argList)
{
  argIterType i;
  string::size_type comma_place,last_comma_place;
  string::size_type start,end;
  ostringstream argListWithNames,argListWithoutNames,argListOnly;
  string tempString,arg;
  int j;

  m_functionName=RemoveWhiteSpace(functionName);


  if(returnType.length()!=0)
    {
      start=returnType.find_first_not_of(' ');
      end=returnType.find_last_not_of(' ');
      m_returnType=returnType.substr(start,end-start+1);
    }
  else
    {
      m_returnType="";
    }

  m_returnsValue=(m_returnType!="void") && (m_returnType!="GLvoid");

  m_pointerToFunctionTypeName="PFN"+m_functionName+"PROC";
  for(j=0;j<(int)m_pointerToFunctionTypeName.length();++j)
    {
      m_pointerToFunctionTypeName[j]=toupper(m_pointerToFunctionTypeName[j]);
    }


  if(argList!="void" && argList!="GLvoid")
    {
      argList=argList;
    }
  else
    {
      argList="";
    }

  //if argList is non-empy it may have one or more argument lists.
  last_comma_place=argList.find_first_of(',');
  if(last_comma_place!=string::npos)
    {

      arg=argList.substr(0,last_comma_place);
      GetTypeAndNameFromArgumentEntry(arg,tempString);
      m_argTypes.push_back(pair<string,string>(tempString,arg));

      //argList has atleast 2 arguments
      last_comma_place++;

      //now last_command_place is at the location just past the first comma.
      for(j=1, comma_place=argList.find_first_of(',',last_comma_place);
          comma_place!=string::npos && comma_place<argList.length();
          comma_place=argList.find_first_of(',',last_comma_place), ++j)
        {
          //add to the end all that was between
          //last_comma_place and comma_place.
          arg=argList.substr(last_comma_place,comma_place-last_comma_place);
          GetTypeAndNameFromArgumentEntry(arg, tempString);
          m_argTypes.push_back(pair<string,string>(tempString,arg));

          last_comma_place=comma_place+1;
        }
      //now there is also the last argument...
      arg=argList.substr(last_comma_place);
      GetTypeAndNameFromArgumentEntry(arg,tempString);
      m_argTypes.push_back(pair<string,string>(tempString,arg));




    }
  else if(argList.size()!=0)
    {
      GetTypeAndNameFromArgumentEntry(argList,tempString);
      m_argTypes.push_back(pair<string,string>(tempString,argList));
    }



  //now go through the list of argtype to
  //build our argument lsit with and without names
  for(j=0, i=m_argTypes.begin();i!=m_argTypes.end();++i, ++j)
    {
      if(j!=0)
        {
          argListWithNames <<",";
          argListWithoutNames <<",";
          argListOnly<<",";
        }

      argListWithNames << i->first << " " << argument_name() << j;
      argListWithoutNames << i->first;
      argListOnly << " " << argument_name() << j;
    }

  m_argListWithNames=argListWithNames.str();
  m_argListWithoutNames=argListWithoutNames.str();
  m_argListOnly=argListOnly.str();

  m_functionPointerName=sm_function_prefix+"function_ptr_"+m_functionName;
  m_debugFunctionName=sm_function_prefix+"debug_function__"+m_functionName;
  m_localFunctionName=sm_function_prefix+"local_function_"+m_functionName;
  m_doNothingFunctionName=sm_function_prefix+"do_nothing_function_"+m_functionName;
  m_existsFunctionName=sm_function_prefix+"exists_function_"+m_functionName;
  m_getFunctionName=sm_function_prefix+"get_function_ptr_"+m_functionName;
}
Пример #2
0
void
openGL_function_info::
output_to_header(ostream &headerFile)
{

  if(!m_newDeclaration)
    {
      //      cerr << "Warning: " << function_name() << " in list twice not putting into header file!\n";
      return;
    }

  headerFile << "\ntypedef  " << return_type() << "( APIENTRY* " << function_pointer_type()
             << " )("   << full_arg_list_withoutnames() << ");\n";

  headerFile << "extern " << function_pointer_type() << " "
             << function_pointer_name() << ";\n";

  if(m_use_function_pointer)
    {
      headerFile << "int " << m_existsFunctionName << "(void);\n"
                 << function_pointer_type() << " " << m_getFunctionName << "(void);\n";
    }
  else
    {
      headerFile << "inline int " << m_existsFunctionName << "(void) { return 1; }\n"
                 << "inline " << function_pointer_type() << " " << m_getFunctionName
                 << "(void) { return " << m_functionName << "; }\n";
    }
  headerFile << "#ifdef GL_DEBUG\n";
  headerFile << return_type() << " " << debug_function_name() << "(";

  if(number_arguments()!=0)
    {
      headerFile << full_arg_list_with_names() << ", " ;
    }
  headerFile << "const char *file, int line, const char *call";

  for(int i=0;i<number_arguments();++i)
    {
      headerFile << ", const char *argumentName_" << i;
    }
  headerFile << ");\n"
             << "#define "  << function_name()
             << "(" << argument_list_names_only()
             << ") " << sm_namespace << "::" << debug_function_name()  << "(";

  if(number_arguments()!=0)
    {
      headerFile << argument_list_names_only() << "," ;
    }

  headerFile << " __FILE__, __LINE__, \"" << function_name() << "(\"";

  for(int i=0;i<number_arguments();++i)
    {
      if(i!=0)
        headerFile << "\",\"";
      headerFile << "#" << argument_name() << i;
    }
  headerFile << "\")\"";
  for(int i=0;i<number_arguments();++i)
    {
      headerFile << ", #" <<  argument_name() << i;
    }


  headerFile << ")\n"
             << "#else\n" << "#define " << function_name() << "(" << argument_list_names_only()
             << ") "
             << sm_namespace << "::" << function_pointer_name() <<  "(" << argument_list_names_only()
             << ")\n#endif\n\n";



}
Пример #3
0
static void
  add_typedesc (Type t, struct buffer_s *data, /* OUT */ list referenced)
{
  unsigned int i, j;
  Argument arg;
  EnumField ef;
  Exception exn;
  Class obj;
  Procedure meth;
  struct ilu_integerLiteral_s lit;

  printmToBuffer (data, "(type %s %s ",
		  t->builtIn ? "ilu" : interface_name(type_interface(t)),
		  type_name(t));

  add_quoted_string(t->brand, data);
  switch (type_basic_type(t))
    {
    case array_Type:
      print0ToBuffer (data, " (array ");
      add_typeref (type_description(t)->structuredDes.array.type, data, referenced);
      for (i = 0;  i < list_size(type_description(t)->structuredDes.array.dimensions);  i++) {
	printmToBuffer (data, " (fixed %lu)",
			(unsigned) list_ref(type_description(t)->structuredDes.array.dimensions, i));
      }
      print0ToBuffer (data, ")");
      break;

    case sequence_Type:
      print0ToBuffer (data, " (sequence ");
      add_typeref (type_description(t)->structuredDes.sequence.type, data, referenced);
      printmToBuffer (data, " (variable %lu))",
		      (type_description(t)->structuredDes.sequence.limit == 0) ? 0xFFFFFFFF : ((unsigned long) type_description(t)->structuredDes.sequence.limit));
      break;

    case record_Type:
      print0ToBuffer (data, " (record");
      for (i = 0;  i < list_size(type_description(t)->structuredDes.record.fields); i++) {
	printmToBuffer (data, " (field %s ", argument_name((Argument) list_ref(type_description(t)->structuredDes.record.fields, i)));
	add_typeref (argument_type((Argument) list_ref(type_description(t)->structuredDes.record.fields, i)), data, referenced);
	print0ToBuffer (data, ")");
      };
      print0ToBuffer (data, ")");
      break;
      
    case optional_Type:
      print0ToBuffer (data, " (optional ");
      add_typeref (type_description(t)->structuredDes.optional, data, referenced);
      print0ToBuffer (data, ")");
      break;

    case reference_Type:
      print0ToBuffer (data, " (reference ");
      add_typeref (type_description(t)->structuredDes.reference.base_type, data, referenced);
      printmToBuffer (data, " (optional %s)",
		      type_description(t)->structuredDes.reference.optional ? "true" : "false");
      printmToBuffer (data, " (aliased %s)",
		      type_description(t)->structuredDes.reference.aliased ? "true" : "false");
      print0ToBuffer (data, ")");
      break;

    case union_Type:
      print0ToBuffer (data, " (union ");
      add_typeref (type_description(t)->structuredDes.uniond.discriminator_type, data, referenced);
      for (i = 0;  i < list_size(type_description(t)->structuredDes.uniond.types); i++) {
	arg = (Argument) list_ref(type_description(t)->structuredDes.uniond.types, i);
	print0ToBuffer (data, " (arm ");
	add_typeref (argument_type(arg), data, referenced);
	if (argument_name(arg) != NULL)
	  printmToBuffer (data, "(name %s) ", argument_name(arg));
	printmToBuffer (data, "(%s)",
			(arg == type_description(t)->structuredDes.uniond.default_arm) ? "default" : "");
	for (j = 0;  j < list_size(arg->values);  j++) {
	  print0ToBuffer(data, "(val");
	  add_constant (list_ref(arg->values, j), data);
	  print0ToBuffer(data, ")");
	}
	print0ToBuffer (data, ")");
      }
      if (type_description(t)->structuredDes.uniond.others_allowed)
	print0ToBuffer (data, " ((default) void)");
      print0ToBuffer (data, ")");
      break;

    case enumeration_Type:
      print0ToBuffer (data, " (enumeration");
      for (i = 0;  i < list_size(type_description(t)->structuredDes.enumeration);  i++) {
	ef = (EnumField) list_ref(type_description(t)->structuredDes.enumeration, i);
	printmToBuffer (data, " (element %s %d)", ef->name, ef->id);
      }
      print0ToBuffer (data, ")");
      break;

    case fixedpoint_Type:
      print0ToBuffer (data, " (fixedpoint ");
      add_integer_literal (type_description(t)->structuredDes.fixed.min_numerator, data);
      print0ToBuffer (data, " ");
      add_integer_literal (type_description(t)->structuredDes.fixed.max_numerator, data);
      print0ToBuffer (data, " ");
      lit = *type_description(t)->structuredDes.fixed.denominator;
      if (lit.negative) {
	lit.negative = FALSE;
	print0ToBuffer (data, "1/");
      }
      add_integer_literal (&lit, data);
      print0ToBuffer (data, ")");
      break;

    case string_Type:
      printmToBuffer (data, " (string %lu \"%s\" %u)",
		      type_description(t)->structuredDes.string.max_length,
		      ((type_description(t)->structuredDes.string.language != 0)
		       ? type_description(t)->structuredDes.string.language : ""),
		      type_description(t)->structuredDes.string.charset);
      break;

    case object_Type:
      obj = class_object(t);
      print0ToBuffer (data, " (object");
      if (obj->singleton != NULL)
	printmToBuffer (data, " (singleton \"%s\")", obj->singleton);
      if (obj->optional)
	print0ToBuffer (data, " optional");
      if (obj->collectible)
	print0ToBuffer (data, " collectible");
      for (i = 0;  i < list_size(obj->superclasses);  i++) {
	print0ToBuffer (data, " (supertype ");
	add_typeref ((Type) list_ref(obj->superclasses, i), data, referenced);
	print0ToBuffer (data, ")");
      }
      for (i = 0;  i < list_size(obj->methods); i++) {
	meth = (Procedure) list_ref(obj->methods, i);
	printmToBuffer (data, " (method %s %s%s(returns",
			name_base_name(meth->name),
			meth->asynch ? "asynchronous " : "",
			meth->functional ? "functional " : "");
	if (meth->returnType != NULL && (type_ur_kind(meth->returnType) != void_Type)) {
	  print0ToBuffer (data, " ");
	  add_typeref (meth->returnType, data, referenced);
	} else {
	  print0ToBuffer (data, " void");
	}
	for (j = 0;  j < list_size(meth->exceptions);  j++) {
	  print0ToBuffer (data, " ");
	  exn = (Exception) list_ref(meth->exceptions, j);
	  add_exnref (exn, data, referenced);
	}
	print0ToBuffer (data, ")");
	for (j = 0;  j < list_size(meth->arguments);  j++) {
	  arg = (Argument) list_ref(meth->arguments, j);
	  printmToBuffer (data, " (parameter %s %s ", argument_name(arg), argument_direction(arg));
	  add_typeref (argument_type(arg), data, referenced);
	  if (arg->sibling)
	    print0ToBuffer (data, " sibling");
	  print0ToBuffer(data, ")");
	}
	print0ToBuffer (data, ")");
      }
      print0ToBuffer (data, ")");
      break;

    case alias_Type:
      print0ToBuffer (data, " (redef ");
      add_typeref(under_type(t), data, referenced);
      printmToBuffer (data, " \"%s\")", type_uid(t));
      break;

    default:
      break;
    }
  print0ToBuffer (data, ")");
}