Skip to content

Commit

Permalink
Initial attempt at getting compiler attributes to parse properly
Browse files Browse the repository at this point in the history
  • Loading branch information
noelchalmers committed Dec 15, 2023
1 parent c17644b commit 35c0456
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 73 deletions.
10 changes: 5 additions & 5 deletions src/occa/internal/lang/builtins/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace occa {
const qualifier_t volatile_ ("volatile" , qualifierType::volatile_);
const qualifier_t long_ ("long" , qualifierType::long_);
const qualifier_t longlong_ ("long long" , qualifierType::longlong_);
const qualifier_t attribute_ ("__attribute__" , qualifierType::attribute_);

// Windows types
const qualifier_t declspec_ ("__declspec" , qualifierType::declspec_);

const qualifier_t extern_ ("extern" , qualifierType::extern_);
const qualifier_t externC ("extern \"C\"" , qualifierType::externC);
Expand All @@ -29,10 +33,6 @@ namespace occa {
const qualifier_t struct_ ("struct" , qualifierType::struct_);
const qualifier_t union_ ("union" , qualifierType::union_);

// Windows types
// TODO: Properly handle compiler extension attributes
const qualifier_t dllexport_ ("__declspec(dllexport)", qualifierType::dllexport_);

const primitive_t bool_ ("bool");
const primitive_t char_ ("char");
const primitive_t char16_t_ ("char16_t");
Expand Down Expand Up @@ -89,6 +89,6 @@ namespace occa {
const primitive_t double2 ("double2");
const primitive_t double3 ("double3");
const primitive_t double4 ("double4");

} // namespace lang
}
11 changes: 6 additions & 5 deletions src/occa/internal/lang/builtins/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace occa {
extern const qualifier_t volatile_;
extern const qualifier_t long_;
extern const qualifier_t longlong_;
extern const qualifier_t attribute_;

// Windows types
// TODO: Properly handle compiler extension attributes
extern const qualifier_t declspec_;

extern const qualifier_t extern_;
extern const qualifier_t externC;
Expand All @@ -32,10 +37,6 @@ namespace occa {
extern const qualifier_t struct_;
extern const qualifier_t union_;

// Windows types
// TODO: Properly handle compiler extension attributes
extern const qualifier_t dllexport_;

extern const primitive_t bool_;
extern const primitive_t char_;
extern const primitive_t char16_t_;
Expand Down Expand Up @@ -92,7 +93,7 @@ namespace occa {
extern const primitive_t double2;
extern const primitive_t double3;
extern const primitive_t double4;

// DPCPP Primitives
extern const primitive_t syclQueue;
extern const primitive_t syclNdRange;
Expand Down
2 changes: 2 additions & 0 deletions src/occa/internal/lang/keyword.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ namespace occa {
keywords.add(*(new qualifierKeyword(volatile_)));
keywords.add(*(new qualifierKeyword(long_)));
keywords.add(*(new qualifierKeyword(longlong_)));
keywords.add(*(new qualifierKeyword(attribute_)));
keywords.add(*(new qualifierKeyword(declspec_)));

keywords.add(*(new qualifierKeyword(extern_)));
keywords.add(*(new qualifierKeyword(externC)));
Expand Down
89 changes: 64 additions & 25 deletions src/occa/internal/lang/loaders/typeLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,18 @@ namespace occa {
return true;
}

const int tokenCount = tokenContext.size();
int tokenPos;

for (tokenPos = 0; tokenPos < tokenCount; ++tokenPos) {
token_t *token = tokenContext[tokenPos];
if (!tokenContext.size()) {
tokenContext.printError("Unable to load type");
return false;
}

if (token->type() & tokenType::comment) {
while (tokenContext.size()) {
if (tokenContext[0]->type() & tokenType::comment) {
++tokenContext;
continue;
}

keyword_t &keyword = parser.keywords.get(smntContext, token);
keyword_t &keyword = parser.keywords.get(smntContext, tokenContext[0]);
const int kType = keyword.type();
if (kType & keywordType::none) {
break;
Expand All @@ -69,39 +70,35 @@ namespace occa {
type_t *type = NULL;
if (qualifier == class_) {
// TODO: type = loadClass();
token->printError("Classes are not supported yet");
tokenContext[0]->printError("Classes are not supported yet");
success = false;
}
if (!success) {
return false;
}

if (!type) {
loadVartypeQualifier(token,
keyword.to<qualifierKeyword>().qualifier,
vartype);
loadVartypeQualifier(qualifier, vartype);
} else {
vartype.type = type;
vartype.typeToken = (identifierToken*) type->source->clone();
}
if (!success) {
return false;
}
continue;
}
if ((kType & keywordType::type) &&
!vartype.isValid()) {
vartype.type = &(keyword.to<typeKeyword>().type_);
vartype.typeToken = (identifierToken*) token->clone();
vartype.typeToken = (identifierToken*) tokenContext[0]->clone();
++tokenContext;
continue;
}

break;
}

if (tokenPos) {
tokenContext += tokenPos;
} else {
tokenContext.printError("Unable to load type");
return false;
}

if (vartype.isValid()) {
return true;
}
Expand All @@ -127,9 +124,11 @@ namespace occa {
return false;
}

void typeLoader_t::loadVartypeQualifier(token_t *token,
const qualifier_t &qualifier,
void typeLoader_t::loadVartypeQualifier(const qualifier_t &qualifier,
vartype_t &vartype) {
token_t *token = tokenContext[0];
++tokenContext;

// Handle long/long long case
if (&qualifier == &long_) {
if (vartype.has(long_)) {
Expand All @@ -148,13 +147,53 @@ namespace occa {
return;
}

// Non-long qualifiers
if (!vartype.has(qualifier)) {
// qualifier takes arguments
if (token_t::safeOperatorType(tokenContext[0]) & operatorType::parenthesesStart) {
tokenContext.pushPairRange();

exprNodeVector args;
tokenRangeVector argRanges;
getArgumentRanges(tokenContext, argRanges);

const int argCount = (int) argRanges.size();

for (int i = 0; i < argCount; ++i) {
tokenContext.push(argRanges[i].start,
argRanges[i].end);

if (!tokenContext.size()) {
args.push_back(new emptyNode());
tokenContext.popAndSkip();
continue;
}

args.push_back(tokenContext.parseExpression(smntContext, parser));

if (!success) {
freeExprNodeVector(args);
return;
}

tokenContext.popAndSkip();
}

vartype.add(token->origin,
qualifier);
qualifier,
args);

freeExprNodeVector(args);
tokenContext.popAndSkip();

} else {
token->printWarning("Ignoring duplicate qualifier");
// Non-long qualifiers
if (!vartype.has(qualifier)) {
vartype.add(token->origin,
qualifier);
} else {
token->printWarning("Ignoring duplicate qualifier");
}
}

}

void typeLoader_t::setVartypePointers(vartype_t &vartype) {
Expand Down
3 changes: 1 addition & 2 deletions src/occa/internal/lang/loaders/typeLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace occa {

bool loadType(vartype_t &vartype);

void loadVartypeQualifier(token_t *token,
const qualifier_t &qualifier,
void loadVartypeQualifier(const qualifier_t &qualifier,
vartype_t &vartype);

void setVartypePointers(vartype_t &vartype);
Expand Down
Loading

0 comments on commit 35c0456

Please sign in to comment.