本文整理汇总了C++中ASTType::HasType方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTType::HasType方法的具体用法?C++ ASTType::HasType怎么用?C++ ASTType::HasType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTType
的用法示例。
在下文中一共展示了ASTType::HasType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResolveTypes
void ResolveTypes(ASTNode* node, ScopeResolveTypes& tscope, bool verbose=false)
{
# define LOCATIONINFO " (line %d, source \"%s\").\n"
# define LOCATIONINFODATA nodeType->tokenSource->Tokens[nodeType->typeName[0].Index].TokenLine, nodeType->tokenSource->SourceIdentifier()
bool isScope = false;
ASTType* nodeType = dynamic_cast<ASTType*>(node);
if (nodeType && nodeType->HasType() && nodeType->IsBuiltinType() == false)
{
bool typeNameFromRoot = false;
std::string typeName = nodeType->ToNameString(false);
if (typeName.size() >= 2 && typeName.at(0) == ':' && typeName.at(1) == ':')
{
typeNameFromRoot = true;
typeName.erase(typeName.begin(), typeName.begin() + 2);
}
if (verbose)
{
fprintf(stderr, "RESOLVE ");
for (auto it : tscope.usingNamespaces)
fprintf(stderr, "{%s} ", it.c_str());
for (auto it : tscope.inScopes)
fprintf(stderr, "[%s] ", it->ToString().c_str());
fprintf(stderr, "%s", nodeType->ToNameString().c_str());
}
// check if name points directly to node
std::string resolvedAs;
//if (typeNameFromRoot)
{
// try to find directly
if (resolvedAs.empty())
{
auto found = allCustomTypes.find(typeName);
if (found != allCustomTypes.end())
{
nodeType->resolvedType = found->second;
resolvedAs = found->first;
}
}
// go backwards over scopes and try to find that way
if (resolvedAs.empty())
{
for (int i = tscope.inScopes.size() - 1; i >= 0; i--)
{
std::string prefix;
for (int j = 0; j <= i; j++)
prefix += tscope.inScopes[j]->ToString() + "::";
auto found = allCustomTypes.find(prefix + typeName);
if (found != allCustomTypes.end())
{
nodeType->resolvedType = found->second;
resolvedAs = found->first;
break;
}
}
}
// try finding with "using namespace"
if (resolvedAs.empty())
{
for (int i = 0; i < tscope.usingNamespaces.size(); i++)
{
auto found = allCustomTypes.find(tscope.usingNamespaces[i] + "::" + typeName);
if (found != allCustomTypes.end())
{
if (resolvedAs.empty() == false)
fprintf(stderr, "Warning: Ambiguous \"using namespace\" detected during type resolve: \"%s\" could also be \"%s\". Using latter." LOCATIONINFO, resolvedAs.c_str(), found->first.c_str(), LOCATIONINFODATA);
nodeType->resolvedType = found->second;
resolvedAs = found->first;
}
}
}
}
if (verbose)
fprintf(stderr, " AS \"%s\"\n", resolvedAs.c_str());
if (resolvedAs.empty() && nodeType->GetType() != ASTNode::Type::TemplateArg)
fprintf(stderr, "Warning: Type \"%s\" could not be resolved " LOCATIONINFO, typeName.c_str(), LOCATIONINFODATA);
# undef LOCATIONINFO
# undef LOCATIONINFODATA
}
// nesting
switch (node->GetType())
{
case ASTNode::Type::Class:
case ASTNode::Type::Struct:
case ASTNode::Type::Union:
case ASTNode::Type::Namespace:
case ASTNode::Type::Template:
isScope = true;
break;
//.........这里部分代码省略.........