void TSExpression::Build(SemanticApi::TGlobalBuildContext build_context) { assert(first_op.get() == nullptr); TSemanticTreeBuilder b(build_context, GetSyntax(), GetOwner(), GetMethod(), this); auto syntax = GetSyntax(); if (!syntax->IsEmpty()) first_op.reset(b.VisitNode(syntax)); expression_result = dynamic_cast<TSOperation*>(first_op.get())->GetFormalParameter(); }
void TSStatement::TestBoolExpr(TExpressionResult& compare_result, std::unique_ptr<TActualParamWithConversion>& conversion) { int conv_needed; TSClass* bool_class = owner->GetClass(GetSyntax()->source->GetIdFromName("bool")); TFormalParameter formal_param(bool_class, false); if (!IsEqualClasses(compare_result, formal_param, conv_needed)) GetSyntax()->Error("Выражение невозможно преобразовать в логический тип!"); conversion.reset(new TActualParamWithConversion()); conversion->BuildConvert(compare_result, formal_param); }
void TSParameter::CalculateSize() { if (GetSyntax()->IsRef()) SetSize(1); else SetSize(GetClass()->GetSize()); }
bool TSParameter::IsEqualTo(const TSParameter& right)const { return type.IsEqualTo(right.type) && GetSyntax()->IsRef() == right.GetSyntax()->IsRef(); }
bool CCCommandManager::ParseMessage(CCCommand* pCmd, char* szErrMsg, int nErrMsgMaxLength, const char* szMsg) { //#define USE_SLASH #ifdef USE_SLASH if(!(szMsg[0]=='/' && szMsg[1]!=0)){ CCStrNCpy(szErrMsg, nErrMsgMaxLength, "Use Slash('/') First"); return false; } #endif CCLexicalAnalyzer la; #ifdef USE_SLASH la.Create(szMsg+1); #else la.Create(szMsg); #endif if(la.GetCount()==0){ CCStrNCpy(szErrMsg, nErrMsgMaxLength, "Syntax Error"); return false; } #define ASMESSAGE_LENGTH 256 char szTemp[ASMESSAGE_LENGTH]; strcpy(szTemp, la.GetByStr(0)); CCCommandAliasMap::iterator itor = m_CommandAlias.find(string(szTemp)); if (itor != m_CommandAlias.end()) { strcpy(szTemp, (*itor).second.c_str()); } //for(int i=0; i<(int)m_CommandDescs.size(); i++){ for (CCCommandDescMap::iterator itor = m_CommandDescs.begin(); itor != m_CommandDescs.end(); ++itor) { CCCommandDesc* pCD = (*itor).second; //CCCommandDesc* pCD = m_CommandDescs[i]; if(stricmp(szTemp, pCD->GetName())==0){ //if(pCD->IsFlag(ASCDF_CHEAT)==true && EnableDevDebug()==false) return false; // 개발자 전용 커맨드이면... Debug가 Enable되어 있어야 한다. pCmd->SetID(pCD); int nLAMaxCount = la.GetCount(); int nLACount = 1; for(int j=0; j<pCD->GetParameterDescCount(); j++){ CCCommandParameterDesc* pPD = pCD->GetParameterDesc(j); bool bSyntaxError = false; CCCommandParameter* pParam = NULL; switch(pPD->GetType()){ case MPT_INT: if(nLACount+1>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterInt(la.GetByInt(nLACount)); nLACount++; break; case MPT_UINT: { if(nLACount+1>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterUInt(la.GetByLong(nLACount)); nLACount++; break; } break; case MPT_FLOAT: if(nLACount+1>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterFloat(la.GetByFloat(nLACount)); nLACount++; break; case MPT_STR: if(nLACount+1>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterString(la.GetByStr(nLACount)); nLACount++; break; case MPT_VECTOR: if(nLACount+3>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterVector(la.GetByFloat(nLACount), la.GetByFloat(nLACount+1), la.GetByFloat(nLACount+2)); nLACount+=3; break; case MPT_POS: if(nLACount+3>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterPos(la.GetByFloat(nLACount), la.GetByFloat(nLACount+1), la.GetByFloat(nLACount+2)); nLACount+=3; break; case MPT_DIR: if(nLACount+3>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterDir(la.GetByFloat(nLACount), la.GetByFloat(nLACount+1), la.GetByFloat(nLACount+2)); nLACount+=3; break; case MPT_COLOR: if(nLACount+3>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterColor(la.GetByFloat(nLACount), la.GetByFloat(nLACount+1), la.GetByFloat(nLACount+2)); nLACount+=3; break; case MPT_BOOL: if(nLACount+1>nLAMaxCount){ bSyntaxError = true; break; } pParam = new CCCommandParameterBool(la.GetByInt(nLACount)>0?true:false); nLACount++; break; case MPT_UID: if(nLACount+2>nLAMaxCount){ bSyntaxError = true; break; } // UINT를 만들어야 한다. pParam = new CCCommandParameterUID(CCUID(la.GetByInt(nLACount), la.GetByInt(nLACount+1))); nLACount+=2; break; default: _ASSERT(false); // 아직 핸들링할 코드가 준비 안된 파라미터 return false; //break; } if(bSyntaxError==true){ char szSyntax[256]; static char temp[512]; GetSyntax(szSyntax, pCmd->m_pCommandDesc); sprintf(temp, "Sytax Error: [Syntax] %s", szSyntax); CCStrNCpy(szErrMsg, nErrMsgMaxLength, temp); return false; } if(pParam!=NULL) pCmd->AddParameter(pParam); } return true; } } CCStrNCpy(szErrMsg, nErrMsgMaxLength, "Unknown Command"); return false; }
void MadHighlightingDialog::WxListBoxSyntaxSelected(wxCommandEvent& event) { wxString title=WxListBoxSyntax->GetString(event.GetSelection()); g_Syntax=GetSyntax(title); // build keyword list WxListCtrlKeyword->Freeze(); WxListCtrlKeyword->DeleteAllItems(); g_KeywordInfoTable.clear(); int index=0; // system attributes for(int ae=aeText; ae<aeNone; ++ae) { long item = WxListCtrlKeyword->InsertItem(index++, MadSyntax::GetAttributeName((MadAttributeElement)ae)); MadAttributes *attr = g_Syntax->GetAttributes((MadAttributeElement)ae); int kind=kindSysAttr1; if(ae==aeActiveLine || ae==aeBookmark) kind=kindSysAttr2; g_KeywordInfoTable.push_back(KeywordInfo(kind, attr, NULL)); if(ae==aeText) { WxListCtrlKeyword->SetBackgroundColour(attr->bgcolor); } SetItemColour(WxListCtrlKeyword, item, attr->color, attr->bgcolor); wxFont font=GetItemFont(WxListCtrlKeyword, item); SetFontStyle(font, attr->style); SetItemFont(WxListCtrlKeyword, item, font); } // custom ranges size_t i; for(i=0; i<g_Syntax->m_CustomRange.size(); ++i) { wxString text; text.Printf(wxT("Range %s %s"), g_Syntax->m_CustomRange[i].begin.c_str(), g_Syntax->m_CustomRange[i].end.c_str()); long item = WxListCtrlKeyword->InsertItem(index++, text); wxColour *bg = &(g_Syntax->m_CustomRange[i].bgcolor); g_KeywordInfoTable.push_back( KeywordInfo(kindRange, NULL, bg) ); SetItemColour(WxListCtrlKeyword, item, g_KeywordInfoTable[0].attr->color, *bg); } // custom keywords for(i=0; i<g_Syntax->m_CustomKeyword.size(); ++i) { long item = WxListCtrlKeyword->InsertItem(index++, g_Syntax->m_CustomKeyword[i].m_Name); MadAttributes *attr = &(g_Syntax->m_CustomKeyword[i].m_Attr); g_KeywordInfoTable.push_back(KeywordInfo(kindKeyword, attr, NULL)); SetItemColour(WxListCtrlKeyword, item, attr->color, attr->bgcolor); wxFont font=GetItemFont(WxListCtrlKeyword, item); SetFontStyle(font, attr->style); SetItemFont(WxListCtrlKeyword, item, font); } WxListCtrlKeyword->SetColumnWidth( 0, WxListCtrlKeyword->GetClientSize().x - 4); WxListCtrlKeyword->Thaw(); g_Index=-1; wxListEvent e; e.m_itemIndex=0; WxListCtrlKeywordSelected(e); }
SemanticApi::IVariable* TSExpression::GetVar(Lexer::TNameId name) { return GetParentStatements()->GetVar(name, GetSyntax()->GetStmtId()); }
void Visit(SyntaxApi::IOperations::IId* operation_node) { SemanticApi::IVariable* var = parent->GetVar(operation_node->GetName()); if (var != nullptr) { switch (var->GetVariableType()) { case SemanticApi::VariableType::ClassField: { ValidateAccess(syntax_node, owner, (TSClassField*)var); auto var_field = dynamic_cast<TSClassField*>(var); if ((!var_field->GetSyntax()->IsStatic()) && method->GetSyntax()->IsStatic()) syntax_node->Error("К нестатическому полю класса нельзя обращаться из статического метода!"); TSExpression::TGetClassField* result = new TSExpression::TGetClassField( nullptr, TExpressionResult(dynamic_cast<TSClass*>(var_field->GetClass()), true), var_field); Return(result); }break; case SemanticApi::VariableType::Local: { TSExpression::TGetLocal* result = new TSExpression::TGetLocal(dynamic_cast<TSLocalVar*>(var)); Return(result); }break; case SemanticApi::VariableType::Parameter: { TSExpression::TGetParameter* result = new TSExpression::TGetParameter(dynamic_cast<TSParameter*>(var)); Return(result); }break; default: assert(false);//ошибка в поиске переменной } } else { std::vector<SemanticApi::ISMethod*> methods; if (method->GetSyntax()->IsStatic()) { owner->GetMethods(methods, operation_node->GetName(), SemanticApi::Filter::True); if (methods.size() == 0) { std::vector<SemanticApi::ISMethod*> temp; if (owner->GetMethods(temp, operation_node->GetName(), SemanticApi::Filter::False)) { syntax_node->Error("К нестатическому методу класса нельзя обращаться из статического метода!"); } } } else { owner->GetMethods(methods, operation_node->GetName()); } if (methods.size() != 0) { TSExpression::TGetMethods* result = new TSExpression::TGetMethods(nullptr, TExpressionResult(), TExpressionResult(methods, method->GetSyntax()->IsStatic())); Return(result); } else { syntax_node->Error("Неизвестный идентификатор!"); } } }
void Visit(SyntaxApi::IOperations::IGetMemberOp* operation_node) { TSOperation *left; left = VisitNode(operation_node->GetLeft()); TExpressionResult left_result = left->GetFormalParameter(); auto left_class = dynamic_cast<TSClass*>(left_result.GetClass()); if (left_result.IsMethods()) syntax_node->Error("Оператор доступа к члену класса нельзя применить к методу!"); if (left_result.IsType()) { auto left_result_class = dynamic_cast<TSClass*>(left_result.GetType()); if (left_result_class->GetSyntax()->IsEnumeration()) { int id = left_result_class->GetSyntax()->GetEnumId(operation_node->GetName()); //TODO ввести спец функции min max count if (id == -1) syntax_node->Error("Перечислимого типа с таким именем не существует!"); else { delete left; TSExpression::TEnumValue* result = new TSExpression::TEnumValue(owner, dynamic_cast<TSClass*>(left_result.GetType())); result->val = id; Return(result); } } else { TSClassField* static_member = left_result_class->GetField(operation_node->GetName(), true, true); if (static_member != nullptr) { TSExpression::TGetClassField* result = new TSExpression::TGetClassField( left, left_result, static_member); Return(result); } else { std::vector<SemanticApi::ISMethod*> methods; if (left_result_class->GetMethods(methods, operation_node->GetName(), SemanticApi::Filter::True)) { TSExpression::TGetMethods* result = new TSExpression::TGetMethods( left, left_result, TExpressionResult(methods, method->GetSyntax()->IsStatic())); Return(result); } else syntax_node->Error("Статического поля или метода с таким именем не существует!"); } } } else { TSClassField* member = (left_class != nullptr) ? left_class->GetField(operation_node->GetName(), true) : nullptr; if (member != nullptr) { if (member->GetSyntax()->IsStatic()) syntax_node->Error("Оператор доступа к члену класса нельзя применить к объекту для доступа к статическому члену, \nвместо объекта следует использовать имя класса!"); ValidateAccess(syntax_node, owner, member); TSExpression::TGetClassField* result = new TSExpression::TGetClassField( left, left_result, member); Return(result); } else { std::vector<SemanticApi::ISMethod*> methods; if (left_class->GetMethods(methods, operation_node->GetName(), SemanticApi::Filter::False)) { TSExpression::TGetMethods* result = new TSExpression::TGetMethods( left, left_result, TExpressionResult(methods, false)); Return(result); } else syntax_node->Error("Члена класса с таким именем не существует!"); } } }
SyntaxApi::IParameter * TSParameter::IGetSyntax() const { return GetSyntax(); }