ScriptContext::ScriptContext() : m_VariableIndex(0) , m_DataIndex(0) { m_Functions.push_back(Function("+",OP_ADD,12,2,scriptAddOperation)); m_Functions.push_back(Function("*",OP_MUL,16,2,scriptMul)); //m_Functions.push_back(Function("/",OP_DIV,16,2)); //m_Functions.push_back(Function("-",OP_SUB,12,2)); //m_Functions.push_back(Function("sin",OP_SIN,17,1)); //m_Functions.push_back(Function("cos",OP_COS,17,1)); m_Functions.push_back(Function("=",OP_ASSIGN,1,1,scriptAssign)); m_Functions.push_back(Function("random",OP_RND,20,2,scriptRandom)); m_Functions.push_back(Function("print",OP_RND,19,1,scriptPrint)); m_Functions.push_back(Function("vector2",OP_NEW_VEC2,20,2,scriptNewVec2)); m_Constants.push_back(ConstantValue("PI",3.14159265359f)); m_Declarations.push_back(TypeDeclaration("int",DT_INT)); m_Declarations.push_back(TypeDeclaration("float",DT_FLOAT)); m_Declarations.push_back(TypeDeclaration("vec2",DT_VEC2)); m_Declarations.push_back(TypeDeclaration("vec3",DT_VEC3)); m_Declarations.push_back(TypeDeclaration("color",DT_COLOR)); }
void AstCompilationUnit::Unparse(Ostream& os, LexStream* lex_stream) { unsigned i; if (debug_unparse) os << "/*AstCompilationUnit:#" << id << "*/"; os << "// " << lex_stream -> FileName() << endl; if (package_declaration_opt) package_declaration_opt -> Unparse(os, lex_stream); for (i = 0; i < NumImportDeclarations(); i++) ImportDeclaration(i) -> Unparse(os, lex_stream); for (i = 0; i < NumTypeDeclarations(); i++) TypeDeclaration(i) -> Unparse(os, lex_stream); if (debug_unparse) os << "/*:AstCompilationUnit#" << id << "*/"; }
TypeDeclaration consumeType(TokenVector::const_iterator &token, TokenVector::const_iterator end, bool allowIdentifier, const TokenKindSet &stopTokens) { IndirectionVector indirections; BaseType baseType = consumeBaseType(token, end, allowIdentifier, stopTokens); if (!baseType.isValid()) { return TypeDeclaration(); } // Keep going until we run out of tokens or hit a stop token while(token != end && (stopTokens.count(token->getKind()) == 0)) { if (token->is(clang::tok::raw_identifier)) { const std::string identifier(identifierString(*token)); if (identifier == "const") { // Is this applying to a * if (!indirections.empty() && (indirections.back() == Indirection::Pointer)) { // Convert to a const * indirections.back() = Indirection::ConstPointer; } else { // Unexpected return TypeDeclaration(); } } else if (allowIdentifier && (++token == end)) { // Trailing identifier break; } else { // Unexpected return TypeDeclaration(); } } else if (token->is(clang::tok::amp)) { indirections.push_back(Indirection::Reference); } else if (token->is(clang::tok::star)) { // Assume non-const, following "const" may modify it indirections.push_back(Indirection::Pointer); } else { // Something we don't know about return TypeDeclaration(); } token++; } return TypeDeclaration(baseType.isConst, baseType.typeName, indirections); }