Token PSWToken2(Type type, char *val, char *ind) { register Token token = (Token)psw_calloc(sizeof(TokenRec), 1); Item dictVal = (Item) PSWDictLookup(currentDict, val); Item dvi; token->next = NULL; token->type = type; token->val = val; token->sourceLine = yylineno; /* Assert(type == T_SUBSCRIPTED); */ if (((PSWDictValue) dictVal == -1) || (dictVal->isoutput)) { ErrIntro(yylineno); fprintf(stderr,"%s not an input parameter\n", val); } else if (!dictVal->subscripted) { ErrIntro(yylineno); fprintf(stderr,"%s not an array\n", val); } else if (dictVal->type >= T_NUMSTR) { ErrIntro(yylineno); fprintf(stderr,"cannot subscript numstring %s\n", val); } else if (IsCharType(dictVal->type)) { ErrIntro(yylineno); fprintf(stderr,"%s not a scalar type\n", val); } else { dvi = (Item) PSWDictLookup(currentDict, (char *)ind); if (((PSWDictValue) dvi != -1) && ((dvi->isoutput) || IsCharType(dvi->type))) { ErrIntro(yylineno); fprintf(stderr,"%s wrong type\n",(char *) ind); } else { token->body.var = (char *) ind; token->namedFormal = dictVal; /* ok, so assign a value */ return token; } } /* ERRORS fall through */ free(token); return (PSWToken(T_NAME,val)); }
//++ ------------------------------------------------------------------------------------ // Details: Retrieve from the LLDB SB Value object the value of the variable described in // text if it has a simple format (not composite). // Type: Method. // Args: vwrValue - (W) The SBValue in a string format. // Return: MIstatus::success - Function succeeded. // MIstatus::failure - Function failed. // Throws: None. //-- bool CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilString &vwrValue) const { const MIuint nChildren = m_rValue.GetNumChildren(); if (nChildren == 0) { if (m_bHandleCharType && IsCharType()) { vwrValue = GetSimpleValueChar(); return MIstatus::success; } else { const char *pValue = m_rValue.GetValue(); vwrValue = pValue != nullptr ? pValue : m_pUnkwn; return MIstatus::success; } } else if (IsPointerType()) { if (m_bHandleCharType && IsFirstChildCharType()) { vwrValue = GetSimpleValueCStringPointer(); return MIstatus::success; } else { const char *pValue = m_rValue.GetValue(); vwrValue = pValue != nullptr ? pValue : m_pUnkwn; return MIstatus::success; } } else if (IsArrayType()) { CMICmnLLDBDebugSessionInfo &rSessionInfo(CMICmnLLDBDebugSessionInfo::Instance()); bool bPrintCharArrayAsString = false; bPrintCharArrayAsString = rSessionInfo.SharedDataRetrieve<bool>(rSessionInfo.m_constStrPrintCharArrayAsString, bPrintCharArrayAsString) && bPrintCharArrayAsString; if (bPrintCharArrayAsString && m_bHandleCharType && IsFirstChildCharType()) { vwrValue = GetSimpleValueCStringArray(); return MIstatus::success; } else if (vbHandleArrayType) { vwrValue = CMIUtilString::Format("[%u]", nChildren); return MIstatus::success; } } // Composite variable type i.e. struct return MIstatus::failure; }
//++ //------------------------------------------------------------------------------------ // Details: Retrieve from the LLDB SB Value object the value of the variable // described in // text if it has a simple format (not composite). // Type: Method. // Args: vwrValue - (W) The SBValue in a string format. // Return: MIstatus::success - Function succeeded. // MIstatus::failure - Function failed. // Throws: None. //-- bool CMICmnLLDBUtilSBValue::GetSimpleValue(const bool vbHandleArrayType, CMIUtilString &vwrValue) const { const MIuint nChildren = m_rValue.GetNumChildren(); if (nChildren == 0) { vwrValue = GetValueSummary(!m_bHandleCharType && IsCharType(), m_pUnkwn); return MIstatus::success; } else if (IsPointerType()) { vwrValue = GetValueSummary(!m_bHandleCharType && IsPointeeCharType(), m_pUnkwn); return MIstatus::success; } else if (IsArrayType()) { CMICmnLLDBDebugSessionInfo &rSessionInfo( CMICmnLLDBDebugSessionInfo::Instance()); bool bPrintCharArrayAsString = false; bPrintCharArrayAsString = rSessionInfo.SharedDataRetrieve<bool>( rSessionInfo.m_constStrPrintCharArrayAsString, bPrintCharArrayAsString) && bPrintCharArrayAsString; if (bPrintCharArrayAsString && m_bHandleCharType && IsFirstChildCharType()) { vwrValue = GetValueSummary(false); return MIstatus::success; } else if (vbHandleArrayType) { vwrValue = CMIUtilString::Format("[%u]", nChildren); return MIstatus::success; } } else { // Treat composite value which has registered summary // (for example with AddCXXSummary) as simple value vwrValue = GetValueSummary(false); if (!vwrValue.empty()) return MIstatus::success; } // Composite variable type i.e. struct return MIstatus::failure; }
Token PSWToken(Type type, char *val) { register Token token = (Token)psw_calloc(sizeof(TokenRec), 1); token->next = NULL; token->type = type; token->val = val; token->sourceLine = yylineno; switch (type) { case T_STRING: case T_NAME: case T_LITNAME: { Item dictVal = (Item) PSWDictLookup(currentDict, (char *)val); if ((PSWDictValue) dictVal != -1) { if ((type != T_NAME) && (dictVal->isoutput)) { ErrIntro(yylineno); fprintf(stderr,"output parameter %s used as %s\n", dictVal->name, (type == T_STRING) ? "string": "literal name"); } else if ((type != T_NAME) && !IsCharType(dictVal->type)) { ErrIntro(yylineno); fprintf(stderr,"non-char input parameter %s used as %s\n", dictVal->name, (type == T_STRING) ? "string": "literal name"); } else token->namedFormal = dictVal; /* ok, so assign a value */ } break; } default: break; } return token; }
static JILError GetToken(JCLFile* _this, JCLString* pToken, JILLong* pTokenID) { JILError err = JCL_No_Error; JILChar c; JILChar d; // clear output string *pTokenID = tk_unknown; JCLClear(pToken); // check what we have found c = JCLGetCurrentChar(_this->mipText); d = JCLGetChar(_this->mipText, JCLGetLocator(_this->mipText) + 1); // verbatim string literal? if( (c == '/' || c == '@') && d == '\"' ) { // read the entire string literal err = GetStrLiteral(_this, pToken); *pTokenID = tk_lit_string; } // part of keyword or identifier characters? else if( IsCharType(c, kKeywordChars) ) { // try to read as many characters of the keyword or identifier JCLSpanIncluding(_this->mipText, kIdentifierChars, pToken); // check if it is a keyword *pTokenID = GetTokenID(JCLGetString(pToken), kKeywordList); // check err if( *pTokenID == tk_unknown ) *pTokenID = tk_identifier; } // part of operator characters? else if( IsCharType(c, kOperatorChars) && (c != '.' || !IsDigit(d)) ) { // try to find a matching operator token err = FindTokenAtPosition(_this, pToken, pTokenID, kOperatorList); } // part of number characters? else if( IsCharType(c, kFirstDigitChars) && (c != '.' || IsDigit(d)) ) { JILLong type; // check if long or float number, scan in the token and return tk_lit_int or tk_lit_float! JCLSpanNumber(_this->mipText, pToken, &type); *pTokenID = (type || _this->mipOptions->miDefaultFloat) ? tk_lit_float : tk_lit_int; } else if( IsCharType(c, kCharacterChars) ) { // try to read as many characters as possible JCLSpanIncluding(_this->mipText, kCharacterChars, pToken); // try to find the character in the list *pTokenID = GetTokenID(JCLGetString(pToken), kCharacterList); // check err if( *pTokenID == tk_unknown ) err = JCL_ERR_Unexpected_Token; } else if( IsCharType(c, kSingleChars) ) { // must read only a single character JCLFill(pToken, JCLGetCurrentChar(_this->mipText), 1); JCLSeekForward(_this->mipText, 1); // try to find the character in the list *pTokenID = GetTokenID(JCLGetString(pToken), kCharacterList); // check err if( *pTokenID == tk_unknown ) err = JCL_ERR_Unexpected_Token; } else { // single characters switch( c ) { case '\"': // read the entire string literal err = GetStrLiteral(_this, pToken); *pTokenID = tk_lit_string; break; case '\'': // read the entire character literal err = GetStrLiteral(_this, pToken); *pTokenID = tk_lit_char; break; default: err = JCL_ERR_Unexpected_Token; break; } } return err; }
/* Complete construction of the Header tree and make some semantic checks */ Header PSWHeader(boolean isStatic, Args inArgs, Args outArgs) { char *name = currentPSWName; register Arg arg, prevArg; register Item item, prevItem; int nextTag = 0; Header hdr = (Header)psw_calloc(sizeof(HeaderRec), 1); hdr->isStatic = isStatic; hdr->name = name; currentDict = CreatePSWDict(511); prevArg = NULL; for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */ prevItem = NULL; for (item = arg->items; item; item = item->next) { if (IsCharType(arg->type) && !(item->starred || item->subscripted)) { ErrIntro(item->sourceLine); fprintf(stderr, "char input parameter %s must be starred or subscripted\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free(item); XXX? */ continue; } if(item->scaled && !IsNumStrType(arg->type)) { ErrIntro(item->sourceLine); fprintf(stderr,"only numstring parameters may be scaled\n"); } if (IsNumStrType(arg->type) && (item->starred || !item->subscripted)) { ErrIntro(item->sourceLine); fprintf(stderr, "numstring parameter %s may only be subscripted\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free(item); XXX? */ continue; } if (arg->type != T_CONTEXT) { if (PSWDictLookup(currentDict, item->name) != -1) { ErrIntro(item->sourceLine); fprintf(stderr,"parameter %s reused\n", item->name); if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free this ? */ continue; } PSWDictEnter(currentDict, item->name, (PSWDictValue) item); item->isoutput = false; item->type = arg->type; prevItem = item; } } if (arg->items == NULL) { if (prevArg) { prevArg->next = arg->next; } else if (arg == inArgs) { inArgs = arg->next; } continue; } prevArg = arg; } prevArg = NULL; for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */ prevItem = NULL; for (item = arg->items; item; item = item->next) { if (arg->type == T_USEROBJECT) { ErrIntro(item->sourceLine); fprintf(stderr,"output parameter %s can not be of type userobject\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free(item); XXX */ continue; } if (arg->type == T_NUMSTR || arg->type == T_FLOATNUMSTR || arg->type == T_LONGNUMSTR || arg->type == T_SHORTNUMSTR) { ErrIntro(item->sourceLine); fprintf(stderr,"output parameter %s can not be of type numstring\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free(item); XXX */ continue; } if (!(item->starred || item->subscripted)) { ErrIntro(item->sourceLine); fprintf(stderr,"output parameter %s must be starred or subscripted\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free(item); XXX */ continue; } if (PSWDictLookup(currentDict, item->name) != -1) { ErrIntro(item->sourceLine); fprintf(stderr,"parameter %s reused\n", item->name); /* remove item from list */ if (prevItem) { prevItem->next = item->next; } else if (item == arg->items) { arg->items = item->next; }; /* free the storage? XXX */ continue; } PSWDictEnter(currentDict, item->name, (PSWDictValue) item); item->isoutput = true; item->type = arg->type; item->tag = nextTag++; prevItem = item; } /* inside for loop */ if (arg->items == NULL) { if (prevArg) { prevArg->next = arg->next; } else if (arg == outArgs) { outArgs = arg->next; } continue; } prevArg = arg; } /* outside for loop */ /* now go looking for subscripts that name an input arg */ for (arg = inArgs; arg; arg = arg->next) { /* foreach input arg */ for (item = arg->items; item; item = item->next) { if (item->subscripted && !item->subscript->constant) { PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name); if (v != -1) { Item subItem = (Item)v; if (subItem->isoutput) { ErrIntro(subItem->sourceLine); fprintf(stderr,"output parameter %s used as a subscript\n", subItem->name); continue; } if (subItem->type != T_INT) { ErrIntro(subItem->sourceLine); fprintf(stderr, "input parameter %s used as a subscript is not an int\n", subItem->name); continue; } } } } } for (arg = outArgs; arg; arg = arg->next) { /* foreach output arg */ for (item = arg->items; item; item = item->next) { if (item->subscripted && !item->subscript->constant) { PSWDictValue v = PSWDictLookup(currentDict, item->subscript->name); if (v != -1) { Item subItem = (Item)v; if (subItem->isoutput) { ErrIntro(subItem->sourceLine); fprintf(stderr,"output parameter %s used as a subscript\n", subItem->name); continue; } if (subItem->type != T_INT) { ErrIntro(subItem->sourceLine); fprintf(stderr, "input parameter %s used as a subscript is not an int\n", subItem->name); continue; } } } } } hdr->inArgs = inArgs; hdr->outArgs = outArgs; return hdr; }