MCPcopy Create free account
hub / github.com/anjo76/angelscript / ExtractDeclaration

Method ExtractDeclaration

sdk/add_on/scriptbuilder/scriptbuilder.cpp:956–1079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

954}
955
956int CScriptBuilder::ExtractDeclaration(int pos, string &name, string &declaration, int &type)
957{
958 declaration = "";
959 type = 0;
960
961 int start = pos;
962
963 std::string token;
964 asUINT len = 0;
965 asETokenClass t = asTC_WHITESPACE;
966
967 // Skip white spaces, comments, and leading decorators
968 do
969 {
970 pos += len;
971 t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
972 token.assign(&modifiedScript[pos], len);
973 } while ( t == asTC_WHITESPACE || t == asTC_COMMENT ||
974 token == "private" || token == "protected" ||
975 token == "shared" || token == "external" ||
976 token == "final" || token == "abstract" );
977
978 // We're expecting, either a class, interface, function, or variable declaration
979 if( t == asTC_KEYWORD || t == asTC_IDENTIFIER )
980 {
981 token.assign(&modifiedScript[pos], len);
982 if( token == "interface" || token == "class" || token == "enum" )
983 {
984 // Skip white spaces and comments
985 do
986 {
987 pos += len;
988 t = engine->ParseToken(&modifiedScript[pos], modifiedScript.size() - pos, &len);
989 } while ( t == asTC_WHITESPACE || t == asTC_COMMENT );
990
991 if( t == asTC_IDENTIFIER )
992 {
993 type = MDT_TYPE;
994 declaration.assign(&modifiedScript[pos], len);
995 pos += len;
996 return pos;
997 }
998 }
999 else
1000 {
1001 // For function declarations, store everything up to the start of the
1002 // statement block, except for succeeding decorators (final, override, etc)
1003
1004 // For variable declaration store just the name as there can only be one
1005
1006 // We'll only know if the declaration is a variable or function declaration
1007 // when we see the statement block, or absense of a statement block.
1008 bool hasParenthesis = false;
1009 int nestedParenthesis = 0;
1010 declaration.append(&modifiedScript[pos], len);
1011 pos += len;
1012 for(; pos < (int)modifiedScript.size();)
1013 {

Callers

nothing calls this directly

Calls 2

ParseTokenMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected