Commits

Jason McKesson committed 0ae57f6

glscene: parser now stores the original identifier name string and the truncated version.

  • Participants
  • Parent commits 258bbff

Comments (0)

Files changed (5)

File glscene/Test/test.glscene

 				texture 0 <tex> <spl>
 				uniform_buffer 0 <ubuff>
 				uniform_buffer 1 <ubuff> 32
-				storage_buffer 0 <ubuff>
+				storage_buffer 0 <sbuff>
 			end
 		end
 		

File glscene/glscene_format.doxy

 
 The `pipeline` subcommand `program` works almost identically to the higher-level `program` command, except that the `program_resource` is followed by a sequence of `[stage]` enumerators. These enumerators define which stages the given program affects; they are a list and at least one stage must be specified. Multiple `program` subcommands can be listed, but the same stage cannot be specified multiple times. Also, the same `program` subcommand cannot use the same stage twice.
 
+The possible `[stage]` values are:
+
+- `vert`
+- `tess_control`
+- `tess_eval`
+- `geom`
+- `frag`
+
 The `program` command (whether within `pipeline` or not) has only one sub-command. It can appear 0 or more times:
 
 - `uniform <uniform_resource>`: Defines a global uniform resource to be used by the program object.

File glscene/source/Parse.cpp

 				while(IsCurrToken(TOK_IDENTIFIER))
 				{
 					std::string styleName = GetStringTokenData();
-					IdString styleId = styleName;
+					ParsedIdentifier styleId(styleName);
 					if(m_scene.styleChecks.find(styleId) != m_scene.styleChecks.end())
 						ThrowParseError("The check style '" + styleName + "' has already been defined.", curr_throw);
 					m_scene.styleChecks.insert(styleId);
 
 			if(IsCurrToken(TOK_IDENTIFIER))
 			{
-				IdString nodeId = ParseIdentifier(m_scene.nodeNamePositions, false, TOK_NODE);
+				ParsedIdentifier nodeId = ParseIdentifier(m_scene.nodeNamePositions, false, TOK_NODE);
 				m_scene.nodeNamePositions[nodeId] = m_posStack.top();
 				node.name = nodeId;
 			}
 			PosStackPusher push(*this);
 			EatOneToken();
 
-			IdString id = ParseIdentifier(node.localPositions, false, TOK_LOCAL);
+			ParsedIdentifier id = ParseIdentifier(node.localPositions, false, TOK_LOCAL);
 			m_scene.allLocals.emplace_back(id);
 			ParsedLocalDef &local = m_scene.allLocals[m_scene.allLocals.size() - 1];
 			local.pos = m_posStack.top();
 			EatOneToken();
 
 			ExpectToken(TOK_IDENTIFIER);
-			IdString id(GetStringTokenData());
+			ParsedIdentifier id(GetStringTokenData());
 			if(node.styles.find(id) != node.styles.end())
-				MultipleIdentifierOfSameType(GetStringTokenData(), TOK_STYLE, GetPosFromDef(*node.styles.find(id)));
+				MultipleIdentifierOfSameType(id, TOK_STYLE, GetPosFromDef(*node.styles.find(id)));
 			if(!m_scene.styleChecks.empty())
 			{
 				if(m_scene.styleChecks.find(id) == m_scene.styleChecks.end())
 				EatOneToken();
 				while(IsCurrToken(TOK_IDENTIFIER))
 				{
-					IdString usingId((GetStringTokenData()));
+					ParsedIdentifier usingId((GetStringTokenData()));
 					const ParsedLocalDef *pLocal = dest.scope.IncludeLocal(usingId);
 					if(!pLocal)
 					{
-						std::string msg = "The identifier name '" + std::string(usingId) +
+						std::string msg = "The identifier name '" + usingId.str() +
 							"' refers to a local definition that is not in scope at this point.";
 						ThrowParseError(msg, curr_throw);
 					}
 					{
 						EatOneToken();
 						unsigned int texUnit = ParseSingleUInt();
-						IdString textureId = ParseIdentifier(m_resources.textures, true, tok.id());
-						IdString samplerId = ParseIdentifier(m_resources.samplers, true, TOK_SAMPLER_RES);
+						ParsedIdentifier textureId = ParseIdentifier(m_resources.textures, true, tok.id());
+						ParsedIdentifier samplerId = ParseIdentifier(m_resources.samplers, true, TOK_SAMPLER_RES);
 						data.textures.push_back(ParsedTextureRefDef(textureId, samplerId));
 						data.textures.back().pos = pos;
 						data.textures.back().texUnit = texUnit;
 					{
 						EatOneToken();
 						unsigned int binding = ParseSingleUInt();
-						IdString bufferId = ParseIdentifier(m_resources.uniformBuffers, true, tok.id());
+						ParsedIdentifier bufferId = ParseIdentifier(m_resources.uniformBuffers, true, tok.id());
 						data.uniformBuffers.push_back(ParsedBufferRefDef(bufferId));
 						ParsedBufferRefDef &bufferDef = data.uniformBuffers.back();
 						bufferDef.pos = pos;
 					{
 						EatOneToken();
 						unsigned int binding = ParseSingleUInt();
-						IdString bufferId = ParseIdentifier(m_resources.storageBuffers, true, tok.id());
+						ParsedIdentifier bufferId = ParseIdentifier(m_resources.storageBuffers, true, tok.id());
 						data.storageBuffers.push_back(ParsedBufferRefDef(bufferId));
 						ParsedBufferRefDef &bufferDef = data.storageBuffers.back();
 						bufferDef.pos = pos;
 		}
 
 		template<typename MapType>
-		IdString ParseIdentifier(const MapType &search, bool mustFind, size_t currentCmd)
+		ParsedIdentifier ParseIdentifier(const MapType &search, bool mustFind, size_t currentCmd)
 		{
 			ExpectToken(TOK_IDENTIFIER);
 			std::string idToken = GetTokenText();
-			IdString ident(string_ref(&idToken[0] + 1, idToken.size() - 2));
+			ParsedIdentifier ident(string_ref(&idToken[0] + 1, idToken.size() - 2));
 
 			if(mustFind)
 			{
 				if(search.find(ident) == search.end())
-					FailedToFindIdentifier(idToken, currentCmd);
+					FailedToFindIdentifier(ident, currentCmd);
 			}
 			else
 			{
 				MapType::const_iterator foundIt = search.find(ident);
 				if(foundIt != search.end())
-					MultipleIdentifierOfSameType(idToken, currentCmd, GetPosFromDef(*foundIt));
+					MultipleIdentifierOfSameType(ident, currentCmd, GetPosFromDef(*foundIt));
 			}
 
 			EatOneToken();
 			return ident;
 		}
 
-		void FailedToFindIdentifier(const std::string &idToken, size_t currentCmd)
+		void FailedToFindIdentifier(const ParsedIdentifier &ident, size_t currentCmd)
 		{
-			std::string msg = "The identifier name '" + idToken + "' refers to a " +
+			std::string msg = "The identifier name '" + ident.str() + "' refers to a " +
 				GetTokenErrorName(currentCmd) + " that has not been defined.";
 			ThrowParseError(msg, curr_throw);
 		}
 
-		void MultipleIdentifierOfSameType(const std::string &idToken, size_t currentCmd,
+		void MultipleIdentifierOfSameType(const ParsedIdentifier &ident, size_t currentCmd,
 			const FilePosition &earlyDefPos)
 		{
 			std::stringstream str;
-			str << "The identifier name '" << idToken << "' has already been used in a ";
+			str << "The identifier name '" << ident.str() << "' has already been used in a ";
 			str << GetTokenErrorName(currentCmd) << " definition before. It may not be defined again." << std::endl;
 			str << "\tIt was first defined in file '" << earlyDefPos.fileName << "' line ";
 			str << earlyDefPos.lineNumber << " column " << earlyDefPos.columnNumber << std::endl;
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_SAMPLER_RES);
-			IdString ident = ParseIdentifier(m_resources.samplers, false, TOK_SAMPLER_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.samplers, false, TOK_SAMPLER_RES);
 			ParsedSamplerDef &samplerData = m_resources.samplers[ident];
 			samplerData.pos = m_posStack.top();
 
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_CAMERA_RES);
-			IdString ident = ParseIdentifier(m_resources.cameras, false, TOK_CAMERA_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.cameras, false, TOK_CAMERA_RES);
 			ParsedCameraDef &cameraData = m_resources.cameras[ident];
 			cameraData.pos = m_posStack.top();
 			
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_UNIFORM_BUFFER_RES);
-			IdString ident = ParseIdentifier(m_resources.uniformBuffers, false, TOK_UNIFORM_BUFFER_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.uniformBuffers, false, TOK_UNIFORM_BUFFER_RES);
 			ParsedBufferDef &bufferDef = m_resources.uniformBuffers[ident];
 			bufferDef.pos = m_posStack.top();
 
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_STORAGE_BUFFER_RES);
-			IdString ident = ParseIdentifier(m_resources.storageBuffers, false, TOK_STORAGE_BUFFER_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.storageBuffers, false, TOK_STORAGE_BUFFER_RES);
 			ParsedBufferDef &bufferDef = m_resources.storageBuffers[ident];
 			bufferDef.pos = m_posStack.top();
 
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_MESH_RES);
-			IdString ident = ParseIdentifier(m_resources.meshes, false, TOK_MESH_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.meshes, false, TOK_MESH_RES);
 			ParsedMeshDef &meshDef = m_resources.meshes[ident];
 			meshDef.pos = m_posStack.top();
 
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_TEXTURE_RES);
-			IdString ident = ParseIdentifier(m_resources.textures, false, TOK_TEXTURE_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.textures, false, TOK_TEXTURE_RES);
 			ParsedTextureDef &textureDef = m_resources.textures[ident];
 			textureDef.pos = m_posStack.top();
 
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_PROGRAM_RES);
-			IdString ident = ParseIdentifier(m_resources.programs, false, TOK_PROGRAM_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.programs, false, TOK_PROGRAM_RES);
 			ParsedProgramDef &programDef = m_resources.programs[ident];
 			programDef.pos = m_posStack.top();
 			programDef.isSeparate = false;
 			PosStackPusher push(*this);
 
 			ExpectAndEatToken(TOK_UNIFORM_RES);
-			IdString ident = ParseIdentifier(m_resources.uniforms, false, TOK_UNIFORM_RES);
+			ParsedIdentifier ident = ParseIdentifier(m_resources.uniforms, false, TOK_UNIFORM_RES);
 			ParsedUniformDef &uniformDef = m_resources.uniforms[ident];
 			uniformDef.pos = m_posStack.top();
 

File glscene/source/ParsedData.h

 #include <glm/gtc/matrix_transform.hpp>
 
 namespace glscene { namespace _detail {
+
+	class ParsedIdentifier
+	{
+	public:
+		explicit ParsedIdentifier(boost::string_ref idName)
+			: m_id(idName)
+			, m_fullName(idName.data(), idName.size())
+		{}
+
+		operator IdString() const {return m_id;}
+		boost::string_ref ref() const {return m_fullName;}
+		const std::string &str() const {return m_fullName;}
+
+		bool operator<(const ParsedIdentifier &rhs) const {return m_id < rhs.m_id;}
+
+		bool operator==(const ParsedIdentifier &rhs) const {return m_id == rhs.m_id;}
+		bool operator!=(const ParsedIdentifier &rhs) const {return m_id != rhs.m_id;}
+
+	private:
+		IdString m_id;
+		std::string m_fullName;
+	};
+
 	struct ParsedUniformDef
 	{
 		FilePosition pos;
 	template<typename Key, typename Def>
 	FilePosition GetPosFromDef(const std::pair<Key, Def> &pairDef) {return GetFilePosition(pairDef.second);}
 
-	typedef boost::container::flat_map<IdString, ParsedUniformDef> ParsedUniformMap;
-	typedef boost::container::flat_map<IdString, ParsedSamplerDef> ParsedSamplerMap;
-	typedef boost::container::flat_map<IdString, ParsedCameraDef> ParsedCameraMap;
-	typedef boost::container::flat_map<IdString, ParsedBufferDef> ParsedBufferMap;
-	typedef boost::container::flat_map<IdString, ParsedProgramDef> ParsedProgramMap;
-	typedef boost::container::flat_map<IdString, ParsedMeshDef> ParsedMeshMap;
-	typedef boost::container::flat_map<IdString, ParsedTextureDef> ParsedTextureMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedUniformDef> ParsedUniformMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedSamplerDef> ParsedSamplerMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedCameraDef> ParsedCameraMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedBufferDef> ParsedBufferMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedProgramDef> ParsedProgramMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedMeshDef> ParsedMeshMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedTextureDef> ParsedTextureMap;
 
 	struct ParsedResources
 	{
 	struct ParsedMeshRefDef
 	{
 		FilePosition pos;
-		IdString meshId;
+		ParsedIdentifier meshId;
 		boost::optional<std::string> variant;
 
-		ParsedMeshRefDef(const IdString &_id) : meshId(_id) {}
+		ParsedMeshRefDef(const ParsedIdentifier &_id) : meshId(_id) {}
 	};
 
 	struct ParsedTextureRefDef
 	{
 		FilePosition pos;
 		unsigned int texUnit;
-		IdString textureId;
-		IdString samplerId;
+		ParsedIdentifier textureId;
+		ParsedIdentifier samplerId;
 
-		ParsedTextureRefDef(const IdString &_textureId, const IdString &_samplerId)
+		ParsedTextureRefDef(const ParsedIdentifier &_textureId, const ParsedIdentifier &_samplerId)
 			: textureId(_textureId)
 			, samplerId(_samplerId)
 		{}
 	{
 		FilePosition pos;
 		unsigned int buffBinding;
-		IdString bufferId;
+		ParsedIdentifier bufferId;
 		unsigned int offset;
 
-		ParsedBufferRefDef(const IdString &_bufferId) : bufferId(_bufferId), offset(0) {}
+		ParsedBufferRefDef(const ParsedIdentifier &_bufferId) : bufferId(_bufferId), offset(0) {}
+	};
+
+	struct ParsedSingleProgramDef
+	{
+		FilePosition pos;
+		ParsedIdentifier programId;
+		std::vector<ParsedIdentifier> uniformReferences;
 	};
 
 	struct ParsedStyleData
 	struct ParsedLocalDef
 	{
 		FilePosition pos;
-		IdString name;
+		ParsedIdentifier name;
 		ParsedStyleData data;
 
-		ParsedLocalDef(const IdString &_name) : name(_name) {}
+		ParsedLocalDef(const ParsedIdentifier &_name) : name(_name) {}
 	};
 
 	struct ParsedStyleDef
 		ParsedStyleData data;
 	};
 
-	typedef boost::container::flat_map<IdString, ParsedStyleDef> ParsedStyleMap;
+	typedef boost::container::flat_map<ParsedIdentifier, ParsedStyleDef> ParsedStyleMap;
 
 	class LocalsInScope
 	{
 			m_scope[local.name] = &local;
 		}
 
-		const ParsedLocalDef *IncludeLocal(const IdString &name) const
+		const ParsedLocalDef *IncludeLocal(const ParsedIdentifier &name) const
 		{
 			LocalScope::const_iterator theIt = m_scope.find(name);
 			if(theIt == m_scope.end())
 		}
 
 	private:
-		typedef boost::container::flat_map<IdString, const ParsedLocalDef *> LocalScope;
+		typedef boost::container::flat_map<ParsedIdentifier, const ParsedLocalDef *> LocalScope;
 		LocalScope m_scope;
 	};
 
 	struct ParsedNodeDef
 	{
 		FilePosition pos;
-		boost::optional<IdString> name;
+		boost::optional<ParsedIdentifier> name;
 		LayerSet layers;
 		std::vector<ParsedNodeDef*> childNodes;
 		ParsedNodeDef *pParent;
 		ParsedTransformDef nodeTM;
 		ParsedTransformDef objectTM;
 		ParsedStyleMap styles;
-		boost::container::flat_map<IdString, FilePosition> localPositions;
+		boost::container::flat_map<ParsedIdentifier, FilePosition> localPositions;
 
 		ParsedNodeDef& operator=(const ParsedNodeDef &other)
 		{
 		FilePosition pos;
 		LayerSet layers;
 		std::vector<std::string> layerOrder;
-		boost::container::flat_set<IdString> styleChecks;
-		boost::container::flat_map<IdString, FilePosition> nodeNamePositions;
+		boost::container::flat_set<ParsedIdentifier> styleChecks;
+		boost::container::flat_map<ParsedIdentifier, FilePosition> nodeNamePositions;
 		boost::container::stable_vector<ParsedNodeDef> nodes;
 		boost::container::stable_vector<ParsedLocalDef> allLocals;
 	};

File glscene/source/ParserEnums.h

 		refs::array_ref<string_ref>(g_meshCreateEnumNames),
 	};
 
+	string_ref g_programStageEnumNames[] =
+	{
+		"vert",
+		"tess_control",
+		"tess_eval",
+		"geom",
+		"frag",
+	};
 
+	GLenum g_programStageEnumerators[] =
+	{
+		gl::VERTEX_SHADER_BIT,
+		gl::TESS_CONTROL_SHADER_BIT,
+		gl::TESS_EVALUATION_SHADER_BIT,
+		gl::GEOMETRY_SHADER_BIT,
+		gl::FRAGMENT_SHADER_BIT,
+	};
+
+	const EnumData<GLenum> g_programStageEnumeration =
+	{
+		"program stage",
+		refs::array_ref<string_ref>(g_programStageEnumNames),
+		refs::array_ref<GLenum>(g_programStageEnumerators),
+	};
 }
 
 #endif //GLSDK_GLSCENE_PARSER_ENUMS_H