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

Last change on this file since 209 was 206, checked in by dai_9181, 17 years ago

コード全体のリファクタリングを実施

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