Skip to content

Commit 73ec76e

Browse files
committed
modify: 增加std::前缀,解决clang下编译问题
1 parent e1d0694 commit 73ec76e

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

ast/NodeAST.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ llvm::Value *BinaryExprAST::codegen() {
7474
// auto boolR = Builder.CreateICmpNE(R,ConstantInt::get(getTypeFromStr("bool"),0));
7575
// Builder.
7676
// return Builder.CreateICmpSLE(boolL, boolR, "less_equ");
77-
default:
78-
return LogErrorV(("invalid binary operator"));
77+
default:
78+
return LogErrorV(("invalid binary operator"));
7979
}
8080
} else {
8181
// 类型不相同,做类型转换
@@ -220,10 +220,10 @@ llvm::Value *CallExprAST::codegen() {
220220
argsV.push_back(av);
221221
}
222222

223-
if (func == NIL){
224-
auto ev = ExternFunctionLinker::tryHandleFuncCall(TheContext,*TheModule,callName,&argsV);
223+
if (func == NIL) {
224+
auto ev = ExternFunctionLinker::tryHandleFuncCall(TheContext, *TheModule, callName, &argsV);
225225
// Extern直接处理,就直接返回
226-
if (ev){
226+
if (ev) {
227227
return ev;
228228
}
229229
}
@@ -254,7 +254,7 @@ llvm::Function *PrototypeAST::codegen() {
254254
}
255255
llvm::FunctionType *FT = llvm::FunctionType::get(getTypeFromStr(returnType), Args, false);;
256256
llvm::Function *F =
257-
llvm::Function::Create(FT, llvm::Function::ExternalLinkage, name, TheModule.get());
257+
llvm::Function::Create(FT, llvm::Function::ExternalLinkage, getName(), TheModule.get());
258258

259259
// Set names for all arguments.
260260
unsigned Idx = 0;
@@ -407,8 +407,7 @@ string ForExprAST::toString() {
407407

408408

409409
const std::string &PrototypeAST::getName() const {
410-
auto str = FuncPrefix + name;
411-
return move(str);
410+
return name;
412411
}
413412

414413
PrototypeAST::PrototypeAST(const string &returnType, const string &name, const vector<VariableDeclarationAST *> &args)
@@ -426,7 +425,8 @@ void FunctionAST::cleanCodeGenContext() {
426425
}
427426

428427
llvm::Function *FunctionAST::codegen() {
429-
llvm::Function *function = TheModule->getFunction(Proto->getName());
428+
auto name = Proto->getName();
429+
llvm::Function *function = TheModule->getFunction(name);
430430
// 设置返回值block
431431
auto retBB = BasicBlock::Create(TheContext, "function_ret");
432432
TheCodeGenContext->setRetBb(retBB);
@@ -867,21 +867,23 @@ vector<Constant *> *VariableArrDeclarationAST::genGlobalExprs() {
867867
// for (auto exp = exprs->begin(); exp != exprs->end() ; exp++) {
868868
//
869869
// }
870-
for_each(exprs->begin(), exprs->end(), [&](NodeAST *e) {
870+
for_each(exprs->begin(), exprs->end(), [&](NodeAST *e) -> void {
871871
auto v = e->codegen();
872872
if (!isa<Constant>(v)) {
873873
if (v->getType()->isIntegerTy()) {
874874
// auto id = typeid(v);
875875
auto ty = dyn_cast<IntegerType>(v->getType());
876876
if (ty == NIL) {
877-
return LogErrorV("全局数组初始化必须为常量声明");
877+
LogErrorV("全局数组初始化必须为常量声明");
878+
return;
878879
} else {
879880
// TODO FixME!
880881
auto info = typeid(v).name();
881882
v = ConstantInt::get(getTypeFromStr("int"), 0);
882883
}
883884
} else {
884-
return LogErrorV("全局数组初始化必须为常量声明");
885+
LogErrorV("全局数组初始化必须为常量声明");
886+
return;
885887
}
886888
}
887889
arr_index_value_vector->push_back(dyn_cast<Constant>(v));
@@ -950,12 +952,14 @@ vector<uint64_t> VariableArrDeclarationAST::getIndexVal() {
950952
if (vmaxindex.empty()) {
951953
vmaxindex.push_back(INT_MAX);
952954
} else {
953-
return LogErrorV("只允许数组index首部为空值,要不然无法编译,我就罢工了");
955+
LogError("只允许数组index首部为空值,要不然无法编译,我就罢工了");
956+
return;
954957
}
955958
} else {
956959
auto value_index = dyn_cast<ConstantInt>(e->codegen());
957960
if (value_index == NIL) {
958-
return LogErrorV("声明一个数组长度不能使用非常量");
961+
LogError("声明一个数组长度不能使用非常量");
962+
return;
959963
} else {
960964
if (value_index->getBitWidth() <= 32) {
961965
vmaxindex.push_back(value_index->getSExtValue());
@@ -1158,7 +1162,7 @@ llvm::Value *StringExprAST::codegen() {
11581162
if (TheCodeGenContext->getFunc() == NIL) {
11591163
auto sz = str->size();
11601164
auto arr_type = ArrayType::get(getTypeFromStr("char"), sz + 1);
1161-
gv = new GlobalVariable(*TheModule,arr_type,
1165+
gv = new GlobalVariable(*TheModule, arr_type,
11621166
true, GlobalValue::PrivateLinkage, ConstantDataArray::getString(TheContext, *str),
11631167
getUniqueId());
11641168
// for (int i = 0; i < sz; ++i) {
@@ -1168,7 +1172,7 @@ llvm::Value *StringExprAST::codegen() {
11681172
// 反斜杠0
11691173
// v.push_back(ConstantInt::get(getTypeFromStr("char"), '\0'));
11701174
gv->setUnnamedAddr(GlobalVariable::UnnamedAddr::Global);
1171-
return ConstantExpr::getBitCast(gv,getTypeFromStr("str"));
1175+
return ConstantExpr::getBitCast(gv, getTypeFromStr("str"));
11721176
} else {
11731177
gv = Builder.CreateGlobalString(*str, StringExprAST::getUniqueId());
11741178
}

extern/ExternFunctionLinker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ Value* ExternFunctionLinker::tryHandleFuncCall(LLVMContext &context, Module &mod
2020
void ExternFunctionLinker::registerHandler(ExternFunctionHandler *handler) {
2121
if (handler != NIL && std::find(handlers.begin(),handlers.end(),handler) == handlers.end()) {
2222
handlers.push_back(handler);
23-
sort(handlers.begin(),handlers.end(),ExternFunctionHandler::externFunctionHandlerCompRule);
23+
std::sort(handlers.begin(), handlers.end(), ExternFunctionHandler::externFunctionHandlerCompRule);
2424
}
2525
}

0 commit comments

Comments
 (0)