- 
                Notifications
    You must be signed in to change notification settings 
- Fork 35
          Update GetBinaryOperator to GetOperator
          #394
        
          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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|  | @@ -37,42 +37,57 @@ namespace Cpp { | |||||
| using TInterp_t = void*; | ||||||
| using TCppObject_t = void*; | ||||||
|  | ||||||
| enum BinaryOperator { | ||||||
| PtrMemD = 0, | ||||||
| PtrMemI, | ||||||
| Mul, | ||||||
| Div, | ||||||
| Rem, | ||||||
| Add, | ||||||
| Sub, | ||||||
| Shl, | ||||||
| Shr, | ||||||
| Cmp, | ||||||
| LT, | ||||||
| GT, | ||||||
| LE, | ||||||
| GE, | ||||||
| EQ, | ||||||
| NE, | ||||||
| And, | ||||||
| Xor, | ||||||
| Or, | ||||||
| LAnd, | ||||||
| LOr, | ||||||
| Assign, | ||||||
| MulAssign, | ||||||
| DivAssign, | ||||||
| RemAssign, | ||||||
| AddAssign, | ||||||
| SubAssign, | ||||||
| ShlAssign, | ||||||
| ShrAssign, | ||||||
| AndAssign, | ||||||
| XorAssign, | ||||||
| OrAssign, | ||||||
| Comma, | ||||||
| enum Operator { | ||||||
| OP_None, | ||||||
| OP_New, | ||||||
| OP_Delete, | ||||||
| OP_Array_New, | ||||||
| OP_Array_Delete, | ||||||
| OP_Plus, | ||||||
| OP_Minus, | ||||||
| OP_Star, | ||||||
| OP_Slash, | ||||||
| OP_Percent, | ||||||
| OP_Caret, | ||||||
| OP_Amp, | ||||||
| OP_Pipe, | ||||||
| OP_Tilde, | ||||||
| OP_Exclaim, | ||||||
| OP_Equal, | ||||||
| OP_Less, | ||||||
| OP_Greater, | ||||||
| OP_PlusEqual, | ||||||
| OP_MinusEqual, | ||||||
| OP_StarEqual, | ||||||
| OP_SlashEqual, | ||||||
| OP_PercentEqual, | ||||||
| OP_CaretEqual, | ||||||
| OP_AmpEqual, | ||||||
| OP_PipeEqual, | ||||||
| OP_LessLess, | ||||||
| OP_GreaterGreater, | ||||||
| OP_LessLessEqual, | ||||||
| OP_GreaterGreaterEqual, | ||||||
| OP_EqualEqual, | ||||||
| OP_ExclaimEqual, | ||||||
| OP_LessEqual, | ||||||
| OP_GreaterEqual, | ||||||
| OP_Spaceship, | ||||||
| OP_AmpAmp, | ||||||
| OP_PipePipe, | ||||||
| OP_PlusPlus, | ||||||
| OP_MinusMinus, | ||||||
| OP_Comma, | ||||||
| OP_ArrowStar, | ||||||
| OP_Arrow, | ||||||
| OP_Call, | ||||||
| OP_Subscript, | ||||||
| OP_Conditional, | ||||||
| OP_Coawait, | ||||||
| }; | ||||||
|  | ||||||
| enum OperatorArity { kUnary = 1, kBinary, kBoth }; | ||||||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: enum 'OperatorArity' uses a larger base type ('unsigned int', size: 4 bytes) than necessary for its value set, consider using 'std::uint8_t' (1 byte) as the base type to reduce its size [performance-enum-size]   enum OperatorArity { kUnary = 1, kBinary, kBoth };
       ^There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
        Suggested change
       
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not understand this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, my bad, fixed the suggestion. | ||||||
|  | ||||||
| /// A class modeling function calls for functions produced by the interpreter | ||||||
| /// in compiled code. It provides an information if we are calling a standard | ||||||
| /// function, constructor or destructor. | ||||||
|  | @@ -513,9 +528,13 @@ namespace Cpp { | |||||
| CPPINTEROP_API std::string GetFunctionArgName(TCppFunction_t func, | ||||||
| TCppIndex_t param_index); | ||||||
|  | ||||||
| ///\returns function that performs operation op on lc and rc | ||||||
| void GetBinaryOperator(TCppScope_t scope, enum BinaryOperator op, | ||||||
| std::vector<TCppFunction_t>& operators); | ||||||
| ///\returns arity of the operator or kNone | ||||||
| OperatorArity GetOperatorArity(TCppFunction_t op); | ||||||
|  | ||||||
| ///\returns list of operator overloads | ||||||
| void GetOperator(TCppScope_t scope, Operator op, | ||||||
| std::vector<TCppFunction_t>& operators, | ||||||
| OperatorArity kind = kBoth); | ||||||
|  | ||||||
| /// Creates an instance of the interpreter we need for the various interop | ||||||
| /// services. | ||||||
|  | ||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -3315,22 +3315,43 @@ | |
| return PI->getNameAsString(); | ||
| } | ||
|  | ||
| void GetBinaryOperator(TCppScope_t scope, enum BinaryOperator op, | ||
| std::vector<TCppFunction_t>& operators) { | ||
| Decl* D = static_cast<Decl*>(scope); | ||
| auto* DC = llvm::dyn_cast<DeclContext>(D); | ||
| Scope* S = getSema().getScopeForContext(DC); | ||
| if (!S) | ||
| return; | ||
|  | ||
| clang::UnresolvedSet<8> lookup; | ||
| OperatorArity GetOperatorArity(TCppFunction_t op) { | ||
| Decl* D = static_cast<Decl*>(op); | ||
| if (auto* FD = llvm::dyn_cast<FunctionDecl>(D)) { | ||
|         
                  Vipul-Cariappa marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| if (FD->isOverloadedOperator()) { | ||
|         
                  Vipul-Cariappa marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| switch (FD->getOverloadedOperator()) { | ||
|         
                  Vipul-Cariappa marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, \ | ||
|          | ||
| MemberOnly) \ | ||
| case OO_##Name: \ | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]     auto *D = (clang::Decl *)method;
              ^ | ||
| if ((Unary) && (Binary)) \ | ||
| return kBoth; \ | ||
| if (Unary) \ | ||
| return kUnary; \ | ||
| if (Binary) \ | ||
| return kBinary; \ | ||
| break; | ||
| #include "clang/Basic/OperatorKinds.def" | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| return (OperatorArity)~0U; | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: The value '4294967295' provided to the cast expression is not in the valid range of values for 'OperatorArity' [clang-analyzer-optin.core.EnumCastOutOfRange]     return (OperatorArity)~0U;
           ^Additional contextinclude/clang/Interpreter/CppInterOp.h:88: enum declared here   enum OperatorArity { kUnary = 1, kBinary, kBoth };
       ^lib/Interpreter/CppInterOp.cpp:3319: Assuming 'D' is not a 'CastReturnType'     if (auto* FD = llvm::dyn_cast<FunctionDecl>(D)) {
                   ^lib/Interpreter/CppInterOp.cpp:3319: 'FD' is null     if (auto* FD = llvm::dyn_cast<FunctionDecl>(D)) {
              ^lib/Interpreter/CppInterOp.cpp:3319: Taking false branch     if (auto* FD = llvm::dyn_cast<FunctionDecl>(D)) {
    ^lib/Interpreter/CppInterOp.cpp:3338: The value '4294967295' provided to the cast expression is not in the valid range of values for 'OperatorArity'     return (OperatorArity)~0U;
           ^ | ||
| } | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]     auto *D = (clang::Decl *)func;
              ^ | ||
|  | ||
| getSema().LookupBinOp(S, SourceLocation(), (clang::BinaryOperatorKind)op, | ||
| lookup); | ||
| void GetOperator(TCppScope_t scope, Operator op, | ||
| std::vector<TCppFunction_t>& operators, OperatorArity kind) { | ||
| Decl* D = static_cast<Decl*>(scope); | ||
| if (auto* DC = llvm::dyn_cast_or_null<DeclContext>(D)) { | ||
| ASTContext& C = getSema().getASTContext(); | ||
| DeclContextLookupResult Result = | ||
| DC->lookup(C.DeclarationNames.getCXXOperatorName( | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: Called C++ object pointer is null [clang-analyzer-core.CallAndMessage]     return PI->getNameAsString();
           ^Additional contextlib/Interpreter/CppInterOp.cpp:3299: 'PI' initialized to a null pointer value     clang::ParmVarDecl* PI = nullptr;
    ^lib/Interpreter/CppInterOp.cpp:3301: Assuming null pointer is passed into cast     if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(D))
                   ^lib/Interpreter/CppInterOp.cpp:3301: 'FD' is null     if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(D))
              ^lib/Interpreter/CppInterOp.cpp:3301: Taking false branch     if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionDecl>(D))
    ^lib/Interpreter/CppInterOp.cpp:3303: Assuming null pointer is passed into cast     else if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(D))
                        ^lib/Interpreter/CppInterOp.cpp:3303: 'FD' is null     else if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(D))
                   ^lib/Interpreter/CppInterOp.cpp:3303: Taking false branch     else if (auto* FD = llvm::dyn_cast_or_null<clang::FunctionTemplateDecl>(D))
         ^lib/Interpreter/CppInterOp.cpp:3306: Called C++ object pointer is null     return PI->getNameAsString();
           ^ | ||
| (clang::OverloadedOperatorKind)op)); | ||
|  | ||
| for (NamedDecl* D : lookup) { | ||
| if (auto* FD = llvm::dyn_cast<Decl>(D)) | ||
| operators.push_back(FD); | ||
| for (auto* i : Result) { | ||
| if (kind & GetOperatorArity(i)) | ||
| operators.push_back(i); | ||
| } | ||
| } | ||
| } | ||
|  | ||
|  | ||
Uh oh!
There was an error while loading. Please reload this page.