source: dev/trunk/abdev/BasicCompiler_Common/src/Compiler.cpp@ 283

Last change on this file since 283 was 273, checked in by dai_9181, 17 years ago
File size: 3.1 KB
Line 
1#include "stdafx.h"
2
3#include <jenga/include/smoothie/SmoothieException.h>
4
5#include <Compiler.h>
6#include <Type.h>
7
8Compiler compiler;
9
10void Compiler::StaticLink( ObjectModules &staticLibraries )
11{
12 BOOST_FOREACH( ObjectModule *pStaticLibrary, staticLibraries )
13 {
14 // メタ情報
15 pNowObjectModule->StaticLink( *pStaticLibrary );
16 }
17}
18
19bool 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 );
27 type.SetIndex( compiler.GetObjectModule().meta.GetProcPointers().Add( typeName ) );
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" ){
53 type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetObjectClassPtr() );
54 return true;
55 }
56
57 // String型だったとき
58 if( typeName == "String" ){
59 type.SetType( DEF_OBJECT, compiler.GetObjectModule().meta.GetClasses().GetStringClassPtr() );
60 return true;
61 }
62
63
64 ////////////////////
65 // TypeDefされた型
66 ////////////////////
67 int i=compiler.GetObjectModule().meta.GetTypeDefs().GetIndex( typeName );
68 if(i!=-1){
69 type = compiler.GetObjectModule().meta.GetTypeDefs()[i].GetBaseType();
70 return true;
71 }
72
73 //クラス
74 const CClass *pobj_c = compiler.GetObjectModule().meta.GetClasses().Find( typeName );
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
90const string Compiler::TypeToString( const Type &type )
91{
92 if( PTR_LEVEL( type.GetBasicType() ) ){
93 //ポインタレベルが1以上の場合
94 Type tempType( type );
95 tempType.PtrLevelDown();
96
97 return (string)"*" + TypeToString( tempType );
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{
115 if( compiler.GetObjectModule().meta.GetProcPointers()[type.GetIndex()]->ReturnType().IsNull() ){
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}
Note: See TracBrowser for help on using the repository browser.