/// <summary> /// Adds a type to the type list /// </summary> public static Int32 AddType(TypeInfo type) { Types.Add(type); return Types.Count - 1; }
/// <summary> /// Parse a type /// Syntax: /// struct type_name /// { /// datatype identifier; /// ... /// } /// </summary> public void ParseTypeDeclaration() { //Ignore the word TYPE NextToken(); if (CurrentToken.Type != TokenType.Identifier || !Database.CheckValidName(CurrentToken.Value)) Error("Invalid Type Name", CurrentToken.LineStart); //Set type info TypeInfo type = new TypeInfo(); type.Name = CurrentToken.Value; //Keep a record of all the members to ensure none are repeated List<String> memberNames = new List<String>(); NextToken(); if (CurrentToken.Value != "{") Error("Expected member list { ... }", CurrentToken.LineStart); //NEW and DELETE of the type are functions, if they are incoming, skip and parse later while (CheckFunctionIncoming()) { SkipBlock(); NextToken(); } NextToken(); //Get member declarations do { VariableInfo var = new VariableInfo(); ParseDeclaration(ref var); //Check if valid member if (memberNames.Contains(var.Name)) Error("Type " + type.Name + " already contains a member named " + var.Name, CurrentToken.LineStart); memberNames.Add(var.Name); //If the next token isn't a semicolon we have an error if (CurrentToken.Value != ";") { Error("Expected semicolon", CurrentToken.LineStart); } NextToken(); //Skip any function while (CheckFunctionIncoming()) { SkipBlock(); NextToken(); } //Add new member to the members list type.Members.Add(var); } while (CurrentToken.Value != "}"); //Add the new type to the database Database.AddType(type); NextToken(); }
/// <summary> /// Changes a type in the type list /// </summary> public static void ChangeType(Int32 typeIndex, TypeInfo type) { Types[typeIndex] = type; }