[206] | 1 | #include "stdafx.h"
|
---|
| 2 |
|
---|
[193] | 3 | #include <jenga/include/smoothie/SmoothieException.h>
|
---|
| 4 |
|
---|
[184] | 5 | #include <Compiler.h>
|
---|
[206] | 6 | #include <Type.h>
|
---|
[184] | 7 |
|
---|
[195] | 8 | Compiler compiler;
|
---|
[193] | 9 |
|
---|
[270] | 10 | void Compiler::StaticLink( ObjectModules &staticLibraries )
|
---|
| 11 | {
|
---|
| 12 | BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
|
---|
| 13 | {
|
---|
| 14 | // メタ情報
|
---|
[273] | 15 | pNowObjectModule->StaticLink( *pStaticLibrary );
|
---|
[270] | 16 | }
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[193] | 19 | bool Compiler::StringToType( const string &typeName, Type &type ){
|
---|
| 20 | type.SetIndex( -1 );
|
---|
| 21 |
|
---|
| 22 | if( typeName[0] == '*' ){
|
---|
| 23 | if( typeName.size() >= 3
|
---|
| 24 | && typeName[1] == 1 && ( typeName[2] == ESC_FUNCTION || typeName[2] == ESC_SUB ) ){
|
---|
| 25 | //関数ポインタ(*Function)
|
---|
| 26 | type.SetBasicType( DEF_PTR_PROC );
|
---|
[265] | 27 | type.SetIndex( compiler.GetObjectModule().meta.GetProcPointers().Add( typeName ) );
|
---|
[193] | 28 | return true;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | const string &nextTypeName = typeName.substr( 1 );
|
---|
| 32 |
|
---|
| 33 | if( !StringToType( nextTypeName, type ) ){
|
---|
| 34 | return false;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | type.PtrLevelUp();
|
---|
| 38 |
|
---|
| 39 | return true;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | {
|
---|
| 43 | int basicType;
|
---|
| 44 | if( Type::StringToBasicType( typeName, basicType ) ){
|
---|
| 45 | // 基本型だったとき
|
---|
| 46 | type.SetBasicType( basicType );
|
---|
| 47 | return true;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | // Object型だったとき
|
---|
| 52 | if( typeName == "Object" ){
|
---|
[265] | 53 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
|
---|
[193] | 54 | return true;
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | // String型だったとき
|
---|
| 58 | if( typeName == "String" ){
|
---|
[265] | 59 | type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() );
|
---|
[193] | 60 | return true;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | ////////////////////
|
---|
| 65 | // TypeDefされた型
|
---|
| 66 | ////////////////////
|
---|
[265] | 67 | int i=compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( typeName );
|
---|
[193] | 68 | if(i!=-1){
|
---|
[265] | 69 | type = compiler.GetObjectModule().meta.GetTypeDefs()[i].GetBaseType();
|
---|
[193] | 70 | return true;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | //クラス
|
---|
[265] | 74 | const CClass *pobj_c = compiler.GetObjectModule().meta.GetClasses().Find( typeName );
|
---|
[193] | 75 | if(pobj_c){
|
---|
| 76 | type.SetClassPtr( pobj_c );
|
---|
| 77 |
|
---|
| 78 | if( pobj_c->IsStructure() ){
|
---|
| 79 | type.SetBasicType( DEF_STRUCT );
|
---|
| 80 | }
|
---|
| 81 | else{
|
---|
| 82 | type.SetBasicType( DEF_OBJECT );
|
---|
| 83 | }
|
---|
| 84 | return true;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | return false;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | const string Compiler::TypeToString( const Type &type )
|
---|
| 91 | {
|
---|
| 92 | if( PTR_LEVEL( type.GetBasicType() ) ){
|
---|
| 93 | //ポインタレベルが1以上の場合
|
---|
| 94 | Type tempType( type );
|
---|
| 95 | tempType.PtrLevelDown();
|
---|
| 96 |
|
---|
[196] | 97 | return (string)"*" + TypeToString( tempType );
|
---|
[193] | 98 | }
|
---|
| 99 | else if( type.IsObject() || type.IsStruct() ){
|
---|
| 100 | //オブジェクトまたは構造体
|
---|
| 101 |
|
---|
| 102 | if( !( type.GetIndex() == 0 || type.GetIndex() == -1 ) ){
|
---|
| 103 | if( type.GetClass().GetNamespaceScopes().size() >= 1 )
|
---|
| 104 | {
|
---|
| 105 | return type.GetClass().GetNamespaceScopes().ToString() + "." + type.GetClass().GetName();
|
---|
| 106 | }
|
---|
| 107 | return type.GetClass().GetName();
|
---|
| 108 | }
|
---|
| 109 | }
|
---|
| 110 | else if( type.IsProcPtr() ){
|
---|
| 111 | if( type.GetIndex() == 0 || type.GetIndex() == -1 ){
|
---|
| 112 | return "VoidPtr";
|
---|
| 113 | }
|
---|
| 114 | else{
|
---|
[265] | 115 | if( compiler.GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){
|
---|
[193] | 116 | return "*Sub";
|
---|
| 117 | }
|
---|
| 118 | return "*Function";
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | else{
|
---|
| 122 | // 基本型
|
---|
| 123 | const char *lpszTypeName = Type::BasicTypeToCharPtr( type );
|
---|
| 124 | if( lpszTypeName )
|
---|
| 125 | {
|
---|
| 126 | return (const string)lpszTypeName;
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | SmoothieException::Throw( 1 );
|
---|
| 131 |
|
---|
| 132 | return (string)"(null)";
|
---|
| 133 | }
|
---|