00001 #include "stdafx.h"
00002
00003 #include "BON.h"
00004 #include "BONImpl.h"
00005
00006 #include "ConstraintFuncRep.h"
00007 #include "Regexp.h"
00008
00009 #include "globals.h"
00010 extern Globals global_vars;
00011
00012
00013 ConstraintFuncRep::ConstraintFuncRep( BON::FCO& ptr)
00014 : Any( ptr),
00015 m_context(""), m_returntype(""), m_stereotype(""),
00016 m_definition(""), m_parameterlist("")
00017 {
00018 }
00019
00020 void ConstraintFuncRep::fetch()
00021 {
00022 CString strWS = "[\t ]*";
00023 CString strID = "[_a-zA-Z][_a-zA-Z0-9]*";
00024 CString strT = strID + "(::" + strID + ")*";
00025 CString strP = strID + strWS + ":" + strWS + strT;
00026
00027 std::string paramlist = m_ptr->getAttribute( "CFuncParamList")->getStringValue();
00028 Regexp rePL( "^(" + strWS + strP + ")?" + "(" + strWS + "," + strWS + strP + ")*$", TRUE );
00029 if ( ! rePL.CompiledOK() )
00030 global_vars.err << MSG_ERROR << "Internal Interpreter Error: [REGEXP] " << rePL.GetErrorString() << "\n";
00031 else
00032 if ( ! rePL.Match( paramlist.c_str() ) )
00033 global_vars.err << MSG_ERROR << "Invalid format for parameterlist in Constraint Function: " << m_ptr
00034 << "\nCorrect format: <paramname> : <paramtype> [, <paramname> : <paramtype>] ...\n";
00035
00036 m_parameterlist = paramlist;
00037
00038 std::string contexttype = m_ptr->getAttribute( "CFuncContext")->getStringValue();
00039 if ( contexttype.empty() )
00040 {
00041 global_vars.err << MSG_ERROR << "No context found for Constraint Function: " << m_ptr << ". It will be Project implicitly.\n";
00042 contexttype = "gme::Project";
00043 }
00044 m_context = contexttype;
00045 bool modify = false;
00046 if( modify && m_ptr->isInLibrary() && !m_namespace.empty())
00047 {
00048 if( m_context.substr(0, 6) == "meta::" && m_context.substr( 6).find( "::") == std::string::npos)
00049 {
00050 m_context.insert( 6, Any::NamespaceDelimiter_str);
00051 m_context.insert( 6, m_namespace);
00052 }
00053 }
00054
00055 std::string returntype = m_ptr->getAttribute( "CFuncReturnType")->getStringValue();
00056 if ( returntype.empty())
00057 {
00058 global_vars.err << MSG_ERROR << "No return type found for Constraint Function: " << m_ptr << ". It will be bool implicitly.\n";
00059 returntype = "ocl::Boolean";
00060 }
00061 m_returntype = returntype;
00062
00063 std::string definition = m_ptr->getAttribute( "CFuncDefinition")->getStringValue();
00064 if ( definition.empty() )
00065 global_vars.err << MSG_ERROR <<"No definition found for Constraint Function: " << m_ptr << ".\n";
00066 m_definition = definition;
00067
00068 std::string stereotype = m_ptr->getAttribute( "CFuncStereotype")->getStringValue();
00069 if ( stereotype == "attribute" && ! paramlist.empty())
00070 {
00071 global_vars.err << MSG_ERROR << "Attribute cannot have parameters. Parameterlist is ignored for Constraint Function: " << m_ptr << ".\n";
00072 paramlist.empty();
00073 }
00074 m_stereotype = stereotype;
00075
00076
00077 m_defdForNamesp = m_namespace;
00078 }
00079
00080 std::string ConstraintFuncRep::getName() const
00081 {
00082 ASSERT( m_ptr);
00083 return m_ptr->getName();
00084 }
00085
00086 std::string ConstraintFuncRep::doDump()
00087 {
00088 fetch();
00089 std::string mmm = "";
00090
00091 mmm += indStr() + "<constraint type=\"function\" name=\"" + getName() + "\"";
00095 if( !m_defdForNamesp.empty() && m_ptr && m_ptr->isInLibrary()) mmm+= " defdfornamesp = \"" + m_defdForNamesp + "\"";
00096 mmm += ">\n";
00097 ++ind;
00098 mmm += indStr() + "<![CDATA["
00099 + m_stereotype + ";" + m_context + ";"
00100 + m_parameterlist + ";" + m_returntype + ";\n";
00101 mmm += indStr() + m_definition + "]]>\n";
00102 --ind;
00103 mmm += indStr() + "</constraint>\n";
00104
00105 return mmm;
00106 }