本文整理汇总了C++中Method::getCodeBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ Method::getCodeBuffer方法的具体用法?C++ Method::getCodeBuffer怎么用?C++ Method::getCodeBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Method
的用法示例。
在下文中一共展示了Method::getCodeBuffer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseKeyword_Return
/**
* Parses the keyword "return" from the given token stack
*/
int CodeParser::parseKeyword_Return( Scope* scope, TokenStack* stack ) {
// get the scope type
ScopeType type = scope->getScopeType();
if( type != METHOD_SCOPE ) {
SYNTAX_ERROR( "Statement is only permissible within a method block", stack->last() );
return -1;
}
// get the method instance
Method* method = (Method*)scope;
// TODO support "return value" syntax
// add the instruction
INSTRUCTION_T instruction = RET << A_OP;
method->getCodeBuffer()->putInstruction( instruction );
return 0;
}
示例2: parseMethod
/**
* Parses a method definition
*/
int CodeParser::parseMethod( Scope* scope, const char* name, TypeReference* type, TokenStack* stack ) {
int errorCode = 0;
const char* signature;
list<Parameter*> params;
Method *method;
// step through the tokens ...
int step = 0;
bool done = false;
while( !errorCode && !done && stack->hasNext() ) {
switch( ++step ) {
// step 1: create the method
case 1:
// get the method parameters
if( !( errorCode = parseMethodParameters( scope, stack, params ) ) ) {
// create the method signature
signature = generateSignature( name, params );
// create the method
printf( "CodeParser::parseMethod - method '%s' signature = '%s' modifiers = %s\n", name, signature, toBinary( this->modifiers ) );
method = new Method( scope, name, signature, type, this->modifiers );
}
// reset the modifier for the current scope
this->modifiers = 0;
break;
// step 2: process the method code block
case 2:
// must be a code block
if( stack->peek()->getType() != tok::CODE_BLOCK ) {
SYNTAX_ERROR( "symbol '{' expected", stack->next() );
return NULL;
}
// process the method code block
errorCode = parse( method, ((ComplexToken*)stack->next())->getChildren() );
method->getCodeBuffer()->putInstruction( RET << A_OP ); // RET
done = true;
break;
}
}
// is there already an error code?
if( errorCode ) {
return errorCode;
}
// did it complete?
if( !done ) {
SYNTAX_ERROR( "unexpected end of statement", stack->last() );
return -1;
}
// add the method to the scope
if( scope->getScopeType() != CLASS_SCOPE ) {
SYNTAX_ERROR( "method cannot be defined here", stack->last() );
return -1;
}
// add the method to the scope
ScopeContainer* container = (ScopeContainer*)scope;
container->addMethod( method );
return 0;
}