00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "TestUtil.hpp"
00035 #include "../CToken.hpp"
00036 #include <iostream>
00037 #include <string>
00038 #include <sstream>
00039
00040 using namespace cfront;
00041
00042 RefNode
00043 parseString(std::string str, void (cfront::CParser::* ruleFunc)())
00044 {
00045 Logs logs;
00046 ParserLexerSharedState sharedState;
00047 std::stringstream s(str);
00048 cfront::CLexer lexer(s);
00049 lexer.setTokenObjectFactory(CToken::factory);
00050 lexer.setParserSharedState(&sharedState);
00051
00052 CAnalyzer analyzer;
00053 analyzer.initialize();
00054 analyzer.setLogs(&logs);
00055 TargetInfo* targetInfo = makeDefaultTargetInfo();
00056 analyzer.setTargetInfo(targetInfo);
00057
00058 cfront::CParser parser(lexer);
00059 parser.setLogs(&logs);
00060
00061 antlr::ASTFactory astFactory("ValueNode", ValueNode::factory);
00062 parser.initializeASTFactory(astFactory);
00063 analyzer.setASTFactory(&astFactory);
00064 parser.setASTFactory(&astFactory);
00065 parser.setAnalyzer(&analyzer);
00066
00067 (parser.*ruleFunc)();
00068
00069 delete targetInfo;
00070
00071 return RefNode(parser.getAST());
00072 }
00073
00074 TargetInfo*
00075 makeDefaultTargetInfo()
00076 {
00077
00078 TargetInfo* info = new TargetInfo();
00079 info->setSize(TargetInfo::POINTER, 8);
00080 info->setSize(TargetInfo::BOOL, 1);
00081 info->setSize(TargetInfo::CHAR, 1);
00082 info->setSize(TargetInfo::SHORT, 2);
00083 info->setSize(TargetInfo::INT, 4);
00084 info->setSize(TargetInfo::LONG, 8);
00085 info->setSize(TargetInfo::LLONG, 8);
00086 info->setSize(TargetInfo::FLOAT, 4);
00087 info->setSize(TargetInfo::DOUBLE, 8);
00088 info->setSize(TargetInfo::LDOUBLE, 12);
00089 info->setSize(TargetInfo::VECTOR, 16);
00090
00091 info->setAlign(TargetInfo::POINTER, 8);
00092 info->setAlign(TargetInfo::BOOL, 1);
00093 info->setAlign(TargetInfo::CHAR, 1);
00094 info->setAlign(TargetInfo::SHORT, 2);
00095 info->setAlign(TargetInfo::INT, 4);
00096 info->setAlign(TargetInfo::LONG, 8);
00097 info->setAlign(TargetInfo::LLONG, 8);
00098 info->setAlign(TargetInfo::FLOAT, 4);
00099 info->setAlign(TargetInfo::DOUBLE, 8);
00100 info->setAlign(TargetInfo::LDOUBLE, 12);
00101 info->setAlign(TargetInfo::VECTOR, 16);
00102
00103 return info;
00104 }