void typeDefinitions (void) { while (curToken == TKN_IDENTIFIER) { SymTableNodePtr typeIdPtr; searchAndEnterLocalSymTable(typeIdPtr); typeIdPtr->defn.key = DFN_TYPE; typeIdPtr->library = CurLibrary; getToken(); ifTokenGetElseError(TKN_EQUAL, ABL_ERR_SYNTAX_MISSING_EQUAL); //---------------------------------- // Process the type specification... typeIdPtr->typePtr = doType(); if (typeIdPtr->typePtr->typeIdPtr == NULL) typeIdPtr->typePtr->typeIdPtr = typeIdPtr; analyzeTypeDefn(typeIdPtr); //--------------- // Error synch... synchronize(followDeclarationList, declarationStartList, statementStartList); if (curToken == TKN_SEMICOLON) getToken(); else if (tokenIn(declarationStartList) || tokenIn(statementStartList)) syntaxError(ABL_ERR_SYNTAX_MISSING_SEMICOLON); } }
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, StringBuffer& buf) { const char* typeName = type->queryName(); if (type->isComplexType()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", type->queryName()); } else { int flds = type->getFieldCount(); for (int i=0; i<flds; i++) { const char* fldName = type->queryFieldName(i); buf.appendf("<%s>", fldName); if (typeName) parent.push_back(typeName); doType(parent,indent+1,fldName,type->queryFieldType(i),buf); buf.appendf("</%s>", fldName); if (typeName) parent.pop_back(); } } } else if (type->isArray()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", type->queryName()); } else { const char* itemName = type->queryFieldName(0); IXmlType* itemType = type->queryFieldType(0); if (typeName) parent.push_back(typeName); for (int i=0; i<m_items; i++) { buf.appendf("<%s>", itemName); doType(parent,indent+2,itemName, itemType, buf); buf.appendf("</%s>", itemName); } if (m_ecl2esp) buf.appendf("<%s/>", itemName); if (typeName) parent.pop_back(); } } else { //TODO: handle restriction etc if (strcmp(typeName,"string")==0) // string type: [tag-typeName] { if (m_gx) buf.append("*** MISSING ***"); else if (m_ecl2esp) buf.append("[?]"); else buf.appendf("[%s]", tag); } else setDefaultValue(buf,type,tag); } }
void MessageGenerator::doType(StringStack& parent, int indent, const char* tag, IXmlType* type, IPTree* tmplat, StringBuffer& buf) { const char* typeName = type->queryName(); if (type->isComplexType()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", typeName); } else { int flds = type->getFieldCount(); for (int i=0; i<flds; i++) { const char* fldName = type->queryFieldName(i); buf.appendf("<%s>", fldName); IPTree* existing = tmplat->queryBranch(fldName); if (typeName) parent.push_back(typeName); if (existing) doType(parent,indent+1,fldName, type->queryFieldType(i), existing, buf); else doType(parent,indent+1,fldName,type->queryFieldType(i),buf); buf.appendf("</%s>", fldName); if (typeName) parent.pop_back(); } } } else if (type->isArray()) { if (typeName && std::find(parent.begin(),parent.end(),typeName) != parent.end()) { //DBGLOG("Recursive type: %s, ignored", typeName); } else { const char* itemName = type->queryFieldName(0); IXmlType* itemType = type->queryFieldType(0); int childCount = tmplat->numChildren(); if (typeName) parent.push_back(typeName); if (childCount>0) { Owned<IPTreeIterator> items = tmplat->getElements(itemName); for (items->first(); items->isValid(); items->next()) { buf.appendf("<%s>", itemName); doType(parent,indent+2,itemName,itemType,&items->query(),buf); buf.appendf("</%s>", itemName); } } else { for (int i=0; i<m_items; i++) { buf.appendf("<%s>", itemName); doType(parent,indent+2,itemName, itemType, buf); buf.appendf("</%s>", itemName); } if (m_ecl2esp) buf.appendf("<%s/>", itemName); } if (typeName) parent.pop_back(); } } else { const char* existing = tmplat->queryProp("."); if (existing && isNotBlank(existing)) encodeXML(existing,buf); else if (m_gx) buf.append("*** MISSING ***"); else { DefValMap::const_iterator it = m_cfgDefValues.find(tag); if (it != m_cfgDefValues.end()) buf.append(it->second.c_str()); else type->getSampleValue(buf,tag); } } }
void MessageGenerator::genRoxieMessage(const char* templatemsg, StringBuffer& message) { Owned<IPropertyTree> tmplat; StringBuffer root; if (templatemsg) { tmplat.setown(createPTreeFromXMLString(templatemsg)); if(!tmplat.get()) throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml."); root = tmplat->queryName(); tmplat.setown(tmplat->getPropTree(VStringBuffer("//Results/Result"))); if (!tmplat.get()) throw MakeStringException(-1, "can't find Results/Result in input XML"); } else root = "Unknown"; // TODO: find out the root? message.appendf("<!-- <%s> --> %s", root.str(), LT); message.appendf(" <!-- <Results> --> %s", LT); message.appendf(" <Result>%s", LT); Owned<IPropertyTreeIterator> it = m_roxieSchemaRoot->getElements(VStringBuffer("XmlSchema")); for (it->first(); it->isValid(); it->next()) { IPropertyTree* ds = &it->query(); const char* name = ds->queryProp("@name"); if (!name) { ERRLOG("XmlSchema without name"); continue; } IPropertyTree* p = ds->queryBranch(VStringBuffer("%s:schema", xsdNs())); m_schemaTree.setown(LINK(p)); IXmlSchema* xs = createXmlSchemaFromPTree(m_schemaTree); IXmlType* type = xs->queryElementType("Dataset"); if (!type) { ERRLOG("Can not find type '%s'", name); continue; } // get the Row type type = type->queryFieldType(0); if (!type) { ERRLOG("The root element for %s is not an array", name); continue; } IPropertyTree* dsTmplat = tmplat.get() ? tmplat->queryPropTree(VStringBuffer("Dataset[@name='%s']",name)) : NULL; if (dsTmplat && dsTmplat->numChildren()>0) { message.appendf(" <Dataset name=\"%s\">%s", name, LT); Owned<IPropertyTreeIterator> row = dsTmplat->getElements("Row"); for (row->first(); row->isValid(); row->next()) { message.appendf(" <Row>%s", LT); StringStack parent; doType(parent,5,"Row",type, &row->query(), message); message.appendf(" </Row>%s", LT); } message.appendf(" </Dataset>%s", LT); } else if (m_genAllDatasets) { message.appendf(" <Dataset name=\"%s\">%s", name, LT); for (int i=0; i < m_items; i++) { message.appendf(" <Row>%s", LT); StringStack parent; doType(parent,6,"Row",type,message); message.appendf(" </Row>%s", LT); } if (m_ecl2esp) message.appendf(" <Row/>%s", LT); message.appendf(" </Dataset>%s", LT); } } message.appendf(" </Result>%s", LT); message.appendf(" <!-- </Results> --> %s", LT); message.appendf("<!-- </%s> --> %s", root.str(), LT); }
void MessageGenerator::genNonRoxieMessage(const char* method, const char* templatemsg, StringBuffer& message) { if (m_soapWrap) message.appendf("<?xml version=\"1.0\" encoding=\"utf-8\"?>" "%s<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"" " xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"" " xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/04/secext\"><soap:Body>%s", LT, LT); const char* element = method; IPTree* schema = NULL; if(m_schemaType == WSDL) schema = m_schemaTree->queryPropTree("types/xsd:schema"); else schema = m_schemaTree; if (schema) { const char* ns = schema->queryProp("@targetNamespace"); if(ns && ns && !m_ecl2esp) message.appendf(" <%s xmlns=\"%s\">", element, ns); else message.appendf(" <%s>", element); Owned<IXmlSchema> s = createXmlSchemaFromPTree(LINK(schema)); if (s.get()) { IXmlType* type = s->queryElementType(element); if (type) { StringStack parent; if (templatemsg && *templatemsg) { Owned<IPropertyTree> tmplat = createPTreeFromXMLString(templatemsg); if(!tmplat.get()) throw MakeStringException(-1, "can't generate property tree from input, please make sure it's valid xml."); IPropertyTree* tmp = NULL; if (strcmp(tmplat->queryName(),element)==0) tmp = tmplat; else tmp = tmplat->queryPropTree(VStringBuffer("//%s",element)); if (tmp) doType(parent,2, element, type, tmp, message); else doType(parent,2, element, type, message); } else doType(parent,2, element, type, message); } } message.appendf("</%s>%s", element, LT); } if (m_soapWrap) message.append("</soap:Body></soap:Envelope>"); }
void varOrFieldDeclarations (SymTableNodePtr routineIdPtr, long offset) { bool varFlag = (routineIdPtr != NULL); SymTableNodePtr idPtr = NULL; SymTableNodePtr firstIdPtr = NULL; SymTableNodePtr lastIdPtr = NULL; SymTableNodePtr prevLastIdPtr = NULL; long totalSize = 0; while ((curToken == TKN_IDENTIFIER) || (curToken == TKN_ETERNAL) || (curToken == TKN_STATIC)) { VariableType varType = VAR_TYPE_NORMAL; if ((curToken == TKN_ETERNAL) || (curToken == TKN_STATIC)) { if (curToken == TKN_ETERNAL) varType = VAR_TYPE_ETERNAL; else varType = VAR_TYPE_STATIC; getToken(); if (curToken != TKN_IDENTIFIER) syntaxError(ABL_ERR_SYNTAX_MISSING_IDENTIFIER); } firstIdPtr = NULL; //------------------------------ // Process the variable type... TypePtr typePtr = doType(); //------------------------------------------------------------------ // Since we haven't really assigned it here, decrement its // numInstances. Every variable in this list will set it properly... typePtr->numInstances--; long size = typePtr->size; //------------------------------------------------------- // Now that we've read the type, read in the variable (or // possibly list of variables) declared of this type. // Loop to process every variable (and field, if records // are being implemented:) in sublist... while (curToken == TKN_IDENTIFIER) { if (varFlag) { //--------------------------------------------- // We're working with a variable declaration... if (varType == VAR_TYPE_ETERNAL) { long curLevel = level; level = 0; searchAndEnterThisTable (idPtr, SymTableDisplay[0]); level = curLevel; } else searchAndEnterLocalSymTable(idPtr); idPtr->library = CurLibrary; idPtr->defn.key = DFN_VAR; } else syntaxError(ABL_ERR_SYNTAX_NO_RECORD_TYPES); idPtr->labelIndex = 0; //------------------------------------------ // Now, link Id's together into a sublist... if (!firstIdPtr) { firstIdPtr = lastIdPtr = idPtr; if (varFlag && (varType != VAR_TYPE_ETERNAL) && (routineIdPtr->defn.info.routine.locals == NULL)) routineIdPtr->defn.info.routine.locals = idPtr; } else { lastIdPtr->next = idPtr; lastIdPtr = idPtr; } getToken(); ifTokenGet(TKN_COMMA); } //-------------------------------------------------------------------------- // Assign the offset and the type to all variable or field Ids in sublist... for (idPtr = firstIdPtr; idPtr != NULL; idPtr = idPtr->next) { idPtr->typePtr = setType(typePtr); if (varFlag) { idPtr->defn.info.data.varType = varType; switch (varType) { case VAR_TYPE_NORMAL: totalSize += size; idPtr->defn.info.data.offset = offset++; break; case VAR_TYPE_ETERNAL: { idPtr->defn.info.data.offset = eternalOffset; //----------------------------------- // Initialize the variable to zero... StackItemPtr dataPtr = (StackItemPtr)stack + eternalOffset; if (typePtr->form == FRM_ARRAY) { dataPtr->address = (Address)ABLStackMallocCallback((size_t)size); if (!dataPtr->address) ABL_Fatal(0, " ABL: Unable to AblStackHeap->malloc eternal array "); memset(dataPtr->address, 0, size); EternalVariablesSizes[eternalOffset] = size; } else { dataPtr->integer = 0; EternalVariablesSizes[eternalOffset] = 0; } eternalOffset++; } break; case VAR_TYPE_STATIC: { if (NumStaticVariables == MaxStaticVariables) syntaxError(ABL_ERR_SYNTAX_TOO_MANY_STATIC_VARS); idPtr->defn.info.data.offset = NumStaticVariables; if (typePtr->form == FRM_ARRAY) StaticVariablesSizes[NumStaticVariables] = size; else StaticVariablesSizes[NumStaticVariables] = 0; NumStaticVariables++; } break; } analyzeVarDecl(idPtr); } else { //---------------- // record field... idPtr->defn.info.data.varType = VAR_TYPE_NORMAL; idPtr->defn.info.data.offset = offset; offset += size; } } //-------------------------------------------------- // Now, link this sublist to the previous sublist... if (varType != VAR_TYPE_ETERNAL) { if (prevLastIdPtr != NULL) prevLastIdPtr->next = firstIdPtr; prevLastIdPtr = lastIdPtr; } //--------------------- // Error synchronize... if (varFlag) synchronize(followVariablesList, declarationStartList, statementStartList); if (curToken == TKN_SEMICOLON) getToken(); else if (varFlag && (tokenIn(declarationStartList) || tokenIn(statementStartList))) syntaxError(ABL_ERR_SYNTAX_MISSING_SEMICOLON); } synchronize(followVarBlockList, NULL, NULL); if (varFlag) { //---------------------------------------------------------------- // If the following error occurs too frequently, simply make the // totalLocalSize field an unsigned long instead, and dramatically // increase the totalSize limit here... if (totalSize > 32000) syntaxError(ABL_ERR_SYNTAX_TOO_MANY_LOCAL_VARIABLES); routineIdPtr->defn.info.routine.totalLocalSize = (unsigned short)totalSize; } }