Skip to content
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
10 changes: 5 additions & 5 deletions sdk/angelscript/source/as_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,13 @@ void asCBuilder::Reset()
}

#ifndef AS_NO_COMPILER
int asCBuilder::AddCode(const char *name, const char *code, int codeLength, int lineOffset, int sectionIdx, bool makeCopy)
int asCBuilder::AddCode(const char *name, asStringView code, int lineOffset, int sectionIdx, bool makeCopy)
{
asCScriptCode *script = asNEW(asCScriptCode);
if( script == 0 )
return asOUT_OF_MEMORY;

int r = script->SetCode(name, code, codeLength, makeCopy);
int r = script->SetCode(name, code, makeCopy);
if( r < 0 )
{
asDELETE(script, asCScriptCode);
Expand All @@ -227,17 +227,17 @@ int asCBuilder::AddCode(const char *name, const char *code, int codeLength, int
return 0;
}

asCScriptCode *asCBuilder::FindOrAddCode(const char *name, const char *code, size_t length)
asCScriptCode *asCBuilder::FindOrAddCode(const char *name, asStringView code)
{
for (asUINT n = 0; n < scripts.GetLength(); n++)
if( scripts[n]->name == name && scripts[n]->codeLength == length && memcmp(scripts[n]->code, code, length) == 0 )
if( scripts[n]->name == name && asStringView(scripts[n]->code,scripts[n]->codeLength) == code)
return scripts[n];

asCScriptCode *script = asNEW(asCScriptCode);
if (script == 0)
return 0;

int r = script->SetCode(name, code, length, true);
int r = script->SetCode(name, code, true);
if (r < 0)
{
asDELETE(script, asCScriptCode);
Expand Down
4 changes: 2 additions & 2 deletions sdk/angelscript/source/as_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ class asCBuilder
int ValidateVirtualProperty(asCScriptFunction *func);

#ifndef AS_NO_COMPILER
int AddCode(const char *name, const char *code, int codeLength, int lineOffset, int sectionIdx, bool makeCopy);
asCScriptCode *FindOrAddCode(const char *name, const char *code, size_t length);
int AddCode(const char *name, asStringView code, int lineOffset, int sectionIdx, bool makeCopy);
asCScriptCode *FindOrAddCode(const char *name, asStringView code);
int Build();

int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asCScriptFunction **outFunc);
Expand Down
12 changes: 6 additions & 6 deletions sdk/angelscript/source/as_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2618,7 +2618,7 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray<asCExp

// Parse the default arg string
asCParser parser(builder);
asCScriptCode *code = builder->FindOrAddCode("default arg", func->defaultArgs[n]->AddressOf(), func->defaultArgs[n]->GetLength());
asCScriptCode *code = builder->FindOrAddCode("default arg", asStringView(*func->defaultArgs[n]));
int r = parser.ParseExpression(code);
if( r < 0 )
{
Expand Down Expand Up @@ -2704,7 +2704,7 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray<asCExp
return anyErrors ? -1 : 0;
}

asUINT asCCompiler::MatchFunctions(asCArray<int> &funcs, asCArray<asCExprContext*> &args, asCScriptNode *node, const char *name, asCArray<asSNamedArgument> *namedArgs, asCObjectType *objectType, bool isConstMethod, bool silent, bool allowObjectConstruct, const asCString &scope)
asUINT asCCompiler::MatchFunctions(asCArray<int> &funcs, asCArray<asCExprContext*> &args, asCScriptNode *node, asStringView name, asCArray<asSNamedArgument> *namedArgs, asCObjectType *objectType, bool isConstMethod, bool silent, bool allowObjectConstruct, const asCString &scope)
{
asCArray<int> origFuncs = funcs; // Keep the original list for error message
asUINT cost = 0;
Expand Down Expand Up @@ -8485,7 +8485,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy
args.PushLast(ctx);

// Don't allow making copy of argument here, else the compiler can enter an infinite recursive loop
cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, node, 0, 0, 0, false, true, false);
cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, node, asStringView(), 0, 0, false, true, false);

// Did we find a matching constructor?
if (funcs.GetLength() == 1)
Expand Down Expand Up @@ -8590,7 +8590,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat
asCArray<asCExprContext *> args;
args.PushLast(ctx);

cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, node, 0, 0, 0, false, true, false);
cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, node, asStringView(), 0, 0, false, true, false);

// Did we find a matching constructor?
if( funcs.GetLength() == 1 )
Expand Down Expand Up @@ -9125,7 +9125,7 @@ asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asC
arg.exprNode = ctx->exprNode; // Use the same node for compiler messages
asCArray<asCExprContext*> args;
args.PushLast(&arg);
asUINT cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, 0, 0, 0, objType, false, true, false);
asUINT cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, 0, asStringView(), 0, objType,false, true, false);
if( funcs.GetLength() != 1 )
return asCC_NO_CONV;

Expand Down Expand Up @@ -15551,7 +15551,7 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont
// Returns negative on compile error
// zero on no matching operator
// one on matching operator
int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char *methodName, asCExprContext *lctx, asCExprContext *rctx, bool leftToRight, asCExprContext *ctx, bool specificReturn, const asCDataType &returnType)
int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, asStringView methodName, asCExprContext *lctx, asCExprContext *rctx, bool leftToRight, asCExprContext *ctx, bool specificReturn, const asCDataType &returnType)
{
// Find the matching method
if( lctx->type.dataType.IsObject() &&
Expand Down
4 changes: 2 additions & 2 deletions sdk/angelscript/source/as_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class asCCompiler
void CompileComparisonOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
void CompileBooleanOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, asCExprContext *out, eTokenType opToken = ttUnrecognizedToken);
bool CompileOverloadedDualOperator(asCScriptNode *node, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool isHandle = false, eTokenType opToken = ttUnrecognizedToken);
int CompileOverloadedDualOperator2(asCScriptNode *node, const char *methodName, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool specificReturn = false, const asCDataType &returnType = asCDataType::CreatePrimitive(ttVoid, false));
int CompileOverloadedDualOperator2(asCScriptNode *node, asStringView methodName, asCExprContext *l, asCExprContext *r, bool leftToRight, asCExprContext *out, bool specificReturn = false, const asCDataType &returnType = asCDataType::CreatePrimitive(ttVoid, false));

void CompileInitList(asCExprValue *var, asCScriptNode *node, asCByteCode *bc, int isVarGlobOrMem);
int CompileInitListElement(asSListPatternNode *&patternNode, asCScriptNode *&valueNode, int bufferTypeId, short bufferVar, asUINT &bufferSize, asCByteCode &byteCode, int &elementsInSubList);
Expand Down Expand Up @@ -345,7 +345,7 @@ class asCCompiler
bool IsVariableInitialized(asCExprValue *type, asCScriptNode *node);
void Dereference(asCExprContext *ctx, bool generateCode);
bool CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode = true);
asUINT MatchFunctions(asCArray<int>& funcs, asCArray<asCExprContext*>& args, asCScriptNode* node, const char* name, asCArray<asSNamedArgument>* namedArgs = NULL, asCObjectType* objectType = NULL, bool isConstMethod = false, bool silent = false, bool allowObjectConstruct = true, const asCString& scope = "");
asUINT MatchFunctions(asCArray<int>& funcs, asCArray<asCExprContext*>& args, asCScriptNode* node, asStringView name, asCArray<asSNamedArgument>* namedArgs = NULL, asCObjectType* objectType = NULL, bool isConstMethod = false, bool silent = false, bool allowObjectConstruct = true, const asCString& scope = "");
asUINT MatchArgument(asCArray<int> &funcs, asCArray<asSOverloadCandidate> &matches, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
int MatchArgument(asCScriptFunction *desc, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true);
void PerformFunctionCall(int funcId, asCExprContext *out, bool isConstructor = false, asCArray<asCExprContext*> *args = 0, asCObjectType *objTypeForConstruct = 0, bool useVariable = false, int varOffset = 0, int funcPtrVar = 0);
Expand Down
2 changes: 1 addition & 1 deletion sdk/angelscript/source/as_configgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ int asCConfigGroup::Release()
return refCount;
}

asCTypeInfo *asCConfigGroup::FindType(const char *obj)
asCTypeInfo *asCConfigGroup::FindType(asStringView obj)
{
for( asUINT n = 0; n < types.GetLength(); n++ )
if( types[n]->name == obj )
Expand Down
2 changes: 1 addition & 1 deletion sdk/angelscript/source/as_configgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class asCConfigGroup
int AddRef();
int Release();

asCTypeInfo *FindType(const char *name);
asCTypeInfo *FindType(asStringView name);
void RefConfigGroup(asCConfigGroup *group);

bool HasLiveObjects();
Expand Down
2 changes: 1 addition & 1 deletion sdk/angelscript/source/as_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ int asCModule::AddScriptSection(const char *in_name, const char *in_code, size_t
return asOUT_OF_MEMORY;
}

return m_builder->AddCode(in_name, in_code, (int)in_codeLength, in_lineOffset, (int)m_engine->GetScriptSectionNameIndex(in_name ? in_name : ""), m_engine->ep.copyScriptSections);
return m_builder->AddCode(in_name, asStringView(in_code, in_codeLength), in_lineOffset, (int)m_engine->GetScriptSectionNameIndex(in_name ? in_name : ""), m_engine->ep.copyScriptSections);
#endif
}

Expand Down
3 changes: 1 addition & 2 deletions sdk/angelscript/source/as_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,7 @@ void asCParser::GetToken(sToken *token)
token->length = 0;
}
else
token->type = engine->tok.GetToken(&script->code[sourcePos], sourceLength - sourcePos, &token->length);

token->type = engine->tok.GetToken(asStringView(&script->code[sourcePos], sourceLength - sourcePos), &token->length);
token->pos = sourcePos;

// Update state
Expand Down
25 changes: 8 additions & 17 deletions sdk/angelscript/source/as_scriptcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,36 @@ asCScriptCode::~asCScriptCode()
}
}

int asCScriptCode::SetCode(const char *in_name, const char *in_code, bool in_makeCopy)
int asCScriptCode::SetCode(const char *in_name, asStringView in_code, bool in_makeCopy)
{
return SetCode(in_name, in_code, 0, in_makeCopy);
}

int asCScriptCode::SetCode(const char *in_name, const char *in_code, size_t in_length, bool in_makeCopy)
{
if( !in_code) return asINVALID_ARG;
this->name = in_name ? in_name : "";
if( !sharedCode && code )
asDELETEARRAY(code);

if( in_length == 0 )
in_length = strlen(in_code);
if( in_makeCopy )
{
codeLength = in_length;
codeLength = in_code.len;
sharedCode = false;
code = asNEWARRAY(char, in_length);
code = asNEWARRAY(char, in_code.len);
if( code == 0 )
return asOUT_OF_MEMORY;
memcpy(code, in_code, in_length);
memcpy(code, in_code.string, in_code.len);
}
else
{
codeLength = in_length;
code = const_cast<char*>(in_code);
codeLength = in_code.len;
code = const_cast<char*>(in_code.string);
sharedCode = true;
}

// Find the positions of each line
linePositions.PushLast(0);
for( size_t n = 0; n < in_length; n++ )
for( size_t n = 0; n < in_code.len; n++ )
if( in_code[n] == '\n' ) linePositions.PushLast(n+1);
linePositions.PushLast(in_length);
linePositions.PushLast(in_code.len);

return asSUCCESS;
}

void asCScriptCode::ConvertPosToRowCol(size_t pos, int *row, int *col)
{
if( linePositions.GetLength() == 0 )
Expand Down
3 changes: 1 addition & 2 deletions sdk/angelscript/source/as_scriptcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ class asCScriptCode
asCScriptCode();
~asCScriptCode();

int SetCode(const char *name, const char *code, bool makeCopy);
int SetCode(const char *name, const char *code, size_t length, bool makeCopy);
int SetCode(const char *name, asStringView code, bool makeCopy);

void ConvertPosToRowCol(size_t pos, int *row, int *col);

Expand Down
16 changes: 8 additions & 8 deletions sdk/angelscript/source/as_scriptengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ int asCScriptEngine::ParseNamespace(const char* nameSpace, asCArray<asCString>&

for (; pos < ns.GetLength(); pos += len)
{
t = tok.GetToken(ns.AddressOf() + pos, ns.GetLength() - pos, &len);
t = tok.GetToken(asStringView(ns.AddressOf() + pos, ns.GetLength() - pos), &len);
if ((expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope))
return asINVALID_DECLARATION;

Expand Down Expand Up @@ -1422,7 +1422,7 @@ asETokenClass asCScriptEngine::ParseToken(const char *string, size_t stringLengt

size_t len;
asETokenClass tc;
tok.GetToken(string, stringLength, &len, &tc);
tok.GetToken(asStringView(string, stringLength), &len, &tc);

if( tokenLength )
*tokenLength = (asUINT)len;
Expand Down Expand Up @@ -1696,7 +1696,7 @@ int asCScriptEngine::RegisterInterface(const char *name)

// Make sure the name is not a reserved keyword
size_t tokenLen;
int token = tok.GetToken(name, strlen(name), &tokenLen);
int token = tok.GetToken(name, &tokenLen);
if( token != ttIdentifier || strlen(name) != tokenLen )
return ConfigError(asINVALID_NAME, "RegisterInterface", name, 0);

Expand Down Expand Up @@ -1989,7 +1989,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD
{
// Make sure the name is not a reserved keyword
size_t tokenLen;
int token = tok.GetToken(name, typeName.GetLength(), &tokenLen);
int token = tok.GetToken(asStringView(name, typeName.GetLength()), &tokenLen);
if( token != ttIdentifier || typeName.GetLength() != tokenLen )
return ConfigError(asINVALID_NAME, "RegisterObjectType", name, 0);

Expand Down Expand Up @@ -6184,7 +6184,7 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
asCDataType dataType;

// Create the data type
token = tok.GetToken(decl, strlen(decl), &tokenLen);
token = tok.GetToken(decl, &tokenLen);
switch(token)
{
case ttBool:
Expand All @@ -6211,7 +6211,7 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl)
dataType = asCDataType::CreatePrimitive(token, false);

// Make sure the name is not a reserved keyword
token = tok.GetToken(type, strlen(type), &tokenLen);
token = tok.GetToken(type, &tokenLen);
if( token != ttIdentifier || strlen(type) != tokenLen )
return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl);

Expand Down Expand Up @@ -6269,7 +6269,7 @@ int asCScriptEngine::RegisterEnum(const char* typeName, const char* underlyingTy

// make sure the type is valid
size_t tokenLen;
eTokenType token = tok.GetToken(underlyingType, strlen(underlyingType), &tokenLen);
eTokenType token = tok.GetToken(underlyingType, &tokenLen);

if (!(token >= ttUInt && token <= ttUInt64) && !(token >= ttInt && token <= ttInt64))
return ConfigError(asINVALID_NAME, "RegisterEnum", underlyingType, 0);
Expand All @@ -6295,7 +6295,7 @@ int asCScriptEngine::RegisterEnum(const char* typeName, const char* underlyingTy
}

// Make sure the name is not a reserved keyword
token = tok.GetToken(typeName, strlen(typeName), &tokenLen);
token = tok.GetToken(typeName, &tokenLen);
if( token != ttIdentifier || strlen(typeName) != tokenLen )
return ConfigError(asINVALID_NAME, "RegisterEnum", typeName, 0);

Expand Down
2 changes: 1 addition & 1 deletion sdk/angelscript/source/as_scriptfunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char
asCDataType dt;
asCBuilder builder(engine, 0);
asCScriptCode code;
code.SetCode("", decl, 0, false);
code.SetCode("", decl, false);

// For list factory we get the object type from the return type, for list constructor we get it from the object type directly
dt = builder.CreateDataTypeFromNode(listNodes, &code, engine->defaultNamespace, false, objectType ? objectType : CastToObjectType(returnType.GetTypeInfo()));
Expand Down
37 changes: 14 additions & 23 deletions sdk/angelscript/source/as_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@
#include "as_string.h"
#include "as_string_util.h"

asStringView::asStringView(const asCString &cstr) : string(cstr.AddressOf()), len(cstr.GetLength()) {}
asStringView::asStringView(asCString &cstr) : string(cstr.AddressOf()), len(cstr.GetLength()) {}
bool operator==(asStringView a, asStringView b) {
return asCompareStrings(a.string, a.len, b.string, b.len) == 0;
}
bool operator!=(asStringView a, asStringView b) {
return asCompareStrings(a.string, a.len, b.string, b.len) != 0;
}


asCString::asCString()
{
length = 0;
Expand Down Expand Up @@ -250,18 +260,9 @@ void asCString::Concatenate(const char *str, size_t len)
AddressOf()[length] = 0;
}

asCString &asCString::operator +=(const char *str)
asCString &asCString::operator +=(asStringView str)
{
size_t len = strlen(str);
Concatenate(str, len);

return *this;
}

asCString &asCString::operator +=(const asCString &str)
{
Concatenate(str.AddressOf(), str.length);

Concatenate(str.string,str.len);
return *this;
}

Expand Down Expand Up @@ -341,19 +342,9 @@ asCString asCString::SubString(size_t in_start, size_t in_length) const
return tmp;
}

int asCString::Compare(const char *str) const
{
return asCompareStrings(AddressOf(), length, str, strlen(str));
}

int asCString::Compare(const asCString &str) const
{
return asCompareStrings(AddressOf(), length, str.AddressOf(), str.GetLength());
}

int asCString::Compare(const char *str, size_t len) const
int asCString::Compare(asStringView str) const
{
return asCompareStrings(AddressOf(), length, str, len);
return asCompareStrings(AddressOf(), length, str.string, str.len);
}

size_t asCString::RecalculateLength()
Expand Down
Loading