private bool ParseAndAddGlobalVariableOrFunction(Token variableType) { bool isMemberFunctionBody = false; _source.IgnoreAsteriskIfPresent(); FixedOffsetVariable importedVersion = null; Token variableName = _source.ReadNextToken(); if ((variableName.Type == TokenType.GlobalVariable) && (variableName.Variable.IsImported) && (!variableName.Variable.IsAccessed)) { importedVersion = variableName.Variable; } else { ReadNameOfNewGlobalVariableOrFunction(variableName, out isMemberFunctionBody); } if (_source.NextIsKeyword(PredefinedSymbol.OpenParenthesis)) { ParseAndAddFunctionDefinition(variableType, variableName, isMemberFunctionBody); return(true); } else { CompilerUtils.SetArrayPropertiesOnTokenFromStream(_source, variableName); ParseAndAddGlobalVariableDefinition(variableType, variableName, importedVersion); } return(false); }
private void DeclareLocalVariable(Token variableType) { _source.IgnoreAsteriskIfPresent(); Token variableName = _source.ReadNextTokenAndThrowIfAlreadyDefined(); CompilerUtils.SetArrayPropertiesOnTokenFromStream(_source, variableName); CompilerUtils.VerifyModifiersAgainstType(ModifierTargets.LocalVariable, _state.NextTokenModifiers); /* TODO: get this working * ScriptVariable newVariable = ProcessVariableDeclaration(variableType, _output.GlobalData, null, _state.NextTokenModifiers); * * variableName.Define(TokenType.LocalVariable, newVariable); */ if (_source.NextIsKeyword(PredefinedSymbol.SetEqual)) { Expression setEqualTo = ReadExpression(false, PredefinedSymbol.Semicolon, PredefinedSymbol.Comma); // TODO: check types, assign result to variable } }
private void ParseAndAddMemberToStruct(Token variableType, Token structName, ScriptStruct structDefinition, Token parentStruct) { _source.IgnoreAsteriskIfPresent(); Token memberName = _source.ReadNextToken(); if ((memberName is KeywordToken) || (memberName is OperatorToken) || (memberName is ModifierToken)) { throw new CompilerMessage(ErrorCode.TokenAlreadyDefined, "Cannot use '" + memberName.Name + "' as variable name since it has another meaning"); } string mangledName; memberName = GetTokenForStructMember(structName, memberName, out mangledName); if (memberName != null) { throw new CompilerMessage(ErrorCode.TokenAlreadyDefined, "Member '" + mangledName + "' already exists"); } memberName = new Token(mangledName, true); // TODO: Set necessary fields on new token for this struct member _tokenizedScript.AddToken(memberName); CompilerUtils.SetArrayPropertiesOnTokenFromStream(_source, memberName); if (_source.NextIsKeyword(PredefinedSymbol.OpenParenthesis)) { VerifyModifiersAgainstType(ModifierTargets.MemberFunction); VerifyReturnTypeValidForFunction(variableType); ScriptFunction func = new ScriptFunction(variableType, memberName); ParseFunctionParameterList(func); func.IsPrototypeOnly = true; } else { VerifyModifiersAgainstType(ModifierTargets.MemberVariable); ProcessVariableDeclaration(variableType, structDefinition, parentStruct, _state.NextTokenModifiers); } }