interface TODO: typedef: Accept complex types for the typedefs
| 6167 | // interface |
| 6168 | // TODO: typedef: Accept complex types for the typedefs |
| 6169 | int asCScriptEngine::RegisterTypedef(const char *type, const char *decl) |
| 6170 | { |
| 6171 | if( type == 0 ) return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl); |
| 6172 | |
| 6173 | // Verify if the name has been registered as a type already |
| 6174 | // TODO: Must check against registered funcdefs too |
| 6175 | if( GetRegisteredType(type, defaultNamespace) ) |
| 6176 | // Let the application recover from this error, for example if the same typedef is registered twice |
| 6177 | return asALREADY_REGISTERED; |
| 6178 | |
| 6179 | // Grab the data type |
| 6180 | size_t tokenLen; |
| 6181 | eTokenType token; |
| 6182 | asCDataType dataType; |
| 6183 | |
| 6184 | // Create the data type |
| 6185 | token = tok.GetToken(decl, strlen(decl), &tokenLen); |
| 6186 | switch(token) |
| 6187 | { |
| 6188 | case ttBool: |
| 6189 | case ttInt: |
| 6190 | case ttInt8: |
| 6191 | case ttInt16: |
| 6192 | case ttInt64: |
| 6193 | case ttUInt: |
| 6194 | case ttUInt8: |
| 6195 | case ttUInt16: |
| 6196 | case ttUInt64: |
| 6197 | case ttFloat: |
| 6198 | case ttDouble: |
| 6199 | if( strlen(decl) != tokenLen ) |
| 6200 | { |
| 6201 | return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); |
| 6202 | } |
| 6203 | break; |
| 6204 | |
| 6205 | default: |
| 6206 | return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); |
| 6207 | } |
| 6208 | |
| 6209 | dataType = asCDataType::CreatePrimitive(token, false); |
| 6210 | |
| 6211 | // Make sure the name is not a reserved keyword |
| 6212 | token = tok.GetToken(type, strlen(type), &tokenLen); |
| 6213 | if( token != ttIdentifier || strlen(type) != tokenLen ) |
| 6214 | return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl); |
| 6215 | |
| 6216 | asCBuilder bld(this, 0); |
| 6217 | int r = bld.CheckNameConflict(type, 0, 0, defaultNamespace, true, false, false); |
| 6218 | if( r < 0 ) |
| 6219 | return ConfigError(asNAME_TAKEN, "RegisterTypedef", type, decl); |
| 6220 | |
| 6221 | // Don't have to check against members of object |
| 6222 | // types as they are allowed to use the names |
| 6223 | |
| 6224 | // Put the data type in the list |
| 6225 | asCTypedefType *td = asNEW(asCTypedefType)(this); |
| 6226 | if( td == 0 ) |
nothing calls this directly
no test coverage detected