本文整理汇总了C++中AstVar::type方法的典型用法代码示例。如果您正苦于以下问题:C++ AstVar::type方法的具体用法?C++ AstVar::type怎么用?C++ AstVar::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AstVar
的用法示例。
在下文中一共展示了AstVar::type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visitBlockNode
void BytecodeGenerationVisitor::visitBlockNode(BlockNode* node) { // DONE
Scope* prevScope = currentScope;
currentScope = node->scope();
Scope::VarIterator varsToSave(currentScope);
while (varsToSave.hasNext()) {
AstVar* v = varsToSave.next();
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_LOADVAR]);
bytecode->addInt16(getVarId(v));
locals.push_back(v);
}
Scope::VarIterator varsToInit(currentScope);
while (varsToInit.hasNext()) {
AstVar* v = varsToInit.next();
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_LOAD0]);
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_STOREVAR]);
bytecode->addInt16(getVarId(v));
}
Scope::FunctionIterator functionsToAdd(node -> scope());
while (functionsToAdd.hasNext()) {
AstFunction *astFunction = functionsToAdd.next();
BytecodeFunction *bytecodeFunction = new BytecodeFunction(astFunction);
code -> addFunction(bytecodeFunction);
}
Scope::FunctionIterator functionsToBuild(node -> scope());
while (functionsToBuild.hasNext()) {
AstFunction *astFunction = functionsToBuild.next();
astFunction->node()->visit(this);
}
for (unsigned int i = 0; i < (node -> nodes()); i++) {
node -> nodeAt(i) -> visit(this);
if (currentType != VT_VOID && !(node->nodeAt(i)->isReturnNode())) {
bytecode -> addInsn(BC_POP);
}
}
Scope::VarIterator varsToRestore(currentScope);
stack<AstVar*> variables;
while (varsToRestore.hasNext()) {
variables.push(varsToRestore.next());
}
while (!variables.empty()) {
AstVar* v = variables.top();
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_STOREVAR]);
bytecode->addInt16(getVarId(v));
locals.pop_back();
variables.pop();
}
currentScope = prevScope;
currentType = VT_VOID;
}
示例2: visitVarDecls
// private:
// visitBlockNodeImpl
void BytecodeGenerator::visitVarDecls(BlockNode* node) {
Bytecode* bc = _state.currentBcToFill();
Scope::VarIterator varIt(node->scope());
while(varIt.hasNext()) {
AstVar* var = varIt.next();
uint16_t varId = _state.currentCtxAddVar(var->name(), node->position());
Instruction bcLoad0 = typedInsn(var->type(), BC_ILOAD0, BC_DLOAD0, BC_SLOAD0);
bc->addInsn(bcLoad0);
Instruction bcStore = typedInsn(var->type(), BC_STOREIVAR, BC_STOREDVAR, BC_STORESVAR);
genBcInsnWithId(bc, bcStore, varId);
}
}
示例3: visitCallNode
void BytecodeGenerationVisitor::visitCallNode(CallNode* node) {
const Signature& sign = code->functionByName(node->name())->signature();
AstFunction* f = currentScope->lookupFunction(node->name());
for (unsigned int i = 0; i < node->parametersNumber(); i++) {
AstVar* v = f->scope()->lookupVariable(sign[i + 1].second);
uint16_t varId = getVarId(v);
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_LOADVAR]);
bytecode->addInt16(varId);
}
for (unsigned int i = 0; i < node->parametersNumber(); i++) {
node->parameterAt(i)->visit(this);
if (currentType == VT_INT && sign[i + 1].first == VT_DOUBLE) {
bytecode->addInsn(BC_I2D);
} else if (currentType == VT_DOUBLE && sign[i + 1].first == VT_INT) {
bytecode->addInsn(BC_D2I);
}
}
for (int i = node->parametersNumber(); i > 0; i--) {
AstVar* v = f->scope()->lookupVariable(sign[i].second);
uint16_t varId = getVarId(v);
bytecode->addInsn(insnByUntypedInsn[sign[i].first][UT_STOREVAR]);
bytecode->addInt16(varId);
}
bytecode->addInsn(BC_CALL);
bytecode->addInt16(code->functionByName(node->name())->id());
if (sign[0].first == VT_VOID) {
for (unsigned int i = node->parametersNumber(); i > 0; i--) {
AstVar* v = f->scope()->lookupVariable(sign[i].second);
uint16_t varId = getVarId(v);
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_STOREVAR]);
bytecode->addInt16(varId);
}
} else {
for (unsigned int i = node->parametersNumber(); i > 0; i--) {
AstVar* v = f->scope()->lookupVariable(sign[i].second);
uint16_t varId = getVarId(v);
bytecode->addInsn(BC_SWAP);
bytecode->addInsn(insnByUntypedInsn[v->type()][UT_STOREVAR]);
bytecode->addInt16(varId);
}
}
currentType = sign[0].first;
}
示例4: visitFunctionNode
void ASTtoByteCodeTranslator::visitFunctionNode(FunctionNode* node) {
uint16_t varId = 0;
for(size_t i = 0; i < node->parametersNumber(); ++i) {
AstVar *var = node->body()->scope()->lookupVariable(node->parameterName(node->parametersNumber() - i - 1));
varMap[var] = varId;
Bytecode *bytecode = funStack.top()->bytecode();
switch (var->type()) {
case VT_INT:
bytecode->addInsn(BC_STOREIVAR);
break;
case VT_DOUBLE:
bytecode->addInsn(BC_STOREDVAR);
break;
case VT_STRING:
bytecode->addInsn(BC_STORESVAR);
break;
default:
bytecode->addInsn(BC_INVALID);
break;
}
bytecode->addUInt16(varId++);
}
node->body()->visit(this);
}
示例5: visitBlockNode
void AstPrinterVisitor::visitBlockNode(BlockNode* node) {
if (!isMainScope(node->scope())) {
_output << "{" << endl;
}
Scope::VarIterator varIt(node->scope());
while(varIt.hasNext()) {
AstVar* var = varIt.next();
printVarType(var->type());
_output << " " << var->name();
printSemicolon();
}
Scope::FunctionIterator funcIt(node->scope());
while(funcIt.hasNext()) {
FunctionNode* func = funcIt.next()->node();
func->visit(this);
}
for (uint32_t i = 0; i < node->nodes(); ++i) {
node->nodeAt(i)->visit(this);
if (!(node->nodeAt(i)->isIfNode()
|| node->nodeAt(i)->isWhileNode()
|| node->nodeAt(i)->isForNode()
|| node->nodeAt(i)->isReturnNode()
|| node->nodeAt(i)->isBlockNode())) {
printSemicolon();
}
}
if (!isMainScope(node->scope())) {
_output << "}" << endl;
}
}
示例6: printBlockContents
void Printer::printBlockContents(BlockNode* node) {
// functions delcarations
Scope::FunctionIterator funIt(node->scope());
while (funIt.hasNext()) {
funIt.next()->node()->visit(this);
out << '\n';
}
// variables declarations
Scope::VarIterator varIt(node->scope());
while (varIt.hasNext()) {
AstVar* var = varIt.next();
out << typeToName(var->type())
<< " " << var->name() << ";\n";
}
// nodes
for (size_t i = 0; i < node->nodes(); ++i) {
AstNode* subNode = node->nodeAt(i);
subNode->visit(this);
if (!subNode->isIfNode() &&
!subNode->isWhileNode() &&
!subNode->isForNode()) {
out << ';';
}
out << '\n';
}
}
示例7: visitFunctionNode
void ByteCodeVisitor::visitFunctionNode(mathvm::FunctionNode *node) {
BytecodeFunction *dump = currentBytecodeFunction;
if (currScope) {
AstFunction *function = currScope->lookupFunction(node->name());
if (!function) {
error("undeclared function %s", node->name().c_str());
}
AstFunctionInfo *astFunctionInfo = (AstFunctionInfo *) function->info();
currentBytecodeFunction = astFunctionInfo->function;
} else {
currentBytecodeFunction = dynamic_cast<BytecodeFunction *>(interpreterCode->functionById((uint16_t) 0));
}
std::vector<VarType> newStack;
currStack = &newStack;
Scope::VarIterator varIterator(node->body()->scope()->parent());
while (varIterator.hasNext()) {
AstVar *var = varIterator.next();
pushStack(var->type());//ensure that variables on stack is ok
store(var);
}
visitBlockNode(node->body());
currentBytecodeFunction = dump;
currScope = currScope->parent();//jump parameters scope
}
示例8: printVars
void printVars(Scope *scope)
{
Scope::VarIterator iter(scope);
while (iter.hasNext()) {
AstVar *astVar = iter.next();
out << typeToName(astVar->type()) << " " << astVar->name() << ";" << endl;
}
}
示例9: processFunction
void TypeInferenceVisitor::processFunction(AstFunction* function) {
Scope* scope = function->scope();
Scope::VarIterator vit(scope);
while(vit.hasNext()) {
AstVar* var = vit.next();
_types[var] = var->type();
}
function->node()->visit(this);
}
示例10: variableDeclaration
void variableDeclaration(Scope* scope) {
Scope::VarIterator iter(scope);
while (iter.hasNext()) {
AstVar* x = iter.next();
indent();
_output << typeToName(x->type()) << " "
<< x->name() << ";"
<< endl;
}
}
示例11: printScopeDeclarations
void ASTAnalyzer::printScopeDeclarations (Scope* scope) {
Scope::FunctionIterator fuctions(scope);
while (fuctions.hasNext()) {
fuctions.next()->node()->visit(this);
}
Scope::VarIterator vars(scope);
while (vars.hasNext()) {
AstVar* var = vars.next();
output << typeToName(var->type()) << " " << var->name() << ";\n";
}
}
示例12: visitScope
void visitScope(Scope * scope) {
Scope::VarIterator varIter(scope);
while (varIter.hasNext()) {
addIndent();
AstVar * var = varIter.next();
out<< typeToName(var->type())<< " "<< var->name()<< ";"<< endl;
}
Scope::FunctionIterator funcIter(scope);
while (funcIter.hasNext()) {
funcIter.next()->node()->visit(this);
}
}
示例13: indent
void Ast2SrcVisitor::initScope(Scope* scope) {
std::string indent(_indent, ' ');
Scope::VarIterator varIt(scope);
while (varIt.hasNext()) {
AstVar* var = varIt.next();
_out << indent << mathvm::typeToName(var->type()) << " "<< var->name() << ";" << std::endl;
}
Scope::FunctionIterator funcIt(scope);
while (funcIt.hasNext()) {
funcIt.next()->node()->visit(this);
_out << std::endl;
}
}
示例14: printScope
void PrettyPrinter::printScope(Scope *scope)
{
std::string indentation(m_indent, ' ');
//why constructor doesn't get const pointer?
Scope::VarIterator ivar(scope);
//Java-style iterators in C++?
while (ivar.hasNext())
{
AstVar *var = ivar.next();
m_out << indentation << typeToName(var->type()) << " "
<< var->name() << ";" << std::endl;
}
Scope::FunctionIterator ifun(scope);
while (ifun.hasNext()) ifun.next()->node()->visit(this);
}
示例15: printScopeDeclarations
void AstPrinter::printScopeDeclarations(Scope* scope) {
Scope::VarIterator varIterator(scope);
while(varIterator.hasNext()) {
AstVar *var = varIterator.next();
print(typeToName(var->type()));
print(" ");
print(var->name());
print(";\n");
}
Scope::FunctionIterator funcIterator(scope);
while(funcIterator.hasNext()) {
AstFunction *func = funcIterator.next();
printFunction(func);
}
print("\n");
}