Skip to content

Normalize type names #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions include/rosdiscover-clang/Ast/Stmt/SymbolicDeclRef.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <clang/AST/Type.h>

#include "SymbolicExpr.h"
#include "../../Value/Value.h"
#include "../../ApiCall/Calls/Util.h"

namespace rosdiscover {
Expand All @@ -20,7 +21,7 @@ class SymbolicDeclRef : public SymbolicExpr {
std::string qualifiedName
) : isInstanceMember(isInstanceMember),
isClassMember(isClassMember),
typeName(typeName),
typeName(normalizeTypeName(typeName)),
name(name),
qualifiedName(qualifiedName)
{}
Expand All @@ -31,10 +32,18 @@ class SymbolicDeclRef : public SymbolicExpr {
// Complex logic needed here to avoid duplication in sub-classes.
) : isInstanceMember(declRef->getDecl()->isCXXInstanceMember()),
isClassMember(declRef->getDecl()->isCXXClassMember()),
typeName(declRef->getType().getAsString()),
typeName(normalizeTypeName(declRef->getType().getAsString())),
name(createName(declRef)),
qualifiedName(declRef->getDecl()->getQualifiedNameAsString()) {}

static std::string normalizeTypeName(std::string clangTypeName) {
auto symbolicType = SymbolicValue::getSymbolicType(clangTypeName);
if (symbolicType == SymbolicValueType::Unsupported) {
return clangTypeName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we're losing information here since Clang types aren't real symbolic types and we lose the ability to distinguish them from actual symbolic types.

}
return SymbolicValue::getSymbolicTypeAsString(symbolicType);
}

virtual std::string toString() const override {
return name;
}
Expand Down
4 changes: 4 additions & 0 deletions include/rosdiscover-clang/Value/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class SymbolicValue : public SymbolicExpr {
static SymbolicValueType getSymbolicType(clang::QualType clangType) {
clangType = clangType.getUnqualifiedType();
auto typeName = clangType.getAsString();
return getSymbolicType(typeName);
}

static SymbolicValueType getSymbolicType(std::string typeName) {
llvm::outs() << "DEBUG: determining symbolic type for Clang type [" << typeName << "]\n";
if (typeName == "std::string"
|| typeName.find("const char") != std::string::npos
Expand Down