Changeset 637

Show
Ignore:
Timestamp:
08/22/08 13:22:44 (3 months ago)
Author:
weyrick
Message:

switch to boost::spirit lexer. requires boost 1.36

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/rphp/CMakeLists.txt

    r613 r637  
    1212set(RPHP_COMPILER_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/compiler) 
    1313 
    14 Find_Package(Boost COMPONENTS program_options REQUIRED
     14Find_Package(Boost
    1515FIND_PACKAGE(ICU) 
    1616 
    17 add_subdirectory(tools) 
     17#add_subdirectory(tools) 
    1818add_subdirectory(runtime) 
    1919add_subdirectory(compiler) 
  • trunk/rphp/compiler/CMakeLists.txt

    r629 r637  
    33 
    44# TODO: move this to a FindLLVM in cmake/modules 
     5# see frontend/cli/CMakeLists.txt as well 
    56EXECUTE_PROCESS(COMMAND llvm-config --libs core jit bitreader bitwriter linker interpreter OUTPUT_VARIABLE LLVM_LIBRARIES OUTPUT_STRIP_TRAILING_WHITESPACE) 
    67EXECUTE_PROCESS(COMMAND llvm-config --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) 
     
    1314add_definitions(${LLVM_CPP_FLAGS} -fPIC) 
    1415 
    15 include_directories (${PROJECT_SOURCE_DIR}/tools/kdevelop-pg/include 
     16include_directories ( 
    1617                     ${ICU_INCLUDE_DIRS}/unicode 
    1718                     ${ICU_INCLUDE_DIRS} 
    1819                     ${RPHP_RUNTIME_INCLUDE_DIR} 
    1920                     ${LLVM_INCLUDE_DIRS} 
    20                      ) 
     21                     ${Boost_INCLUDE_DIRS} 
     22                    ) 
    2123 
    2224set(EVAL_SRC_FILES 
    23   parser/rphp_default_visitor.cpp 
    24   parser/rphp_parser.cpp 
    25   parser/rphp_visitor.cpp 
    26   parser/phplexer.cpp 
    2725  pDriver.cpp 
    2826) 
  • trunk/rphp/compiler/pDriver.cpp

    r636 r637  
    4343#include "llvm/ExecutionEngine/GenericValue.h" 
    4444 
    45 #include "parser/rphp_debug_visitor.h" 
    46 #include "parser/phplexer.h" 
    47 #include "parser/rphp_parser.h" 
     45#include "pLexers.h" 
    4846#include "pDriver.h" 
    4947 
     
    298296 
    299297 
    300 /** 
    301 * print the token with the same text as php tokens - so they can be compared with 
    302 * the result of get_token_all (see test-tokenize.php) 
    303 **/ 
    304 template <class LexerType, class StringType> 
    305 void printToken(int token, const LexerType& lexer, const StringType& content) 
     298void pDriver::dumpTokens(string fileName) { 
     299 
     300    ifstream inFile; 
     301 
     302    std::string contents = readFile(fileName); 
     303 
     304    pLangTokens tokens; 
     305    pLangLexer lexer(tokens); 
     306 
     307    std::string::iterator source_it = contents.begin(); 
     308    for (tokIteratorType iter = lexer.begin(source_it, contents.end()); iter != lexer.end(); ++iter) 
     309    { 
     310        std::cout << "tok: " << (*iter).id() << ">" << (*iter).value() << "<" << std::endl; 
     311        if ((*iter).id() == 0) 
     312            break; 
     313    } 
     314 
     315 
     316
     317 
     318std::string pDriver::readFile(std::string fileName) 
    306319{ 
    307     int begin = lexer.tokenBegin(); 
    308     int end = lexer.tokenEnd(); 
    309     //UnicodeString tokenText = content.replace(begin, end-begin+1,"\n", "\\n"); 
    310     StringType tokenText(content, begin, end-begin+1); 
    311     if (token == parser::Token_INLINE_HTML) { 
    312         cout << tokenText << " T_INLINE_HTML" << endl; 
    313     } else if (token == parser::Token_OPEN_TAG) { 
    314         cout << tokenText << " T_OPEN_TAG" << endl; 
    315     } else if (token == parser::Token_CLOSE_TAG) { 
    316         cout << tokenText << " T_CLOSE_TAG" << endl; 
    317     } else if (token == parser::Token_ECHO) { 
    318         cout << tokenText << " T_ECHO" << endl; 
    319     } else if (token == parser::Token_WHITESPACE) { 
    320         cout << tokenText << " T_WHITESPACE" << endl; 
    321     } else if (token == parser::Token_CONSTANT_ENCAPSED_STRING) { 
    322         cout << tokenText << " T_CONSTANT_ENCAPSED_STRING" << endl; 
    323     } else if (token == parser::Token_SEMICOLON) { 
    324         cout << tokenText << " ;" << endl; 
    325     } else if (token == parser::Token_VARIABLE) { 
    326         cout << tokenText << " T_VARIABLE" << endl; 
    327     } else if (token == parser::Token_DOUBLE_QUOTE) { 
    328         cout << tokenText << " \"" << endl; 
    329     } else if (token == parser::Token_ENCAPSED_AND_WHITESPACE) { 
    330         cout << tokenText << " T_ENCAPSED_AND_WHITESPACE" << endl; 
    331     } else if (token == parser::Token_OBJECT_OPERATOR) { 
    332         cout << tokenText << " T_OBJECT_OPERATOR" << endl; 
    333     } else if (token == parser::Token_LBRACKET) { 
    334         cout << tokenText << " [" << endl; 
    335     } else if (token == parser::Token_RBRACKET) { 
    336         cout << tokenText << " ]" << endl; 
    337     } else if (token == parser::Token_NUM_STRING) { 
    338         cout << tokenText << " T_NUM_STRING" << endl; 
    339     } else if (token == parser::Token_STRING) { 
    340         cout << tokenText << " T_STRING" << endl; 
    341     } else if (token == parser::Token_ASSIGN) { 
    342         cout << tokenText << " =" << endl; 
    343     } else if (token == parser::Token_DNUMBER) { 
    344         cout << tokenText << " T_DNUMBER" << endl; 
    345     } else if (token == parser::Token_LNUMBER) { 
    346         cout << tokenText << " T_LNUMBER" << endl; 
    347     } else if (token == parser::Token_PLUS) { 
    348         cout << tokenText << " +" << endl; 
    349     } else if (token == parser::Token_MINUS) { 
    350         cout << tokenText << " -" << endl; 
    351     } else if (token == parser::Token_CONCAT) { 
    352         cout << tokenText << " ." << endl; 
    353     } else if (token == parser::Token_INC) { 
    354         cout << tokenText << " T_INC" << endl; 
    355     } else if (token == parser::Token_DEC) { 
    356         cout << tokenText << " T_DEC" << endl; 
    357     } else if (token == parser::Token_IS_EQUAL) { 
    358         cout << tokenText << " T_IS_EQUAL" << endl; 
    359     } else if (token == parser::Token_IS_NOT_EQUAL) { 
    360         cout << tokenText << " T_IS_NOT_EQUAL" << endl; 
    361     } else if (token == parser::Token_IS_IDENTICAL) { 
    362         cout << tokenText << " T_IS_IDENTICAL" << endl; 
    363     } else if (token == parser::Token_IS_NOT_IDENTICAL) { 
    364         cout << tokenText << " T_IS_NOT_IDENTICAL" << endl; 
    365     } else if (token == parser::Token_IS_SMALLER) { 
    366         cout << tokenText << " <" << endl; 
    367     } else if (token == parser::Token_IS_GREATER) { 
    368         cout << tokenText << " >" << endl; 
    369     } else if (token == parser::Token_IS_SMALLER_OR_EQUAL) { 
    370         cout << tokenText << " T_IS_SMALLER_OR_EQUAL" << endl; 
    371     } else if (token == parser::Token_IS_GREATER_OR_EQUAL) { 
    372         cout << tokenText << " T_IS_GREATER_OR_EQUAL" << endl; 
    373     } else if (token == parser::Token_BOOLEAN_OR) { 
    374         cout << tokenText << " T_BOOLEAN_OR" << endl; 
    375     } else if (token == parser::Token_BOOLEAN_AND) { 
    376         cout << tokenText << " T_BOOLEAN_AND" << endl; 
    377     } else if (token == parser::Token_PLUS_ASSIGN) { 
    378         cout << tokenText << " T_PLUS_EQUAL" << endl; 
    379     } else if (token == parser::Token_MINUS_ASSIGN) { 
    380         cout << tokenText << " T_MINUS_EQUAL" << endl; 
    381     } else if (token == parser::Token_MUL_ASSIGN) { 
    382         cout << tokenText << " T_MUL_EQUAL" << endl; 
    383     } else if (token == parser::Token_DIV_ASSIGN) { 
    384         cout << tokenText << " T_DIV_EQUAL" << endl; 
    385     } else if (token == parser::Token_CONCAT_ASSIGN) { 
    386         cout << tokenText << " T_CONCAT_EQUAL" << endl; 
    387     } else if (token == parser::Token_MOD_ASSIGN) { 
    388         cout << tokenText << " T_MOD_EQUAL" << endl; 
    389     } else if (token == parser::Token_AND_ASSIGN) { 
    390         cout << tokenText << " T_AND_EQUAL" << endl; 
    391     } else if (token == parser::Token_OR_ASSIGN) { 
    392         cout << tokenText << " T_OR_EQUAL" << endl; 
    393     } else if (token == parser::Token_XOR_ASSIGN) { 
    394         cout << tokenText << " T_XOR_EQUAL" << endl; 
    395     } else if (token == parser::Token_SL_ASSIGN) { 
    396         cout << tokenText << " T_SL_EQUAL" << endl; 
    397     } else if (token == parser::Token_SR_ASSIGN) { 
    398         cout << tokenText << " T_SR_EQUAL" << endl; 
    399     } else if (token == parser::Token_BANG) { 
    400         cout << tokenText << " !" << endl; 
    401     } else if (token == parser::Token_QUESTION) { 
    402         cout << tokenText << " ?" << endl; 
    403     } else if (token == parser::Token_COLON) { 
    404         cout << tokenText << " :" << endl; 
    405     } else if (token == parser::Token_BIT_AND) { 
    406         cout << tokenText << " &" << endl; 
    407     } else if (token == parser::Token_BIT_OR) { 
    408         cout << tokenText << " |" << endl; 
    409     } else if (token == parser::Token_BIT_XOR) { 
    410         cout << tokenText << " ^" << endl; 
    411     } else if (token == parser::Token_SL) { 
    412         cout << tokenText << " T_SL" << endl; 
    413     } else if (token == parser::Token_SR) { 
    414         cout << tokenText << " T_SR" << endl; 
    415     } else if (token == parser::Token_MUL) { 
    416         cout << tokenText << " *" << endl; 
    417     } else if (token == parser::Token_DIV) { 
    418         cout << tokenText << " /" << endl; 
    419     } else if (token == parser::Token_MOD) { 
    420         cout << tokenText << " %" << endl; 
    421     } else if (token == parser::Token_TILDE) { 
    422         cout << tokenText << " ~" << endl; 
    423     } else if (token == parser::Token_LPAREN) { 
    424         cout << tokenText << " (" << endl; 
    425     } else if (token == parser::Token_RPAREN) { 
    426         cout << tokenText << " )" << endl; 
    427     } else if (token == parser::Token_LBRACE) { 
    428         cout << tokenText << " {" << endl; 
    429     } else if (token == parser::Token_RBRACE) { 
    430         cout << tokenText << " }" << endl; 
    431     } else if (token == parser::Token_COMMA) { 
    432         cout << tokenText << " ," << endl; 
    433     } else if (token == parser::Token_AT) { 
    434         cout << tokenText << " @" << endl; 
    435     } else if (token == parser::Token_INCLUDE) { 
    436         cout << tokenText << " T_INCLUDE" << endl; 
    437     } else if (token == parser::Token_INCLUDE_ONCE) { 
    438         cout << tokenText << " T_INCLUDE_ONCE" << endl; 
    439     } else if (token == parser::Token_EVAL) { 
    440         cout << tokenText << " T_EVAL" << endl; 
    441     } else if (token == parser::Token_REQUIRE) { 
    442         cout << tokenText << " T_REQUIRE" << endl; 
    443     } else if (token == parser::Token_REQUIRE_ONCE) { 
    444         cout << tokenText << " T_REQUIRE_ONCE" << endl; 
    445     } else if (token == parser::Token_PRINT) { 
    446         cout << tokenText << " T_PRINT" << endl; 
    447     } else if (token == parser::Token_ABSTRACT) { 
    448         cout << tokenText << " T_ABSTRACT" << endl; 
    449     } else if (token == parser::Token_BREAK) { 
    450         cout << tokenText << " T_BREAK" << endl; 
    451     } else if (token == parser::Token_CASE) { 
    452         cout << tokenText << " T_CASE" << endl; 
    453     } else if (token == parser::Token_CATCH) { 
    454         cout << tokenText << " T_CATCH" << endl; 
    455     } else if (token == parser::Token_CLASS) { 
    456         cout << tokenText << " T_CLASS" << endl; 
    457     } else if (token == parser::Token_CONST) { 
    458         cout << tokenText << " T_CONST" << endl; 
    459     } else if (token == parser::Token_CONTINUE) { 
    460         cout << tokenText << " T_CONTINUE" << endl; 
    461     } else if (token == parser::Token_DEFAULT) { 
    462         cout << tokenText << " T_DEFAULT" << endl; 
    463     } else if (token == parser::Token_DO) { 
    464         cout << tokenText << " T_DO" << endl; 
    465     } else if (token == parser::Token_ELSE) { 
    466         cout << tokenText << " T_ELSE" << endl; 
    467     } else if (token == parser::Token_EXTENDS) { 
    468         cout << tokenText << " T_EXTENDS" << endl; 
    469     } else if (token == parser::Token_FINAL) { 
    470         cout << tokenText << " T_FINAL" << endl; 
    471     } else if (token == parser::Token_FOR) { 
    472         cout << tokenText << " T_FOR" << endl; 
    473     } else if (token == parser::Token_IF) { 
    474         cout << tokenText << " T_IF" << endl; 
    475     } else if (token == parser::Token_IMPLEMENTS) { 
    476         cout << tokenText << " T_IMPLEMENTS" << endl; 
    477     } else if (token == parser::Token_INSTANCEOF) { 
    478         cout << tokenText << " T_INSTANCEOF" << endl; 
    479     } else if (token == parser::Token_INTERFACE) { 
    480         cout << tokenText << " T_INTERFACE" << endl; 
    481     } else if (token == parser::Token_NEW) { 
    482         cout << tokenText << " T_NEW" << endl; 
    483     } else if (token == parser::Token_PRIVATE) { 
    484         cout << tokenText << " T_PRIVATE" << endl; 
    485     } else if (token == parser::Token_PROTECTED) { 
    486         cout << tokenText << " T_PROTECTED" << endl; 
    487     } else if (token == parser::Token_PUBLIC) { 
    488         cout << tokenText << " T_PUBLIC" << endl; 
    489     } else if (token == parser::Token_RETURN) { 
    490         cout << tokenText << " T_RETURN" << endl; 
    491     } else if (token == parser::Token_STATIC) { 
    492         cout << tokenText << " T_STATIC" << endl; 
    493     } else if (token == parser::Token_SWITCH) { 
    494         cout << tokenText << " T_SWITCH" << endl; 
    495     } else if (token == parser::Token_THROW) { 
    496         cout << tokenText << " T_THROW" << endl; 
    497     } else if (token == parser::Token_TRY) { 
    498         cout << tokenText << " T_TRY" << endl; 
    499     } else if (token == parser::Token_WHILE) { 
    500         cout << tokenText << " T_WHILE" << endl; 
    501     } else if (token == parser::Token_INT_CAST) { 
    502         cout << tokenText << " T_INT_CAST" << endl; 
    503     } else if (token == parser::Token_DOUBLE_CAST) { 
    504         cout << tokenText << " T_DOUBLE_CAST" << endl; 
    505     } else if (token == parser::Token_STRING_CAST) { 
    506         cout << tokenText << " T_STRING_CAST" << endl; 
    507     } else if (token == parser::Token_ARRAY_CAST) { 
    508         cout << tokenText << " T_ARRAY_CAST" << endl; 
    509     } else if (token == parser::Token_OBJECT_CAST) { 
    510         cout << tokenText << " T_OBJECT_CAST" << endl; 
    511     } else if (token == parser::Token_BOOL_CAST) { 
    512         cout << tokenText << " T_BOOL_CAST" << endl; 
    513     } else if (token == parser::Token_UNSET_CAST) { 
    514         cout << tokenText << " T_UNSET_CAST" << endl; 
    515     } else if (token == parser::Token_CLONE) { 
    516         cout << tokenText << " T_CLONE" << endl; 
    517     } else if (token == parser::Token_EXIT) { 
    518         cout << tokenText << " T_EXIT" << endl; 
    519     } else if (token == parser::Token_ELSEIF) { 
    520         cout << tokenText << " T_ELSEIF" << endl; 
    521     } else if (token == parser::Token_ENDIF) { 
    522         cout << tokenText << " T_ENDIF" << endl; 
    523     } else if (token == parser::Token_ENDWHILE) { 
    524         cout << tokenText << " T_ENDWHILE" << endl; 
    525     } else if (token == parser::Token_ENDFOR) { 
    526         cout << tokenText << " T_ENDFOR" << endl; 
    527     } else if (token == parser::Token_FOREACH) { 
    528         cout << tokenText << " T_FOREACH" << endl; 
    529     } else if (token == parser::Token_ENDFOREACH) { 
    530         cout << tokenText << " T_ENDFOREACH" << endl; 
    531     } else if (token == parser::Token_DECLARE) { 
    532         cout << tokenText << " T_DECLARE" << endl; 
    533     } else if (token == parser::Token_ENDDECLARE) { 
    534         cout << tokenText << " T_ENDDECLARE" << endl; 
    535     } else if (token == parser::Token_AS) { 
    536         cout << tokenText << " T_AS" << endl; 
    537     } else if (token == parser::Token_ENDSWITCH) { 
    538         cout << tokenText << " T_ENDSWITCH" << endl; 
    539     } else if (token == parser::Token_FUNCTION) { 
    540         cout << tokenText << " T_FUNCTION" << endl; 
    541     } else if (token == parser::Token_USE) { 
    542         cout << tokenText << " T_USE" << endl; 
    543     } else if (token == parser::Token_GLOBAL) { 
    544         cout << tokenText << " T_GLOBAL" << endl; 
    545     } else if (token == parser::Token_VAR) { 
    546         cout << tokenText << " T_VAR" << endl; 
    547     } else if (token == parser::Token_UNSET) { 
    548         cout << tokenText << " T_UNSET" << endl; 
    549     } else if (token == parser::Token_ISSET) { 
    550         cout << tokenText << " T_ISSET" << endl; 
    551     } else if (token == parser::Token_ISSET) { 
    552         cout << tokenText << " T_ISSET" << endl; 
    553     } else if (token == parser::Token_EMPTY) { 
    554         cout << tokenText << " T_EMPTY" << endl; 
    555     } else if (token == parser::Token_HALT_COMPILER) { 
    556         cout << tokenText << " T_HALT_COMPILER" << endl; 
    557     } else if (token == parser::Token_DOUBLE_ARROW) { 
    558         cout << tokenText << " T_DOUBLE_ARROW" << endl; 
    559     } else if (token == parser::Token_LIST) { 
    560         cout << tokenText << " T_LIST" << endl; 
    561     } else if (token == parser::Token_ARRAY) { 
    562         cout << tokenText << " T_ARRAY" << endl; 
    563     } else if (token == parser::Token_CLASS_C) { 
    564         cout << tokenText << " T_CLASS_C" << endl; 
    565     } else if (token == parser::Token_METHOD_C) { 
    566         cout << tokenText << " T_METHOD_C" << endl; 
    567     } else if (token == parser::Token_FUNC_C) { 
    568         cout << tokenText << " T_FUNC_C" << endl; 
    569     } else if (token == parser::Token_LINE) { 
    570         cout << tokenText << " T_LINE" << endl; 
    571     } else if (token == parser::Token_FILE) { 
    572         cout << tokenText << " T_FILE" << endl; 
    573     } else if (token == parser::Token_COMMENT) { 
    574         cout << tokenText << " T_COMMENT" << endl; 
    575     } else if (token == parser::Token_DOC_COMMENT) { 
    576         cout << tokenText << " T_DOC_COMMENT" << endl; 
    577     } else if (token == parser::Token_PAAMAYIM_NEKUDOTAYIM) { 
    578         cout << tokenText << " T_DOUBLE_COLON" << endl; 
    579     } else if (token == parser::Token_OPEN_TAG_WITH_ECHO) { 
    580         cout << tokenText << " T_OPEN_TAG_WITH_ECHO" << endl; 
    581     } else if (token == parser::Token_CURLY_OPEN) { 
    582         cout << tokenText << " T_CURLY_OPEN" << endl; 
    583     } else if (token == parser::Token_STRING_VARNAME) { 
    584         cout << tokenText << " T_STRING_VARNAME" << endl; 
    585     } else if (token == parser::Token_DOLLAR_OPEN_CURLY_BRACES) { 
    586         cout << tokenText << " T_DOLLAR_OPEN_CURLY_BRACES" << endl; 
    587     } else if (token == parser::Token_DOLLAR) { 
    588         cout << tokenText << " $" << endl; 
    589     } else if (token == parser::Token_LOGICAL_XOR) { 
    590         cout << tokenText << " T_LOGICAL_XOR" << endl; 
    591     } else if (token == parser::Token_LOGICAL_AND) { 
    592         cout << tokenText << " T_LOGICAL_AND" << endl; 
    593     } else if (token == parser::Token_LOGICAL_OR) { 
    594         cout << tokenText << " T_LOGICAL_OR" << endl; 
    595     } else if (token == parser::Token_START_HEREDOC) { 
    596         cout << tokenText << " T_START_HEREDOC" << endl; 
    597     } else if (token == parser::Token_END_HEREDOC) { 
    598         cout << tokenText << " T_END_HEREDOC" << endl; 
    599     } else if (token == parser::Token_BACKTICK) { 
    600         cout << tokenText << " `" << endl; 
    601     } else if (token == 0) { 
    602         cout << tokenText << " end of file" << endl; 
    603     } else { 
    604         cout << tokenText << " unknown token" << token; 
    605     } 
    606 
    607  
    608 void pDriver::dumpTokens(string fileName) { 
    609  
    610     ifstream inFile; 
    611  
    612     inFile.open(fileName.c_str(), ifstream::in); 
    613     if (!inFile) { 
    614         cout << "Unable to open file: " << fileName << endl; 
    615         exit(1); // terminate with error 
    616     } 
    617  
    618     string contents; 
    619     char buf[512]; 
    620     while (inFile) { 
    621         inFile.getline(buf, 512); 
    622         //cout << "read: " << buf << endl; 
    623         contents += buf; 
    624     } 
    625  
    626     inFile.close(); 
    627  
    628     cout << "contents: " << contents << endl; 
    629  
    630     BLexer lexer(0, contents); 
    631     int token; 
    632     while (token = lexer.nextTokenKind()) { 
    633         printToken(token, lexer, contents); 
    634     } 
    635     printToken(token, lexer, contents); 
    636  
     320    std::ifstream instream(fileName.c_str()); 
     321    if (!instream.is_open()) { 
     322        std::cerr << "Couldn't open file: " << fileName << std::endl; 
     323        exit(-1); 
     324    } 
     325    instream.unsetf(std::ios::skipws); 
     326    return std::string(std::istreambuf_iterator<char>(instream.rdbuf()), 
     327                       std::istreambuf_iterator<char>()); 
    637328} 
    638329 
    639330void pDriver::dumpAST(string fileName) { 
    640  
     331/* 
    641332    ifstream inFile; 
    642333 
     
    676367        std::cout << "Couldn't parse content" << std::endl; 
    677368    } 
    678  
    679 } 
    680  
    681  
    682 } 
    683  
    684  
     369*/ 
     370} 
     371 
     372 
     373} 
     374 
     375 
  • trunk/rphp/compiler/pDriver.h

    r622 r637  
    3232    private: 
    3333        llvm::Module* compileToIR(std::string fileName); 
     34        std::string readFile(std::string fileName); 
    3435 
    3536    public: