本文整理汇总了C++中Symbol类的典型用法代码示例。如果您正苦于以下问题:C++ Symbol类的具体用法?C++ Symbol怎么用?C++ Symbol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Symbol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: import
void Symbol::import(BlockScopeRawPtr scope, const Symbol &src_sym) {
setName(src_sym.getName());
setSystem();
if (src_sym.declarationSet()) {
ConstructPtr sc = src_sym.getDeclaration();
if (sc) sc->resetScope(scope);
setDeclaration(sc);
}
if (src_sym.valueSet()) {
ConstructPtr sc = src_sym.getValue();
if (sc) sc->resetScope(scope);
setValue(sc);
}
if (src_sym.isDynamic()) {
setDynamic();
}
if (src_sym.isConstant()) {
setConstant();
}
m_coerced = src_sym.m_coerced;
}
示例2: ASTNode
ASTvariable_declaration::ASTvariable_declaration (OSLCompilerImpl *comp,
const TypeSpec &type,
ustring name, ASTNode *init,
bool isparam, bool ismeta,
bool isoutput, bool initlist)
: ASTNode (variable_declaration_node, comp, 0, init, NULL /* meta */),
m_name(name), m_sym(NULL),
m_isparam(isparam), m_isoutput(isoutput), m_ismetadata(ismeta),
m_initlist(initlist)
{
m_typespec = type;
Symbol *f = comp->symtab().clash (name);
if (f) {
std::string e = Strutil::format ("\"%s\" already declared in this scope", name.c_str());
if (f->node()) {
boost::filesystem::path p(f->node()->sourcefile().string());
e += Strutil::format ("\n\t\tprevious declaration was at %s:%d",
p.filename().c_str(), f->node()->sourceline());
}
if (f->scope() == 0 && f->symtype() == SymTypeFunction && isparam) {
// special case: only a warning for param to mask global function
warning ("%s", e.c_str());
} else {
error ("%s", e.c_str());
}
}
if (name[0] == '_' && name[1] == '_' && name[2] == '_') {
error ("\"%s\" : sorry, can't start with three underscores",
name.c_str());
}
SymType symtype = isparam ? (isoutput ? SymTypeOutputParam : SymTypeParam)
: SymTypeLocal;
m_sym = new Symbol (name, type, symtype, this);
if (! m_ismetadata)
oslcompiler->symtab().insert (m_sym);
// A struct really makes several subvariables
if (type.is_structure() || type.is_structure_array()) {
ASSERT (! m_ismetadata);
// Add the fields as individual declarations
m_compiler->add_struct_fields (type.structspec(), m_sym->name(),
symtype, type.arraylength(), this);
}
}
示例3: assert
void
SemanticAnalysis::visitNameProxy(NameProxy *proxy)
{
Symbol *sym = proxy->sym();
VariableSymbol *var = sym->asVariable();
// If we see that a symbol is a function literal, then we bypass the scope
// chain operations entirely and hardcode the function literal.
if (sym->isFunction()) {
assert(sym->scope()->kind() == Scope::Global);
hir_ = new (pool_) HFunction(proxy, sym->asFunction());
return;
}
if (value_context_ == kLValue) {
// Egads! We're being asked to construct an l-value instead of an r-value.
*outp_ = LValue(var);
return;
}
Scope *in = sym->scope();
switch (in->kind()) {
case Scope::Global:
hir_ = new (pool_) HGlobal(proxy, var);
return;
case Scope::Function:
{
assert(var->storage() == VariableSymbol::Arg);
// Since we're in an r-value context, we need to strip the reference type.
Type *type = var->type();
if (type->isReference())
type = type->toReference()->contained();
hir_ = new (pool_) HLocal(proxy, type, var);
return;
}
default:
assert(in->kind() == Scope::Block);
assert(var->storage() == VariableSymbol::Local);
hir_ = new (pool_) HLocal(proxy, var->type(), var);
return;
}
}
示例4: execute
void execute() {
std::sort(m_rootEntries.begin(), m_rootEntries.end(), reCmp);
for (int i = 0; i < m_size; i++) {
RootEntry &re = m_rootEntries[i];
if (!re.second) break;
const AstWalkerState &s = re.first[re.first.size() - 1];
StatementPtr sp(dynamic_pointer_cast<Statement>(s.cp));
assert(sp);
StatementListPtr sl;
int ix;
if (sp->is(Statement::KindOfStatementList)) {
sl = static_pointer_cast<StatementList>(sp);
ix = (s.index - 1) / 2;
} else {
assert(sp->is(Statement::KindOfBlockStatement));
sl = static_pointer_cast<BlockStatement>(sp)->getStmts();
if (!sl) continue;
ix = 0;
}
ExpressionPtr e = m_dict.get(re.second);
assert(e && e->is(Expression::KindOfSimpleVariable));
SimpleVariablePtr sv(static_pointer_cast<SimpleVariable>(e));
Symbol *sym = sv->getSymbol();
bool inGen = sv->getFunctionScope()->isGenerator();
if (!sym || sym->isGlobal() || sym->isStatic() || sym->isParameter() ||
sym->isClosureVar() || sv->isThis() || inGen) {
continue;
}
sym->setShrinkWrapped();
e = e->clone();
e->clearContext();
e->recomputeEffects();
e->setContext(Expression::Declaration);
StatementPtr sub = (*sl)[ix];
e->setLocation(sub->getLocation());
e->setBlockScope(sub->getScope());
ExpStatementPtr exp(
new ExpStatement(sub->getScope(), sub->getLocation(), e));
sl->insertElement(exp, ix);
}
}
示例5: switch
BPatch_variableExpr *BPatch_image::createVarExprByName(BPatch_module *mod, const char *name)
{
Symbol syminfo;
BPatch_type *type;
type = mod->getModuleTypes()->globalVarsByName[name];
if (!type) {
switch (syminfo.size()) {
case 1:
type = findType("char");
break;
case 2:
type = findType("short");
break;
case 8:
type = findType("integer*8");
break;
case 4:
default:
type = findType("int");
break;
}
}
if (!type) return NULL;
if (!proc->llproc->getSymbolInfo(name, syminfo)) {
return NULL;
}
// Error case.
if (syminfo.addr() == 0)
return NULL;
BPatch_variableExpr *var = AddrToVarExpr->hash[syminfo.addr()];
if (!var) {
var = new BPatch_variableExpr( const_cast<char *>(name), proc,
(void *)syminfo.addr(), type);
AddrToVarExpr->hash[syminfo.addr()] = var;
}
return var;
}
示例6: cg_printf
void VariableTable::outputPHP(CodeGenerator &cg, AnalysisResultPtr ar) {
if (Option::GenerateInferredTypes) {
for (unsigned int i = 0; i < m_symbolVec.size(); i++) {
Symbol *sym = m_symbolVec[i];
if (isInherited(sym->getName())) continue;
if (sym->isParameter()) {
cg_printf("// @param ");
} else if (sym->isGlobal()) {
cg_printf("// @global ");
} else if (sym->isStatic()) {
cg_printf("// @static ");
} else {
cg_printf("// @local ");
}
cg_printf("%s\t$%s\n", sym->getFinalType()->toString().c_str(),
sym->getName().c_str());
}
}
if (Option::ConvertSuperGlobals && !getAttribute(ContainsDynamicVariable)) {
std::set<string> convertibles;
typedef std::pair<const string,Symbol> symPair;
BOOST_FOREACH(symPair &sym, m_symbolMap) {
if (sym.second.isSuperGlobal() && !sym.second.declarationSet()) {
convertibles.insert(sym.second.getName());
}
}
if (!convertibles.empty()) {
cg_printf("/* converted super globals */ global ");
for (std::set<string>::const_iterator iter = convertibles.begin();
iter != convertibles.end(); ++iter) {
if (iter != convertibles.begin()) cg_printf(",");
cg_printf("$%s", iter->c_str());
}
cg_printf(";\n");
}
}
示例7: analyzeProgram
void ClosureExpression::analyzeProgram(AnalysisResultPtr ar) {
m_func->analyzeProgram(ar);
if (m_vars) {
m_values->analyzeProgram(ar);
if (ar->getPhase() == AnalysisResult::AnalyzeAll) {
m_func->getFunctionScope()->setClosureVars(m_vars);
// closure function's variable table (not containing function's)
VariableTablePtr variables = m_func->getFunctionScope()->getVariables();
for (int i = 0; i < m_vars->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_vars)[i]);
string name = param->getName();
{
Symbol *sym = variables->addSymbol(name);
sym->setClosureVar();
if (param->isRef()) {
sym->setRefClosureVar();
}
}
}
return;
}
if (ar->getPhase() == AnalysisResult::AnalyzeFinal) {
// closure function's variable table (not containing function's)
VariableTablePtr variables = m_func->getFunctionScope()->getVariables();
for (int i = 0; i < m_vars->getCount(); i++) {
ParameterExpressionPtr param =
dynamic_pointer_cast<ParameterExpression>((*m_vars)[i]);
string name = param->getName();
// so we can assign values to them, instead of seeing CVarRef
Symbol *sym = variables->getSymbol(name);
if (sym && sym->isParameter()) {
sym->setLvalParam();
}
}
}
}
}
示例8: ILOC
void IdentifierNode::generateILOCCode(Node* context) {
if (this->children->size() == 0) { // Variable
Symbol* symbol = Scope::getSymbol(this->symbol->getText());
Node* symbolScope = Scope::getScope(this->symbol->getText());
std::string* varAddressRegisterName = ILOC::getRegister(symbol->getText());
std::string registerBaseAddress = (symbolScope->getNodeType() == Common::NT_PROGRAM) ? "bss" : "fp";
std::stringstream symbolOffsetStr;
symbolOffsetStr << symbol->getOffset();
ILOC* instruction = new ILOC(Common::ILOC_LOADAI, registerBaseAddress, symbolOffsetStr.str(), *varAddressRegisterName, "");
this->addInstruction(instruction);
this->setLastRegister(*varAddressRegisterName);
} else { // vector
Symbol* symbol = Scope::getSymbol(this->symbol->getText());
Node* symbolScope = Scope::getScope(this->symbol->getText());
std::string* vectorAddressRegisterName = ILOC::getRegister(symbol->getText());
std::string registerBaseAddress = (symbolScope->getNodeType() == Common::NT_PROGRAM) ? "bss" : "fp";
std::stringstream symbolOffsetStr;
symbolOffsetStr << symbol->getOffset();
ILOC* instruction = new ILOC(Common::ILOC_ADDI, registerBaseAddress, symbolOffsetStr.str(), *vectorAddressRegisterName, "");
this->addInstruction(instruction);
std::string lastBaseRegister = *vectorAddressRegisterName;
std::string* indexRegisterName;
for (unsigned int i = 0; i < this->children->size(); i++) {
ExpressionNode* expression = dynamic_cast<ExpressionNode*>(this->children->at(i));
expression->generateILOCCode(this);
std::stringstream indexStream;
indexStream << i;
std::string* multResultRegisterName = ILOC::getRegister("INST_MULT_VEC_RESULT_" + indexStream.str());
indexRegisterName = ILOC::getRegister("INDEX_REGISTER_NAME_" + indexStream.str());
ILOC* instructionMult = new ILOC(Common::ILOC_MULTI, expression->getLastRegister(), "4", *multResultRegisterName, "");
ILOC* instructionLoadAO = new ILOC(Common::ILOC_LOADA0, lastBaseRegister, *multResultRegisterName, *indexRegisterName, "");
lastBaseRegister = *indexRegisterName;
this->addInstruction(instructionMult);
this->addInstruction(instructionLoadAO);
}
this->setLastRegister(*indexRegisterName);
}
}
示例9: SQLiteStatement
void DisassemblerDatabase::saveSymbols()
{
SQLiteStatement(this->_disassemblerdb, "BEGIN").execute();
SQLiteStatement s(this->_disassemblerdb, "INSERT INTO SymbolTable (Address, Name, Type, Size, ReferenceCount) VALUES (?, ?, ?, ?, ?)");
for(SymbolTable::Iterator it = this->_symboltable->begin(); it != this->_symboltable->end(); it++)
{
Symbol* symbol = it.value();
const QList<DataValue>& sources = symbol->sources();
sqlite3_int64 address = symbol->startAddress().compatibleValue<sqlite3_int64>();
s.bind(1, address);
s.bind(2, symbol->name().toUtf8().constData());
s.bind(3, static_cast<sqlite3_int64>(symbol->type()));
s.bind(4, symbol->size().compatibleValue<sqlite3_int64>());
s.bind(5, sources.count());
s.step();
s.reset();
}
SQLiteStatement(this->_disassemblerdb, "COMMIT").execute();
}
示例10: ASSERT
void
ASTfunction_declaration::add_meta (ASTNode *meta)
{
for ( ; meta; meta = meta->nextptr()) {
ASSERT (meta->nodetype() == ASTNode::variable_declaration_node);
const ASTvariable_declaration *metavar = static_cast<const ASTvariable_declaration *>(meta);
Symbol *metasym = metavar->sym();
if (metasym->name() == "builtin") {
m_is_builtin = true;
if (func()->typespec().is_closure()) // It is a builtin closure
// Force keyword arguments at the end
func()->argcodes(ustring(std::string(func()->argcodes().c_str()) + "."));
}
else if (metasym->name() == "derivs")
func()->takes_derivs (true);
else if (metasym->name() == "printf_args")
func()->printf_args (true);
else if (metasym->name() == "texture_args")
func()->texture_args (true);
else if (metasym->name() == "rw")
func()->readwrite_special_case (true);
}
}
示例11: GetSymtab
AddressClass ObjectFile::GetAddressClass(addr_t file_addr) {
Symtab *symtab = GetSymtab();
if (symtab) {
Symbol *symbol = symtab->FindSymbolContainingFileAddress(file_addr);
if (symbol) {
if (symbol->ValueIsAddress()) {
const SectionSP section_sp(symbol->GetAddressRef().GetSection());
if (section_sp) {
const SectionType section_type = section_sp->GetType();
switch (section_type) {
case eSectionTypeInvalid:
return eAddressClassUnknown;
case eSectionTypeCode:
return eAddressClassCode;
case eSectionTypeContainer:
return eAddressClassUnknown;
case eSectionTypeData:
case eSectionTypeDataCString:
case eSectionTypeDataCStringPointers:
case eSectionTypeDataSymbolAddress:
case eSectionTypeData4:
case eSectionTypeData8:
case eSectionTypeData16:
case eSectionTypeDataPointers:
case eSectionTypeZeroFill:
case eSectionTypeDataObjCMessageRefs:
case eSectionTypeDataObjCCFStrings:
case eSectionTypeGoSymtab:
return eAddressClassData;
case eSectionTypeDebug:
case eSectionTypeDWARFDebugAbbrev:
case eSectionTypeDWARFDebugAddr:
case eSectionTypeDWARFDebugAranges:
case eSectionTypeDWARFDebugFrame:
case eSectionTypeDWARFDebugInfo:
case eSectionTypeDWARFDebugLine:
case eSectionTypeDWARFDebugLoc:
case eSectionTypeDWARFDebugMacInfo:
case eSectionTypeDWARFDebugMacro:
case eSectionTypeDWARFDebugPubNames:
case eSectionTypeDWARFDebugPubTypes:
case eSectionTypeDWARFDebugRanges:
case eSectionTypeDWARFDebugStr:
case eSectionTypeDWARFDebugStrOffsets:
case eSectionTypeDWARFAppleNames:
case eSectionTypeDWARFAppleTypes:
case eSectionTypeDWARFAppleNamespaces:
case eSectionTypeDWARFAppleObjC:
return eAddressClassDebug;
case eSectionTypeEHFrame:
case eSectionTypeARMexidx:
case eSectionTypeARMextab:
case eSectionTypeCompactUnwind:
return eAddressClassRuntime;
case eSectionTypeELFSymbolTable:
case eSectionTypeELFDynamicSymbols:
case eSectionTypeELFRelocationEntries:
case eSectionTypeELFDynamicLinkInfo:
case eSectionTypeOther:
return eAddressClassUnknown;
case eSectionTypeAbsoluteAddress:
// In case of absolute sections decide the address class based on
// the symbol
// type because the section type isn't specify if it is a code or a
// data
// section.
break;
}
}
}
const SymbolType symbol_type = symbol->GetType();
switch (symbol_type) {
case eSymbolTypeAny:
return eAddressClassUnknown;
case eSymbolTypeAbsolute:
return eAddressClassUnknown;
case eSymbolTypeCode:
return eAddressClassCode;
case eSymbolTypeTrampoline:
return eAddressClassCode;
case eSymbolTypeResolver:
return eAddressClassCode;
case eSymbolTypeData:
return eAddressClassData;
case eSymbolTypeRuntime:
return eAddressClassRuntime;
case eSymbolTypeException:
return eAddressClassRuntime;
case eSymbolTypeSourceFile:
return eAddressClassDebug;
case eSymbolTypeHeaderFile:
return eAddressClassDebug;
case eSymbolTypeObjectFile:
return eAddressClassDebug;
case eSymbolTypeCommonBlock:
return eAddressClassDebug;
case eSymbolTypeBlock:
return eAddressClassDebug;
case eSymbolTypeLocal:
//.........这里部分代码省略.........
示例12: error
//.........这里部分代码省略.........
track_variable_lifetimes ();
check_for_illegal_writes ();
// if (m_optimizelevel >= 1)
// coalesce_temporaries ();
}
if (! error_encountered()) {
if (m_output_filename.size() == 0)
m_output_filename = default_output_filename ();
write_oso_file (m_output_filename);
}
oslcompiler = NULL;
}
return ! error_encountered();
}
struct GlobalTable {
const char *name;
TypeSpec type;
};
static GlobalTable globals[] = {
{ "P", TypeDesc::TypePoint },
{ "I", TypeDesc::TypeVector },
{ "N", TypeDesc::TypeNormal },
{ "Ng", TypeDesc::TypeNormal },
{ "u", TypeDesc::TypeFloat },
{ "v", TypeDesc::TypeFloat },
{ "dPdu", TypeDesc::TypeVector },
{ "dPdv", TypeDesc::TypeVector },
#if 0
// Light variables -- we don't seem to be on a route to support this
// kind of light shader, so comment these out for now.
{ "L", TypeDesc::TypeVector },
{ "Cl", TypeDesc::TypeColor },
{ "Ns", TypeDesc::TypeNormal },
{ "Pl", TypeDesc::TypePoint },
{ "Nl", TypeDesc::TypeNormal },
#endif
{ "Ps", TypeDesc::TypePoint },
{ "Ci", TypeSpec (TypeDesc::TypeColor, true) },
{ "time", TypeDesc::TypeFloat },
{ "dtime", TypeDesc::TypeFloat },
{ "dPdtime", TypeDesc::TypeVector },
{ NULL }
};
void
OSLCompilerImpl::initialize_globals ()
{
for (int i = 0; globals[i].name; ++i) {
Symbol *s = new Symbol (ustring(globals[i].name), globals[i].type,
SymTypeGlobal);
symtab().insert (s);
}
}
std::string
OSLCompilerImpl::default_output_filename ()
{
if (m_shader && shader_decl())
return shader_decl()->shadername().string() + ".oso";
return std::string();
}
void
OSLCompilerImpl::write_oso_metadata (const ASTNode *metanode) const
{
ASSERT (metanode->nodetype() == ASTNode::variable_declaration_node);
const ASTvariable_declaration *metavar = static_cast<const ASTvariable_declaration *>(metanode);
Symbol *metasym = metavar->sym();
ASSERT (metasym);
TypeSpec ts = metasym->typespec();
oso ("%%meta{%s,%s,", ts.string().c_str(), metasym->name().c_str());
const ASTNode *init = metavar->init().get();
ASSERT (init);
if (ts.is_string() && init->nodetype() == ASTNode::literal_node)
oso ("\"%s\"", ((const ASTliteral *)init)->strval());
else if (ts.is_int() && init->nodetype() == ASTNode::literal_node)
oso ("%d", ((const ASTliteral *)init)->intval());
else if (ts.is_float() && init->nodetype() == ASTNode::literal_node)
oso ("%.8g", ((const ASTliteral *)init)->floatval());
// FIXME -- what about type constructors?
else {
std::cout << "Error, don't know how to print metadata "
<< ts.string() << " with node type "
<< init->nodetypename() << "\n";
ASSERT (0); // FIXME
}
oso ("} ");
}
示例13: switch
void BytecodePrinter::print_attributes(int bci, outputStream* st) {
// Show attributes of pre-rewritten codes
Bytecodes::Code code = Bytecodes::java_code(raw_code());
// If the code doesn't have any fields there's nothing to print.
// note this is ==1 because the tableswitch and lookupswitch are
// zero size (for some reason) and we want to print stuff out for them.
if (Bytecodes::length_for(code) == 1) {
st->cr();
return;
}
switch(code) {
// Java specific bytecodes only matter.
case Bytecodes::_bipush:
st->print_cr(" " INT32_FORMAT, get_byte());
break;
case Bytecodes::_sipush:
st->print_cr(" " INT32_FORMAT, get_short());
break;
case Bytecodes::_ldc:
if (Bytecodes::uses_cp_cache(raw_code())) {
print_constant(get_index_u1_cpcache(), st);
} else {
print_constant(get_index_u1(), st);
}
break;
case Bytecodes::_ldc_w:
case Bytecodes::_ldc2_w:
if (Bytecodes::uses_cp_cache(raw_code())) {
print_constant(get_index_u2_cpcache(), st);
} else {
print_constant(get_index_u2(), st);
}
break;
case Bytecodes::_iload:
case Bytecodes::_lload:
case Bytecodes::_fload:
case Bytecodes::_dload:
case Bytecodes::_aload:
case Bytecodes::_istore:
case Bytecodes::_lstore:
case Bytecodes::_fstore:
case Bytecodes::_dstore:
case Bytecodes::_astore:
st->print_cr(" #%d", get_index_special());
break;
case Bytecodes::_iinc:
{ int index = get_index_special();
jint offset = is_wide() ? get_short(): get_byte();
st->print_cr(" #%d " INT32_FORMAT, index, offset);
}
break;
case Bytecodes::_newarray: {
BasicType atype = (BasicType)get_index_u1();
const char* str = type2name(atype);
if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) {
assert(false, "Unidentified basic type");
}
st->print_cr(" %s", str);
}
break;
case Bytecodes::_anewarray: {
int klass_index = get_index_u2();
ConstantPool* constants = method()->constants();
Symbol* name = constants->klass_name_at(klass_index);
st->print_cr(" %s ", name->as_C_string());
}
break;
case Bytecodes::_multianewarray: {
int klass_index = get_index_u2();
int nof_dims = get_index_u1();
ConstantPool* constants = method()->constants();
Symbol* name = constants->klass_name_at(klass_index);
st->print_cr(" %s %d", name->as_C_string(), nof_dims);
}
break;
case Bytecodes::_ifeq:
case Bytecodes::_ifnull:
case Bytecodes::_iflt:
case Bytecodes::_ifle:
case Bytecodes::_ifne:
case Bytecodes::_ifnonnull:
case Bytecodes::_ifgt:
case Bytecodes::_ifge:
case Bytecodes::_if_icmpeq:
case Bytecodes::_if_icmpne:
case Bytecodes::_if_icmplt:
case Bytecodes::_if_icmpgt:
case Bytecodes::_if_icmple:
case Bytecodes::_if_icmpge:
case Bytecodes::_if_acmpeq:
case Bytecodes::_if_acmpne:
case Bytecodes::_goto:
case Bytecodes::_jsr:
st->print_cr(" %d", bci + get_short());
//.........这里部分代码省略.........
示例14: new
Symbol* Symbol::create(VM& vm)
{
Symbol* symbol = new (NotNull, allocateCell<Symbol>(vm.heap)) Symbol(vm);
symbol->finishCreation(vm);
return symbol;
}
示例15:
bool operator==(const std::string &lhs, const Symbol &rhs)
{
return rhs.GetName() == lhs;
}