📄 cimmofparser.cpp
字号:
// representing the corresponding decimal integer// ATTN: 2001 P1 BB Need to support 64-bit integers in string conversion// ATTN: 2001 P1 BB Needs to support non-ascii strings in string conversion// ------------------------------------------------------------------char *cimmofParser::hex_to_dec(const String &hexrep) const { unsigned long hval = 0; char buf[40]; // can't overrrun on an itoa of a long//The format of hexrep string is 0x[0-9A-Fa-f]+//E.g., 0x9FFF (hex) = 40959 (decimal) for (unsigned int i = 2; i <= hexrep.size() - 1; i++) { hval *= 16; switch(hexrep[i]) { case '1': hval += 1; break; case '2': hval += 2; break; case '3': hval += 3; break; case '4': hval += 4; break; case '5': hval += 5; break; case '6': hval += 6; break; case '7': hval += 7; break; case '8': hval += 8; break; case '9': hval += 9; break; case 'a': case 'A': hval += 10; break; case 'b': case 'B': hval += 11; break; case 'c': case 'C': hval += 12; break; case 'd': case 'D': hval += 13; break; case 'e': case 'E': hval += 14; break; case 'f': case 'F': hval += 15; break; } } sprintf(buf, "%ld", hval); // ltoa(hval, buf, 10); return strdup(buf);}// -----------------------------------------------------------------// Convert a String representing a binary integer to a String// representing the corresponding decimal integer// ATTN: P1 BB 2001 Need to support 64-bit integers in string conversion// ------------------------------------------------------------------char *cimmofParser::binary_to_dec(const String &binrep) const { signed long bval = 0; char buf[40]; // can't overrrun on an itoa of a long//The format of binrep string is [+-][01]+[Bb]//E.g., +01011b = 11 for (unsigned int i = 1; i <= binrep.size() - 2; i++) { bval *= 2; bval += (binrep[i] == '1' ? 1 : 0); } if (binrep[0] == '-') { bval = -bval; } sprintf(buf, "%ld", bval); return strdup(buf);} //------------------------------------------------------------------ // Handle the processing of CIM-specific constructs //------------------------------------------------------------------//--------------------------------------------------------------------// Take the compiler-local action specified by the #pragma (directive).// Note that the Include #pragma is handled elsewhere.//--------------------------------------------------------------------voidcimmofParser::processPragma(const String &name, const String &value) { // The valid names are: // instancelocale // locale // namespace // nonlocal // nonlocaltype // source // sourcetype // ATTN: P1 BB 2001 Des not process several Pragmas // instancelocale, locale, namespace, nonlocal, nonlocaltype, source, etc. // at least.}//-------------------------------------------------------------------// When a class declaration production is complete, try to add it to// the Repository//-------------------------------------------------------------------intcimmofParser::addClass(CIMClass *classdecl){ int ret = 0; String message; cimmofMessages::arglist arglist; arglist.append(classdecl->getClassName().getString()); if (_cmdline) { if (_cmdline->xml_output() ) { if (classdecl) { cout << "<VALUE.OBJECT>" << endl; XmlWriter::printClassElement(*classdecl, PEGASUS_STD(cout)); cout << "</VALUE.OBJECT>" << endl; cout << endl; } return ret; } else if (_cmdline->trace() ) { String header; cimmofMessages::getMessage(header, cimmofMessages::ADD_CLASS); trace(header,""); if (classdecl) XmlWriter::printClassElement(*classdecl, _cmdline->traceos()); } } if (_cmdline && _cmdline->operationType() != compilerCommonDefs::USE_REPOSITORY) { return ret; } try { Boolean classExist; cimmofMessages::MsgCode updateMessage; // Determine if class can be updated or added. Class is updated or // added based on the compiler options specified. if (updateClass(*classdecl, updateMessage, classExist)) { if (classExist) { _repository.modifyClass(getNamespacePath(), *classdecl); } else { _repository.addClass(getNamespacePath(), *classdecl); } } else { if (updateMessage == cimmofMessages::NO_CLASS_UPDATE) { // This was added to maintain backward compatibility of messages seen by // the user. cimmofMessages::getMessage(message, cimmofMessages::CLASS_EXISTS_WARNING, arglist); } else { arglist.append(cimmofMessages::msgCodeToString(updateMessage)); cimmofMessages::getMessage(message, cimmofMessages::CLASS_NOT_UPDATED, arglist); } wlog(message); } } catch(AlreadyExistsException&) { //ATTN: P1 2001 BB We should be able to modify the class through the compiler // 04/26/2003 GM See cimmofParser::updateClass() for info on why modify was not // done here cimmofMessages::getMessage(message, cimmofMessages::CLASS_EXISTS_WARNING, arglist); wlog(message); } catch (CIMException &e) { if (e.getCode() == CIM_ERR_ALREADY_EXISTS) { // 04/26/2003 GM See cimmofParser::updateClass() for info on why modify // was not done here. This where cimmofl and cimmof fell into prior to // changes above cimmofMessages::getMessage(message, cimmofMessages::CLASS_EXISTS_WARNING, arglist); wlog(message); } else { arglist.append(e.getMessage()); cimmofMessages::getMessage(message, cimmofMessages::ADD_CLASS_ERROR, arglist); maybeThrowParseError(message); } } catch(Exception &e) { arglist.append(e.getMessage()); cimmofMessages::getMessage(message, cimmofMessages::ADD_CLASS_ERROR, arglist); maybeThrowParseError(message); } if (_cmdline && _cmdline->trace()) { String ok; cimmofMessages::getMessage(ok, cimmofMessages::TAB_OK); trace(ok, ""); } return ret;}//---------------------------------------------------------------------// When a new class declaration is detected, create the CIMClassDecl// object//---------------------------------------------------------------------CIMClass *cimmofParser::newClassDecl(const CIMName &name, const CIMName &superclassname){ CIMClass *c = 0; try { c = new CIMClass(name, superclassname); } catch(CIMException &e) { cimmofMessages::arglist arglist; arglist.append(name.getString()); arglist.append(e.getMessage()); String message; cimmofMessages::getMessage(message, cimmofMessages::NEW_CLASS_ERROR, arglist); maybeThrowParseError(message); } return c;}//---------------------------------------------------------------------// When an instance production is complete, add it to the Repository//---------------------------------------------------------------------intcimmofParser::addInstance(CIMInstance *instance){ cimmofMessages::arglist arglist; String message; int ret = 0; Boolean err_out = false; if (_cmdline) { if (_cmdline->xml_output()) { if (instance) { cout << "<VALUE.OBJECT>" << endl; XmlWriter::printInstanceElement(*instance, PEGASUS_STD(cout)); cout << "</VALUE.OBJECT>" << endl; cout << endl; } return ret; } else if (_cmdline->trace()) { String header; cimmofMessages::getMessage(header, cimmofMessages::ADD_INSTANCE); trace(header, ""); if (instance) XmlWriter::printInstanceElement(*instance, _cmdline->traceos()); } } if (_cmdline && _cmdline->operationType() != compilerCommonDefs::USE_REPOSITORY) { return ret; } try { _repository.addInstance(getNamespacePath(), *instance); } catch (CIMException &e) { arglist.append(e.getMessage()); if (e.getCode() == CIM_ERR_ALREADY_EXISTS) { // ATTN: P1 BB 2001 We should be able to modify the instance through the compiler cimmofMessages::getMessage(message, cimmofMessages::INSTANCE_EXISTS_WARNING, arglist); wlog(message); } else { err_out = true; } } catch (Exception &e) { arglist.append(e.getMessage()); err_out = true; } if (err_out) { cimmofMessages::getMessage(message, cimmofMessages::ADD_INSTANCE_ERROR, arglist); maybeThrowParseError(message); } if (_cmdline && _cmdline->trace()) { String ok; cimmofMessages::getMessage(ok, cimmofMessages::TAB_OK); trace(ok, ""); } return ret;}//---------------------------------------------------------------------// When the start of a Qualifier Declaration is found, create the new// CIMQualifierDecl object//---------------------------------------------------------------------CIMQualifierDecl *cimmofParser::newQualifierDecl(const String &name, const CIMValue *value, const CIMScope & scope, const CIMFlavor & flavor) { CIMQualifierDecl *q = 0; try { q = new CIMQualifierDecl(name, *value, scope, flavor); } catch(Exception &e) { cimmofMessages::arglist arglist; arglist.append(name); arglist.append(e.getMessage()); String message; cimmofMessages::getMessage(message, cimmofMessages::NEW_QUALIFIER_DECLARATION_ERROR, arglist); maybeThrowParseError(message); } return q;}//---------------------------------------------------------------------// When a QualifierDeclaration production is complete, add the qualifier// to the Repository.//---------------------------------------------------------------------intcimmofParser::addQualifier(CIMQualifierDecl *qualifier){ int ret = 0; cimmofMessages::arglist arglist; if (qualifier) arglist.append(qualifier->getName().getString()); String message; if (_cmdline) { if (_cmdline->xml_output()) { if (qualifier) { cout << "<VALUE.OBJECT>" << endl; XmlWriter::printQualifierDeclElement(*qualifier, PEGASUS_STD(cout)); cout << "</VALUE.OBJECT>" << endl; cout << endl; } return ret; } else if (_cmdline->trace()) { String header; cimmofMessages::getMessage(header, cimmofMessages::ADD_QUALIFIER); trace(header, ""); if (qualifier) XmlWriter::printQualifierDeclElement(*qualifier, _cmdline->traceos()); } } if (_cmdline && _cmdline->operationType() != compilerCommonDefs::USE_REPOSITORY) { return ret; } try { _repository.addQualifier(getNamespacePath(), *qualifier); } catch(CIMException& e) { if (e.getCode() == CIM_ERR_NOT_SUPPORTED) { // OK, just skip it for now. // In a later implementation we will overwrite if the compiler // switches say to do so. } else { arglist.append(e.getMessage()); cimmofMessages::getMessage(message, cimmofMessages::ADD_QUALIFIER_ERROR, arglist); maybeThrowParseError(message); } } catch(Exception& e) { // ATTN:2001 P1 BB at the time of writing, the Common code does not throw // an CIM_ERR_ALREADY_EXISTS CIMException. It might at any time. arglist.append(e.getMessage()); cimmofMessages::getMessage(message, cimmofMessages::ADD_QUALIFIER_ERROR, arglist); maybeThrowParseError(message); } if (_cmdline && _cmdline->trace()) { String ok; cimmofMessages::getMessage(ok, cimmofMessages::TAB_OK); trace(ok, ""); } return ret;}//--------------------------------------------------------------------// When a qualifier itself (not its declaration) is detected,// create the CIMQualifier object.//--------------------------------------------------------------------CIMQualifier *cimmofParser::newQualifier(const String &name, const CIMValue &value, const CIMFlavor & flavor){ CIMQualifier *q = 0; try { q = new CIMQualifier(name, value, flavor); } catch(Exception &e) { cimmofMessages::arglist arglist; arglist.append(name); arglist.append(e.getMessage()); String message; cimmofMessages::getMessage(message, cimmofMessages::NEW_QUALIFIER_ERROR, arglist); maybeThrowParseError(message); } return q;}//----------------------------------------------------------------------// When a new instance declaration heading is detected, create the// backing instance object of that class. We may add it later, or// use it to modify an existing instance//----------------------------------------------------------------------CIMInstance *cimmofParser::newInstance(const CIMName &className){ CIMInstance *instance = 0; try { instance = new CIMInstance(className); } catch (Exception &e) { cimmofMessages::arglist arglist; arglist.append(className.getString()); arglist.append(e.getMessage()); String message; cimmofMessages::getMessage(message, cimmofMessages::NEW_INSTANCE_ERROR, arglist); maybeThrowParseError(message); } return instance;}//----------------------------------------------------------------------// When a property of a class being declared is discovered, creat the// new CIMProperty object.//----------------------------------------------------------------------// KS 8 Mar 2002 - Added is array and arraySize to parametersCIMProperty *cimmofParser::newProperty(const CIMName &name, const CIMValue &val, const Boolean isArray, const Uint32 arraySize, const CIMName &referencedObject) const{ CIMProperty *p = 0; try { //ATTNKS: P1 Note that we are not passing isArray p = new CIMProperty(name, val, arraySize, referencedObject); } catch(Exception &e) { cimmofMessages::arglist arglist; arglist.append(name.getString()); arglist.append(e.getMessage()); String message; cimmofMessages::getMessage(message, cimmofMessages::NEW_PROPERTY_ERROR, arglist); maybeThrowParseError(message); } return p;}//-----------------------------------------------------------------------// When a property production is complete, apply it to the// class being declared.//-----------------------------------------------------------------------intcimmofParser::applyProperty(CIMClass &c, CIMProperty &p){ cimmofMessages::arglist arglist; arglist.append(c.getClassName().getString()); arglist.append(p.getName().getString()); String message; try { c.addProperty(p); } catch(UninitializedObjectException&) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -