Exemplo n.º 1
0
void __fastcall TDesignFrm::btAddSubHeadClick(TObject *Sender)
{
    String  key = vleHeadDef->Keys[vleHeadDef->Row];
    if(key == "")
    {
        ShowMessage("请先选择封包头!");
        return;
    }

    String  fileName;
    if(InputQuery("输入文件名(不加后缀)", "输入文件名(不加后缀)", fileName))
    {
        if(fileName == "")
            return;

        if(fileName.Pos("."))
            fileName = LeftString(fileName, ".");
        fileName += ".eggxp";

        WorkSpace	*  selWorkSpace = m_WorkSpaceManager->CreateNewWorkSpace();
        selWorkSpace->InitWorkSpace(m_WorkSpaceManager->GetFilePath(),
                    fileName, key);
        selWorkSpace->SaveToFile();
        m_WorkSpaceManager->ReloadWorkSpacePack();
        WorkspaceToGUI();
    }
}
Exemplo n.º 2
0
void __fastcall TMDIChild::actSaveFileExecute(TObject *Sender)
{
    if(m_ActiveFileStruct == NULL)
        return;

    m_ActiveFileStruct->GetMemory()->Clear();
    m_HexEditor->SaveToStream(m_ActiveFileStruct->GetMemory());

    String fileName = m_WorkSpace->GetFileName();

    if(fileName == "")
    {
        if(InputQuery("输入文件名(不要加后缀)", "输入保存的文件名(不要加后缀)", fileName))
        {
            if(fileName.Pos("."))
                fileName = LeftString(fileName, ".");
            fileName += ".eggxp";
            m_WorkSpace->SetFileName(fileName);
        }
        else
            return;
    }

    //保存工作区
//	if(m_WorkSpace->GetPath() == "")
//	{
    if(NeedSaveReq)
        NeedSaveReq();
//	}

    if(m_WorkSpace->GetComment() == "" && m_HexEditor->DataSize >= 2)
    {
        //自动生成注释
        if(m_WorkSpace->GetComment() == "")
        {
            char	*pointer = m_HexEditor->GetFastPointer(0, m_HexEditor->DataSize);
            String comment = BinToStr(pointer, 2);
            m_WorkSpace->SetComment(comment);
            if(RefreshWorkSpaceReq)
                RefreshWorkSpaceReq();
        }
    }

    if(m_WorkSpace->IsNewFile())
    {
        if(m_WorkSpace->GetPath() == "")
            return;
        m_WorkSpace->SaveToFile(fileName);
    }
    else
    {
        m_WorkSpace->SaveToFile();
    }

    DoSetTabCaption();
    m_HexEditor->Modified = false;
    m_bTreeModify = false;
    CheckModify();
}
Exemplo n.º 3
0
void __fastcall 	TMDIChild::FastParseExecute(TObject *Sender)
{
    TMenuItem * selMenu = (TMenuItem * )Sender;
    String typeName = selMenu->Caption;

    //修正typeName
    if(selMenu->Caption == "-")
        return;

    if(typeName.Pos("["))
        typeName = LeftString(typeName, "[");

    ClassData * curClass = GetCurParseClass();

//	bool	haveResult = false;
    String 	defaultName;
    if(curClass == NULL)
    {
        //当前无结构体, 新建结构体
        int classCount = m_WorkSpace->GetClassManager()->GetClassCount();
        defaultName = FormatStr("tagUnNamedStruct%d", classCount);

        curClass = m_WorkSpace->GetClassManager()->AddClass();
        curClass->Init(defaultName, "");
        RefreshAllClassView();
    }

    String arrayVar;
    if(selMenu->Tag == 0)
        arrayVar = "";
    else
        arrayVar = IntToStr(selMenu->Tag);

    ClassMember * curMember = curClass->AddMember();
    defaultName = FormatStr("UnKnown%d", m_ParseTree->GetSize() + m_FastParsePos);

    curMember->Init(typeName, defaultName, "", arrayVar);

    m_ParseTree->BindClass(curClass);
    ExpandFirstNode();
    ParseData(false);

    tagSelRect	selRect;
    if(GetTreeSelRect(selRect) == false)
        return;
    GotoPosition(selRect.SelStart + selRect.SelLength);
}
Exemplo n.º 4
0
FunctionModel FunctionFind(std::vector<Token>::const_iterator& it, std::vector<Token>::const_iterator end, bool TimeDefault)
{
    // we should be at start of function

    std::string returnType = it->GetValue();
    ++it;
    bool Volatile = false;
    bool time =TimeDefault;
    bool threadsafe = false;

    if (it == end)
        throw("function half declared at end of file");

    std::string functionDesc("too lazy to comment this function");

    if (it->GetType() == Token::comment)
    {
        functionDesc = it->GetValue();
        ++it;
    }

    if (it == end)
        throw("function half declared at end of file");

    while (it->GetType() == Token::comment)
    {
        std::string commentString = it->GetValue();

        if (LeftString(commentString,5UL) != "<xlw:")
            throw("unexpected comment in function definition before function name");

        bool found = false;
        if (commentString == "<xlw:volatile")
        {
            Volatile =true;
            ++it;
            found = true;
            if (it == end)
                throw("function half declared at end of file");
        }
        if (commentString == "<xlw:time")
        {
            time = true;
            ++it;
            found = true;
            if (it == end)
                throw("function half declared at end of file");
        }
        if (commentString == "<xlw:threadsafe")
        {
            threadsafe = true;
            ++it;
            found = true;
            if (it == end)
                throw("function half declared at end of file");
        }
        if (!found)
            throw("unknown xlw command: "+commentString);
    }

    if (it->GetType() != Token::identifier)
        throw("function name expected after return type");
    
    std::string functionName(it->GetValue());

    FunctionModel theFunction(returnType,functionName,functionDesc,Volatile,time,threadsafe);

    ++it;
    if (it == end)
        throw("function half declared at end of file");

    if ( it->GetType() != Token::left)
        throw("left parenthesis expected after function name: "+functionName);

    ++it;
    if (it == end)
        throw("function half declared at end of file "+functionName);

    while ( it->GetType() != Token::right)
    {
        if (it->GetType() != Token::identifier)
            throw("return type expected in arg list "+functionName);

        std::string argType = it->GetValue(); 

        ++it;
        if (it == end)
            throw("function half declared at end of file "+functionName);

        if (it->GetType() != Token::identifier)
            throw("argument name expected in arg list "+functionName);

        std::string argName = it->GetValue(); 

        ++it;
        if (it == end)
            throw("function half declared at end of file "+functionName);

        std::string argComment("too lazy to comment this one");

        if (it->GetType() == Token::comment)
        {
            argComment = it->GetValue();
            ++it;
            if (it == end)
                throw("function half declared at end of file "+functionName);
        }

        // ok got this argument's data

        theFunction.AddArgument(argType,argName,argComment);

        if (it->GetType() == Token::comma)
        {
            ++it;
            if (it == end)
                throw("function half declared at end of file "+functionName);
        }

    }
    ++it; // get past final right bracket
    return theFunction;

}
Exemplo n.º 5
0
std::vector<FunctionModel> ConvertToFunctionModel(const std::vector<Token>& input, std::string& LibraryName)
{
    std::vector<FunctionModel> output;
    bool timeDefault=false;

    std::vector<Token>::const_iterator it = input.begin();

    while (it != input.end())
    {
        Token ThisToken = *it;

        switch (ThisToken.GetType())
        {
            case Token::preprocessor :
                ++it;
                break; // ignore preprocessor directives
            case Token::curlyleft :
                throw("curly bracket found, only functions can be coped with");
                break;
            case Token::curlyright :
                throw("curly bracket found, only functions can be coped with");
                break;
            case Token::ampersand :
                throw("unexpected ampersand found, return type expected");
                break;
            case Token::comma :
                throw("unexpected comma found, return type expected");
                break;
            case Token::right :
                throw("unexpected ) found, return type expected");
                break;
            case Token::left :
                throw("unexpected ( found, return type expected");
                break;
            case Token::semicolon :
                ++it;
                break;
            case Token::comment :
                {
                    std::string val = it->GetValue();
                    if (LeftString(val,5) == "<xlw:")
                    {
                        bool found = false;

                        if (val.size()>= 19 && val.substr(0,17) == "<xlw:libraryname=")
                        {
                            LibraryName = val.substr(17,val.size());
                            found =true;
                        }

                        if (LeftString(val,12) == "<xlw:timeall")
                        {
                            timeDefault = true;
                            found =true;

                        }

                        if (LeftString(val,13) == "<xlw:timenone")
                        {
                            timeDefault = false;
                            found =true;

                        }

                        if (!found)
                            std::cout << "Unknown xlw command "+val+"\n";

                    }
                    ++it; //ignore comment unless in function definition
                }
                break;
            case Token::identifier :

                if (it->GetValue() == "using") {
                    // Ignore 'using namespace xxx;'
                    ++it;
                    if (it == input.end() || it->GetType() != Token::identifier || it->GetValue() != "namespace")
                        throw("invalid syntax for declaration : 'using namespace xxx;'");
                    ++it;
                    if (it == input.end() || it->GetType() != Token::identifier)
                        throw("invalid syntax for declaration : 'using namespace xxx;'");
                    ++it;
                } else {
                    // Process a function declaration
                    output.push_back(FunctionFind(it,input.end(),timeDefault));
                }

                break;
            default:
                throw("unknown token type found");
        }



    }

    return output;

}